:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #17212e;
  --muted: #5d6b7c;
  --line: #dfe5ec;
  --accent: #f2c200;          /* highlight */
  --accent-ink: #1a1a1a;
  --brand: #13263f;
  --live: #1f9d61;
  --danger: #c23b3b;
  --me: #e7eefc;
  --pt: #ffffff;
  --sheet: #fffdf7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 28, 45, .06), 0 8px 24px rgba(16, 28, 45, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .4rem; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

.btn {
  font: inherit; font-weight: 600; border-radius: 10px; padding: .65rem 1.1rem; cursor: pointer;
  border: 1px solid transparent; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1d3658; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: #e9eef4; }
.btn-ghost.on { background: #fff4cc; border-color: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a83030; }

/* ---- brand ---- */
.brand { display: flex; gap: .7rem; align-items: center; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 20px; height: 20px; }
.brand-title { font-weight: 700; }
.brand-sub { font-size: .8rem; color: var(--muted); }

/* ---- login ---- */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 420px; background: var(--card); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { margin-top: 1.4rem; font-size: 1.35rem; }
.login-form { display: grid; gap: .5rem; margin-top: 1rem; }
.login-form label { font-weight: 600; font-size: .9rem; }
input[type=password], input[type=text] {
  font: inherit; padding: .7rem .85rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.form-error { color: var(--danger); margin: .2rem 0; font-size: .9rem; }
.login-form .btn { margin-top: .5rem; }

/* ---- top bar ---- */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line); }

/* ---- pick a patient ---- */
.pick { max-width: 980px; margin: 0 auto; padding: 32px 16px; }
.name-field { display: grid; gap: .35rem; max-width: 420px; margin: 1.2rem 0 1.4rem; font-weight: 600; font-size: .9rem; }
.cases { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.case {
  font: inherit; text-align: left; color: inherit; cursor: pointer; display: flex; gap: 16px; align-items: stretch;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s;
}
.case:hover { transform: translateY(-2px); border-color: var(--accent); }
.case-face { width: 120px; flex: none; border-radius: 10px; overflow: hidden; background: #e6ecf2; }
.case-face svg { display: block; width: 100%; height: 100%; }
.case-body { display: flex; flex-direction: column; gap: .2rem; padding: 4px 0; }
.case-name { font-weight: 700; font-size: 1.1rem; }
.case-age { color: var(--muted); font-size: .9rem; }
.case-brief { margin-top: .3rem; }
.case-go { margin-top: auto; font-weight: 600; color: var(--brand); padding-top: .6rem; }

/* ---- the consultation ---- */
.room { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 20px; padding: 20px 24px; max-width: 1280px; margin: 0 auto; height: calc(100vh - 63px); }
.stage { display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.patient-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.face-wrap { position: relative; aspect-ratio: 400 / 460; background: #e6ecf2; }
.face, .face svg { width: 100%; height: 100%; display: block; }
.speaking-dot { position: absolute; left: 14px; top: 14px; width: 12px; height: 12px; border-radius: 50%; background: #9aa7b5; box-shadow: 0 0 0 4px rgba(255,255,255,.7); transition: background .15s; }
.speaking-dot.on { background: var(--live); }
.patient-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px 4px; }
.patient-name { font-weight: 700; font-size: 1.1rem; }
.patient-age { color: var(--muted); font-size: .88rem; }
.call-state { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.state-pill { font-size: .78rem; font-weight: 700; padding: .2rem .6rem; border-radius: 99px; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.state-pill.live { background: #e1f5ea; color: var(--live); }
.state-pill.done { background: #f3e8e8; color: var(--danger); }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--muted); }
.timer.warn { color: var(--danger); }
.controls { display: flex; gap: 8px; padding: 12px 16px 16px; }
.controls .btn { flex: 1; }

.findings { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; min-height: 0; overflow: auto; }
.findings-head { font-weight: 700; margin-bottom: .5rem; }
.tray { display: flex; flex-direction: column; gap: 8px; }
.chip { font: inherit; text-align: left; cursor: pointer; border: 1px solid var(--line); border-left: 4px solid #6c8bb3; background: #fbfcfe; border-radius: 10px; padding: .5rem .7rem; display: flex; flex-direction: column; }
.chip.lab { border-left-color: var(--accent); }
.chip:hover { background: #f1f5fa; }
.chip-kind { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.chip-title { font-weight: 600; }

.chat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; }
.log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; background: #f8fafc; }
.msg { max-width: 78%; padding: .6rem .85rem; border-radius: 14px; box-shadow: 0 1px 1px rgba(16,28,45,.05); }
.msg .who { font-size: .72rem; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.msg.pt { align-self: flex-start; background: var(--pt); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.me { align-self: flex-end; background: var(--me); border-bottom-right-radius: 4px; }
.msg.live .text { color: var(--muted); }
.msg.live .text::after { content: " …"; }
.msg.sys { align-self: center; background: #fff4cc; color: #5c4a00; font-size: .82rem; font-weight: 600; padding: .3rem .8rem; border-radius: 99px; box-shadow: none; }
.ended { border-top: 1px solid var(--line); padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ended p { margin: 0; font-weight: 600; }

/* ---- the exams pop-up: a sheet of the clinical record ---- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(12, 20, 32, .5); display: grid; place-items: center; padding: 16px; z-index: 20; animation: fade .15s ease-out; }
.sheet {
  width: 100%; max-width: 620px; max-height: calc(100vh - 32px); overflow: auto;
  background: var(--sheet); border-radius: 6px; box-shadow: 0 24px 60px rgba(0,0,0,.3);
  border-top: 8px solid var(--brand); animation: rise .2s ease-out;
}
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 20px 24px 8px; }
.sheet-kind { font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; color: var(--muted); }
.sheet-head h2 { margin: .15rem 0 0; font-size: 1.35rem; }
.sheet-close { font-size: 1.6rem; line-height: 1; background: none; border: 0; cursor: pointer; color: var(--muted); padding: 0 4px; }
.sheet-patient { margin: 0 24px; padding: 8px 0 12px; border-bottom: 2px solid var(--ink); font-size: .88rem; color: var(--muted); }
.sheet-body { padding: 8px 24px 8px; }
.sheet-body dl { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; margin: 0; }
.sheet-body dt, .sheet-body dd { margin: 0; padding: .6rem 0; border-bottom: 1px dashed #d8d2c0; }
.sheet-body dt { font-weight: 700; padding-right: 12px; }
.sheet-body dt.bullet { color: var(--muted); }
.sheet-body dd { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .92rem; }
.sheet-body dd.pending { color: var(--muted); font-style: italic; font-family: inherit; }
.sheet-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 24px 20px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

@media (max-width: 860px) {
  .room { grid-template-columns: 1fr; height: auto; padding: 16px; }
  .face-wrap { aspect-ratio: 4 / 3.4; }
  .chat { min-height: 60vh; }
  .topbar { padding: 10px 16px; }
  .msg { max-width: 90%; }
  .sheet-body dl { grid-template-columns: 1fr; }
  .sheet-body dt { border-bottom: 0; padding-bottom: 0; }
}

/* ---- reports: letterhead, lab table, imaging report, photos ---- */
.sheet-patient[hidden] { display: none; }
.chip.img { border-left-color: #8a6fc9; }
.pager { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.pager .btn { padding: .4rem .7rem; }
.report-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid var(--ink); padding: 4px 0 8px; }
.report-org { font-weight: 800; letter-spacing: .02em; text-transform: uppercase; font-size: .95rem; }
.report-no { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--muted); font-size: .85rem; }
.report-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; padding: 10px 0 12px; border-bottom: 1px solid #d8d2c0; font-size: .88rem; }
.report-meta .k { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.report-meta .v { font-weight: 600; }
.lab-wrap { overflow-x: auto; margin-top: 8px; }
table.lab { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.lab th { text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 8px 6px 0; border-bottom: 1px solid var(--ink); white-space: nowrap; }
table.lab td { padding: 7px 8px 7px 0; border-bottom: 1px dashed #d8d2c0; vertical-align: top; }
table.lab td.val, table.lab td.ref { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: nowrap; }
table.lab td.unit { color: var(--muted); white-space: nowrap; }
table.lab td.flag { font-weight: 800; color: var(--danger); width: 1.5em; }
table.lab tr.out td.val { font-weight: 800; }
.report-legend { font-size: .78rem; color: var(--muted); margin: 10px 0 0; }
.report-sec { padding: 12px 0 4px; }
.report-sec h3 { margin: 0 0 4px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.report-sec p { margin: 0; line-height: 1.6; }
.report-sec.conclusion p { font-weight: 700; }
.report-sign { margin-top: 22px; padding-top: 8px; border-top: 1px solid #d8d2c0; width: 60%; font-size: .8rem; color: var(--muted); font-style: italic; }
figure.photo { margin: 8px 0 12px; border-radius: 6px; overflow: hidden; background: #111; }
figure.photo img { display: block; width: 100%; height: auto; }
figure.photo.crop { aspect-ratio: 912 / 585; }
figure.photo.crop img { height: 100%; object-fit: cover; object-position: top; }
figure.photo figcaption { background: #fff; color: var(--muted); font-size: .82rem; padding: 6px 8px; }
@media (max-width: 860px) { .report-meta { grid-template-columns: 1fr; } .sheet-foot { flex-wrap: wrap; } }
