/* Iris — v0.12
 *
 * A clinician reads this between patients, so the job is information design
 * rather than decoration: what is dangerous has to be visible before anything
 * is read. Allergies sit above everything, severity carries colour, and an
 * out-of-range result is legible without checking the reference beside it.
 *
 * The palette is cool and desaturated on purpose. Red and amber are reserved
 * for clinical severity and are never spent on branding or chrome, so that when
 * something is red it means something.
 */

:root {
  --paper:      #F4F6F6;
  --card:       #FFFFFF;
  --ink:        #131A1E;
  --soft:       #4B565E;
  --faint:      #79858D;
  --rule:       #DCE2E1;
  --rule-soft:  #EBEFEE;

  --iris:       #4A44AE;      /* the one brand colour */
  --iris-bg:    #ECEBF7;

  --danger:     #A93520;      /* severe / critical */
  --danger-bg:  #F9E8E3;
  --warn:       #8A5A12;      /* out of range */
  --warn-bg:    #FBF0DC;
  --ok:         #1C6B58;
  --ok-bg:      #E3F0EC;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --shadow: 0 1px 2px rgba(19,26,30,.05), 0 6px 20px -14px rgba(19,26,30,.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:     #0F1316;
    --card:      #161B1F;
    --ink:       #E5EAE9;
    --soft:      #A2AEB4;
    --faint:     #78848B;
    --rule:      #293037;
    --rule-soft: #1F262C;
    --iris:      #9891EE;
    --iris-bg:   #1D1D33;
    --danger:    #E8927A;
    --danger-bg: #2C1712;
    --warn:      #D9AE63;
    --warn-bg:   #2A2113;
    --ok:        #5CBBA2;
    --ok-bg:     #12231F;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px -14px rgba(0,0,0,.8);
  }
}

*, *::before, *::after { box-sizing: border-box; }

/* Any rule that sets `display` on an element silently defeats the browser's
   own [hidden] styling. Every panel here sets display, so state this once
   rather than remembering it at each call site. */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.screen { height: 100%; }
.centred { display: grid; place-items: center; padding: 1.5rem; }
.spacer { flex: 1; }
.muted { color: var(--faint); }
.small { font-size: .8rem; }

/* --- sign in ------------------------------------------------------------ */
.panel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 5px;
  box-shadow: var(--shadow);
  padding: 1.9rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
}
.narrow { width: min(24rem, 100%); }
.panel h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.02em; }
.panel .sub { margin: 0 0 .9rem; color: var(--faint); font-size: .88rem; }

.tag {
  display: inline-block; font-family: var(--mono); font-size: .68rem;
  padding: .1rem .4rem; border: 1px solid var(--rule); border-radius: 2px;
  color: var(--faint); vertical-align: middle;
}

label { font-size: .78rem; font-weight: 600; color: var(--soft); margin-top: .45rem; }
input {
  font: inherit; padding: .55rem .7rem; border-radius: 3px;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink);
  width: 100%;
}
input:focus-visible { outline: 2px solid var(--iris); outline-offset: 1px; }

button {
  font: inherit; cursor: pointer; border-radius: 3px; border: 1px solid transparent;
  padding: .55rem .9rem; background: var(--iris); color: #fff;
}
button:focus-visible { outline: 2px solid var(--iris); outline-offset: 2px; }
button[disabled] { opacity: .55; cursor: default; }
button.ghost {
  background: transparent; color: var(--soft); border-color: var(--rule);
  padding: .35rem .7rem; font-size: .82rem;
}
button.ghost:hover:not([disabled]) { color: var(--ink); border-color: var(--faint); }
button.ghost[aria-pressed="true"] { background: var(--iris-bg); color: var(--iris); border-color: var(--iris); }

#signin-btn { margin-top: 1rem; }
#demo-btn { margin-top: .5rem; }
.error {
  margin: .7rem 0 0; padding: .5rem .7rem; border-radius: 3px;
  background: var(--danger-bg); color: var(--danger); font-size: .86rem;
  border-left: 2px solid var(--danger);
}
.footnote { margin: 1rem 0 0; font-size: .76rem; color: var(--faint); }

.clinic-list { display: flex; flex-direction: column; gap: .5rem; margin: .3rem 0 1rem; }
.clinic {
  text-align: left; background: var(--card); color: var(--ink);
  border: 1px solid var(--rule); padding: .7rem .85rem;
  display: flex; flex-direction: column; gap: .15rem;
}
.clinic:hover { border-color: var(--iris); background: var(--iris-bg); }
.clinic .role { font-size: .76rem; color: var(--faint); font-family: var(--mono); }

/* --- shell -------------------------------------------------------------- */
#main { display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem 1rem; background: var(--card);
  border-bottom: 1px solid var(--rule); flex: none;
}
.brand { font-size: 1.02rem; letter-spacing: -.01em; }
.body { flex: 1; display: grid; grid-template-columns: 19rem 1fr; min-height: 0; }
.body:has(#assistant:not([hidden])) { grid-template-columns: 19rem 1fr 25rem; }

/* --- patient list ------------------------------------------------------- */
.sidebar {
  border-right: 1px solid var(--rule); background: var(--card);
  display: flex; flex-direction: column; min-height: 0;
}
.search { padding: .7rem; border-bottom: 1px solid var(--rule-soft); }
.patients { overflow-y: auto; flex: 1; }
.patient {
  width: 100%; text-align: left; background: transparent; color: var(--ink);
  border: 0; border-bottom: 1px solid var(--rule-soft); border-radius: 0;
  padding: .6rem .8rem; display: flex; flex-direction: column; gap: .1rem;
}
.patient:hover { background: var(--paper); }
.patient[aria-current="true"] { background: var(--iris-bg); box-shadow: inset 2px 0 0 var(--iris); }
.patient .who { font-weight: 600; font-size: .92rem; }
.patient .meta { font-family: var(--mono); font-size: .74rem; color: var(--faint); }
.list-note { padding: 1rem .8rem; color: var(--faint); font-size: .84rem; }

/* --- chart -------------------------------------------------------------- */
.chart { overflow-y: auto; padding: 1.4rem 1.6rem 3rem; min-height: 0; }
.empty { display: grid; place-content: center; height: 100%; text-align: center; gap: .3rem; }

.chart-head { display: flex; align-items: baseline; gap: .8rem; flex-wrap: wrap; margin-bottom: .3rem; }
.chart-head h2 { margin: 0; font-size: 1.5rem; letter-spacing: -.015em; }
.chart-head .ids { font-family: var(--mono); font-size: .8rem; color: var(--faint); }
.chart-sub { margin: 0 0 1.3rem; color: var(--soft); font-size: .88rem; }

section.block { margin-bottom: 1.5rem; }
section.block > h3 {
  margin: 0 0 .55rem; font-size: .74rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--faint); font-weight: 650;
}
.cards { display: grid; gap: .5rem; }
.row {
  background: var(--card); border: 1px solid var(--rule); border-radius: 4px;
  padding: .6rem .8rem; display: flex; gap: .8rem; align-items: baseline; flex-wrap: wrap;
}
.row .name { font-weight: 600; }
.row .detail { color: var(--soft); font-size: .88rem; }
.row .code { font-family: var(--mono); font-size: .76rem; color: var(--faint); }
.row .right { margin-left: auto; font-family: var(--mono); font-size: .78rem; color: var(--faint); }

/* Severity is the only thing allowed to shout. */
.row.severe { border-left: 3px solid var(--danger); background: var(--danger-bg); }
.row.severe .name { color: var(--danger); }
.pill {
  font-family: var(--mono); font-size: .7rem; padding: .08rem .4rem;
  border-radius: 2px; border: 1px solid currentColor;
}
.pill.danger { color: var(--danger); background: var(--danger-bg); }
.pill.warn   { color: var(--warn);   background: var(--warn-bg); }
.pill.ok     { color: var(--ok);     background: var(--ok-bg); }
.pill.flat   { color: var(--faint); background: var(--rule-soft); border-color: var(--rule); }

.vitals { display: grid; grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); gap: .5rem; }
.vital {
  background: var(--card); border: 1px solid var(--rule); border-radius: 4px; padding: .55rem .7rem;
}
.vital .k { font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.vital .v { font-family: var(--mono); font-size: 1.05rem; font-variant-numeric: tabular-nums; }

table.results { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.results th {
  text-align: left; font-size: .72rem; letter-spacing: .07em; text-transform: uppercase;
  color: var(--faint); font-weight: 650; padding: .35rem .6rem; border-bottom: 1px solid var(--rule);
}
table.results td { padding: .45rem .6rem; border-bottom: 1px solid var(--rule-soft); }
table.results td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.scroll-x { overflow-x: auto; }

/* --- assistant ---------------------------------------------------------- */
.assistant {
  border-left: 1px solid var(--rule); background: var(--card);
  display: flex; flex-direction: column; min-height: 0;
}
.assistant[hidden] { display: none; }
.assistant-head {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem .8rem; border-bottom: 1px solid var(--rule-soft);
}
.assistant-head b { font-size: .92rem; }
.ai-log { flex: 1; overflow-y: auto; padding: .8rem; display: flex; flex-direction: column; gap: .6rem; }
.ai-turn { display: flex; flex-direction: column; gap: .2rem; }
.ai-who { font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.ai-bubble {
  border: 1px solid var(--rule); border-radius: 4px; padding: .55rem .7rem;
  white-space: pre-wrap; font-size: .89rem; background: var(--paper);
}
.ai-turn.you .ai-bubble { background: var(--iris-bg); border-color: var(--iris); }
.ai-tool {
  font-family: var(--mono); font-size: .74rem; color: var(--soft);
  border: 1px solid var(--rule); border-left: 2px solid var(--iris);
  border-radius: 0 3px 3px 0; padding: .35rem .55rem;
  display: flex; gap: .4rem; flex-wrap: wrap; align-items: baseline;
}
.ai-tool.failed { border-left-color: var(--danger); background: var(--danger-bg); color: var(--danger); }
.ai-tool .t { color: var(--iris); font-weight: 600; }
.ai-tool.failed .t { color: var(--danger); }
.ai-tool .d { margin-left: auto; color: var(--faint); }
.ai-wait { font-size: .8rem; color: var(--faint); font-style: italic; }
.ai-form { display: flex; gap: .5rem; padding: .7rem; border-top: 1px solid var(--rule-soft); }
.ai-form input { flex: 1; }
.assistant .footnote { padding: 0 .7rem .7rem; margin: 0; }

.assistant.off .ai-form, .assistant.off .ai-log { opacity: .5; pointer-events: none; }

/* --- narrow ------------------------------------------------------------- */
@media (max-width: 60rem) {
  .body, .body:has(#assistant:not([hidden])) { grid-template-columns: 1fr; }
  .sidebar { max-height: 14rem; }
  .assistant { border-left: 0; border-top: 1px solid var(--rule); max-height: 24rem; }
}
