:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --bg: #f4f5f9;
  --card-bg: #ffffff;
  --text: #1f2330;
  --muted: #6b7280;
  --border: #e5e7eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.navbar {
  background: var(--primary-dark);
  color: #fff;
  padding: 0.85rem 1.25rem;
}

.navbar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.navbar .brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
}

.nav-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.6rem;
}

.navbar a {
  color: #eef0ff;
  text-decoration: none;
  margin-right: 1.1rem;
  font-size: 0.94rem;
  padding: 0.35rem 0;
}

.navbar a:hover { color: #fff; text-decoration: underline; }

.navbar .nav-right {
  display: flex;
  align-items: center;
  margin-left: auto;
}

.navbar .nav-right a { margin-left: 1rem; margin-right: 0; }

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  background: transparent;
  border: none;
  padding: 0.4rem;
  cursor: pointer;
}

.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
}

.badge-role {
  background: rgba(255,255,255,0.15);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  font-size: 0.78rem;
  margin-left: 0.5rem;
}

/* ---------------------------------------------------------------------
   Mobile navbar: collapse links behind a hamburger toggle
--------------------------------------------------------------------- */
@media (max-width: 768px) {
  .nav-toggle { display: flex; }

  .nav-links {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .nav-links.open { display: flex; }

  .navbar a {
    margin-right: 0;
    padding: 0.65rem 0.2rem;
    border-bottom: 1px solid rgba(255,255,255,0.12);
  }

  .navbar .nav-right {
    margin-left: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
    margin-top: 0.4rem;
  }

  .navbar .nav-right a { margin-left: 0; }
}

.container {
  max-width: 1080px;
  margin: 1.75rem auto;
  padding: 0 1.25rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

h1, h2, h3 { margin-top: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
}

.stat-card .num { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-card .label { color: var(--muted); font-size: 0.9rem; margin-top: 0.25rem; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.02em; }

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.55rem 1.05rem;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.92rem;
  cursor: pointer;
}

.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #6b7280; }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.82rem; }
.btn.danger { background: var(--danger); }

.tag {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.tag.ATTENDANCE { background: #e0e7ff; color: #3730a3; }
.tag.DINING, .tag.BREAKFAST, .tag.LUNCH, .tag.DINNER { background: #fef3c7; color: #92400e; }
.tag.TEA_BREAK { background: #dcfce7; color: #166534; }
.tag.CUSTOM { background: #f3e8ff; color: #6b21a8; }
.tag.inactive { background: #fee2e2; color: #991b1b; }

form input, form select, form textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.94rem;
}

label { font-weight: 600; font-size: 0.88rem; display: block; margin-bottom: 0.3rem; }

.messages { list-style: none; padding: 0; margin: 0 0 1rem 0; }
.messages li {
  padding: 0.7rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}
.messages .success { background: #dcfce7; color: #166534; }
.messages .warning { background: #fef3c7; color: #92400e; }
.messages .error { background: #fee2e2; color: #991b1b; }

.login-wrap {
  max-width: 380px;
  margin: 4rem auto;
}

#qr-reader {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

#scan-result {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 10px;
  font-weight: 600;
  text-align: center;
  display: none;
}
#scan-result.success { background: #dcfce7; color: #166534; display: block; }
#scan-result.duplicate { background: #fef3c7; color: #92400e; display: block; }
#scan-result.error { background: #fee2e2; color: #991b1b; display: block; }

/* ---------------------------------------------------------------------
   ID Card (140mm x 100mm)
--------------------------------------------------------------------- */
.id-card {
  position: relative;
  width: 140mm;
  height: 100mm;
  overflow: hidden;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
  margin: 0 auto;
}

.id-card-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  z-index: 0;
}

.id-card-inner {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.id-card-header, .id-card-footer {
  width: 100%;
  flex: 0 0 auto;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.id-card-header img, .id-card-footer img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.id-card-body {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 6mm;
  padding: 4mm 6mm;
  min-height: 0;
}

.id-card-qr {
  flex: 0 0 auto;
  width: 32mm;
  height: 32mm;
  display: flex;
  align-items: center;
  justify-content: center;
}

.id-card-qr img { width: 100%; height: 100%; object-fit: contain; }

.id-card-qr-placeholder {
  background: #eef0f5;
  color: #9aa0ad;
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 4px;
}

.id-card-details {
  flex: 1 1 auto;
  min-width: 0;
}

.id-card-name {
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 1mm;
  word-break: break-word;
}

.id-card-line {
  font-size: 0.85rem;
  margin-bottom: 0.8mm;
  word-break: break-word;
}

.id-card-line.small { font-size: 0.75rem; opacity: 0.85; }

.id-card-tag {
  display: inline-block;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  margin: 1mm 0;
}

.id-card-code {
  margin-top: 1.5mm;
  font-family: "Courier New", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  opacity: 0.8;
}

.card-designer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .card-designer-grid { grid-template-columns: 1fr; }
}

.color-row {
  display: flex;
  gap: 1rem;
}
.color-row > div { flex: 1; }
.color-row input[type="color"] {
  padding: 0.2rem;
  height: 2.6rem;
  cursor: pointer;
}

.preview-sticky {
  position: sticky;
  top: 1.5rem;
  display: flex;
  justify-content: center;
  padding: 1rem;
  background: #eef0f5;
  border-radius: 12px;
  overflow-x: auto;
}

@media print {
  body * { visibility: hidden; }
  .id-card, .id-card * { visibility: visible; }
  .id-card {
    position: fixed;
    top: 0;
    left: 0;
    box-shadow: none;
    border: none;
  }

  /* Browsers strip background colors/images from print output by default
     to save ink. Force them to print so the card design (background color,
     background watermark, accent-colored tags) actually shows up. */
  html, body, .id-card, .id-card * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
}

/* ---------------------------------------------------------------------
   Responsive tables: scroll horizontally instead of breaking layout
--------------------------------------------------------------------- */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-responsive table { min-width: 560px; }

/* ---------------------------------------------------------------------
   Card that holds the ID card preview: lets a physically-sized card
   (measured in mm) shrink to fit on a phone screen without cutting off.
--------------------------------------------------------------------- */
.card-scale-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  justify-content: center;
  padding-bottom: 0.5rem;
}

/* ---------------------------------------------------------------------
   General mobile tweaks (phones and small tablets)
--------------------------------------------------------------------- */
@media (max-width: 640px) {
  .container { padding: 0 0.85rem; margin: 1.1rem auto; }

  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.15rem; }
  h3 { font-size: 1rem; }

  .card { padding: 1.1rem; border-radius: 10px; }

  .grid { gap: 0.75rem; }

  .stat-card .num { font-size: 1.5rem; }

  /* Buttons: comfortable tap targets, and let action groups wrap onto
     their own lines instead of overflowing table cells. */
  .btn {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 0.9rem;
  }

  td .btn, td .btn.small {
    margin: 0.15rem 0.2rem 0.15rem 0;
  }

  .login-wrap { margin: 2rem auto; max-width: 92vw; }

  .color-row {
    flex-direction: column;
    gap: 0;
  }

  .card-designer-grid { gap: 1rem; }

  #qr-reader { max-width: 100%; }

  .manual-checkin-form {
    flex-direction: column;
    align-items: stretch !important;
    max-width: 100% !important;
  }

  .manual-checkin-form .btn { width: 100%; }
}
