/* DIAGNODDS Companion — clean clinical UI. Self-contained, system fonts, light+dark. */
:root {
  --bg: #f6f4ef; --surface: #ffffff; --ink: #23303a; --muted: #7d8894;
  --line: #e7e3db; --teal: #0f766e; --teal-2: #0d9488;
  --amber: #b45309; --amber-bg: #fef3c7; --red: #b91c1c; --red-bg: #fee2e2;
  --ok: #15803d; --ok-bg: #dcfce7; --shadow: 0 1px 3px rgba(20,30,40,.07), 0 1px 2px rgba(20,30,40,.04);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#151b1f; --surface:#1d262b; --ink:#e7edf0; --muted:#93a1ab; --line:#2b363d;
    --teal:#2dd4bf; --amber:#f59e0b; --amber-bg:#3a2e12; --red:#f87171; --red-bg:#3a1c1c;
    --ok:#4ade80; --ok-bg:#16351f; --shadow:none; }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; font-size: .85em; }
.thin { font-weight: 300; }

/* topbar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: .7rem 1.2rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .7rem; }
.logo { font-size: 1.6rem; }
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.brand-sub { font-size: .74rem; color: var(--muted); }
.topbar-right { display: flex; gap: .5rem; align-items: center; }
.badge {
  font-size: .72rem; font-weight: 600; padding: .28rem .6rem; border-radius: 999px;
  background: var(--teal); color: #fff; letter-spacing: .02em;
}
.badge-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }

/* layout */
.workspace { max-width: 1180px; margin: 1.1rem auto; padding: 0 1.2rem; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }
.col { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 .7rem; font-size: .95rem; font-weight: 700; letter-spacing: -.01em; }

/* patient header */
.patient-header {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
  display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .4rem;
}
.ph-name { font-size: 1.25rem; font-weight: 700; }
.ph-meta { color: var(--muted); font-size: .9rem; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: .32rem .6rem; font-size: .84rem; white-space: nowrap;
}
.chip b { font-weight: 600; }
.chip.abn { border-color: var(--amber); background: var(--amber-bg); }

/* labs */
.lab-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: .6rem; align-items: center;
  padding: .4rem 0; border-bottom: 1px solid var(--line);
}
.lab-row:last-child { border-bottom: none; }
.lab-name { font-weight: 500; }
.lab-name .code { color: var(--muted); font-size: .78rem; margin-left: .35rem; }
.lab-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.lab-ref { color: var(--muted); font-size: .78rem; text-align: right; }
.spark { display: block; margin-top: 2px; }
.st-normal { }
.st-high, .st-low { color: var(--amber); }
.st-critical_high, .st-critical_low { color: var(--red); font-weight: 700; }
.pill { font-size: .68rem; padding: .1rem .4rem; border-radius: 6px; margin-left: .4rem; vertical-align: middle; }
.pill.high, .pill.low { background: var(--amber-bg); color: var(--amber); }
.pill.critical_high, .pill.critical_low { background: var(--red-bg); color: var(--red); }

/* verdict */
.verdict-card { border-top: 3px solid var(--teal); }
.summary-line { font-size: 1.02rem; font-weight: 600; margin-bottom: .7rem; }
.block-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: .8rem 0 .3rem; }
.flag {
  border-radius: 8px; padding: .5rem .7rem; margin: .35rem 0; font-size: .9rem;
  border-left: 4px solid var(--amber); background: var(--amber-bg);
}
.flag.CRITICO { border-left-color: var(--red); background: var(--red-bg); }
.flag .flag-name { font-weight: 700; }
.flag .flag-action { color: var(--ink); opacity: .85; font-size: .85rem; }
.dx { display: flex; gap: .5rem; padding: .4rem 0; border-bottom: 1px dashed var(--line); }
.dx:last-child { border-bottom: none; }
.dx .rank { font-weight: 700; color: var(--teal); min-width: 1.2rem; }
.dx .dx-name { font-weight: 600; }
.dx .dx-band { font-size: .72rem; color: var(--muted); }
.dx .dx-why { font-size: .82rem; color: var(--muted); }
.derived-item, .workup-item { font-size: .86rem; padding: .25rem 0; }
.derived-item.rf { color: var(--amber); font-weight: 600; }
.disposition { margin: .6rem 0; font-weight: 600; }
.disposition .u-emergent { color: var(--red); }
.disposition .u-urgent { color: var(--amber); }
.disposition .u-routine { color: var(--ok); }
.occult { margin: .6rem 0; padding: .5rem .7rem; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); font-size: .88rem; }
.occult.escalate { border-color: var(--amber); background: var(--amber-bg); }
.data-gaps { font-size: .8rem; color: var(--muted); margin-top: .6rem; }
.disclaimer { font-size: .74rem; color: var(--muted); margin-top: .8rem; border-top: 1px solid var(--line); padding-top: .5rem; }

/* lists */
.listblock { font-size: .88rem; margin: .3rem 0; }
.listblock .lb-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }

/* note */
.note-head { display: flex; justify-content: space-between; align-items: center; }
.note {
  width: 100%; min-height: 320px; margin-top: .5rem; padding: .8rem; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); color: var(--ink);
  font: 13px/1.5 "SF Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace; resize: vertical;
}

/* buttons */
.btn {
  background: var(--teal); color: #fff; border: none; border-radius: 8px; padding: .5rem .9rem;
  font-weight: 600; cursor: pointer; font-size: .88rem;
}
.btn:hover { filter: brightness(1.05); }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }

/* picker */
.picker { max-width: 720px; margin: 2rem auto; padding: 0 1.2rem; }
.picker h2 { margin-bottom: .2rem; }
.picker-search { display: flex; gap: .5rem; margin: 1rem 0; }
.picker-search input { flex: 1; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.picker-results { display: flex; flex-direction: column; gap: .4rem; }
.picker-row {
  display: flex; justify-content: space-between; align-items: center; padding: .6rem .8rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.picker-row:hover { border-color: var(--teal); }
.picker-row .pr-name { font-weight: 600; }
.picker-row .pr-meta { color: var(--muted); font-size: .84rem; }

/* view nav (Chart / Review) */
.viewnav { display: flex; gap: .2rem; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: .15rem; }
.navbtn {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font: 600 .8rem inherit; padding: .34rem .8rem; border-radius: 999px; display: inline-flex; align-items: center; gap: .35rem;
}
.navbtn.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.navcount { background: var(--amber); color: #fff; font-size: .66rem; font-weight: 700; border-radius: 999px; padding: 0 .38rem; min-width: 1.1rem; text-align: center; }

/* review screen */
.review { max-width: 1180px; margin: 1.1rem auto; padding: 0 1.2rem; }
.review-head h2 { margin: 0 0 .2rem; }
.review-head p { margin: 0 0 1rem; max-width: 70ch; }
.addbar { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
@media (max-width: 780px) { .addbar { grid-template-columns: 1fr; } }
.dropzone {
  border: 2px dashed var(--line); border-radius: 10px; background: var(--bg); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
  padding: 1.2rem; text-align: center; transition: .12s;
}
.dropzone:hover, .dropzone.over { border-color: var(--teal); background: var(--surface); }
.dz-ic { font-size: 1.5rem; }
.dz-main { font-size: .9rem; }
.dz-link { color: var(--teal); font-weight: 600; text-decoration: underline; }
.dz-sub { font-size: .74rem; color: var(--muted); }
.note-input { display: flex; flex-direction: column; gap: .5rem; }
.note-input textarea {
  flex: 1; min-height: 96px; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); font: inherit; font-size: .88rem; resize: vertical;
}
.note-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.btn-ghost { background: transparent; color: var(--teal); border: 1px solid var(--line); }
.btn-ghost.recording { background: var(--red-bg); color: var(--red); border-color: var(--red); }

.review-status { margin: 0 0 .8rem; padding: .55rem .8rem; border-radius: 8px; font-size: .86rem; background: var(--bg); border: 1px solid var(--line); }
.review-status.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.review-status.warn { background: var(--amber-bg); color: var(--amber); border-color: transparent; }
.review-status.err { background: var(--red-bg); color: var(--red); border-color: transparent; }

.review-summary { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.rs-pill { font-size: .8rem; font-weight: 600; padding: .3rem .7rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.rs-pill.st-implemented { background: var(--ok-bg); color: var(--ok); }
.rs-pill.st-review { background: var(--amber-bg); color: var(--amber); }
.rs-pill.st-doubt { background: var(--bg); color: var(--muted); }
.rs-pill.rs-accepted { background: var(--teal); color: #fff; border-color: transparent; }

.review-sec { margin-bottom: 1rem; }
.review-sec-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .5rem; }
.review-item {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: .7rem; align-items: center;
  padding: .55rem .2rem; border-bottom: 1px solid var(--line); border-left: 3px solid transparent; padding-left: .6rem;
}
.review-item:last-child { border-bottom: none; }
.review-item.st-implemented { border-left-color: var(--ok); }
.review-item.st-review { border-left-color: var(--amber); }
.review-item.st-doubt { border-left-color: var(--muted); }
.review-item.decided { opacity: .72; }
.review-item.dec-rejected { opacity: .5; }
.ri-badge { font-size: 1rem; }
.ri-label { font-weight: 600; font-size: .92rem; }
.ri-label .code { color: var(--muted); font-size: .74rem; margin-left: .3rem; font-weight: 400; }
.ri-src { color: var(--muted); font-size: .7rem; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 0 .35rem; margin-left: .3rem; }
.ri-atag { font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; border-radius: 6px; padding: .05rem .4rem; margin-left: .3rem; }
.ri-atag.a-negated, .ri-atag.a-ruled_out { background: var(--red-bg); color: var(--red); }
.ri-atag.a-history { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.ri-atag.a-suspected { background: var(--amber-bg); color: var(--amber); }
.ri-prov { font-size: .78rem; margin-top: .1rem; font-style: italic; }
.ri-val { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.ri-actions { display: flex; align-items: center; gap: .5rem; white-space: nowrap; }
.ri-dec { font-size: .82rem; font-weight: 600; color: var(--ok); }
.dec-rejected .ri-dec { color: var(--red); }
.linkbtn { background: none; border: none; color: var(--teal); cursor: pointer; font: inherit; font-size: .82rem; padding: .2rem; text-decoration: underline; }
.linkbtn:hover { filter: brightness(1.1); }
.review-empty { padding: 2rem; text-align: center; border: 1px dashed var(--line); border-radius: 10px; }
.review-apply { display: flex; align-items: center; gap: .8rem; margin: 1rem 0 2rem; }

.spin { display: inline-block; width: .8rem; height: .8rem; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* misc */
.loading { text-align: center; padding: 3rem; color: var(--muted); }
.error { max-width: 720px; margin: 2rem auto; padding: 1rem 1.2rem; background: var(--red-bg); color: var(--red); border-radius: 10px; }
.footer { text-align: center; color: var(--muted); font-size: .78rem; padding: 1.5rem; }
