:root {
  --primary: #1D9E75;
  --primary-dark: #167a5a;
  --primary-light: #2bc48f;
  --bg: #f5f7f9;
  --surface: #ffffff;
  --text: #1a1d21;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --warn: #f59e0b;
  --success: #10b981;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --radius: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --text: #e5e7eb;
    --text-muted: #9ca3af;
    --border: #2a2f38;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }

/* Shell */
#app { min-height: 100vh; }
.shell { display: flex; min-height: 100vh; }
.sidebar {
  display: none;
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  font-size: 19px; font-weight: 700; color: var(--primary);
  margin-bottom: 24px; padding: 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.sidebar a {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  text-decoration: none; color: var(--text); font-weight: 500;
  font-size: 14px;
}
.sidebar a:hover { background: var(--bg); }
.sidebar a.active { background: var(--primary); color: #fff; }
.sidebar a.active .icon { filter: brightness(1.4); }
.sidebar .icon { font-size: 18px; }
.sidebar-user {
  margin-top: auto; padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted);
}
.sidebar-user strong { display: block; color: var(--text); }
.logout-btn {
  margin-top: 12px; width: 100%;
  padding: 10px; border: 1px solid var(--border);
  background: transparent; color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.logout-btn:hover { background: var(--bg); }

.content {
  flex: 1;
  padding: 20px;
  padding-bottom: 100px;
  max-width: 100%;
  min-width: 0;
}
.page-title { font-size: 22px; margin: 0 0 4px; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: 14px; margin: 0 0 20px; }

/* Bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-around;
  padding: 6px 4px;
  z-index: 10;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
}
.bottom-nav a {
  flex: 1; text-align: center;
  padding: 8px 4px; text-decoration: none;
  color: var(--text-muted);
  font-size: 10px; font-weight: 600;
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 0;
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav .icon { font-size: 22px; line-height: 1; }

@media (min-width: 900px) {
  .sidebar { display: flex; }
  .bottom-nav { display: none; }
  .content { padding: 32px 40px; max-width: 1200px; padding-bottom: 32px; }
  .page-title { font-size: 26px; }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card h3 { margin: 0 0 14px; font-size: 16px; }
.card-title {
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin: 0 0 6px; font-weight: 600;
}
.card-value { font-size: 30px; font-weight: 700; color: var(--text); margin: 0; line-height: 1.1; }
.card-footer { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 20px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 15px;
  min-height: 48px;
  transition: background .15s, transform .05s;
  text-decoration: none;
}
.btn:hover:not(:disabled) { background: var(--primary-dark); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-danger { background: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-lg { padding: 17px 24px; font-size: 16px; min-height: 56px; }

/* Forms */
.field { margin-bottom: 16px; }
.field label {
  display: block; font-weight: 600; font-size: 13px;
  color: var(--text); margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 13px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 48px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 158, 117, 0.15);
}
.field .hint, .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.login-card .brand {
  font-size: 22px; font-weight: 700; color: var(--primary);
  text-align: center; margin-bottom: 4px;
}
.login-card .tagline {
  text-align: center; color: var(--text-muted);
  font-size: 13px; margin-bottom: 24px;
}

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.table th {
  font-weight: 600; color: var(--text-muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--bg);
  position: sticky; top: 0;
}
.table tr:last-child td { border-bottom: none; }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-success { background: rgba(16, 185, 129, 0.15); color: #059669; }
.badge-danger { background: rgba(220, 38, 38, 0.15); color: var(--danger); }
.badge-warn { background: rgba(245, 158, 11, 0.15); color: #d97706; }
.badge-muted { background: rgba(107, 114, 128, 0.15); color: var(--text-muted); }

/* Scanner */
.scanner-video-wrap {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto 16px;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4/3;
}
.scanner-video-wrap video, .scanner-video-wrap canvas {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.scanner-video-wrap canvas { position: absolute; inset: 0; pointer-events: none; }
.scanner-overlay {
  position: absolute; inset: 0;
  border: 4px solid transparent;
  pointer-events: none;
  transition: border-color .15s, background .15s;
}
.scanner-overlay.flash { border-color: var(--primary); background: rgba(29, 158, 117, 0.2); }
.scan-list { max-height: 260px; overflow-y: auto; }
.scan-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-family: ui-monospace, SFMono-Regular, 'Cascadia Code', monospace;
  font-size: 14px;
}
.scan-item button {
  background: transparent; border: none; color: var(--danger);
  font-size: 22px; padding: 0 8px; cursor: pointer; line-height: 1;
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 14px;
  border: 1px solid;
}
.alert-error { background: rgba(220, 38, 38, 0.08); color: var(--danger); border-color: rgba(220, 38, 38, 0.25); }
.alert-success { background: rgba(16, 185, 129, 0.08); color: #059669; border-color: rgba(16, 185, 129, 0.25); }
.alert-warn { background: rgba(245, 158, 11, 0.08); color: #d97706; border-color: rgba(245, 158, 11, 0.25); }

/* Empty */
.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty .icon { font-size: 42px; margin-bottom: 10px; }

/* Utility */
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.hidden { display: none !important; }
.spacer { flex: 1; }
.row { display: flex; gap: 12px; align-items: center; }
code {
  font-family: ui-monospace, SFMono-Regular, monospace;
  background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 12px;
}
