/* OnCall — the physicians' app.
   Cardiology's own material: ECG paper by day, a monitor at night. Everything
   is served from this origin; no external font or stylesheet is ever loaded. */

@font-face { font-family: "Vazirmatn"; src: url("/fonts/vazirmatn-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("/fonts/vazirmatn-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --paper: #FDF6F3; --paper-2: #F6E9E4; --grid: #F0CEC4;
  --ink: #182838; --ink-2: #4E6377; --ink-3: #8496A8; --rule: #E2D2CC;
  --surface: #FFFBFA; --accent: #0F5C73; --on-accent: #FFFFFF;
  --em: #C0322B; --em-bg: #FBE8E6; --ur: #A55F13; --ur-bg: #FBEEDC;
  --ro: #2B6650; --ro-bg: #E3F0E9; --trace: #16303F;
  --shadow: 0 1px 2px rgba(24,40,56,.06), 0 6px 20px rgba(24,40,56,.08);
  --fa: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0D151D; --paper-2: #14212C; --grid: #1A2B38;
    --ink: #E6EFF5; --ink-2: #A5B8C7; --ink-3: #70879A; --rule: #243745;
    --surface: #111C26; --accent: #58C4DE; --on-accent: #06121A;
    --em: #FF7B6E; --em-bg: #3A1714; --ur: #F0B25B; --ur-bg: #33230E;
    --ro: #5FD3A2; --ro-bg: #0F2B20; --trace: #4FE0A8;
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0D151D; --paper-2: #14212C; --grid: #1A2B38;
  --ink: #E6EFF5; --ink-2: #A5B8C7; --ink-3: #70879A; --rule: #243745;
  --surface: #111C26; --accent: #58C4DE; --on-accent: #06121A;
  --em: #FF7B6E; --em-bg: #3A1714; --ur: #F0B25B; --ur-bg: #33230E;
  --ro: #5FD3A2; --ro-bg: #0F2B20; --trace: #4FE0A8;
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--fa); font-size: 16px; line-height: 1.6;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 10px 10px; background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* chrome */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; flex: 1; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pulse { width: 34px; height: 16px; flex: none; }
.pulse path { fill: none; stroke: var(--em); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.iconbtn { border: 1px solid var(--rule); background: var(--surface); border-radius: 12px; width: 42px; height: 42px; font-size: 20px; flex: none; }
.net { font-size: 12px; font-weight: 700; color: var(--ur); background: var(--ur-bg); padding: 3px 10px; border-radius: 999px; }
#view { max-width: 640px; margin: 0 auto; padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--surface); border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabs a { flex: 1; text-align: center; padding: 14px 4px; color: var(--ink-3); text-decoration: none; font-weight: 700; font-size: 14px; }
.tabs a.on { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.toast {
  position: fixed; inset-inline: 16px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); z-index: 30;
  background: var(--ink); color: var(--paper); padding: 12px 16px; border-radius: 14px; font-size: 14px;
  box-shadow: var(--shadow); max-width: 608px; margin: 0 auto;
}

/* building blocks */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: 18px; padding: 14px 16px; box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.muted { color: var(--ink-3); font-size: 13px; }
.lbl { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--ink-3); }
h1, h2, h3 { margin: 0; line-height: 1.35; text-wrap: balance; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

.btn { border: 1px solid var(--rule); background: var(--paper-2); border-radius: 14px; padding: 12px 16px; font-weight: 700; min-height: 48px; }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.danger { background: var(--em); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .45; cursor: default; }
.big {
  width: 100%; border: 0; border-radius: 22px; padding: 22px 16px; background: var(--em); color: #fff;
  font-size: 20px; font-weight: 700; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.big small { font-weight: 400; font-size: 13px; opacity: .9; }

.field { width: 100%; border: 1px solid var(--rule); background: var(--paper); border-radius: 14px; padding: 12px 14px; }
textarea.field { min-height: 110px; resize: vertical; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.p-wait { background: var(--ur-bg); color: var(--ur); }
.p-live { background: var(--ro-bg); color: var(--ro); }
.p-done { background: var(--paper-2); color: var(--ink-2); }
.p-off { background: var(--paper-2); color: var(--ink-3); }
.p-em { background: var(--em); color: #fff; }
.p-ur { background: var(--ur-bg); color: var(--ur); }
.p-ro { background: var(--ro-bg); color: var(--ro); }

.notice { border-radius: 14px; padding: 11px 14px; font-size: 14px; }
.notice.warn { background: var(--ur-bg); color: var(--ur); }
.notice.ok { background: var(--ro-bg); color: var(--ro); }
.notice.info { background: var(--paper-2); color: var(--ink-2); border: 1px dashed var(--rule); }
.notice.em { background: var(--em-bg); color: var(--em); }

.supply { display: flex; align-items: center; gap: 10px; border-radius: 14px; padding: 11px 14px; background: var(--ro-bg); color: var(--ro); font-weight: 700; font-size: 14px; }
.supply.thin { background: var(--ur-bg); color: var(--ur); }
.supply .dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex: none; }
.supply .grow { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px; padding: 4px 10px; font-size: 13px; display: inline-flex; gap: 6px; }
.chip .k { color: var(--ink-3); font-size: 11px; }
.chip.ro { background: var(--em-bg); color: var(--em); border-color: transparent; }

/* case lists */
.item { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--rule); border-radius: 16px; padding: 12px 14px; text-decoration: none; color: inherit; }
.item.live { border-color: var(--em); background: color-mix(in srgb, var(--em-bg) 55%, var(--surface)); }
.item.mine { border-color: var(--accent); }
.tag { font-family: var(--mono); font-size: 12px; font-weight: 700; background: var(--ink); color: var(--paper); border-radius: 8px; padding: 4px 8px; flex: none; white-space: nowrap; }
.item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.t1 { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t2 { font-size: 13px; color: var(--em); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t3 { font-size: 12px; color: var(--ink-3); }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.thumb { width: 64px; height: 48px; border-radius: 10px; object-fit: cover; background: var(--paper-2); border: 1px solid var(--rule); flex: none; }
.empty { text-align: center; color: var(--ink-3); padding: 22px 10px; font-size: 14px; }

/* new case */
.steps { display: flex; gap: 6px; }
.steps span { flex: 1; height: 4px; border-radius: 4px; background: var(--rule); }
.steps span.on { background: var(--accent); }
.canvas-wrap { position: relative; border-radius: 16px; overflow: hidden; border: 1px solid var(--rule); background: #000; touch-action: none; }
.canvas-wrap canvas { display: block; width: 100%; height: auto; }
.urgency { display: flex; flex-direction: column; gap: 10px; }
.ubtn { width: 100%; border: 0; border-radius: 18px; padding: 16px; display: flex; align-items: center; gap: 10px; text-align: start; min-height: 72px; }
.ubtn .u-top { font-size: 17px; font-weight: 700; display: block; }
.ubtn .u-sub { font-size: 13px; opacity: .9; display: block; }
.ubtn .grow { flex: 1; }
.ubtn .u-fee { font-family: var(--mono); font-size: 14px; font-weight: 700; white-space: nowrap; }
.ubtn[disabled] { opacity: .45; cursor: default; filter: grayscale(.4); }
.u-e { background: var(--em); color: #fff; }
.u-u { background: var(--ur-bg); color: var(--ur); }
.u-r { background: var(--ro-bg); color: var(--ro); }
.labelgrid { display: flex; flex-wrap: wrap; gap: 8px; }
.lopt { border: 1px solid var(--rule); background: var(--paper-2); border-radius: 12px; min-width: 48px; min-height: 44px; padding: 8px 12px; font-weight: 700; }
.lopt.on { background: var(--accent); color: var(--on-accent); border-color: transparent; }

/* a case */
.casehead { display: flex; flex-direction: column; gap: 8px; }
.verified { color: var(--ro); font-weight: 700; font-size: 14px; }
.verified .num { color: var(--ink-3); font-weight: 400; font-size: 12px; }
.clock { font-family: var(--mono); font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; letter-spacing: -.02em; }
.ladder { display: flex; flex-direction: column; gap: 6px; }
.rung { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px; color: var(--ink-3); font-size: 14px; }
.rung .d { width: 10px; height: 10px; border-radius: 50%; background: var(--rule); flex: none; }
.rung.done { color: var(--ink-2); } .rung.done .d { background: var(--ro); }
.rung.now { color: var(--ink); background: var(--paper-2); font-weight: 700; }
.rung.now .d { background: var(--em); animation: blip 1.1s infinite; }
@keyframes blip { 50% { opacity: .25; } }
.images { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.images img { height: 120px; border-radius: 12px; border: 1px solid var(--rule); background: var(--paper-2); }
.thread { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 86%; padding: 10px 13px; border-radius: 16px; font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-start; background: var(--accent); color: var(--on-accent); border-start-start-radius: 4px; }
.msg.them { align-self: flex-end; background: var(--surface); border: 1px solid var(--rule); border-start-end-radius: 4px; }
.msg img { max-width: 100%; border-radius: 10px; display: block; }
.msg-time { display: block; font-size: 11px; opacity: .7; margin-top: 3px; font-family: var(--mono); }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 48px; max-height: 160px; }
.quick { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.qr { border: 1px solid var(--rule); background: var(--paper-2); border-radius: 999px; padding: 8px 14px; font-size: 13px; white-space: nowrap; font-weight: 700; }
.qr.add { border-style: dashed; background: transparent; }
.decision { border-inline-start: 4px solid var(--ro); }
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(8,14,20,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet-inner { width: 100%; max-width: 640px; background: var(--surface); border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 12px; max-height: 92vh; overflow-y: auto; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; border: 1px solid var(--rule); background: var(--paper-2); border-radius: 12px; padding: 10px 6px; font-weight: 700; font-size: 14px; min-height: 46px; }
.seg button.on { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.viewer { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; align-items: center; justify-content: center; overflow: auto; touch-action: pinch-zoom pan-x pan-y; }
.viewer img { max-width: 100%; max-height: 100%; }

.switch { width: 56px; height: 32px; border-radius: 999px; background: var(--rule); border: 0; position: relative; flex: none; }
.switch i { position: absolute; top: 4px; inset-inline-start: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: inset-inline-start .18s; }
.switch.on { background: var(--ro); }
.switch.on i { inset-inline-start: 28px; }

/* the consult note — printable */
.note { background: #fff; color: #182838; border-radius: 16px; border: 1px solid var(--rule); padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.note-h { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; border-bottom: 2px solid #182838; padding-bottom: 10px; }
.note-h h1 { font-size: 20px; }
.note-row { display: flex; gap: 12px; border-bottom: 1px dotted #C9B8B1; padding: 6px 0; font-size: 14px; }
.note-k { color: #55697E; flex: 0 0 34%; }
.note-v { flex: 1; font-weight: 700; white-space: pre-wrap; overflow-wrap: anywhere; }
.sig { border: 1px solid #2B6650; border-radius: 12px; padding: 10px 12px; color: #2B6650; font-size: 14px; }
.disc { font-size: 12px; color: #55697E; line-height: 1.7; }

@media print {
  body { background: #fff; padding: 0; }
  .topbar, .tabs, .toast, .noprint { display: none !important; }
  #view { max-width: none; padding: 0; }
  .note { border: 0; box-shadow: none; padding: 0; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
