:root {
  --bg: #eef2f6;
  --ink: #18212f;
  --muted: #6a7280;
  --line: #d9e0e9;
  --panel: #ffffff;
  --primary: #0f766e;
  --accent: #c2410c;
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --shadow: 0 18px 48px rgba(24, 33, 47, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); }
button, input, select { font: inherit; }
button { border: 0; border-radius: 8px; background: var(--primary); color: white; padding: 10px 14px; font-weight: 700; cursor: pointer; }
button:hover { filter: brightness(0.96); }
input, select { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: white; color: var(--ink); }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 700; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(36px, 7vw, 72px); line-height: 0.95; max-width: 760px; }
h2 { margin-bottom: 0; font-size: 30px; }
h3 { margin-bottom: 14px; font-size: 18px; }

.hidden { display: none !important; }
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #0b1722, #163f3d 54%, #6f321b); }
.login-panel { width: min(980px, 100%); display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 32px; align-items: end; color: white; }
.login-copy { color: rgba(255,255,255,0.78); font-size: 18px; max-width: 600px; }
.login-form { background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.22); border-radius: 8px; padding: 24px; backdrop-filter: blur(18px); box-shadow: var(--shadow); }
.login-form label { color: rgba(255,255,255,0.82); }
.login-form button { width: 100%; margin-top: 12px; background: white; color: #163f3d; }
.pin-grid { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; color: rgba(255,255,255,0.8); font-size: 13px; }
.pin-grid span { border: 1px solid rgba(255,255,255,0.2); border-radius: 8px; padding: 10px; }
.form-error { min-height: 20px; color: #fecaca; margin-bottom: 0; }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: 0; font-size: 12px; font-weight: 800; margin-bottom: 6px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 284px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; padding: 22px; background: #101820; color: white; }
.brand-lockup { display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: center; min-height: 56px; }
.brand-lockup span { display: block; color: rgba(255,255,255,0.62); font-size: 12px; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 8px; background: var(--primary); font-weight: 900; }
.main-nav { display: grid; gap: 5px; overflow: auto; padding-right: 4px; }
.nav-button { display: flex; align-items: center; gap: 10px; width: 100%; background: transparent; color: rgba(255,255,255,0.74); text-align: left; padding: 10px 12px; }
.nav-button.active, .nav-button:hover { background: rgba(255,255,255,0.1); color: white; }
.ghost-button { margin-top: auto; background: transparent; border: 1px solid rgba(255,255,255,0.18); color: white; }

.workspace { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 20px 28px; background: rgba(238,242,246,0.92); backdrop-filter: blur(16px); border-bottom: 1px solid var(--line); }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.topbar-actions select { min-width: 180px; }
.status-pill { display: inline-flex; align-items: center; min-height: 32px; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 800; background: #dcfce7; color: var(--good); white-space: nowrap; }
.status-pill.warn { background: #fef3c7; color: var(--warn); }
.status-pill.bad { background: #fee2e2; color: var(--bad); }
.page { display: none; padding: 26px 28px 42px; }
.page.active { display: block; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; box-shadow: 0 1px 0 rgba(24,33,47,0.04); }
.secondary-button { background: #e6edf3; color: var(--ink); }
.danger-button { background: #fee2e2; color: var(--bad); }

.filter-row, .form-grid { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 12px; align-items: end; margin-bottom: 18px; }
.filter-row > input { align-self: end; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric-card { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--primary); border-radius: 8px; padding: 16px; box-shadow: 0 1px 0 rgba(24,33,47,0.04); }
.metric-card span { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.metric-card strong { display: block; margin-top: 8px; font-size: 28px; }
.split-layout, .scanner-layout, .setup-grid { display: grid; grid-template-columns: 1.35fr 0.65fr; gap: 18px; align-items: start; }
.table-wrap { overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; white-space: nowrap; }
th { background: #f7f9fb; color: var(--muted); text-transform: uppercase; font-size: 11px; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; align-items: center; min-height: 24px; border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 800; background: #edf2f7; color: var(--muted); }
.badge.good { background: #dcfce7; color: var(--good); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.bad { background: #fee2e2; color: var(--bad); }
.row-actions { display: flex; gap: 6px; }
.row-actions button { padding: 7px 9px; font-size: 12px; }
.stack-list { display: grid; gap: 10px; }
.list-item { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fbfcfd; }
.list-item strong { display: block; margin-bottom: 4px; }
.list-item p { color: var(--muted); margin-bottom: 0; font-size: 13px; }

.scan-box { display: grid; gap: 14px; justify-items: center; text-align: center; background: #101820; color: white; border-radius: 8px; padding: 28px; box-shadow: var(--shadow); }
.scan-frame { width: min(340px, 100%); aspect-ratio: 1; display: grid; place-items: center; border: 2px solid rgba(255,255,255,0.38); border-radius: 8px; background: radial-gradient(circle at center, rgba(15,118,110,0.45), transparent 60%); }
.scan-frame span { width: 74%; height: 2px; background: #67e8f9; box-shadow: 0 0 18px #67e8f9; animation: scan 2s ease-in-out infinite; }
@keyframes scan { 0%, 100% { transform: translateY(-90px); } 50% { transform: translateY(90px); } }
.inline-form { display: flex; gap: 10px; width: 100%; }
.result-box { width: 100%; min-height: 48px; border-radius: 8px; padding: 12px; background: rgba(255,255,255,0.08); color: inherit; text-align: left; }
.result-box strong { display: block; margin-bottom: 4px; }
.result-box p { margin-bottom: 0; color: rgba(255,255,255,0.72); }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 16px; }
.section-head p { color: var(--muted); margin-bottom: 0; }
.schedule-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.schedule-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.schedule-card .form-grid { grid-template-columns: 1fr 1fr; margin-bottom: 0; }
.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.qr-card { background: white; border: 1px solid var(--line); border-radius: 8px; padding: 16px; text-align: center; break-inside: avoid; }
.qr-card p { color: var(--muted); margin-bottom: 6px; font-size: 13px; }
.qr-card button { margin-top: 12px; width: 100%; }
.qr-code { width: 128px; height: 128px; margin: 0 auto 12px; border: 8px solid white; background: conic-gradient(from 90deg, #111 0 25%, #fff 0 50%, #111 0 75%, #fff 0); box-shadow: inset 0 0 0 10px #111; }
.report-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.report-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.report-card strong { display: block; font-size: 24px; margin: 10px 0; }
.button-stack { display: grid; gap: 10px; }
.portal-shell { max-width: 760px; }
.empty-state { padding: 24px; color: var(--muted); }
dialog { border: 0; border-radius: 8px; padding: 0; box-shadow: var(--shadow); width: min(520px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(16,24,32,0.44); }
.dialog-form { display: grid; gap: 12px; padding: 20px; }
menu { display: flex; justify-content: flex-end; gap: 10px; padding: 0; margin: 8px 0 0; }
.toast { position: fixed; right: 24px; bottom: 24px; background: #101820; color: white; border-radius: 8px; padding: 12px 14px; box-shadow: var(--shadow); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .main-nav { grid-template-columns: repeat(2, 1fr); }
  .filter-row, .form-grid, .metric-grid, .split-layout, .scanner-layout, .setup-grid, .schedule-grid, .report-grid { grid-template-columns: 1fr; }
  .login-panel { grid-template-columns: 1fr; }
  .pin-grid { grid-template-columns: 1fr 1fr; }
}

@media print {
  body * { visibility: hidden; }
  #qrCards, #qrCards * { visibility: visible; }
  #qrCards { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); padding: 18px; }
}
