/* Shared base for all three RhodesMed prototypes. Tokens on :root, components below. */
:root {
  --ink: #0F1F3D;
  --ink-2: #3B4660;
  --muted: #6B7280;
  --line: #E5E7EB;
  --bg: #F6F7FA;
  --surface: #FFFFFF;
  --surface-2: #F0F2F7;
  --accent: #E4572E;
  --accent-ink: #FFFFFF;
  --navy: #0F1F3D;
  --ok: #2A7F62;
  --warn: #B7791F;
  --bad: #B23A48;
  --info: #1F6F8B;
  --violet: #4A2E7A;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15,31,61,.06), 0 4px 16px rgba(15,31,61,.06);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --display: "Inter", "Segoe UI", system-ui, sans-serif;
  --nav-w: 232px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #F3F5F9; --ink-2: #C7CDDA; --muted: #9AA3B5; --line: #2A3347; --bg: #0E1320; --surface: #171D2C; --surface-2: #1F2637;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --ink: #F3F5F9; --ink-2: #C7CDDA; --muted: #9AA3B5; --line: #2A3347; --bg: #0E1320; --surface: #171D2C; --surface-2: #1F2637;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); line-height: 1.45; font-size: 15px; -webkit-font-smoothing: antialiased; }
a { color: var(--info); }
h1, h2, h3, h4 { font-family: var(--display); letter-spacing: -0.01em; margin: 0 0 .35em; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
p { margin: 0 0 .6em; }
small, .muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[tabindex="-1"]:focus-visible { outline: none; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }

/* Layout */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }
.nav { background: var(--navy); color: #fff; padding: 18px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
:root[data-theme="dark"] .nav, :root:not([data-theme="light"]) .nav { background: #0B1426; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .nav { background: var(--navy); } }
.nav .brand { font-weight: 800; font-size: 17px; letter-spacing: -0.02em; padding: 4px 10px 14px; display: flex; align-items: center; gap: 10px; }
.nav .brand .mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: inline-grid; place-items: center; font-size: 15px; }
.nav .brand small { display: block; font-weight: 500; font-size: 11px; opacity: .7; letter-spacing: 0; }
.nav a, .nav button.navlink { display: flex; align-items: center; gap: 10px; color: rgba(255,255,255,.82); text-decoration: none; padding: 9px 10px; border-radius: 9px; font-weight: 600; font-size: 14px; background: none; border: 0; width: 100%; text-align: left; cursor: pointer; font-family: inherit; }
.nav a:hover, .nav button.navlink:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a[aria-current="page"], .nav button.navlink[aria-current="page"] { background: rgba(255,255,255,.14); color: #fff; }
.nav .count { margin-left: auto; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.nav .spacer { flex: 1; }
.nav .foot { font-size: 12px; opacity: .7; padding: 8px 10px; line-height: 1.4; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; margin: 0; }
.topbar .grow { flex: 1; }
.content { padding: 22px 24px 90px; max-width: 1280px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; flex-direction: row; padding: 6px; gap: 0; overflow-x: auto; z-index: 20; }
  .nav .brand, .nav .spacer, .nav .foot, .nav .section-label { display: none; }
  .nav a, .nav button.navlink { flex-direction: column; gap: 2px; font-size: 11px; padding: 8px 6px; min-width: 64px; justify-content: center; text-align: center; }
  .nav .count { margin: 0; position: absolute; transform: translate(18px, -10px); }
  .nav a { position: relative; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .content { padding: 16px 16px 100px; }
  .topbar { padding: 12px 16px; }
}
.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .55; padding: 12px 10px 4px; font-weight: 700; }

/* Components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.tight { padding: 12px 14px; }
.card h2 { display: flex; align-items: center; gap: 8px; }
.card h2 .right { margin-left: auto; font-size: 13px; font-weight: 500; }
.card-link { display: block; color: inherit; text-decoration: none; cursor: pointer; }
.card-link:hover { border-color: var(--accent); }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--navy); background: var(--navy); color: #fff; font-weight: 600; font-size: 14px; padding: 8px 14px; border-radius: 9px; cursor: pointer; font-family: inherit; text-decoration: none; line-height: 1.2; }
.btn:hover { filter: brightness(1.15); }
.btn.btn-accent { background: var(--accent); border-color: var(--accent); }
.btn.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.btn-ok { background: var(--ok); border-color: var(--ok); }
.btn.btn-bad { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-acting { color: var(--ok); background: rgba(42,127,98,.12); }
.badge-waiting { color: var(--accent); background: rgba(228,87,46,.12); }
.badge-verifying { color: var(--info); background: rgba(31,111,139,.12); }
.badge-blocked { color: var(--bad); background: rgba(178,58,72,.12); }
.badge-idle { color: var(--muted); }
.badge-plain::before { display: none; }
.badge-sample { color: var(--warn); background: rgba(183,121,31,.14); }
.badge-sample::before { display: none; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.table tr.rowlink { cursor: pointer; }
.table tr.rowlink:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.kpi { display: grid; gap: 4px; }
.kpi .n { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.kpi .l { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi.hero .n { color: var(--accent); font-size: 40px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.list .when { font-size: 12px; color: var(--muted); min-width: 64px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; flex: 0 0 auto; }
.agent-emoji { width: 36px; height: 36px; border-radius: 10px; display: inline-grid; place-items: center; font-size: 18px; flex: 0 0 auto; }
.notice { border-left: 4px solid var(--accent); background: rgba(228,87,46,.07); padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.notice.info { border-color: var(--info); background: rgba(31,111,139,.08); }
.notice.ok { border-color: var(--ok); background: rgba(42,127,98,.08); }
.notice.warn { border-color: var(--warn); background: rgba(183,121,31,.1); }
.sample-bar { font-size: 12px; color: var(--warn); background: rgba(183,121,31,.1); padding: 6px 24px; border-bottom: 1px solid var(--line); }
.checkpoints { display: flex; gap: 6px; flex-wrap: wrap; }
.checkpoints .cp { font-size: 12px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); }
.checkpoints .cp.done { color: var(--ok); border-color: rgba(42,127,98,.4); background: rgba(42,127,98,.08); }
.checkpoints .cp.you { color: var(--accent); border-color: var(--accent); font-weight: 700; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 12px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit; font-size: 14px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; font-family: inherit; color: var(--ink); }
.chip:hover { border-color: var(--accent); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }
@media (max-width: 760px) { .kv { grid-template-columns: 1fr; } .kv dt { margin-top: 6px; } }
.funnel { display: grid; gap: 6px; }
.funnel .bar { display: grid; grid-template-columns: 170px 1fr 60px; align-items: center; gap: 10px; font-size: 13px; }
.funnel .bar .fill { height: 22px; border-radius: 6px; background: var(--navy); opacity: .85; }
.funnel .bar:last-child .fill { background: var(--accent); opacity: 1; }
.funnel .bar b { text-align: right; }
.spark { display: flex; gap: 6px; align-items: flex-end; height: 60px; }
.spark div { flex: 1; background: var(--navy); border-radius: 4px 4px 0 0; position: relative; min-height: 4px; }
.spark div span { position: absolute; top: -18px; left: 0; right: 0; text-align: center; font-size: 11px; font-weight: 700; }
.spark div small { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 10px; }

/* States */
.skeleton { display: grid; gap: 10px; padding: 6px 0; }
.sk-row { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: sk 1.2s infinite; }
.sk-row:nth-child(2) { width: 85%; } .sk-row:nth-child(3) { width: 60%; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.state { padding: 28px 18px; text-align: center; border-radius: var(--radius); }
.state-empty { background: var(--surface-2); color: var(--ink-2); }
.state-empty .empty-art { font-size: 34px; color: var(--muted); margin-bottom: 6px; }
.state-error { background: rgba(178,58,72,.08); border: 1px solid rgba(178,58,72,.3); }
.state p { margin: 6px 0 12px; }

/* Forms */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; }
.field label { font-weight: 600; font-size: 13px; }
.field input, .field select, .field textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); width: 100%; }
.field textarea { min-height: 90px; resize: vertical; }
.field .hint { font-size: 12px; color: var(--muted); }
.field .field-error { font-size: 12px; color: var(--bad); min-height: 14px; font-weight: 600; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--bad); }
.field input[aria-invalid="true"] { border-color: var(--bad); }
.form-success { background: rgba(42,127,98,.1); border: 1px solid rgba(42,127,98,.35); color: var(--ok); padding: 10px 12px; border-radius: 8px; font-weight: 600; }
.demo { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.demo select { font: inherit; font-size: 12px; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }

/* Drawer + modal */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(15,31,61,.35); z-index: 30; display: none; }
.drawer-backdrop.open { display: block; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface); z-index: 31; transform: translateX(100%); transition: transform .2s ease; overflow-y: auto; padding: 20px 22px 40px; box-shadow: -8px 0 30px rgba(0,0,0,.15); }
.drawer.open { transform: translateX(0); }
.drawer .close { position: absolute; top: 12px; right: 12px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; opacity: 0; transition: all .2s; z-index: 50; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 760px) { .toast { bottom: 80px; } }
.hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.never { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--ok); }
