* { box-sizing: border-box; margin: 0; }
:root {
  --brand: #1f5c3d; --brand-2: #2e8b57; --brand-dark: #143d28;
  --accent: #2ee07a;
  --bg: #edf3ee; --card: #ffffff; --line: #d8e5da;
  --text: #1d2620; --muted: #68786d;
  --shadow: 0 1px 2px rgba(36, 31, 32, .05), 0 6px 20px rgba(36, 31, 32, .07);
  --ecg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='620' height='120' viewBox='0 0 620 120'%3E%3Cpath d='M0 60h96l8-14 10 28 8-52 10 76 8-38h8l6-10h64l8-14 10 28 8-52 10 76 8-38h8l6-10h64l8-14 10 28 8-52 10 76 8-38h8l6-10h130' fill='none' stroke='%23ffffff' stroke-opacity='.22' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --ecg-faint: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='620' height='120' viewBox='0 0 620 120'%3E%3Cpath d='M0 60h96l8-14 10 28 8-52 10 76 8-38h8l6-10h64l8-14 10 28 8-52 10 76 8-38h8l6-10h64l8-14 10 28 8-52 10 76 8-38h8l6-10h130' fill='none' stroke='%231f5c3d' stroke-opacity='.055' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px;
  background-image: var(--ecg-faint); background-repeat: repeat-x;
  background-position: center bottom 28px; background-attachment: fixed;
  min-height: 100vh;
}
.loading { padding: 3rem; text-align: center; color: var(--muted); }

/* ===== header ===== */
header.bar {
  background: linear-gradient(120deg, var(--brand-dark) 0%, var(--brand) 55%, var(--brand-2) 100%);
  background-blend-mode: normal;
  color: #fff; padding: .75rem 1rem; display: flex; align-items: center; gap: .7rem;
  position: sticky; top: 0; z-index: 10;
  box-shadow: 0 2px 14px rgba(20, 61, 40, .35);
  background-image: var(--ecg), linear-gradient(120deg, var(--brand-dark) 0%, var(--brand) 55%, var(--brand-2) 100%);
  background-repeat: repeat-x; background-position: right center;
}
.bar-logo { width: 30px; height: 30px; border-radius: 50%; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
header.bar h1 { font-size: 1.05rem; font-weight: 650; letter-spacing: .01em; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
header.bar button, header.bar a {
  background: rgba(255, 255, 255, .14); color: #fff; border: 1px solid rgba(255,255,255,.22);
  border-radius: 9px; padding: .45rem .8rem; font-size: .85rem; cursor: pointer;
  text-decoration: none; backdrop-filter: blur(4px); transition: background .15s;
}
header.bar button:hover, header.bar a:hover { background: rgba(255,255,255,.26); }

main { max-width: 880px; margin: 0 auto; padding: 1.1rem 1rem 4.5rem; }

/* ===== cards ===== */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 1.05rem 1.15rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card h2 { font-size: 1rem; margin-bottom: .6rem; }
.card h3 { font-size: .95rem; }

/* ===== login ===== */
.login-hero {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem;
  background:
    var(--ecg) repeat-x center 18%,
    var(--ecg) repeat-x center 82%,
    radial-gradient(1100px 500px at 85% -10%, rgba(46, 224, 122, .10), transparent 60%),
    linear-gradient(150deg, #0e1512 0%, #14251b 30%, var(--brand) 75%, var(--brand-2) 100%);
}
.login {
  max-width: 380px; width: 100%; margin: 0; text-align: left;
  border: 0; border-radius: 20px; padding: 2rem 1.8rem 1.8rem;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .38);
}
.login-logo { width: 84px; height: 84px; display: block; margin: 0 auto .8rem; border-radius: 50%; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.login h1 { text-align: center; color: var(--brand); margin-bottom: .15rem; font-size: 1.35rem; letter-spacing: .01em; }
.login-sub { text-align: center; color: var(--muted); font-size: .82rem; margin-bottom: 1rem; }

/* ===== inputs ===== */
label { display: block; font-size: .78rem; font-weight: 550; color: var(--muted); margin: .75rem 0 .25rem; letter-spacing: .01em; }
input, select, textarea {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 10px;
  font-size: 1rem; background: #fff; color: var(--text); transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(46, 139, 87, .2); }
input[readonly] { background: #eef3ef; color: #46504a; }
.computed input { border-style: dashed; }
.computed label::after { content: " · auto"; color: var(--brand-2); font-weight: 650; }

/* ===== buttons ===== */
button.primary {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  color: #fff; border: 0; border-radius: 12px; padding: .75rem 1.2rem; font-size: 1rem;
  font-weight: 600; cursor: pointer; width: 100%; margin-top: 1.1rem;
  box-shadow: 0 6px 16px rgba(31, 92, 61, .3); transition: transform .1s, box-shadow .15s;
}
button.primary:hover { box-shadow: 0 8px 22px rgba(31, 92, 61, .4); }
button.primary:active { transform: translateY(1px); background: var(--brand-dark); }
button.small {
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border: 0;
  border-radius: 9px; padding: .45rem .85rem; font-size: .85rem; font-weight: 600; cursor: pointer;
  box-shadow: 0 3px 10px rgba(31, 92, 61, .25);
}
button.ghost {
  background: #fff; color: var(--brand); border: 1px solid #a9cbb5; border-radius: 9px;
  padding: .42rem .8rem; font-size: .85rem; font-weight: 550; cursor: pointer; transition: background .12s;
}
button.ghost:hover { background: #eef6f0; }
button.danger { background: #fff; color: #b3261e; border: 1px solid #e2b6b3; border-radius: 9px; padding: .3rem .6rem; font-size: .8rem; cursor: pointer; }

/* ===== patient list ===== */
.search-row { display: flex; gap: .6rem; margin-bottom: 1rem; }
.search-row input { flex: 1; border-radius: 12px; box-shadow: var(--shadow); border-color: transparent; }
.pnote { color: var(--muted); font-size: .82rem; margin: -.5rem 0 .7rem; line-height: 1.5; }
.linky { background: none; border: none; padding: 0; color: var(--brand-2); font: inherit; font-weight: 700;
  text-decoration: underline; cursor: pointer; }
.plist { list-style: none; }
.plist li {
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--brand-2);
  border-radius: 12px; margin-bottom: .55rem; box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .15s;
}
.plist li:hover { transform: translateY(-1px); box-shadow: 0 4px 8px rgba(36,31,32,.07), 0 10px 26px rgba(36,31,32,.09); }
.plist a { display: block; padding: .75rem .95rem; text-decoration: none; color: var(--text); }
.plist .nm { font-weight: 650; }
.plist .sub { font-size: .82rem; color: var(--muted); margin-top: .18rem; }
.badge { display: inline-block; font-size: .7rem; font-weight: 600; background: #e6ede8; border-radius: 999px; padding: .13rem .55rem; margin-left: .4rem; color: #52605a; vertical-align: 1px; }
.badge.op { background: #dff2e6; color: #1f5c3d; }

/* ===== patient header ===== */
.phead { display: flex; justify-content: space-between; align-items: flex-start; gap: .6rem; }
.phead .nm { font-size: 1.2rem; font-weight: 750; letter-spacing: -.01em; }
.scores { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .6rem; }
.scores span {
  font-size: .78rem; font-weight: 600; color: #fff; border-radius: 999px; padding: .22rem .7rem;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 2px 8px rgba(31, 92, 61, .3);
}

/* ===== stage sections & logs ===== */
.section { display: flex; justify-content: space-between; align-items: center; padding: .72rem .25rem; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
.section .st { font-weight: 650; font-size: .95rem; }
.section .info { font-size: .8rem; color: var(--muted); margin-top: .12rem; }
.logrow { display: flex; justify-content: space-between; align-items: center; padding: .5rem .2rem .5rem 1rem; font-size: .88rem; border-bottom: 1px dashed var(--line); }

/* ===== forms ===== */
.formgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.1rem; }
@media (max-width: 640px) { .formgrid { grid-template-columns: 1fr; } }
.fullrow { grid-column: 1 / -1; }

/* ===== multiselect & photo ===== */
.multi { border: 1px solid var(--line); border-radius: 10px; padding: .45rem; display: flex; flex-wrap: wrap; gap: .3rem; background: #fff; }
.chk { display: inline-flex; align-items: center; gap: .32rem; border: 1px solid var(--line); border-radius: 999px; padding: .27rem .65rem; font-size: .85rem; cursor: pointer; user-select: none; transition: all .12s; }
.chk:has(input:checked) { background: linear-gradient(135deg, #e6f3ea, #eef8f1); border-color: var(--brand-2); color: var(--brand-dark); font-weight: 600; }
.chk input { width: auto; accent-color: var(--brand); }
.multi .addother { border: 1px dashed var(--line); border-radius: 999px; width: auto; flex: 1; min-width: 9rem; padding: .27rem .65rem; font-size: .85rem; }
.photo { border: 1px dashed #a9cbb5; border-radius: 12px; padding: .55rem; background: #fcfefc; }
.photo img { max-width: 100%; max-height: 180px; border-radius: 10px; display: block; margin-bottom: .4rem; box-shadow: var(--shadow); }
.photo input[type=file] { border: 0; padding: .2rem 0; }
.photo .preview { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }
.photo .pfile { display: inline-flex; align-items: center; gap: 4px; background: #f2f7f3; border: 1px solid #d8e8dd; border-radius: 9px; padding: 4px 6px; }
.photo .pfile img { max-height: 90px; max-width: 130px; margin: 0; }
.photo .pfx { border: 0; background: #e6b0ab; color: #5c1f1a; border-radius: 6px; padding: 2px 7px; font-weight: 700; cursor: pointer; }

/* ===== audit =====
   Two series carry meaning here — off pump and on pump — and the pair was
   checked for colour-blind separation against this white card (worst ΔE 8.4
   under tritanopia, 20.9 in normal vision). A third, absent class ("not
   recorded") is deliberately not a series colour: it is a hatched neutral, so
   a missing answer never looks like a finding. */
.audit-vars, main {
  --s-off: #1f7a4d;      /* off pump */
  --s-on:  #2a78d6;      /* on pump */
  --s-un:  #b9c3bc;      /* not recorded — absence, not a series */
  --s-vol: #46584e;      /* plain volume: deliberately not the pump greens or blues */
  --gridline: #e4ece6;
}
/* one filter row above everything it scopes, never inside a chart card */
.filters { display: flex; flex-wrap: wrap; gap: .5rem .7rem; align-items: center; margin-bottom: 1rem; }
.filters.dates { margin-top: -.5rem; }
.filters.dates label { margin: 0; }
.filters.dates input { width: auto; }
.fgrp { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
button.seg { background: #fff; border: 0; border-right: 1px solid var(--line); padding: .42rem .7rem; font-size: .82rem; color: var(--muted); cursor: pointer; font-weight: 550; }
button.seg:last-child { border-right: 0; }
button.seg.on { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 650; }
/* Names are as long as the surgeon's name, and there may be several, so these
   are separate pills that wrap — a segmented .fgrp clips whatever overflows. */
.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: .8rem; }
button.chip { display: inline-flex; align-items: center; gap: .38rem; background: #fff; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: .38rem .78rem; font-size: .82rem;
  font-weight: 550; cursor: pointer; box-shadow: var(--shadow); }
button.chip .cn { font-size: .74rem; font-weight: 650; opacity: .62; font-variant-numeric: tabular-nums; }
button.chip.on { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 650; border-color: transparent; }
button.chip.on .cn { opacity: .85; }
.card.warn { border-color: #e0a800; background: #fff9e8; }
.bkok { color: #1f7a4d; font-weight: 650; }
.bkbad { color: #b3261e; font-weight: 650; }
h2.sh { font-size: .78rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin: 1.5rem 0 .6rem .15rem; }

/* the one hero figure on the page — same sans as everything, proportional digits */
.hero { display: flex; align-items: baseline; gap: .75rem; margin-bottom: 1rem; }
.hero .hn { font-size: 3rem; font-weight: 700; line-height: 1; letter-spacing: -.03em; color: var(--brand); font-variant-numeric: proportional-nums; }
.hero .hl { font-size: .95rem; font-weight: 600; line-height: 1.35; }
.quiet { color: var(--muted); font-size: .85rem; font-weight: 400; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: .7rem .85rem; box-shadow: var(--shadow); }
.tile .tl { font-size: .74rem; color: var(--muted); font-weight: 550; line-height: 1.3; }
.tile .tv { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; margin: .15rem 0 .1rem; font-variant-numeric: proportional-nums; }
.tile .tn { font-size: .72rem; color: var(--muted); line-height: 1.35; }

/* ===== chart ===== */
.chart { position: relative; }
.legend { display: flex; flex-wrap: wrap; gap: .2rem .9rem; font-size: .76rem; color: var(--muted); margin-bottom: .35rem; }
.legend span { display: inline-flex; align-items: center; gap: .32rem; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw-off { background: var(--s-off); } .sw-on { background: var(--s-on); }
.sw-un { background: var(--s-un); background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.85) 0 1px, transparent 1px 3px); }
/* the SVG is drawn at its own pixel size, so these are real px */
.mchart { display: block; max-width: 100%; overflow: visible; }
.mchart .b-off { fill: var(--s-off); } .mchart .b-on { fill: var(--s-on); }
.mchart .b-un { fill: var(--s-un); }
.mchart .b-vol { fill: var(--s-vol); }
.mchart .grid { stroke: var(--gridline); stroke-width: 1; }   /* hairline, solid, recessive */
.mchart .ylab { font-size: 10px; fill: var(--muted); text-anchor: end; font-variant-numeric: tabular-nums; }
.mchart .xlab { font-size: 10px; fill: var(--muted); text-anchor: middle; }
.mchart .vlab { font-size: 13px; font-weight: 700; fill: var(--text); text-anchor: middle; }
.mchart .hit { fill: transparent; cursor: default; }
.mchart .hit:hover, .mchart .hit:focus { fill: rgba(31, 92, 61, .06); outline: none; }
.ctip { position: absolute; background: #241f20; color: #fff; font-size: .76rem; line-height: 1.4;
  padding: .35rem .55rem; border-radius: 8px; pointer-events: none; white-space: nowrap; z-index: 5;
  box-shadow: 0 6px 18px rgba(0,0,0,.28); }

/* ===== plain tables (the table view every chart needs) ===== */
table.gt { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.gt th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 650; padding: .3rem .45rem; border-bottom: 1px solid var(--line); }
table.gt td { padding: .38rem .45rem; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.gt td:first-child { font-variant-numeric: normal; }
table.gt tr:last-child td { border-bottom: 0; }
table.gt td + td, table.gt th + th { text-align: right; }
table.gt .of, .of { color: var(--muted); font-weight: 400; font-size: .82em; }
/* the safety net: a table that still cannot fit scrolls inside its own box,
   so the page itself never does */
.scrollx { overflow-x: auto; }
/* on a phone, tighten the tables before resorting to that scroll */
@media (max-width: 560px) {
  table.gt { font-size: .8rem; }
  table.gt td, table.gt th { padding: .34rem .28rem; }
  table.gt th { font-size: .66rem; letter-spacing: .03em; }
}
table.gt.cases { min-width: 50rem; }
table.gt .flag { color: #8a5a00; font-weight: 650; }
table.gt.cases td, table.gt.cases th { white-space: nowrap; }

/* ===== toast ===== */
#toast {
  position: fixed; bottom: 1.1rem; left: 50%; transform: translateX(-50%);
  background: #241f20; color: #fff; padding: .65rem 1.2rem; border-radius: 12px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 100; max-width: 90vw;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
