:root {
  --bg: #0b1120;
  --panel: #111a2e;
  --panel-2: #17223a;
  --line: #24314d;
  --text: #e8eefc;
  --muted: #94a3c4;
  --accent: #38bdf8;
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, .14);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, .14);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, .14);
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, .14);
  --ai: #c084fc;
  --ai-bg: rgba(192, 132, 252, .12);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Sinhala", "Noto Sans Tamil", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 var(--font); }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: .25rem 0 .75rem; }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: .9rem; }
.small { font-size: .8rem; }
.hidden { display: none !important; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: .75rem; }

/* ─── Controls ─────────────────────────────────────────────── */
button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 12px; padding: .75rem 1rem; min-height: 48px; cursor: pointer; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; text-decoration: none;
}
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #04121f; }
.btn-red { background: var(--red); border-color: var(--red); color: #fff; }
.btn-green { background: var(--green); border-color: var(--green); color: #03140e; }
.btn-ghost { background: transparent; }
.btn-big { width: 100%; min-height: 64px; font-size: 1.1rem; }
.btn-sm { min-height: 36px; padding: .35rem .7rem; font-size: .85rem; border-radius: 9px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: .65rem .75rem; min-height: 48px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
label.field { display: block; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; }

.check {
  display: flex; gap: .75rem; align-items: flex-start; padding: .7rem .8rem; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg); cursor: pointer; min-height: 48px;
}
.check input { width: 24px; height: 24px; min-height: 0; margin: 0; flex: none; accent-color: var(--accent); }
.check + .check { margin-top: .5rem; }

.ai-filled { box-shadow: 0 0 0 2px var(--ai) !important; background: var(--ai-bg) !important; }
.ai-tag { color: var(--ai); font-size: .75rem; font-weight: 700; }

/* ─── Layout ───────────────────────────────────────────────── */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.card + .card { margin-top: .9rem; }
.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px 120px; }

.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(11, 17, 32, .96); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line); padding: .5rem 16px;
}
.topbar .inner { max-width: 720px; margin: 0 auto; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 800; letter-spacing: .02em; }
.brand small { color: var(--muted); font-weight: 500; }

.clock {
  font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.35rem; padding: .2rem .6rem;
  border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line);
}
.clock.warn { background: var(--amber-bg); border-color: var(--amber); color: var(--amber); }
.clock.alarm { background: var(--red); border-color: var(--red); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .65; } }

.code-pill { padding: .3rem .7rem; border-radius: 999px; font-weight: 700; font-size: .85rem; border: 1px solid var(--line); background: var(--panel-2); }
.code-red { background: var(--red-bg); border-color: var(--red); color: #fecaca; }
.code-blue { background: var(--blue-bg); border-color: var(--blue); color: #bfdbfe; }
.code-amber { background: var(--amber-bg); border-color: var(--amber); color: #fde68a; }

.steps { display: flex; gap: .35rem; margin: .8rem 0; overflow-x: auto; }
.steps button { flex: 1; min-width: 80px; min-height: 40px; padding: .35rem .5rem; font-size: .82rem; border-radius: 10px; }
.steps button.active { background: var(--accent); color: #04121f; border-color: var(--accent); }

.banner { border-radius: 12px; padding: .75rem 1rem; font-weight: 600; margin: .75rem 0; }
.banner-red { background: var(--red); color: #fff; }
.banner-amber { background: var(--amber-bg); border: 1px solid var(--amber); color: #fde68a; }
.banner-ai { background: var(--ai-bg); border: 1px solid var(--ai); color: #ead5ff; font-weight: 500; }
.banner-green { background: var(--green-bg); border: 1px solid var(--green); color: #a7f3d0; }

.safety li { margin: .35rem 0; font-size: 1.05rem; }
.decision { border-radius: var(--radius); padding: 1rem; border: 2px solid var(--line); }
.decision.code-red { border-color: var(--red); }
.decision.code-blue { border-color: var(--blue); }
.decision.code-amber { border-color: var(--amber); }
.decision h3 { font-size: 1.2rem; }
.decision ul { margin: .4rem 0 0; padding-left: 1.2rem; }

.dose { display: grid; grid-template-columns: 1fr; gap: .6rem; }
.dose .drug { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: .8rem; }
.dose .mg { font-size: 1.6rem; font-weight: 800; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 100; max-width: calc(100% - 32px);
  background: var(--panel-2); border: 1px solid var(--line); padding: .7rem 1rem; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

/* ─── Voice dock ───────────────────────────────────────────── */
.voice-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: rgba(17, 26, 46, .97);
  border-top: 1px solid var(--line); padding: .5rem 16px calc(.5rem + env(safe-area-inset-bottom));
}
.voice-dock .inner { max-width: 720px; margin: 0 auto; display: flex; gap: .6rem; align-items: center; }
.mic { width: 56px; height: 56px; border-radius: 50%; padding: 0; flex: none; font-size: 1.4rem; }
.mic.on { background: var(--red); border-color: var(--red); animation: pulse 1.4s infinite; }
.voice-line { flex: 1; min-width: 0; font-size: .88rem; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lang { width: auto; min-height: 40px; padding: .3rem .5rem; }

/* ─── Camera sweep ─────────────────────────────────────────── */
.camera { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.camera video { flex: 1; width: 100%; object-fit: cover; min-height: 0; }
.cam-hud { position: absolute; left: 0; right: 0; top: 0; padding: 12px 16px; background: linear-gradient(#000c, #0000); }
.cam-stage { font-size: 1.3rem; font-weight: 800; }
.cam-cue { color: #dbe4f5; }
.cam-progress { display: flex; gap: 4px; margin-top: .5rem; }
.cam-progress span { flex: 1; height: 6px; border-radius: 3px; background: #ffffff33; }
.cam-progress span.done { background: var(--green); }
.cam-progress span.now { background: var(--accent); }
.cam-count { position: absolute; right: 16px; top: 12px; font-size: 2rem; font-weight: 800; }
.cam-controls { display: flex; gap: .6rem; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: #000; }
.cam-controls button { flex: 1; }
.rec-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--red); margin-right: 6px; animation: pulse 1s infinite; }

/* ─── Analysis / logs ──────────────────────────────────────── */
.stage-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .4rem; }
.stage-item { border: 1px solid var(--line); border-radius: 10px; padding: .5rem .6rem; font-size: .85rem; background: var(--bg); }
.stage-item.miss { border-color: var(--amber); }
.marker { font-variant-numeric: tabular-nums; color: var(--accent); cursor: pointer; background: none; border: 0; padding: 0; min-height: 0; font-weight: 700; }
.log { max-height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: .4rem; }
.log .msg { padding: .45rem .65rem; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); font-size: .88rem; }
.log .msg.etu { border-color: var(--green); }
.log .msg.ai { border-color: var(--ai); }
.log .msg.authorization { border-color: var(--red); font-weight: 600; }
.log .meta { color: var(--muted); font-size: .72rem; }
table.data { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.data td, table.data th { border-bottom: 1px solid var(--line); padding: .35rem .3rem; text-align: left; vertical-align: top; }

/* ─── ETU console ──────────────────────────────────────────── */
.etu { display: grid; grid-template-columns: 300px 1fr; gap: 1rem; padding: 1rem 16px; max-width: 1400px; margin: 0 auto; }
.inc-list { display: flex; flex-direction: column; gap: .5rem; }
.inc-item { text-align: left; display: block; width: 100%; padding: .7rem .8rem; }
.inc-item.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.inc-item .t { font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .25rem .8rem; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
video.review { width: 100%; max-height: 360px; background: #000; border-radius: 10px; }

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

@media print {
  body { background: #fff; color: #000; }
  .topbar, .voice-dock, .no-print, .inc-list-col { display: none !important; }
  .card { border: 1px solid #999; background: #fff; }
  .etu { display: block; }
}
