/* Kidney Plus Clinic — base styles. Calm, readable, works RTL and LTR. */
:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --text: #1d2a33;
  --muted: #5f6f7a;
  --line: #dde3e7;
  --primary: #0f6e78;
  --primary-ink: #ffffff;
  --primary-soft: #e3f1f2;
  --ok: #1e7a46;      --ok-soft: #e4f4ea;
  --warn: #9a6200;    --warn-soft: #fdf1dc;
  --danger: #b3261e;  --danger-soft: #fbe7e5;
  --radius: 8px;
  --font: "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Sans", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.55; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .87rem; }
.nowrap { white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: isolate; }

/* Top bar */
.topbar { background: var(--primary); color: var(--primary-ink); display: flex; align-items: center; gap: 1rem; padding: 0 1rem; min-height: 52px; flex-wrap: wrap; }
.topbar .brand { font-weight: 700; color: inherit; white-space: nowrap; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.topbar nav a { color: inherit; opacity: .85; padding: .9rem .6rem; border-bottom: 3px solid transparent; }
.topbar nav a:hover { opacity: 1; text-decoration: none; }
.topbar nav a.active { opacity: 1; border-bottom-color: #fff; font-weight: 600; }
.topbar .navmenu { position: relative; }
.topbar .navmenu summary { list-style: none; cursor: pointer; opacity: .85; padding: .9rem .6rem; border-bottom: 3px solid transparent; }
.topbar .navmenu summary::-webkit-details-marker { display: none; }
.topbar .navmenu summary::after { content: " ▾"; font-size: .8em; }
.topbar .navmenu summary:hover, .topbar .navmenu[open] summary { opacity: 1; }
.topbar .navmenu summary.active { opacity: 1; border-bottom-color: #fff; font-weight: 600; }
.topbar .navmenu-list { position: absolute; inset-inline-start: 0; top: 100%; z-index: 50; min-width: 12rem; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.15); padding: .3rem 0; display: flex; flex-direction: column; }
.topbar .navmenu-list a { color: var(--text); opacity: 1; padding: .55rem 1rem; border-bottom: 0; }
.topbar .navmenu-list a:hover { background: var(--primary-soft); text-decoration: none; }
.topbar .navmenu-list a.active { color: var(--primary); font-weight: 600; }
.topbar .who { display: flex; gap: .75rem; align-items: center; white-space: nowrap; }
.topbar .who a, .topbar .who button { color: inherit; }
.menu-toggle { display: none; background: none; border: 0; color: inherit; font-size: 1.4rem; cursor: pointer; }

main { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
main.narrow { max-width: 460px; padding-top: 8vh; }

/* Cards and tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.tile { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; color: var(--text); }
.tile:hover { border-color: var(--primary); text-decoration: none; }
.tile strong { display: block; color: var(--primary); margin-bottom: .25rem; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .87rem; background: #fafbfc; }
tr:hover td { background: #fafcfc; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.table-wrap table { border: 0; }
td.center, th.center { text-align: center; }

/* Forms */
label { display: block; font-weight: 600; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .85rem; margin-top: .25rem; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; padding: .55rem .65rem; border: 1px solid #c5cfd5; border-radius: 6px; font: inherit; background: #fff; color: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
input[aria-invalid=true], select[aria-invalid=true], textarea[aria-invalid=true] { border-color: var(--danger); }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.checks { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }
.row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.error { color: var(--danger); font-size: .87rem; margin-top: .25rem; }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: 1rem; }
.toolbar { display: flex; gap: .75rem; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar h1 { margin: 0; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.filters .field { margin: 0; min-width: 140px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem 1rem; border-radius: 6px; border: 1px solid var(--primary); background: var(--primary); color: var(--primary-ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--primary); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.small { padding: .25rem .6rem; font-size: .87rem; }
.btn.block { width: 100%; justify-content: center; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }

/* Status */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.alert.ok { background: var(--ok-soft); border-color: #b5dfc4; color: var(--ok); }
.alert.warn { background: var(--warn-soft); border-color: #f0d49c; color: var(--warn); }
.alert.danger { background: var(--danger-soft); border-color: #f1bcb7; color: var(--danger); }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #eef1f3; color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

.diff { font-size: .85rem; margin: 0; padding: 0; list-style: none; }
.diff del { color: var(--danger); }
.diff ins { color: var(--ok); text-decoration: none; }

.pagination { display: flex; gap: .25rem; list-style: none; padding: 0; margin: 1rem 0; flex-wrap: wrap; }
.pagination a, .pagination span { display: inline-block; padding: .3rem .7rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.pagination .active span { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .disabled span { color: #aab4ba; }

@media (max-width: 760px) {
  .menu-toggle { display: block; }
  .topbar nav { display: none; flex-basis: 100%; flex-direction: column; padding-bottom: .5rem; }
  .topbar nav.open { display: flex; }
  .topbar nav a { padding: .5rem; border-bottom: 0; }
  .topbar .navmenu summary { padding: .5rem; border-bottom: 0; }
  .topbar .navmenu-list { position: static; box-shadow: none; border: 0; background: transparent; padding: 0 1rem 0 0; min-width: 0; }
  .topbar .navmenu-list a { color: inherit; padding: .4rem .5rem; }
  .topbar .navmenu-list a:hover { background: transparent; }
  .topbar .navmenu-list a.active { color: inherit; text-decoration: underline; }
  .topbar .who .name { display: none; }
  main { padding: 1rem .75rem 3rem; }
}

@media print {
  .topbar, .no-print, .actions, .filters { display: none !important; }
  body { background: #fff; }
  .card { border: 0; padding: 0; }
}

/* Small helpers (inline style attributes are blocked by the CSP) */
.inline { display: inline; }
.form-narrow { max-width: 560px; }
h2.first { margin-top: 0; }
.span-all { grid-column: 1 / -1; }
.linkbtn.on-dark { color: inherit; }
.guest-title { text-align: center; color: var(--primary); }
.center-foot { text-align: center; margin-bottom: 0; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0; }
.row-actions { display: flex; gap: 1rem; align-items: baseline; }
.error-page { text-align: center; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--primary); }

/* ---------- Stage 2: patients, queue, booking ---------- */
[hidden] { display: none !important; }
.searchbar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.searchbar input { flex: 1; }
ul.plain { list-style: none; padding: 0; margin: .5rem 0; }
ul.plain li { padding: .15rem 0; }
.span-2 { grid-column: span 2; }
@media (max-width: 760px) { .span-2 { grid-column: 1 / -1; } }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.facts dt { color: var(--muted); font-weight: 600; }
dl.facts dd { margin: 0; }
.pre { white-space: pre-wrap; }
.danger-text { color: var(--danger) !important; }
.big { font-size: 2rem; color: var(--primary); }
.condition-grid { display: grid; gap: .5rem 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.condition { display: flex; gap: .5rem; align-items: center; }
.condition label { flex: 1; margin: 0; }
.condition input[type=text] { flex: 1; padding: .3rem .5rem; }
.pick-row { display: flex; gap: .75rem; align-items: center; justify-content: space-between; padding: .35rem 0; flex-wrap: wrap; }
label.pick-row { justify-content: flex-start; }

.patient-picker { position: relative; margin-bottom: 1rem; }
.picked { display: flex; gap: .75rem; align-items: center; padding: .4rem 0; }
.picker-results { position: absolute; inset-inline: 0; top: 100%; z-index: 20; list-style: none; margin: .15rem 0 0; padding: 0;
  background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.08); max-height: 320px; overflow-y: auto; }
.picker-results li { padding: .5rem .75rem; cursor: pointer; border-bottom: 1px solid var(--line); }
.picker-results li:last-child { border-bottom: 0; }
.picker-results li:hover, .picker-results li.active { background: var(--primary-soft); }
.picker-results li.empty { cursor: default; color: var(--muted); }

.stats { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .9rem; }
.stat span { display: block; color: var(--muted); font-size: .85rem; }
.stat strong { font-size: 1.5rem; }
.stat small { display: block; color: var(--muted); }
.stat.warn strong { color: var(--warn); }
.stat.ok strong { color: var(--ok); }
.stat.primary { border-color: var(--primary); }
.stat.primary strong { color: var(--primary); }
table.queue td.seq { font-size: 1.25rem; font-weight: 700; color: var(--primary); width: 3rem; text-align: center; }
tr.row-muted td { color: #98a4ab; }
tr.row-muted td a { color: #7a8a93; }
tr.row-active td { background: var(--primary-soft); }
.row-actions.wrap { flex-wrap: wrap; gap: .4rem .9rem; align-items: center; }
.row-actions form { margin: 0; }
.finish-form { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.finish-form input[type=date] { width: auto; padding: .2rem .4rem; }
.toolbar input[type=date] { width: auto; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .9rem; border-bottom: 3px solid transparent; color: var(--muted); }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.hp { position: absolute; inset-inline-start: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- Stage 3: visit screen ---------- */
main.wide { max-width: 1600px; }
.visit-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.visit-head h1 { margin: 0 0 .2rem; }
.visit-head .actions { margin-top: 0; }
.visit-head form { margin: 0; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--primary); }
.visit-grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.25fr) minmax(0, .9fr); align-items: start; }
@media (max-width: 1150px) { .visit-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .visit-grid > .col:last-child { grid-column: 1 / -1; } }
@media (max-width: 760px) { .visit-grid { grid-template-columns: minmax(0, 1fr); } }
.visit-grid .card { padding: 1rem; }
.visit-grid textarea { margin-bottom: .75rem; resize: vertical; }
.visit-grid label { margin-top: .25rem; }
.vitals { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .5rem; margin: .25rem 0 .9rem; }
.vitals label { font-size: .8rem; color: var(--muted); margin: 0; }
.vitals input { padding: .35rem .4rem; text-align: center; }
@media (max-width: 760px) { .vitals { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: .15rem .7rem; font-size: .9rem; margin: 0; }
.chip-x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0 .15rem; }
.chip-x:hover { color: var(--danger); }
.inline-add { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.inline-add > input[type=text], .inline-add > .suggest-wrap { flex: 1; min-width: 140px; }
.inline-add select { width: auto; flex: 1; }
.form-error { flex-basis: 100%; }
.suggest-wrap { position: relative; display: block; }
.toolbar.tight { margin-bottom: .5rem; }
.toolbar.tight h2 { margin: 0; }
.warnings { list-style: none; margin: 0 0 .75rem; padding: 0; }
.warnings li { background: var(--warn-soft); border-inline-start: 4px solid var(--warn); padding: .4rem .6rem; margin-bottom: .35rem; border-radius: 4px; font-size: .9rem; }
.warnings li.high { background: var(--danger-soft); border-color: var(--danger); }
.rx-line { display: grid; grid-template-columns: 1.5rem minmax(0, 2.4fr) 4.2rem 3.2rem minmax(0, 2fr) auto; gap: .35rem; align-items: center; margin-bottom: .35rem; }
.rx-line input { padding: .35rem .45rem; }
.rx-no { color: var(--muted); text-align: center; font-weight: 600; }
.rx-add { border-top: 1px dashed var(--line); padding-top: .6rem; margin-top: .4rem; }
.rx-add .suggest-wrap { min-width: 0; }
.rx-tools { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; align-items: center; }
.rx-tools form { margin: 0; }
@media (max-width: 760px) { .rx-line { grid-template-columns: 1.2rem 1fr 3.6rem 2.8rem; } .rx-line .rx-instr { grid-column: 2 / -1; } }
.egfr { margin-bottom: .6rem; }
table.results { background: none; margin-bottom: .75rem; }
table.results th, table.results td { padding: .25rem .35rem; background: none; }
table.results th { color: var(--text); font-weight: 600; width: 4.5rem; }
tr.flag-abnormal td:nth-child(2) { color: var(--warn); font-weight: 600; }
tr.flag-critical td:nth-child(2) { color: #fff; background: var(--danger); font-weight: 700; border-radius: 4px; }
.result-add { display: grid; grid-template-columns: minmax(0, 1fr) 5.5rem; gap: .35rem; }
.result-add select { grid-column: 1 / -1; }
.result-add input[type=date] { grid-column: 1; }
.prev-visit { border-bottom: 1px solid var(--line); padding: .35rem 0; }
.prev-visit summary { cursor: pointer; }
.prev-visit p, .prev-visit ul { margin: .3rem 0; }
.list-tools { display: grid; gap: .75rem; margin-bottom: .75rem; }
.list-add { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin: 0; padding: .75rem; }
.list-field { display: flex; flex-direction: column; gap: .15rem; margin: 0; font-weight: 400; }
.list-rows { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.list-rows .list-row { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; padding: .35rem .6rem; border-bottom: 1px solid var(--line); margin: 0; }
.list-row.head { background: #fafbfc; }
.list-row.row-muted input, .list-row.row-muted select { color: #98a4ab; }
.list-row input, .list-row select { padding: .3rem .45rem; }
.list-row > .sz-s, .list-field.sz-s { width: 7rem; flex: 0 0 auto; }
.list-row > .sz-m, .list-field.sz-m { width: 12rem; flex: 0 0 auto; }
.list-row > .sz-l, .list-field.sz-l { width: auto; flex: 1 1 14rem; min-width: 10rem; }
.list-row > .sz-xl, .list-field.sz-xl { width: auto; flex: 2 1 20rem; min-width: 12rem; }
.list-field > input, .list-field > select { width: 100%; }
.list-row > .sz-xs, .list-field.sz-xs { width: 4.6rem; flex: 0 0 auto; }
.list-row > label.check.sz-xs, .list-add > label.check.sz-xs { width: auto; }

/* ---------- Lab (stage 4) ---------- */
.doc-tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: .9rem; }
.doc-tabs a { padding: .35rem .75rem; border: 1px solid var(--line); border-bottom: 0; border-radius: 6px 6px 0 0; background: #eef2f4; color: var(--muted); font-size: .9rem; margin-bottom: -1px; }
.doc-tabs a.active { background: var(--surface); color: var(--text); font-weight: 600; border-bottom: 1px solid var(--surface); }
.doc-tabs a.row-muted { text-decoration: line-through; }
label.chip { cursor: pointer; font-weight: 400; }
label.chip input { margin: 0; }
.chip.on { background: var(--primary); color: var(--primary-ink); }
.order-more { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: .35rem; align-items: center; }
.order-more .suggest-wrap { min-width: 0; }
@media (max-width: 1100px) { .order-more { grid-template-columns: minmax(0, 1fr) auto; } .order-more .suggest-wrap { grid-column: 1 / -1; } }
ul.orders { list-style: none; padding: 0; margin: 0 0 .75rem; display: flex; flex-wrap: wrap; gap: .3rem; }
ul.orders li { display: inline-flex; gap: .35rem; align-items: center; border: 1px dashed var(--warn); background: var(--warn-soft); border-radius: 6px; padding: .1rem .45rem; }
ul.orders li.done { border-style: solid; border-color: var(--line); background: var(--surface); }
ul.orders li.flag-abnormal .ltr { color: var(--warn); font-weight: 700; }
ul.orders li.flag-critical { background: var(--danger); color: #fff; border-color: var(--danger); }
ul.orders form.inline { margin: 0; }
h3.small { margin: .4rem 0 .35rem; display: flex; gap: .5rem; justify-content: space-between; align-items: baseline; }
.flag-mark { color: var(--warn); font-weight: 700; }
.result-add-box summary { cursor: pointer; color: var(--primary); margin-bottom: .4rem; }
.lab-visit-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; align-items: flex-end; }
.lab-visit-head input[type=date] { width: auto; }
.lab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .5rem .9rem; margin-bottom: .75rem; }
.lab-cell { display: grid; grid-template-columns: minmax(0, 1fr) 6.5rem; grid-template-rows: auto auto; column-gap: .4rem; margin: 0; font-weight: 400; align-items: center; }
.lab-cell .lab-code { grid-column: 1 / -1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lab-cell > input, .lab-cell > select { grid-column: 1; padding: .3rem .45rem; }
.lab-cell > .small { grid-column: 2; }
.lab-cell.done > input, .lab-cell.done > select { background: var(--ok-soft); }
.lab-cell.flag-abnormal > input { color: var(--warn); font-weight: 700; }
.lab-cell.flag-critical > input { color: #fff; background: var(--danger); font-weight: 700; }
label.lab-cell.check { display: flex; gap: .45rem; align-items: center; }
.lab-group { border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem .8rem 0; margin: 0 0 .75rem; }
.lab-group legend { font-weight: 600; padding: 0 .35rem; }
.muted-card { opacity: .85; }
.flowsheet-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
table.flowsheet { border-collapse: separate; border-spacing: 0; background: none; margin: 0; }
table.flowsheet th, table.flowsheet td { padding: .3rem .5rem; white-space: nowrap; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
table.flowsheet thead th { text-align: right; position: sticky; top: 0; background: #fafbfc; }
table.flowsheet .sticky { position: sticky; left: 0; background: var(--surface); text-align: left; z-index: 1; border-right: 1px solid var(--line); }
table.flowsheet thead .sticky { background: #fafbfc; z-index: 2; }
table.flowsheet tr.group th, table.flowsheet tr.group td { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
table.flowsheet tr.derived td, table.flowsheet tr.derived th { background: #fafbfc; }
table.flowsheet td.flag-abnormal { color: var(--warn); font-weight: 700; }
table.flowsheet td.flag-critical { color: #fff; background: var(--danger); font-weight: 700; }
.flag-abnormal-text { color: var(--warn); font-weight: 700; }

/* Charts: one series per chart (series colour validated against the white surface) */
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 30rem), 1fr)); gap: .9rem; margin-bottom: 1rem; }
.chart-card { margin: 0; padding: .75rem .9rem; }
.chart-card figcaption { margin-bottom: .25rem; }
.chart-pick { align-items: center; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; --series-1: #257de0; }
svg.chart .ref-band { fill: #eef1f3; }
svg.chart .grid { stroke: #e6eaed; stroke-width: 1; }
svg.chart .axis { stroke: #b9c3c9; stroke-width: 1; }
svg.chart .tick { fill: var(--muted); font-size: 12px; }
svg.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .pt { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
svg.chart .end-label { fill: var(--text); font-size: 13px; font-weight: 600; }
svg.chart .hit { fill: transparent; cursor: pointer; outline: none; }
svg.chart .hit:hover, svg.chart .hit:focus { fill: rgba(37, 125, 224, .14); }
.chart-tip { position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: #fff; font-size: .8rem; padding: .25rem .5rem; border-radius: 4px; white-space: nowrap; direction: ltr; }
tr.flag-critical td:nth-child(2) .muted, td.flag-critical .muted { color: inherit; opacity: .85; }
.warn-text { color: var(--warn); }
svg.chart .bar { fill: var(--series-1); }
svg.chart rect.hit:hover, svg.chart rect.hit:focus { fill: rgba(25, 25, 25, .05); }

/* Reports */
table.report { width: 100%; font-variant-numeric: tabular-nums; }
table.report td, table.report th { padding: .35rem .5rem; }
table.report tfoot th { border-top: 2px solid var(--text); }
tr.row-muted td { color: #98a4ab; }
table.chart-table { width: auto; margin: .4rem auto 0; background: none; }
table.chart-table th, table.chart-table td { padding: .1rem .6rem; text-align: center; background: none; }
@media print {
  .topbar, .no-print, .menu-toggle { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .card, .stat { box-shadow: none; break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}
pre.code { background: #f2f5f7; border: 1px solid var(--line); border-radius: 6px; padding: .5rem .7rem; white-space: pre-wrap; word-break: break-all; font-size: .85rem; }

/* Messages */
.bell { position: relative; font-size: 1.15rem; line-height: 1; padding: .3rem .4rem; opacity: .85; text-decoration: none; }
.bell.has-new { opacity: 1; }
.bell-count { position: absolute; top: -.35rem; inset-inline-end: -.45rem; background: #fff; color: var(--danger); font-size: .7rem; font-weight: 700; border-radius: 999px; padding: .05rem .35rem; }
.msg { border-bottom: 1px solid var(--line); padding: .5rem 0; }
.msg.new { background: var(--primary-soft); padding-inline: .5rem; border-radius: 4px; }
main.offline { text-align: center; padding-top: 3rem; }
main.offline img { border-radius: 16px; }

/* ---------- Reception, as in the old system ---------- */
.desk-card { max-width: 38rem; }
.card-title { font-size: 1.35rem; margin: 0 0 1rem; }
.req { color: var(--danger); }
.center { text-align: center; }
.btn.block { display: flex; justify-content: center; width: 100%; margin: .75rem 0; }
.btn.big { padding: .8rem 1rem; font-size: 1.1rem; color: var(--primary-ink); }
.btn.danger-outline { background: #fff; color: var(--danger); border-color: var(--danger); }
.pills { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .5rem; }
.pill { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--line); border-radius: 8px; padding: .45rem .9rem; font-weight: 400; margin: 0; cursor: pointer; background: #fff; }
.pill:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); font-weight: 600; }
[data-birth][hidden] { display: none; }

/* search with results as cards (booking page) */
.patient-picker.inline { margin-bottom: .5rem; }
.patient-picker.inline input[type=search] { font-size: 1.05rem; padding: .7rem .9rem; }
.patient-picker.inline .picker-results { position: static; border: 0; box-shadow: none; background: transparent; margin-top: .6rem; }
.patient-picker.inline .picker-results li { border: 1px solid var(--line); border-radius: 8px; margin-bottom: .5rem; background: #fff; padding: .7rem 1rem; }
.patient-picker.inline .picker-results li strong { font-size: 1.05rem; }
.patient-picker.inline .picker-results li.empty { border-style: dashed; }

/* number grid */
.seq-big { font-size: 4rem; font-weight: 800; color: var(--primary); text-align: center; line-height: 1.1; margin: .25rem 0 1rem; }
.seq-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: .45rem; margin-bottom: .5rem; }
.seq { position: relative; margin: 0; }
.seq input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seq span { display: flex; align-items: center; justify-content: center; height: 2.8rem; border: 1px solid var(--line); border-radius: 8px; font-weight: 700; background: #fff; }
.seq:hover span { background: var(--primary-soft); }
.seq input:checked + span { background: var(--primary); color: #fff; border-color: var(--primary); }
.seq input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.seq.taken span { background: #eef1f3; color: #b5bec4; text-decoration: line-through; cursor: not-allowed; }
@media (max-width: 520px) { .seq-grid { grid-template-columns: repeat(5, 1fr); } }

/* arrival */
.kind-options { display: flex; flex-direction: column; gap: .5rem; }
.kind-option { display: flex; align-items: center; gap: .6rem; border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; margin: 0; font-weight: 400; cursor: pointer; }
.kind-option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.kind-option .kind-amount { margin-inline-start: auto; }
.amount-line { font-size: 1.15rem; margin: 1rem 0 .25rem; }
.amount-line strong { font-size: 1.5rem; color: var(--primary); }

/* visits page */
.visits-bar { flex-wrap: wrap; gap: .75rem; }
.visits-bar .chip.ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #bfe3cb; }
.visits-bar .chip.muted { background: #eef1f3; color: var(--muted); }
.btn.big-add { padding: .6rem 1.4rem; font-size: 1.05rem; }
.visit-cards { padding: .5rem; }
.vcard { display: flex; align-items: center; gap: 1rem; padding: .8rem 1rem; border: 1px solid var(--line); border-inline-start: 4px solid #c9d3d9; border-radius: 8px; margin: .5rem; background: #fff; }
.vcard-seq { font-size: 1.6rem; font-weight: 800; color: var(--primary); min-width: 2.2rem; text-align: center; }
.vcard-main { flex: 1; min-width: 0; }
.vcard-name { font-weight: 700; font-size: 1.05rem; }
.vcard-meta { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; color: var(--muted); font-size: .92rem; margin-top: .2rem; }
.vcard-meta .strong { color: var(--primary); font-weight: 700; }
.vcard-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.vcard.st-waiting, .vcard.st-returned { border-inline-start-color: var(--warn); }
.vcard.st-with_doctor { border-inline-start-color: var(--primary); background: var(--primary-soft); }
.vcard.st-done { border-inline-start-color: var(--ok); }
.vcard.st-cancelled, .vcard.st-no_show { opacity: .55; }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: .6rem; }
.total { background: var(--bg); border-radius: 8px; padding: .8rem; text-align: center; }
.total span { display: block; color: var(--muted); font-size: .9rem; }
.total strong { font-size: 1.5rem; color: var(--primary); }

/* doctor's three columns */
.doc-columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .doc-columns { grid-template-columns: 1fr; } }
.doc-col-title { font-size: 1.1rem; display: flex; align-items: center; gap: .5rem; margin: 0 0 .6rem; }
.chip-btn { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: .15rem .7rem; font: inherit; font-size: .85rem; cursor: pointer; color: var(--text); }
.chip-btn:hover { border-color: var(--primary); color: var(--primary); }
.dcard-form { margin: 0; }
.dcard { display: flex; align-items: center; gap: 1rem; width: 100%; text-align: start; font: inherit; color: inherit; cursor: pointer;
  background: #fff; border: 1px solid var(--line); border-inline-start: 4px solid #c9d3d9; border-radius: 8px; padding: .8rem 1rem; margin-bottom: .6rem; text-decoration: none; }
.dcard:hover { box-shadow: 0 2px 10px rgba(0,0,0,.08); text-decoration: none; }
.dcard.st-waiting, .dcard.st-returned { border-inline-start-color: var(--primary); }
.dcard.st-with_doctor { border-inline-start-color: var(--warn); }
.dcard.st-done { border-inline-start-color: var(--ok); }
.dcard-seq { font-size: 1.6rem; font-weight: 800; color: var(--primary); min-width: 2rem; text-align: center; }
.dcard-main { display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.dcard-name { font-weight: 700; color: var(--primary); }
.dcard-meta { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; color: var(--muted); font-size: .9rem; }

/* Patients page: add a new patient right under the search */
.add-patient { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin: -.25rem 0 1rem; }
.add-patient.none-found { background: var(--warn-soft); border: 1px solid #f0d9a8; border-radius: var(--radius); padding: .75rem 1rem; }
.invite-link { margin-bottom: 1rem; }
.copy-row { display: flex; gap: .5rem; margin: .5rem 0; flex-wrap: wrap; }
.copy-row input { flex: 1 1 20rem; }

/* ---------- Visit screen, old-system layout (RTL; clinical fields LTR) ---------- */
.chip.ok { background: var(--ok-soft, #e3f4ea); color: var(--ok, #1b7a43); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.muted { background: #eef1f3; color: var(--muted); }
.vhead { position: sticky; top: 0; z-index: 30; display: grid; grid-template-columns: minmax(0, 1fr) auto 9rem; gap: 1rem; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem 1rem; margin-bottom: .9rem; box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.vhead h1 { margin: 0; font-size: 1.35rem; display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; }
.vhead-edit { font-size: .85rem; font-weight: 400; }
.vhead-meta { display: flex; gap: .9rem; flex-wrap: wrap; color: var(--text); font-size: .92rem; margin: .15rem 0; }
.vhead-badges { display: flex; gap: .4rem; flex-wrap: wrap; }
.vhead-mid { display: flex; gap: .4rem; flex-wrap: nowrap; justify-content: center; align-items: center; }
.hchip { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--line); border-radius: 999px; padding: .2rem .75rem; font-size: .88rem; background: #fafbfc; color: var(--text); }
a.hchip:hover { border-color: var(--primary); text-decoration: none; }
.timer-chip { color: var(--danger); font-weight: 700; min-width: 6.5rem; justify-content: center; font-variant-numeric: tabular-nums; }
.timer-chip .timer { color: inherit; }
/* Fixed widths: the save text changing while typing must not move the timer or the queue chip. */
.hchip.save-state { color: var(--ok, #1b7a43); width: 13rem; justify-content: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vhead-mid .hchip { white-space: nowrap; flex: 0 0 auto; }
.hchip.save-state.danger-text { border-color: var(--danger); }
.vhead-clock { text-align: center; line-height: 1.2; }
.vhead-clock strong { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; color: var(--primary); }
.vhead-clock span { font-size: .85rem; color: var(--muted); }
@media (max-width: 900px) { .vhead { grid-template-columns: 1fr; } .vhead-mid { justify-content: flex-start; flex-wrap: wrap; } .vhead-clock { display: none; } }

.vgrid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.15fr) minmax(0, .9fr); align-items: start; }
@media (max-width: 1150px) { .vgrid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .vgrid > .vcol:last-child { grid-column: 1 / -1; } }
@media (max-width: 760px) { .vgrid { grid-template-columns: minmax(0, 1fr); } }
.vcol-title { font-size: 1.05rem; margin: 0 0 .5rem; color: var(--primary); }
.vgrid .card { padding: .8rem 1rem; margin-bottom: .75rem; }
.vgrid textarea { resize: vertical; margin: 0; }
.field-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .35rem; }
.field-head label, .field-head .label { margin: 0; font-weight: 700; }
.field-actions { margin-inline-start: auto; display: flex; gap: .35rem; flex-wrap: wrap; }
.hist { position: relative; }
.hist summary { list-style: none; cursor: pointer; color: var(--muted); font-size: 1.05rem; line-height: 1; padding: 0 .2rem; }
.hist summary::-webkit-details-marker { display: none; }
.hist[open] summary { color: var(--primary); }
.hist-pop { position: absolute; z-index: 40; inset-inline-start: 0; top: 1.4rem; width: min(26rem, 80vw); max-height: 18rem; overflow-y: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.12); padding: .4rem .6rem; font-size: .88rem; }
.hist-row { padding: .25rem 0; border-bottom: 1px solid var(--line); }
.hist-row:last-child { border-bottom: 0; }
.vitals { grid-template-columns: repeat(5, minmax(0, 1fr)); margin: 0; }
.vital { display: flex; flex-direction: column; gap: .15rem; font-size: .8rem; color: var(--muted); margin: 0; font-weight: 600; }
.vital-in { display: flex; align-items: center; gap: .2rem; }
.vital-in input { padding: .35rem .3rem; text-align: center; min-width: 0; }
.vital-in small { color: var(--muted); font-weight: 400; white-space: nowrap; }
@media (max-width: 760px) { .vitals { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.order-panel { border: 1px solid var(--line); border-radius: 6px; padding: .6rem; margin-bottom: .6rem; background: #fafbfc; }
.order-panel select { margin-top: .4rem; }
.quick-tests { margin: .5rem 0 0; }
.quick-tests .chip { cursor: pointer; background: #fff; border: 1px solid var(--line); color: var(--text); }
.quick-tests .chip.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.quick-tests input { margin: 0; }
.chip-add { margin: 0; }
.chip-add input[type=text] { width: 100%; }
#dx .chips:empty { display: none; }
.rx-top { display: flex; justify-content: flex-end; margin-bottom: .5rem; }
.drug-box { border: 1px solid var(--line); border-radius: 6px; padding: .45rem; margin-bottom: .5rem; background: #fff; }
.drug-box.new { border-style: dashed; background: #fafbfc; }
.drug-row { display: grid; grid-template-columns: minmax(0, 1fr) 4.5rem 3.6rem auto; gap: .35rem; align-items: center; margin-bottom: .35rem; }
.drug-box.new .drug-row { grid-template-columns: minmax(0, 1fr) 4.5rem 3.6rem; }
.drug-row input, .drug-box .rx-instr { padding: .35rem .45rem; }
.drug-row .rx-drug { font-weight: 600; }
.drug-row .suggest-wrap { min-width: 0; }
.drug-x { background: none; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1; width: 2rem; height: 2rem; }
.drug-x:hover { color: var(--danger); border-color: var(--danger); }
.drug-add-row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-top: .4rem; }
.drug-add-row .check { margin: 0; }
.rx-buttons { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.rx-extras { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin-top: .6rem; padding-top: .5rem; border-top: 1px dashed var(--line); }
.rx-extras form { margin: 0; }
#rx-save-template { margin-top: .5rem; }
.finish-card form { margin: 0; display: grid; gap: .6rem; }
.finish-card .check { margin: 0; }
.next-visit { display: flex; flex-direction: column; gap: .2rem; margin: 0; font-weight: 600; }
.review-days input[type=number] { width: 4.5rem; padding: .25rem .35rem; text-align: center; }
.finish-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.discard { margin: .9rem 0 0; padding-top: .6rem; border-top: 1px solid var(--line); }
.vtabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin: -.2rem 0 .6rem; }
.vtab { background: none; border: 0; border-bottom: 3px solid transparent; padding: .4rem .8rem; font: inherit; color: var(--muted); cursor: pointer; }
.vtab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.block-input { width: 100%; }
/* Outside results page: compact rows (code | value | unit · range), save bar stays visible */
.outside-bar { position: sticky; top: 0; z-index: 20; background: var(--bg, #f5f7f8); padding: .5rem 0; margin-bottom: .5rem; border-bottom: 1px solid var(--line); }
.outside-bar h1 { margin: 0; }
.outside-hint { background: var(--primary-soft); border-radius: var(--radius); padding: .5rem .8rem; margin: 0 0 .6rem; font-size: .92rem; }
.outside-date { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; }
.outside-date label { display: flex; gap: .5rem; align-items: center; margin: 0; font-weight: 600; }
.outside-date input[type=date] { width: auto; }
.outside-date input[type=search] { width: auto; flex: 1; min-width: 12rem; }
.outside-groups { columns: 3 19rem; column-gap: .75rem; }
.outside-group { break-inside: avoid; padding: .3rem .6rem .4rem; margin: 0 0 .75rem; }
.outside-group legend { font-size: .95rem; color: var(--primary); }
.outside-group .lab-grid { display: block; margin: 0; }
.outside-group .lab-cell { display: grid; grid-template-columns: 4.6rem 5.5rem minmax(0, 1fr); column-gap: .45rem; align-items: center;
  padding: .18rem 0; border-bottom: 1px dotted var(--line); }
.outside-group .lab-cell:last-child { border-bottom: 0; }
.outside-group .lab-cell .lab-code { grid-column: 1; font-size: .92rem; }
.outside-group .lab-cell > input, .outside-group .lab-cell > select { grid-column: 2; padding: .2rem .35rem; font-size: .92rem; height: 1.9rem; }
.outside-group .lab-cell > .small { grid-column: 3; font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lab-cell.has-value > input, .lab-cell.has-value > select { background: var(--primary-soft); font-weight: 600; }
/* Letter: choose a template */
.template-buttons { display: grid; gap: .5rem; }
.template-btn { display: block; padding: .9rem 1.1rem; border: 1px solid var(--primary); border-radius: var(--radius); background: var(--primary-soft); color: var(--primary); font-weight: 600; font-size: 1.05rem; }
.template-btn:hover { background: var(--primary); color: var(--primary-ink); text-decoration: none; }
.template-btn.blank { border-style: dashed; background: #fff; }

/* Past history rows with a note under each condition */
.cond-list { display: grid; gap: .4rem; margin: .6rem 0; }
.cond { background: #f3f6f8; border: 1px solid var(--line); border-radius: 6px; padding: .35rem .5rem; }
.cond-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin: 0; }
.cond-name { font-weight: 600; }
.cond form { margin: 0; }
.cond-note { margin-top: .3rem; padding: .25rem .45rem; font-size: .9rem; background: #fff; }
.cond-note:placeholder-shown { background: transparent; border-style: dashed; }
.cond-tools { display: flex; align-items: center; gap: .5rem; }
.cond-tools .linkbtn { font-size: .8rem; color: var(--muted); }
.cond-tools .linkbtn:hover { color: var(--primary); }
/* The green bar stays at the top while scrolling; sticky boxes below it start under it. */
.topbar { position: sticky; top: 0; z-index: 60; }
.vhead, .outside-bar { top: var(--topbar-h, 52px); }
@media (max-width: 900px) { .topbar { position: static; } .outside-bar, .vhead { top: 0; } }
@media print { .topbar { position: static; } }
/* Vitals as in the old system: "SBP mmHg" above a full-width box */
.vitals { gap: .45rem; }
.vital { gap: .3rem; }
.vital-label { font-size: .95rem; font-weight: 700; color: var(--text); white-space: nowrap; }
.vital-label small { font-size: .7rem; font-weight: 400; color: var(--muted); }
.vital > input { width: 100%; height: 2.6rem; text-align: center; padding: .3rem; border-radius: 8px; }

/* The name bar stays fixed under the green bar while scrolling, except on phones. */
@media (max-width: 600px) { .vhead { position: static; } }
/* Ordered tests with their result boxes (visit screen) */
.order-rows { display: grid; gap: .3rem; margin-top: .4rem; }
.order-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .4rem; padding: .2rem 0; border-bottom: 1px dotted var(--line); }
.order-form { display: grid; grid-template-columns: 5.5rem 6.5rem minmax(0, 1fr); align-items: center; gap: .5rem; margin: 0; }
.order-code { font-weight: 700; }
.order-form input[type=text], .order-form select { height: 2.3rem; text-align: center; padding: .25rem .35rem; }
.order-form .small { font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-row.done .order-form input, .order-row.done .order-form select { background: var(--ok-soft); font-weight: 600; }
.order-row.flag-abnormal .order-form input { color: var(--warn); background: var(--warn-soft); }
.order-row.flag-critical .order-form input { color: #fff; background: var(--danger); }
.order-x { margin: 0; }
.quick-tests .chip input { accent-color: var(--primary); }
.quick-tests .chip.on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

/* ===== Visit screen v3: sizes, spacing and colours matched to the old system's screen ===== */
main.visit-page { max-width: 1420px; padding-top: .9rem; }
.visit-page .vhead { padding: .55rem 1.1rem; margin-bottom: 1.1rem; }
.visit-page .vhead h1 { font-size: 1.55rem; }
.visit-page .vgrid { grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr) minmax(0, 1fr); gap: 1.1rem; }
.visit-page .vgrid > .vcol.card { padding: 1.1rem 1.3rem 1.3rem; margin: 0; border-radius: 12px; }
.visit-page .vcol-title { font-size: .95rem; font-weight: 600; color: var(--text); margin: 0 0 .9rem; }
.visit-page .vsec { margin-bottom: 1.15rem; }
.visit-page .vsec:last-child { margin-bottom: 0; }
.visit-page .field-head { margin-bottom: .45rem; }
.visit-page .field-head label, .visit-page .field-head .label { font-size: 1.02rem; font-weight: 700; }
.visit-page textarea { min-height: 6.3rem; border-radius: 8px; font-size: 1rem; }
.visit-page #v-notes { min-height: 4.6rem; }
.visit-page .vitals { gap: .45rem; }
.visit-page .vital-label { font-size: .98rem; }
.visit-page .vital > input { height: 2.95rem; }
.visit-page .chip-add input[type=text], .visit-page #conditions .chip-add input { height: 3rem; border-radius: 8px; }
.btn.ghost { background: #fff; color: var(--muted); border-color: var(--line); font-weight: 400; }
/* Ordered tests: bold dotted name (opens the curve) | box | unit ........ range */
.order-row { border-bottom: 0; padding: .15rem 0; }
.order-form { grid-template-columns: 4.6rem 5.8rem 4.5rem minmax(0, 1fr); gap: .6rem; }
.order-form input[type=text], .order-form select { height: 3.05rem; font-size: 1.05rem; font-weight: 600; border-radius: 8px; }
.order-unit { font-size: .8rem; color: var(--muted); }
.order-range { font-size: .8rem; color: var(--muted); text-align: end; white-space: nowrap; }
.order-value { font-weight: 600; }
.test-name { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; font-size: 1.05rem; color: var(--text); cursor: pointer;
  text-decoration: underline dotted; text-underline-offset: 3px; text-align: start; }
.test-name:hover { color: var(--primary); }
.test-name.plain { cursor: default; text-decoration: none; }
table.results th .test-name { font-size: inherit; }
/* Rx column */
.visit-page .rx-top { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.visit-page .rx-top .vcol-title { margin: 0; }
.egfr-box { display: inline-flex; align-items: baseline; gap: .35rem; background: #e8f1fb; border: 1px solid #c9dcf0; color: #1f4f7a; border-radius: 10px; padding: .45rem .8rem; font-size: .8rem; }
.egfr-box strong { font-size: 1.25rem; }
.egfr-box small { font-size: .7rem; color: #4d6f8f; }
.egfr-box .egfr-stage { margin-inline-start: .3rem; }
.egfr-box.muted { background: #f1f3f5; border-color: var(--line); color: var(--muted); }
.visit-page .drug-box { border-radius: 10px; padding: .55rem; }
.visit-page .drug-row input, .visit-page .drug-box .rx-instr { height: 2.9rem; border-radius: 8px; font-size: 1rem; }
.visit-page .drug-row { grid-template-columns: minmax(0, 1fr) 4.2rem 3.6rem 2rem; }
.visit-page .drug-box.new .drug-row { grid-template-columns: minmax(0, 1fr) 4.2rem 3.6rem; }
.visit-page .drug-x { border: 0; width: 2rem; }
.visit-page .rx-buttons { align-items: center; gap: .5rem .8rem; margin: .65rem 0 .4rem; }
.visit-page .rx-buttons a.small { color: var(--muted); }
.visit-page .rx-buttons a.small:hover { color: var(--primary); }
.visit-page .rx-extras { border-top: 0; padding-top: 0; margin-top: .2rem; }
/* Finish box: colours as in the old screen */
.finish-box { margin-top: .9rem; }
.finish-box form { display: grid; gap: .8rem; margin: 0; }
.print-box { display: flex; align-items: center; gap: .5rem; margin: 0; padding: .7rem .9rem; border: 1.5px solid #2f6fa3; background: #eef5fb; border-radius: 10px; font-weight: 600; color: #1f4f7a; }
.review-box { display: flex; align-items: center; gap: .5rem; margin: 0; padding: .55rem .9rem; border: 1px solid var(--line); border-radius: 10px; font-weight: 400; }
.review-box input[type=number] { width: 4.2rem; height: 2.7rem; text-align: center; }
.visit-page .next-visit input { height: 3rem; border-radius: 8px; }
.finish-actions { display: grid; grid-template-columns: 1.1fr 1fr 1fr; gap: .5rem; }
.fbtn { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 3.9rem; padding: .4rem .6rem; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer; border: 1px solid transparent; }
.fbtn.finish { background: #1f5b88; color: #fff; }
.fbtn.finish:hover { background: #184a70; text-decoration: none; }
.fbtn.pause { background: #fdf3d3; border-color: #f0dc9c; color: #7a5a00; }
.fbtn.waive { background: #e3f5e9; border-color: #b8e2c6; color: #1d7a43; }
.fbtn.discard-btn { width: 100%; min-height: 2.9rem; background: #fde8e8; border-color: #f5c2c2; color: #b3261e; font-weight: 600; }
.visit-page .discard { margin: .6rem 0 0; padding: 0; border: 0; }
/* Right column */
.visit-page .vtabs { margin-top: 1rem; }
.visit-page .vtab { font-size: 1rem; }
/* Chart window */
dialog.chart-dialog { width: min(46rem, 94vw); max-height: 88vh; border: 0; border-radius: 12px; padding: 1rem 1.2rem; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
dialog.chart-dialog::backdrop { background: rgba(20, 30, 40, .45); }
.chart-close { position: absolute; top: .4rem; inset-inline-end: .6rem; background: none; border: 0; font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer; }
.chart-pop h3 { margin: .2rem 0 .4rem; font-size: 1.05rem; }
.chart-pop table.results { margin-top: .6rem; }
@media (max-width: 1150px) { .visit-page .vgrid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
@media (max-width: 760px) { .visit-page .vgrid { grid-template-columns: minmax(0, 1fr); } .finish-actions { grid-template-columns: 1fr; } }
/* Letter pages (as in the old system): the main card and «رسائل المريض السابقة» side by side */
main.letters-page { max-width: 1400px; }
.letters-title { font-size: 1.3rem; }
.letters-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .letters-grid { grid-template-columns: 1fr; } }
.letters-grid .card h2.first { font-size: 1.1rem; }
.letters-help { color: var(--muted); line-height: 1.8; margin: 0 0 1rem; }
.template-btn { background: #1f5b88; border-color: #1f5b88; color: #fff; font-size: 1.05rem; padding: .85rem 1.6rem; text-align: left; }
.template-btn:hover { background: #184a70; color: #fff; }
.letters-side .letter-row { display: flex; align-items: center; gap: .8rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.letter-name { font-weight: 700; color: #1f5b88; flex: 1; text-align: right; }
.letter-date { font-weight: 700; }
.letter-new { margin: .9rem 0 .6rem; }
.letter-form label { font-weight: 700; margin-top: .9rem; }
.letter-form label:first-of-type { margin-top: 0; }
.hint-inline { font-weight: 400; font-size: .82rem; color: var(--muted); }
.letter-form input[type=text] { height: 2.9rem; }
.letter-body-input { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: .92rem; line-height: 1.6; min-height: 30rem; }
.result-date { color: var(--muted); text-decoration: underline dotted; text-underline-offset: 3px; }
.result-date:hover { color: var(--primary); }

/* ---------- «التاريخ المرضي» page (old system layout) ---------- */
.hx-page { max-width: 1370px; margin-inline: auto; padding: 1.2rem 1.4rem; }
.hx-title { font-size: 1.35rem; margin: 0 0 1rem; text-align: left; }
.hx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.8rem; }
.hx-sec { margin-bottom: 1.1rem; }
.hx-label { display: block; font-weight: 600; margin-bottom: .45rem; }
.hx-page .pills { margin-bottom: .5rem; }
.hx-page textarea, .hx-page input[type=text] { width: 100%; }
.hx-page .chip-add input { width: 100%; }
.cond-name b { margin-inline-end: .35rem; }
.cond.primary { border-color: #e0b100; background: #fff8dc; }
.star-btn { background: none; border: 0; padding: 0 .15rem; font-size: 1rem; line-height: 1; color: var(--muted); cursor: pointer; }
.star-btn.on, .star-btn:hover { color: #d49b00; }
.cond-mark { color: #d49b00; margin-inline-start: .3rem; }
@media (max-width: 900px) { .hx-grid { grid-template-columns: 1fr; } }
