/* Tema "Obsidian Clinical" (padrão em todas as páginas): escuro neutro e fosco, para a sala de laudo.
   Claro com data-theme="claro" (preferência guardada no navegador). Cores de estado: ativo #3B82F6,
   confirmado #10B981, possível/aviso #F59E0B, erro/rejeitado #EF4444. */
:root {
  --bg: #0d0f12; --sidebar: #12151b; --surface: #16191e; --surface-2: #1f232b; --text: #e3e7ed; --muted: #8a94a3;
  --border: #232730; --accent: #3b82f6; --accent-text: #ffffff;
  --pos: #ef4444; --pos-bg: rgb(239 68 68 / 16%); --possible: #f59e0b; --possible-bg: rgb(245 158 11 / 16%);
  --neg: #10b981; --neg-bg: rgb(16 185 129 / 15%); --warn-bg: rgb(245 158 11 / 12%); --warn-text: #f5c26b;
  --radius: 8px; --sb-full: 248px; --sb-rail: 64px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
:root[data-theme="claro"] {
  --bg: #f5f6f8; --sidebar: #eceff3; --surface: #ffffff; --surface-2: #eef0f3; --text: #1b1f24; --muted: #5b6470;
  --border: #d9dde3; --accent: #1f5fae; --accent-text: #ffffff;
  --pos: #b42318; --pos-bg: #fde8e7; --possible: #9a5b00; --possible-bg: #fff1d6;
  --neg: #22663a; --neg-bg: #e3f3e8; --warn-bg: #fff4e5; --warn-text: #7a4a00;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
a { color: var(--accent); }
header.bar {
  display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2;
}
header.bar h1 { font-size: 16px; margin: 0; font-weight: 600; }
header.bar .spacer { flex: 1; }
header.bar .who { color: var(--muted); font-size: 13px; }
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.banner {
  background: var(--warn-bg); color: var(--warn-text); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 16px; font-size: 14px;
}
button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: var(--radius); cursor: pointer;
}
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--surface-2); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.positivo { background: var(--pos-bg); color: var(--pos); }
.chip.possivel { background: var(--possible-bg); color: var(--possible); }
.chip.negativo { background: var(--neg-bg); color: var(--neg); }
.chip.nao_avaliavel { background: var(--surface); color: var(--muted); border: 1px dashed var(--border); }
.chip.pending { background: var(--surface-2); color: var(--muted); }
.chip.draft { background: var(--possible-bg); color: var(--possible); }
.chip.signed { background: var(--neg-bg); color: var(--neg); }
.muted { color: var(--muted); }
.filters { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; flex-wrap: wrap; }

/* revisão */
.review { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr); gap: 20px; align-items: start; }
@media (max-width: 1000px) { .review { grid-template-columns: 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.viewer { position: sticky; top: 64px; }
.viewer img { width: 100%; height: auto; display: block; background: #000; border-radius: 6px; min-height: 200px; }
.controls { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin-top: 10px; font-size: 14px; }
.controls label { display: flex; gap: 6px; align-items: center; }
.bar-prob { height: 6px; background: var(--surface-2); border-radius: 3px; width: 70px; display: inline-block; vertical-align: middle; }
.bar-prob > span { display: block; height: 100%; border-radius: 3px; background: var(--muted); }
.decision { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.decision input { position: absolute; opacity: 0; pointer-events: none; }
.decision label { padding: 4px 9px; font-size: 13px; cursor: pointer; border-right: 1px solid var(--border); user-select: none; }
.decision label:last-child { border-right: 0; }
.decision input:checked + label.present { background: var(--pos-bg); color: var(--pos); font-weight: 600; }
.decision input:checked + label.absent { background: var(--neg-bg); color: var(--neg); font-weight: 600; }
.decision input:checked + label.uncertain { background: var(--possible-bg); color: var(--possible); font-weight: 600; }
.decision input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -2px; }
textarea { width: 100%; min-height: 260px; font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.status-line { font-size: 13px; color: var(--muted); margin-right: auto; }
.error { color: var(--pos); font-size: 14px; }
h2 { font-size: 15px; margin: 0 0 10px; }

/* login */
.login { max-width: 360px; margin: 12vh auto; }
.login h1 { font-size: 18px; margin: 0 0 4px; }
.login .intro { margin: 0 0 16px; }
.login form { display: grid; gap: 12px; }
.login .sso { display: block; text-align: center; text-decoration: none; margin-bottom: 16px; }
.login .sso[hidden], .login form[hidden] { display: none; }
.login label { display: grid; gap: 4px; }
.login input { font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); }
.stacked { margin-top: 16px; }
.spacer { flex: 1; }
td code { white-space: nowrap; }
.pct { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); min-width: 3ch; display: inline-block; text-align: right; }
.ai-cell { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.patient { margin-bottom: 16px; border-color: var(--accent); }
.patient dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 14px; }
.patient dt { color: var(--muted); }
.patient dd { margin: 0; font-weight: 600; }
.notice { background: var(--neg-bg); color: var(--neg); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }
.notice.ai-change { background: var(--warn-bg); color: var(--warn-text); }
.notice.ai-change ul { margin: 6px 0; padding-left: 20px; }
.notice.ai-change p { margin: 6px 0 0; }

/* navegação e administração */
header.bar .nav { display: flex; gap: 14px; font-size: 14px; }
header.bar .nav a { text-decoration: none; color: var(--muted); }
header.bar .nav a[aria-current="page"] { color: var(--text); font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 14px; }
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); font-weight: 600; }
.chip.ok { background: var(--neg-bg); color: var(--neg); }
.chip.off { background: var(--surface-2); color: var(--muted); }
.chip.alert { background: var(--pos-bg); color: var(--pos); }
.chip.warn { background: var(--possible-bg); color: var(--possible); }
/* Triagem: exame sinalizado, a ler primeiro (lista de trabalho). */
.chip.priority { background: var(--pos); color: #fff; margin-bottom: 4px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-actions button { padding: 4px 10px; font-size: 13px; }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 20px; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog h2 { margin-bottom: 14px; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 14px; }
.form input, .form select { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); }
.form .hint { font-size: 12px; color: var(--muted); }
.secret { display: flex; gap: 8px; align-items: center; margin: 12px 0; }
.secret code { font-size: 18px; padding: 8px 12px; background: var(--surface-2); border-radius: var(--radius);
  user-select: all; overflow-wrap: anywhere; }
.narrow { max-width: 420px; margin: 8vh auto; }
dialog.wide { width: min(980px, calc(100vw - 32px)); }
.detail-section { margin-bottom: 18px; }
.detail-section h3 { font-size: 14px; margin: 0 0 8px; }
.detail-section table { font-size: 13px; }
.history-entry { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 6px; }
.history-entry summary { cursor: pointer; padding: 6px 10px; font-size: 13px; }
.history-entry pre { margin: 0; padding: 10px; white-space: pre-wrap; font-size: 13px; background: var(--surface-2);
  border-top: 1px solid var(--border); }
.small { font-size: 12px; }
.detail-cell { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); max-width: 520px;
  overflow-wrap: anywhere; }
.verify { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.verify.ok { background: var(--neg-bg); color: var(--neg); }
.verify.fail { background: var(--pos-bg); color: var(--pos); }
.verify ul { margin: 6px 0 0; padding-left: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.card .value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card .label { font-size: 13px; color: var(--muted); }
.quality-block { margin-bottom: 28px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.few td { color: var(--muted); }
.alert-list { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 6px; }
.alert-list li { border-radius: var(--radius); padding: 8px 12px; font-size: 14px; }
.alert-list li.firing { background: var(--pos-bg); color: var(--pos); }
.alert-list li.pending { background: var(--possible-bg); color: var(--possible); }
.alert-list .small { display: block; }
.card.bad .value { color: var(--pos); }
.card.warn .value { color: var(--possible); }

/* ---------------------------------------------------------------- barra lateral (todas as páginas) */
body.with-sidebar { display: grid; grid-template-columns: var(--sb-full) minmax(0, 1fr); grid-template-rows: auto 1fr;
  min-height: 100vh; transition: grid-template-columns 0.2s ease-in-out; }
body.with-sidebar[data-sidebar="rail"] { grid-template-columns: var(--sb-rail) minmax(0, 1fr); }
body.with-sidebar > :not(.sidebar):not(dialog) { grid-column: 2; min-width: 0; }
body.with-sidebar > main { width: 100%; }
.sidebar { grid-column: 1; grid-row: 1 / span 99; position: sticky; top: 0; height: 100vh; overflow: hidden auto;
  display: flex; flex-direction: column; gap: 10px; padding: 12px 10px; background: var(--sidebar);
  border-right: 1px solid var(--border); z-index: 5; }
.sidebar .sb-ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.sb-head { display: flex; align-items: center; gap: 6px; }
.sb-logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; flex: 1;
  padding: 6px 8px; min-width: 0; }
.sb-toggle { padding: 6px; border: 0; background: none; color: var(--muted); display: grid; }
.sb-toggle:hover { color: var(--text); background: var(--surface-2); }
.sb-env { align-self: flex-start; margin-left: 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.sb-env.clinical { background: var(--neg-bg); color: var(--neg); }
.sb-nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sb-nav a { position: relative; display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: var(--radius);
  color: var(--muted); text-decoration: none; font-size: 14px; white-space: nowrap; }
.sb-nav a:hover { background: var(--surface-2); color: var(--text); }
.sb-nav a.active { background: rgb(59 130 246 / 14%); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.sb-badge { margin-left: auto; min-width: 22px; padding: 1px 7px; border-radius: 999px; font: 600 12px var(--mono);
  text-align: center; background: var(--surface-2); color: var(--text); }
.sb-badge:empty { display: none; }
.sb-badge.alert { background: var(--pos); color: #fff; }
.sb-badge.warn { background: var(--possible-bg); color: var(--possible); }
.sb-exam { border-top: 1px solid var(--border); padding-top: 10px; display: grid; gap: 8px; align-content: start;
  overflow: hidden auto; flex: 1; min-height: 0; }
.sb-exam:empty, .sb-exam[hidden] { display: none; }
.sb-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 10px; display: grid; gap: 8px; }
.sb-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sb-avatar { position: relative; flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text); font-weight: 700; font-size: 13px; }
.sb-conn { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--sidebar); background: var(--muted); }
.sb-conn.ok { background: var(--neg); }
.sb-conn.off { background: var(--pos); }
.sb-who { display: grid; min-width: 0; font-size: 13px; }
.sb-who > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-ok { color: var(--neg); }
.sb-warn { color: var(--possible); }
.sb-prefs { display: flex; flex-wrap: wrap; gap: 6px; }
.sb-prefs button, .sb-prefs .btn { padding: 4px 9px; font-size: 12px; }
/* Só ícones: rótulos, ambiente e preferências somem; os contadores viram um ponto sobre o ícone. */
.sidebar[data-mode="rail"] .sb-label, .sidebar[data-mode="rail"] .sb-env { display: none; }
.sidebar[data-mode="rail"] .sb-head { flex-direction: column; }
.sidebar[data-mode="rail"] .sb-toggle svg { transform: rotate(180deg); }
.sidebar[data-mode="rail"] .sb-nav a { justify-content: center; padding: 10px 0; }
.sidebar[data-mode="rail"] .sb-badge { position: absolute; top: 2px; right: 4px; min-width: 16px; padding: 0 4px; font-size: 10px; }
.sidebar[data-mode="rail"] .sb-user { justify-content: center; }
@media (max-width: 800px) {
  body.with-sidebar, body.with-sidebar[data-sidebar] { grid-template-columns: var(--sb-rail) minmax(0, 1fr); }
  .sidebar .sb-label, .sidebar .sb-env { display: none; }
}

/* Números em largura fixa (contagens, tempos, probabilidades) e tabelas no padrão escuro. */
.num, td.num, .pct, .card .value, .sb-badge, code { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.card .value { font-family: var(--font); }
table { border: 1px solid var(--border); }
tr.link:hover td { background: var(--surface-2); }
th { background: var(--sidebar); }

/* Filtros rápidos (botões segmentados) */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--border); background: var(--surface); color: var(--muted); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: rgb(59 130 246 / 16%); color: var(--text); font-weight: 600; }
.seg .n { font: 12px var(--mono); color: var(--muted); margin-left: 4px; }
.filters input[type=search], .filters select { background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 7px 10px; font: inherit; min-width: 220px; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
td .chips { max-width: 340px; }
td .chips .chip { white-space: normal; }
th.num { text-align: right; }

/* Marca RadIA na barra: logotipo completo (expandida) ou só o símbolo (ícones), na versão do tema. */
.sb-logo img { display: block; }
.sb-logo .logo-full { height: 34px; width: auto; }
.sb-logo .logo-icon { width: 34px; height: 34px; display: none; }
.sb-logo .logo-on-light { display: none; }
:root[data-theme="claro"] .sb-logo .logo-on-dark { display: none; }
:root[data-theme="claro"] .sb-logo .logo-on-light { display: block; }
.sidebar[data-mode="rail"] .sb-logo .logo-full { display: none !important; }
.sidebar[data-mode="rail"] .sb-logo .logo-icon { display: block; }
.sidebar[data-mode="rail"] .sb-logo { padding: 2px 0; justify-content: center; }
.sb-toggle .icon:last-child { display: none; }
.sidebar[data-mode="rail"] .sb-toggle .icon:first-child { display: none; }
.sidebar[data-mode="rail"] .sb-toggle .icon:last-child { display: block; }
.sidebar[data-mode="rail"] .sb-toggle svg { transform: none; }
.sb-prefs button, .sb-prefs .btn { display: inline-flex; align-items: center; gap: 5px; text-decoration: none; }
.icon { flex: none; vertical-align: middle; }
button .icon, .btn .icon { margin-right: 2px; }
/* Estado vazio: um check discreto, sem alarde. */
.empty-state { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.empty-state .icon { color: #3a4150; }
/* Modalidade (CR, DX, CT, MR, MG) em fonte de largura fixa. */
.modality { display: inline-block; font: 600 11px var(--mono); padding: 1px 6px; border-radius: 4px; margin-right: 6px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.login-logo { height: 44px; margin-bottom: 12px; }
.login .logo-on-light { display: none; }
:root[data-theme="claro"] .login .logo-on-dark { display: none; }
:root[data-theme="claro"] .login .logo-on-light { display: block; }
