/* Antimicrobial CDSS — ward UI. System fonts only: the hospital network may be offline. */
:root {
  color-scheme: light;
  --paper: #F4F7F6;      /* cool chart paper */
  --surface: #FFFFFF;
  --ink: #172B3A;        /* navy ink */
  --muted: #5B6B76;
  --rule: #D5DFDC;
  --ward: #17695A;       /* actions */
  --ward-soft: #E3F0EC;
  --alert: #B3261E;      /* allergy, high scores */
  --alert-soft: #FBE9E7;
  --amber: #8F5300;
  --amber-soft: #FFF3DC;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans", "Noto Sans Arabic", "Geeza Pro", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--font); }
body { min-height: 100vh; }
a { color: var(--ward); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
.num, td.n, .tabular { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid #2F80ED; outline-offset: 2px; }
[dir="rtl"] { unicode-bidi: plaintext; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 5; }
.brand { color: #fff; text-decoration: none; font-weight: 650; white-space: nowrap; }
.quicksearch { flex: 1; max-width: 520px; }
.quicksearch input { width: 100%; border: 0; border-radius: var(--radius); padding: 8px 12px; font: inherit; }
.toplink { color: #C9D8E3; font-size: .85rem; }

main { max-width: 1240px; margin: 0 auto; padding: 24px; outline: none; }

/* buttons and forms */
button, .btn { font: inherit; border-radius: var(--radius); border: 1px solid var(--ward); background: var(--ward); color: #fff;
  padding: 7px 14px; cursor: pointer; text-decoration: none; display: inline-block; }
button.secondary, .btn.secondary { background: var(--surface); color: var(--ward); }
button.quiet { background: none; border-color: transparent; color: var(--ward); padding: 4px 8px; }
button.icon { background: none; border: 0; color: var(--muted); font-size: 1.1rem; padding: 4px 8px; }
button:disabled { opacity: .55; cursor: progress; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 3px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 7px 9px; }
textarea { min-height: 110px; resize: vertical; }
input[type=checkbox] { width: auto; display: inline; margin-right: 6px; }
.check { display: flex; align-items: center; color: var(--ink); font-size: .9rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
fieldset { border: 1px solid var(--rule); border-radius: var(--radius); padding: 10px 14px 4px; margin: 4px 0 14px; }
legend { font-size: .85rem; color: var(--muted); padding: 0 4px; }
.hint { font-size: .8rem; color: var(--muted); margin: -4px 0 12px; }
.error { background: var(--alert-soft); color: var(--alert); border-radius: var(--radius); padding: 8px 12px; margin: 8px 0; white-space: pre-line; }
.note { background: var(--amber-soft); color: var(--amber); border-radius: var(--radius); padding: 8px 12px; margin: 8px 0; font-size: .9rem; }

/* tables */
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; background: var(--paper); }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--ward-soft); }
.scroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); }

/* search page */
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.5rem; }
.searchrow { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.searchrow input { flex: 1; min-width: 220px; }
.empty { padding: 28px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--rule); border-radius: var(--radius); }

/* the wristband: the patient header */
.band { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px; background: var(--surface);
  border: 1px solid var(--rule); border-left: 14px solid var(--ward); border-radius: 10px; padding: 14px 20px; margin-bottom: 18px; }
.band.allergic { border-left-color: var(--alert); }
.band .ident { font-size: .8rem; color: var(--muted); }
.band .ident strong { display: block; font-size: 1.15rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.band .names .ar { font-size: 1.5rem; font-weight: 650; text-align: left; }
.band .names .lat { color: var(--muted); }
.band .facts { font-size: .9rem; color: var(--muted); }
.allergy-strip { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--alert-soft);
  color: var(--alert); margin: 2px -20px -14px -6px; padding: 8px 20px 8px 6px; border-radius: 0 0 10px 0; font-weight: 600; font-size: .9rem; }
.allergy-strip .pill { background: var(--alert); color: #fff; }
.noallergy { grid-column: 1 / -1; font-size: .85rem; color: var(--muted); margin-top: -6px; }

.pill { display: inline-block; border-radius: 999px; padding: 1px 10px; font-size: .78rem; background: var(--ward-soft); color: var(--ward); white-space: nowrap; }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.bad { background: var(--alert-soft); color: var(--alert); }
.pill.grey { background: #EBEFF1; color: var(--muted); }

/* patient and stay layout */
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.section { margin-bottom: 26px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-bottom: 8px;
  border-bottom: 2px solid var(--ink); margin-bottom: 10px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--rule); display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.meta { font-size: .82rem; color: var(--muted); }

/* stay timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--rule); }
.timeline > li { position: relative; padding: 0 0 18px 16px; }
.timeline > li::before { content: ""; position: absolute; left: -25px; top: 6px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--ward); }
.timeline > li.lab::before { border-color: #3B6FB6; }
.timeline > li.medication::before { border-color: var(--alert); background: var(--alert); }
.timeline > li.procedure::before { border-color: var(--amber); }
.timeline .when { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline .what { font-weight: 600; }
.timeline .body { font-size: .92rem; }
.timeline table { margin-top: 6px; font-size: .85rem; }
.kv { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .9rem; }
.kv span b { font-variant-numeric: tabular-nums; }
.abn { color: var(--alert); font-weight: 650; }
.quote { white-space: pre-wrap; background: var(--paper); padding: 8px 10px; border-radius: var(--radius); margin: 4px 0; }

/* computed panel */
.panel { position: sticky; top: 70px; background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 16px; }
.panel h2 { margin-bottom: 4px; }
.panel .asof { display: flex; gap: 6px; align-items: center; font-size: .8rem; color: var(--muted); margin-bottom: 12px; flex-wrap: wrap; }
.panel .asof input { padding: 3px 6px; font-size: .8rem; }
.panel h3 { margin: 14px 0 6px; font-size: .82rem; color: var(--muted); font-weight: 600; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.metric { border: 1px solid var(--rule); border-radius: var(--radius); padding: 8px 10px; }
.metric .v { font-size: 1.45rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.1; }
.metric .v small { font-size: .75rem; font-weight: 500; color: var(--muted); }
.metric .l { font-size: .78rem; color: var(--muted); }
.metric.bad { border-color: var(--alert); background: var(--alert-soft); }
.metric.bad .v { color: var(--alert); }
.metric.warn { border-color: #E2B866; background: var(--amber-soft); }
.metric.incomplete .v { color: var(--muted); font-size: 1rem; }
.missing { font-size: .78rem; color: var(--amber); margin-top: 2px; }

/* drawer */
dialog#drawer { margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(620px, 100vw); border: 0; padding: 0;
  box-shadow: -8px 0 30px rgba(23, 43, 58, .18); background: var(--surface); color: var(--ink); }
dialog#drawer::backdrop { background: rgba(23, 43, 58, .35); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; background: var(--surface); z-index: 1; }
#drawer-body { padding: 18px 20px 28px; }
.formfoot { display: flex; gap: 8px; margin-top: 14px; }
.labrow { display: grid; grid-template-columns: 1.4fr .8fr .8fr .7fr .7fr .6fr auto; gap: 6px; margin-bottom: 6px; }
.labrow input, .labrow select { padding: 5px 6px; font-size: .88rem; min-width: 0; }
.labhead { font-size: .75rem; color: var(--muted); }
.proposal { display: flex; align-items: center; gap: 8px; padding: 4px 0; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 16px;
  border-radius: var(--radius); opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.on { opacity: 1; }

@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
  .panel { position: static; }
  .band { grid-template-columns: 1fr; gap: 8px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .labrow { grid-template-columns: 1fr 1fr 1fr; }
  main { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* tag checkboxes and selection bar */
.tagbox { display: flex; flex-wrap: wrap; gap: 4px 16px; background: var(--surface); }
.tagcheck { margin-bottom: 6px; cursor: pointer; }
.selbar { align-items: center; margin-bottom: 8px; }
.checkgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 2px 12px; margin-bottom: 10px; }
.checkgrid .check { margin-bottom: 4px; }
.checkgrid input:disabled + span { color: var(--muted); }
.comorb { margin-top: 6px; font-size: .9rem; }

/* Phase 2: prompts, infections, rule suggestions, cultures */
.prompt { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--amber-soft); border: 1px solid #E2B866; border-left: 6px solid var(--amber); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 12px; color: var(--ink); }
.prompt.due { background: var(--alert-soft); border-color: #E7A49E; border-left-color: var(--alert); }
.inf { background: var(--surface); border: 1px solid var(--rule); border-left: 5px solid var(--alert); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 10px; }
.inf-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.evid { list-style: none; padding: 0; margin: 6px 0 0; font-size: .88rem; }
.evid li { padding: 2px 0; }
.cand { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--rule); }
.warnc { color: var(--amber); }
td.warnc b { color: var(--amber); }
td.abn b { color: var(--alert); }
.iso { background: var(--paper); }
.astrow { display: grid; grid-template-columns: 1.6fr .6fr 1fr auto; gap: 6px; margin-bottom: 6px; }
.astrow input, .astrow select { padding: 5px 6px; font-size: .88rem; min-width: 0; }
#guard .error, #guard .note { margin: 6px 0; }

/* clinical-time field: the value and how precise it is */
.tfield { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: end; }
.tfield > select { margin-bottom: 10px; font-size: .82rem; padding: 6px; }
.tfield input:disabled { background: var(--paper); }

/* login, top links */
.toplinks { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.toplinks .meta { color: #A9BCCB; }
.whoami { color: #fff; font-size: .9rem; }
button.quiet.light { color: #C9D8E3; }
.login { max-width: 380px; margin: 60px auto; background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 24px 26px; }
.login h1 { font-size: 1.4rem; margin-bottom: 6px; }

/* review: the original report beside the draft */
.docview { width: calc(100% - 640px); min-width: 320px; height: 78vh; border: 1px solid var(--rule); border-radius: var(--radius); background: #fff; object-fit: contain; }
@media (max-width: 900px) { .docview { width: 100%; height: 60vh; } }

/* recommendations */
.rec { background: var(--surface); border: 1px solid var(--rule); border-left: 5px solid var(--ward); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 10px; }
.opt { border-top: 1px dashed var(--rule); padding: 8px 0 4px; }
.cite { margin: 4px 0; padding: 4px 10px; border-left: 3px solid var(--rule); font-size: .88rem; background: var(--paper); }
details summary { cursor: pointer; }
.abg { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 8px; }
.metrics.wide { grid-template-columns: repeat(4, 1fr); margin-bottom: 10px; }
@media (max-width: 900px) { .metrics.wide { grid-template-columns: 1fr 1fr; } }
a.btn.quiet { background: none; border-color: transparent; color: var(--ward); padding: 4px 8px; }
