:root {
  --bg: #f4f6f9; --card: #ffffff; --border: #e3e7ee; --text: #1b2433; --muted: #667085;
  --primary: #155e75; --primary-dark: #0e4a5c; --accent: #0891b2;
  --sidebar-bg: #10222c; --sidebar-text: #cbd8de; --sidebar-active: #0e3947;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}
:root[data-theme="dark"], :root:not([data-theme="light"]) {}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1418; --card: #171d23; --border: #2a323b; --text: #e6e9ec; --muted: #99a3ad;
    --sidebar-bg: #0a1216; --sidebar-text: #a9b7bf; --sidebar-active: #12262d;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1418; --card: #171d23; --border: #2a323b; --text: #e6e9ec; --muted: #99a3ad;
  --sidebar-bg: #0a1216; --sidebar-text: #a9b7bf; --sidebar-active: #12262d;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { font-size: 14px; }
a { color: inherit; text-decoration: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex: none; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex: none; }
.brand-title { font-weight: 700; font-size: 13.5px; color: #fff; }
.brand-sub { font-size: 11px; color: #8fa2ab; margin-top: 1px; }
.nav { flex: 1; padding: 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 7px; font-size: 13px; color: var(--sidebar-text); }
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-item .ic { width: 17px; height: 17px; flex: none; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 8px; border-radius: 8px; cursor: pointer; }
.user-chip:hover { background: rgba(255,255,255,.06); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex: none; }
.uc-name { font-size: 12.5px; font-weight: 600; color: #fff; }
.uc-role { font-size: 11px; color: #8fa2ab; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.quickscan { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; flex: 1; max-width: 480px; }
.quickscan .ic { width: 16px; height: 16px; color: var(--muted); flex: none; }
.quickscan input { border: none; background: transparent; outline: none; width: 100%; font-size: 13px; color: var(--text); }
.content { padding: 22px 26px 60px; max-width: 1400px; width: 100%; margin: 0 auto; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 3px; font-size: 22px; }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.eyebrow { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
.tagtitle { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: -.01em; }
.submeta { display: flex; gap: 10px; align-items: center; margin-top: 4px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn .ic { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn-danger-ghost { color: #dc2626; border-color: #f3c2c2; }
.icon-btn { background: transparent; border: none; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px; display: inline-flex; }
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn .ic { width: 16px; height: 16px; }

.stat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 14px; }
.stat-grid-sm { margin-bottom: 20px; }
@media (max-width: 1100px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow); }
.stat-icon { width: 38px; height: 38px; border-radius: 9px; background: #eef6f8; color: var(--primary); display: flex; align-items: center; justify-content: center; flex: none; }
.stat-icon .ic { width: 19px; height: 19px; }
.tone-blue .stat-icon { background: #e6f0fb; color: #1d4ed8; }
.tone-cyan .stat-icon { background: #e2f7fb; color: #0891b2; }
.tone-green .stat-icon { background: #e7f8ee; color: #16a34a; }
.tone-amber .stat-icon { background: #fef3e0; color: #b45309; }
.tone-red .stat-icon { background: #fde8e8; color: #dc2626; }
.tone-gray .stat-icon { background: #eef0f2; color: #4b5563; }
.stat-value { font-size: 21px; font-weight: 800; line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

.alert-banner { display: flex; gap: 10px; align-items: flex-start; background: #fff7e6; border: 1px solid #fbe1a8; color: #7c4a03; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; font-size: 13px; }
.alert-banner .ic { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.alert-banner a { font-weight: 700; text-decoration: underline; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 14.5px; }
.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: 1fr; } }

.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px; }
.search-box { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; flex: 1; min-width: 220px; background: var(--bg); }
.search-box .ic { width: 15px; height: 15px; color: var(--muted); flex: none; }
.search-box input { border: none; background: transparent; outline: none; width: 100%; font-size: 13px; color: var(--text); }
select, input[type=text], input[type=date], input, textarea {
  border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; font-size: 13px; background: var(--card); color: var(--text); font-family: var(--font);
}
select { cursor: pointer; }

.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--bg); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table tbody tr:hover { background: rgba(8,145,178,.04); }
.tag-link { font-weight: 700; color: var(--primary); font-family: ui-monospace, monospace; }
.row-actions { display: flex; gap: 8px; }
.row-actions a, .row-actions button { color: var(--muted); display: inline-flex; }
.row-actions a:hover, .row-actions button:hover { color: var(--primary); }
.row-actions .ic { width: 16px; height: 16px; }
.empty-state { text-align: center; color: var(--muted); padding: 30px !important; white-space: normal; }
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--border); }
.page-btns { display: flex; align-items: center; gap: 10px; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: color-mix(in srgb, var(--bc) 14%, transparent); color: var(--bc); }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--bc); }
.wpill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.wpill.expired { background: #fde8e8; color: #dc2626; }
.wpill.soon { background: #fef3e0; color: #b45309; }
.wpill.ok { background: #e7f8ee; color: #16a34a; }

.detail-grid { display: grid; grid-template-columns: 300px 1fr 1fr; gap: 14px; }
@media (max-width: 1050px) { .detail-grid { grid-template-columns: 1fr; } }
.barcode-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
.barcode-card svg { max-width: 100%; }
.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.kv { display: flex; flex-direction: column; gap: 2px; }
.kv span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.kv strong { font-size: 13.5px; font-weight: 600; }
.notes-text { white-space: pre-wrap; font-size: 13.5px; }

.timeline { display: flex; flex-direction: column; gap: 14px; }
.tl-item { display: flex; gap: 10px; }
.tl-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); margin-top: 5px; flex: none; }
.tl-dot.alt { background: #9333ea; }
.tl-title { font-weight: 700; font-size: 13px; }
.tl-meta { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.tl-details { font-size: 12.5px; margin-top: 3px; }

.form-card { max-width: 980px; }
.form-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }
.form-row-1 { grid-template-columns: 1fr 1fr; }
.form-row-wrap { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 720px) { .form-row, .form-row-1, .form-row-wrap { grid-template-columns: 1fr; } }
.form-row label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.form-row label.full { grid-column: 1 / -1; }
.form-subhead { font-size: 12.5px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .03em; margin: 6px 0 -2px; }
.tag-preview { font-family: ui-monospace, monospace; font-weight: 700; background: var(--bg); border: 1px dashed var(--border); border-radius: 7px; padding: 8px 10px; color: var(--primary); }
.inline-check { flex-direction: row !important; align-items: center; gap: 6px !important; font-weight: 500 !important; margin-top: 6px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.modal-overlay { position: fixed; inset: 0; background: rgba(10,15,20,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-box { background: var(--card); border-radius: 12px; width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.modal-body label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }

.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1b2433; color: #fff; padding: 11px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.25); opacity: 0; transform: translateY(8px); transition: all .25s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }

.boot { height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted); font-size: 14px; }
.boot-spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.report-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 18px; }
@media (max-width: 900px) { .report-grid { grid-template-columns: repeat(2, 1fr); } }
.report-tile { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; font-size: 12.5px; font-weight: 600; }
.report-tile:hover { border-color: var(--primary); }
.report-tile.active { border-color: var(--primary); background: #eef8fa; color: var(--primary); }
.report-tile .ic { width: 16px; height: 16px; flex: none; }
.report-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 10px; }
.report-header h2 { margin: 0; }

.mapping-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 800px) { .mapping-grid { grid-template-columns: 1fr; } }
.mapping-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.err-text { color: #dc2626; white-space: normal; }

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 5px 6px 5px 12px; font-size: 12.5px; }
.chip button { border: none; background: transparent; cursor: pointer; color: var(--muted); display: flex; padding: 3px; border-radius: 50%; }
.chip button:hover { background: var(--border); }
.chip .ic { width: 12px; height: 12px; }

/* ---- Print views ---- */
.print-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 22px; background: var(--card); border-bottom: 1px solid var(--border); }
.print-toolbar button { display: inline-flex; align-items: center; gap: 6px; background: var(--primary); color: #fff; border: none; padding: 8px 14px; border-radius: 8px; font-weight: 600; cursor: pointer; }
.print-sheet { max-width: 760px; margin: 24px auto; background: var(--card); padding: 32px; border-radius: 10px; border: 1px solid var(--border); }
.print-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.print-co { font-weight: 800; font-size: 17px; }
.print-tag { font-family: ui-monospace, monospace; margin: 6px 0 18px; }
.print-table { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.print-table th { text-align: left; background: var(--bg); font-size: 11.5px; text-transform: uppercase; color: var(--muted); padding: 8px 10px; width: 22%; border: 1px solid var(--border); }
.print-table td { padding: 8px 10px; border: 1px solid var(--border); font-size: 13px; }
.sign-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 40px; }
.sign-line { border-bottom: 1px solid var(--text); height: 36px; }
.sign-row span { font-size: 11.5px; color: var(--muted); }
.print-foot { margin-top: 30px; font-size: 11px; color: var(--muted); }

.label-sheet { display: flex; justify-content: center; padding: 30px; }
.label { width: 320px; border: 1.5px dashed #999; border-radius: 8px; padding: 16px; text-align: center; background: #fff; color: #111; }
.label-co { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.label-tag { font-family: ui-monospace, monospace; font-size: 20px; font-weight: 800; margin: 4px 0; }
.label-meta { font-size: 11px; }
.label-meta.small { color: #555; margin-bottom: 6px; }
.label-barcode { width: 100%; max-width: 280px; }

.menu-toggle { display: none; }
@media (max-width: 880px) {
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); cursor: pointer; flex: none; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 8px 0 24px rgba(0,0,0,.25); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }
  .sidebar-scrim.show { display: block; }
  .topbar { padding: 10px 14px; gap: 10px; }
  .content { padding: 16px 14px 50px; }
  .stat-grid, .stat-grid-sm { grid-template-columns: repeat(2, 1fr) !important; }
  .detail-grid { grid-template-columns: 1fr !important; }
  .quickscan { max-width: none; }
  .page-head { flex-direction: column; }
}
@media print {
  .no-print { display: none !important; }
  body, .content { background: #fff !important; }
  .print-sheet { border: none; box-shadow: none; margin: 0; max-width: 100%; }
  .label-sheet { padding: 0; }
  .label { border-style: solid; }
  @page { margin: 12mm; }
}

/* ---- Login / onboarding screens ---- */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--sidebar-bg); padding: 20px; }
.auth-card { background: var(--card); border-radius: 14px; padding: 32px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand-title-dark { font-weight: 800; font-size: 16px; }
.brand-sub-dark { font-size: 12px; color: var(--muted); }
.auth-card h2 { margin: 0 0 14px; font-size: 18px; }
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
.auth-card input { padding: 9px 11px; }
.auth-notice { background: #eef8fa; color: var(--primary); border-radius: 8px; padding: 8px 12px; font-size: 12.5px; margin-bottom: 14px; }
