:root {
  --bg: #eef0f6;
  --surface: #ffffff;
  --sidebar: #1a2238;
  --sidebar-2: #131a2e;
  --ink: #1a2238;
  --ink-soft: #5a6379;
  --muted: #8a92a6;
  --line: #e6e8ef;
  --accent: #ff3366;
  --accent-2: #ff5b87;
  --accent-soft: #ffe7ee;
  --blue: #3b82f6;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --shadow-sm: 0 1px 2px rgba(20,25,50,.06);
  --shadow:    0 8px 30px rgba(20,25,50,.08);
  --shadow-lg: 0 20px 60px rgba(20,25,50,.12);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ============================================
   DESKTOP DEFAULTS — Mobile-only elements hidden
   ============================================ */
.mobile-topbar  { display: none !important; }
.sidebar-close  { display: none !important; }
.sidebar-overlay { display: none; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: #c8cee0;
  display: flex; flex-direction: column;
  padding: 22px 0;
  position: sticky; top: 0; height: 100vh;
  flex-shrink: 0;
}

.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 0 22px 26px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand-logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 20px; letter-spacing: 1px; color: #fff;
  box-shadow: 0 6px 18px rgba(255,51,102,.45);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name {
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: 2px; font-size: 17px; color: #fff;
}
.brand-sub { font-size: 11px; color: #7a85a3; letter-spacing: .5px; }

.nav { flex: 1; padding: 14px 12px; overflow-y: auto; }
.nav-section {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1.5px;
  color: #5b6582; padding: 16px 12px 8px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; margin: 2px 0;
  border-radius: 10px;
  color: #aab2c8; font-weight: 500; font-size: 13.5px;
  transition: all .15s ease;
}
.nav-item:hover { background: rgba(255,255,255,.04); color: #fff; }
.nav-item.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 6px 18px rgba(255,51,102,.35);
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-foot { padding: 14px 16px 4px; border-top: 1px solid rgba(255,255,255,.06); }
.admin-chip { display: flex; align-items: center; gap: 10px; }
.admin-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, #4a5680, #2c3556);
  color: #fff; font-weight: 700; display: grid; place-items: center;
}
.admin-name { color: #fff; font-size: 13px; font-weight: 600; }
.admin-logout { color: #7a85a3; font-size: 11.5px; }
.admin-logout:hover { color: var(--accent-2); }

/* ---------- Sidebar close (mobile only) ---------- */
.sidebar-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 38px; height: 38px;
  border: none; border-radius: 10px;
  background: rgba(255,255,255,.1);
  color: #fff; font-size: 24px;
  line-height: 1;
  align-items: center; justify-content: center;
  z-index: 5;
}
.sidebar-close:hover { background: rgba(255,255,255,.2); }

/* ---------- Mobile topbar (hidden on desktop) ---------- */
.mobile-topbar {
  position: sticky; top: 0;
  z-index: 30;
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  padding: 12px 16px;
  align-items: center;
  gap: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.mobile-menu-btn {
  width: 42px; height: 42px;
  border: none; border-radius: 10px;
  background: rgba(255,255,255,.1);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.mobile-menu-btn:hover { background: rgba(255,255,255,.18); }
.mobile-menu-btn svg { width: 22px; height: 22px; }
.mobile-topbar-brand {
  display: flex; align-items: center; gap: 10px;
  color: #fff;
}
.mobile-topbar-logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(255,51,102,.45);
}
.mobile-topbar-brand span {
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: 2px; font-size: 16px;
}

.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 45;
}
.sidebar-overlay.show { display: block; }

/* ---------- Main content ---------- */
.main { flex: 1; padding: 28px 36px; max-width: 100%; min-width: 0; }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 22px; gap: 20px; flex-wrap: wrap;
}
.page-title { font-size: 26px; font-weight: 800; margin: 0 0 4px; }
.page-sub { color: var(--ink-soft); font-size: 13.5px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card + .card { margin-top: 18px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; gap: 14px;
  border-left: 4px solid var(--accent);
}
.stat.alt-blue  { border-color: var(--blue); }
.stat.alt-green { border-color: var(--green); }
.stat.alt-amber { border-color: var(--amber); }
.stat-ico { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex-shrink: 0; }
.stat.alt-blue  .stat-ico { background: #e7f0ff; color: var(--blue); }
.stat.alt-green .stat-ico { background: #e6f8f1; color: var(--green); }
.stat.alt-amber .stat-ico { background: #fff5e0; color: var(--amber); }
.stat-ico svg { width: 22px; height: 22px; }
.stat-num { font-size: 22px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fff; color: var(--ink);
  font-size: 13px; font-weight: 600;
  transition: all .15s ease;
}
.btn:hover { border-color: var(--ink); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
  box-shadow: 0 6px 14px rgba(255,51,102,.35);
}
.btn-primary:hover { box-shadow: 0 8px 20px rgba(255,51,102,.45); transform: translateY(-1px); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: #f4f5fa; color: var(--ink); }
.btn-blue { background: var(--blue); color: #fff; border-color: transparent; }
.btn-green { background: var(--green); color: #fff; border-color: transparent; }
.btn-red { background: var(--red); color: #fff; border-color: transparent; }
.btn svg { width: 15px; height: 15px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  font-family: inherit; font-size: 13.5px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff; color: var(--ink);
  outline: none; transition: all .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,51,102,.12);
}
.field textarea { resize: vertical; min-height: 70px; }

/* ---------- Filter bar ---------- */
.filterbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: end;
  padding: 16px 18px;
  background: #f7f8fc;
  border-radius: 12px;
  margin-bottom: 16px;
}
.filterbar .field { flex: 1; min-width: 160px; }
.filterbar .field-actions { display: flex; gap: 8px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; min-width: 720px; }
table.data th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); font-weight: 600;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
table.data td {
  padding: 14px; font-size: 13.5px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #fafbfe; }
.row-name { font-weight: 700; }
.row-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: #eef0f6; color: var(--ink-soft);
}
.badge.green { background: #e6f8f1; color: #047857; }
.badge.red   { background: #fde7e7; color: #b91c1c; }
.badge.amber { background: #fff5e0; color: #b45309; }
.badge.blue  { background: #e7f0ff; color: #1d4ed8; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(20,25,50,.55);
  display: none; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-back.show { display: flex; }
.modal {
  background: #fff; border-radius: 16px;
  width: min(560px, 100%); max-height: 92vh; overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: pop .2s ease;
}
.modal-lg { width: min(720px, 100%); }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--line);
}
.modal-title { font-weight: 700; font-size: 17px; }
.modal-close {
  background: transparent; border: none; font-size: 22px; color: var(--muted);
  width: 32px; height: 32px; border-radius: 8px;
  text-align: center; line-height: 1;
}
.modal-close:hover { background: #f4f5fa; color: var(--ink); }
.modal-body { padding: 22px; }
.modal-foot {
  padding: 14px 22px; border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ---------- Login ---------- */
.login-shell {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(circle at 20% 20%, #2a3556 0%, #131a2e 60%);
  padding: 20px; position: relative; overflow: hidden;
}
.login-shell::before {
  content: ''; position: absolute; width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(255,51,102,.35), transparent 70%);
  top: -200px; right: -150px;
}
.login-card {
  background: #fff; padding: 38px 36px;
  border-radius: 20px; width: min(420px, 100%);
  box-shadow: 0 30px 80px rgba(0,0,0,.4);
  position: relative; z-index: 1;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.login-brand .brand-logo { width: 50px; height: 50px; font-size: 22px; }
.login-title { font-family: 'Bebas Neue', sans-serif; letter-spacing: 3px; font-size: 28px; }
.login-sub { color: var(--ink-soft); margin: 4px 0 26px; font-size: 13.5px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 12px; }
.login-hint {
  margin-top: 18px; font-size: 12px; text-align: center; color: var(--muted);
  padding: 10px; background: #f7f8fc; border-radius: 8px;
}

/* ---------- QR public page ---------- */
.qr-shell {
  min-height: 100vh; padding: 40px 20px;
  background: radial-gradient(circle at top, #2a3556, #131a2e);
  display: grid; place-items: center;
}
.qr-card {
  background: #fff; border-radius: 22px;
  padding: 32px; width: min(440px, 100%);
  box-shadow: 0 30px 80px rgba(0,0,0,.4); text-align: center;
}
.qr-card .brand-logo { margin: 0 auto 12px; width: 56px; height: 56px; font-size: 24px; }
.qr-card h1 { font-family: 'Bebas Neue', sans-serif; letter-spacing: 3px; font-size: 28px; margin: 6px 0 4px; }

/* ---------- Scanner ---------- */
.scan-grid { display: grid; grid-template-columns: 1fr 380px; gap: 22px; }
#reader { width: 100%; border-radius: 14px; overflow: hidden; }
.scan-feed { max-height: 480px; overflow-y: auto; }
.scan-item {
  display: flex; gap: 12px; padding: 12px;
  border-radius: 12px; background: #f7f8fc;
  margin-bottom: 8px; align-items: center;
}
.scan-item.ok { background: #e6f8f1; border-left: 3px solid var(--green); }
.scan-item.bad { background: #fde7e7; border-left: 3px solid var(--red); }
.scan-item-name { font-weight: 700; }
.scan-item-meta { font-size: 12px; color: var(--ink-soft); }
.scan-item-time { margin-left: auto; font-size: 11px; color: var(--muted); }

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 16px; border-radius: 10px;
  margin-bottom: 16px; font-size: 13.5px; font-weight: 500;
}
.alert.success { background: #e6f8f1; color: #047857; border-left: 3px solid var(--green); }
.alert.error { background: #fde7e7; color: #b91c1c; border-left: 3px solid var(--red); }

/* ---------- Detail view ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.detail-item { background: #f7f8fc; padding: 12px 14px; border-radius: 10px; }
.detail-item .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.detail-item .value { font-weight: 600; margin-top: 3px; }

/* ---------- Empty ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 60px; height: 60px; margin-bottom: 12px; opacity: .4; }


/* ============================================
   MOBILE RESPONSIVE (≤900px)
   ============================================ */
@media (max-width: 900px) {
  .mobile-topbar { display: flex !important; }
  .sidebar-close { display: flex !important; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 50;
    height: 100vh;
    width: 270px;
    box-shadow: 6px 0 30px rgba(0,0,0,.3);
  }
  .sidebar.open { transform: translateX(0); }

  .main {
    padding: 18px 16px 24px;
    width: 100%;
  }

  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .page-title { font-size: 22px; }
  .page-sub { font-size: 13px; }

  .stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }
  .stat { padding: 14px; gap: 10px; }
  .stat-ico { width: 38px; height: 38px; }
  .stat-ico svg { width: 18px; height: 18px; }
  .stat-num { font-size: 18px; }
  .stat-label { font-size: 11px; }

  .card { padding: 16px; border-radius: 12px; }

  .filterbar {
    padding: 12px;
    flex-direction: column;
    align-items: stretch;
  }
  .filterbar .field { min-width: 0; width: 100%; }
  .filterbar .field-actions { width: 100%; }
  .filterbar .field-actions .btn {
    flex: 1; justify-content: center;
  }

  table.data { min-width: 0; }
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td {
    display: block;
    width: 100%;
  }
  table.data tr {
    background: #fafbfe;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    border: 1px solid var(--line);
  }
  table.data tr:hover td { background: transparent; }
  table.data td {
    padding: 6px 0;
    border-bottom: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    gap: 10px;
    text-align: right;
  }
  table.data td::before {
    content: attr(data-label);
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 1px;
    flex-shrink: 0;
    text-align: left;
  }
  table.data td:last-child {
    border-top: 1px solid var(--line);
    padding-top: 10px;
    margin-top: 4px;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-start;
  }
  table.data td:last-child::before { display: none; }
  table.data .btn-sm {
    flex: 1;
    justify-content: center;
    min-width: 70px;
  }

  .modal-back { padding: 10px; align-items: flex-start; }
  .modal, .modal-lg {
    width: 100%;
    max-height: 95vh;
    margin-top: 10px;
  }
  .modal-head { padding: 14px 16px; }
  .modal-title { font-size: 15px; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px; flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; justify-content: center; }

  .form-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }

  .scan-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  #reader { min-height: 280px; }
  .scan-feed { max-height: 300px; }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr; }
  .page-title { font-size: 19px; }
  .modal-foot .btn { font-size: 12px; padding: 8px; }
}