/* ---------- Theme tokens (light default, dark via OS setting or the sidebar toggle) ----------
   One neutral ramp, one accent. Surfaces are separated by hairlines, not shadows.
   Status colours (danger / warn / ok) are reserved for things that need attention. */
:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --card: #ffffff;
  --sidebar: #ededea;
  --sidebar-hover: rgba(24, 24, 27, .05);
  --sidebar-border: #e2e2de;
  --text: #18181b;
  --text-2: #3f3f46;
  --muted: #71717a;
  --faint: #a1a1aa;
  --border: #e8e8e5;
  --border-strong: #dcdcd8;
  --input-border: #d9d9d5;
  --hover: #f3f3f1;
  --brand: #3451d1;
  --brand-dark: #2a43b5;
  --brand-soft: #eef1fd;
  --brand-ink: #2c45bd;
  --ring: rgba(52, 81, 209, .22);
  --primary-bg: #18181b;
  --primary-hover: #2e2e33;
  --primary-fg: #ffffff;
  --danger: #c4322f;
  --danger-soft: #fdf1f0;
  --warn: #a35f00;
  --warn-soft: #fdf6ea;
  --ok: #187a47;
  --ok-soft: #eef8f2;
  --info-soft: #f1f5fb;
  --info-ink: #24497a;
  --series-1: #3451d1;   /* medicines */
  --series-2: #12a08a;   /* doctor fees */
  --series-3: #e8913a;   /* X-ray */
  --grid: #efefec;
  --shadow: 0 1px 2px rgba(24, 24, 27, .04);
  --shadow-pop: 0 12px 32px -8px rgba(24, 24, 27, .18), 0 2px 6px rgba(24, 24, 27, .06);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0c0c0d; --card: #141416; --sidebar: #070708; --sidebar-hover: rgba(255, 255, 255, .05); --sidebar-border: #1d1d20; --text: #ededef; --text-2: #c9c9cf; --muted: #93939c; --faint: #66666e;
    --border: #232326; --border-strong: #2e2e33; --input-border: #303035; --hover: #1b1b1e;
    --brand: #7f95ff; --brand-dark: #6b83f5; --brand-soft: #1b2142; --brand-ink: #a4b4ff; --ring: rgba(127, 149, 255, .28);
    --primary-bg: #ededef; --primary-hover: #ffffff; --primary-fg: #0c0c0d;
    --danger: #f07c78; --danger-soft: #2a1716; --warn: #f0b155; --warn-soft: #2a2114;
    --ok: #55c98a; --ok-soft: #13261b; --info-soft: #151d2a; --info-ink: #9fc2ef;
    --series-1: #7f95ff; --series-2: #2bbfa5; --series-3: #f0a35a; --grid: #222225;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-pop: 0 16px 40px -8px rgba(0, 0, 0, .6), 0 0 0 1px #2a2a2e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0c0d; --card: #141416; --sidebar: #070708; --sidebar-hover: rgba(255, 255, 255, .05); --sidebar-border: #1d1d20; --text: #ededef; --text-2: #c9c9cf; --muted: #93939c; --faint: #66666e;
  --border: #232326; --border-strong: #2e2e33; --input-border: #303035; --hover: #1b1b1e;
  --brand: #7f95ff; --brand-dark: #6b83f5; --brand-soft: #1b2142; --brand-ink: #a4b4ff; --ring: rgba(127, 149, 255, .28);
  --primary-bg: #ededef; --primary-hover: #ffffff; --primary-fg: #0c0c0d;
  --danger: #f07c78; --danger-soft: #2a1716; --warn: #f0b155; --warn-soft: #2a2114;
  --ok: #55c98a; --ok-soft: #13261b; --info-soft: #151d2a; --info-ink: #9fc2ef;
  --series-1: #7f95ff; --series-2: #2bbfa5; --series-3: #f0a35a; --grid: #222225;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-pop: 0 16px 40px -8px rgba(0, 0, 0, .6), 0 0 0 1px #2a2a2e;
}

* { box-sizing: border-box; }
html { overscroll-behavior: none; font-size: 14px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
body {
  overscroll-behavior: none;
  margin: 0;
  font-family: Geist, "Inter var", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-feature-settings: "ss01", "cv11";
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}
::selection { background: var(--ring); }
/* Thin, theme-coloured scrollbars (Windows shows thick grey ones by default; macOS hides them). */
html { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--faint); }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
h1 { font-size: 1.6rem; font-weight: 600; margin: 0; letter-spacing: -.025em; line-height: 1.2; }
h2 { font-size: 1rem; font-weight: 600; margin: 0 0 1rem; letter-spacing: -.01em; }
h3 { font-weight: 600; }
b, strong { font-weight: 600; }
small { font-size: .85em; }
svg.icon { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.btn svg.icon { width: 16px; height: 16px; margin-left: -2px; }
small a svg.icon { width: 12px; height: 12px; vertical-align: -2px; margin-right: 2px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); }
.text-warn { color: var(--warn); }
.text-ok { color: var(--ok); }
.loading, .empty { padding: 4rem 1rem; text-align: center; color: var(--muted); }
.empty-small { padding: 2rem 1rem; text-align: center; color: var(--muted); margin: 0; }
.sr-only { position: absolute; left: 0; top: 0; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- Layout ---------- */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex-shrink: 0; background: var(--sidebar); border-right: 1px solid var(--sidebar-border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: .65rem; padding: 1.1rem 1.1rem 1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand img { display: block; width: 30px; height: 30px; border-radius: 50%; box-shadow: 0 0 0 1px var(--border); flex-shrink: 0; }
.brand b { display: block; font-size: .93rem; line-height: 1.25; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { display: block; color: var(--muted); font-size: .78rem; line-height: 1.3; }
.brand span { min-width: 0; }
.sidebar nav { flex: 1; overflow-y: auto; padding: .25rem .7rem 1rem; }
.nav-label {
  display: block; font-size: .72rem; font-weight: 500; color: var(--faint); letter-spacing: .02em;
  padding: 1rem .6rem .35rem;
}
.sidebar nav a {
  display: flex; gap: .65rem; align-items: center; color: var(--text-2); height: 32px; padding: 0 .6rem;
  border-radius: 7px; margin-bottom: 1px; font-weight: 500; font-size: .93rem; border: 1px solid transparent;
}
.sidebar nav a .icon { color: var(--muted); width: 17px; height: 17px; }
.sidebar nav a:hover { background: var(--sidebar-hover); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--primary-bg); color: var(--primary-fg); border-color: var(--primary-bg); box-shadow: var(--shadow); }
.sidebar nav a.active .icon { color: var(--primary-fg); }
.sidebar nav a.active:hover { background: var(--primary-hover); color: var(--primary-fg); }
.sidebar-foot { padding: .8rem .8rem 1rem; border-top: 1px solid var(--sidebar-border); display: grid; gap: .7rem; }
.user-row { display: flex; align-items: center; gap: .6rem; padding: 0 .2rem; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--text); color: var(--card);
  display: grid; place-items: center; font-weight: 600; font-size: .8rem; flex-shrink: 0;
}
.user-row b { display: block; font-size: .9rem; color: var(--text); line-height: 1.25; }
.user-row small { color: var(--muted); font-size: .78rem; }
.user-row .icon-btn { margin-left: auto; color: var(--muted); }
.user-row .icon-btn:hover { background: var(--sidebar-hover); color: var(--text); }
.theme-toggle { display: grid; grid-template-columns: 1fr 1fr; background: var(--sidebar-hover); border: 1px solid var(--sidebar-border); border-radius: 8px; padding: 2px; }
.theme-toggle button {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: .82rem; font-weight: 500;
  padding: .3rem; border-radius: 6px; cursor: pointer;
}
.theme-toggle button:hover { color: var(--text); }
.theme-toggle button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow), 0 0 0 1px var(--border); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: 0 2rem; height: 56px; justify-content: space-between;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: saturate(1.4) blur(10px);
}
.search { position: relative; width: min(360px, 100%); }
.search .icon { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--faint); width: 16px; height: 16px; }
.search input { padding-left: 2.1rem; background: var(--card); height: 34px; }
.search input::placeholder { color: var(--faint); }
#page { flex: 1; padding: 1.9rem 2rem 4rem; width: 100%; }
.menu-toggle { display: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.6rem; flex-wrap: wrap; }
.page-head .back { display: inline-block; font-size: .875rem; color: var(--muted); margin-bottom: .35rem; }
.page-head .back:hover { color: var(--text); text-decoration: none; }
.page-head p { margin: .35rem 0 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border);
  padding: 1.25rem 1.4rem; margin-bottom: 1.25rem;
}
.card .page-head { margin-bottom: .8rem; align-items: center; }
.card .page-head h2 { margin: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; margin-bottom: 1rem; }
.card-head h2 { margin: 0; }
.card-head a, .card-head .small { font-size: .85rem; }
.card-head a { color: var(--muted); }
.card-head a:hover { color: var(--text); text-decoration: none; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + * { margin-top: 1.25rem; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border);
  padding: 1rem 1.15rem; color: var(--text); display: block;
}
a.stat:hover { text-decoration: none; border-color: var(--border-strong); background: color-mix(in srgb, var(--card) 70%, var(--hover)); }
.stat small { color: var(--muted); display: block; font-weight: 500; font-size: .85rem; }
.stat b { font-size: 1.5rem; font-weight: 600; letter-spacing: -.025em; display: block; margin: .3rem 0 .1rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat.warn b { color: var(--warn); }
.stat.danger b { color: var(--danger); }

/* Dashboard metrics: one panel split by hairlines rather than many floating cards. */
.kpis {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; margin-bottom: 1.25rem;
  background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.kpi {
  position: relative; container-type: inline-size; background: var(--card);
  padding: 1.15rem 1.3rem 1.2rem; display: flex; flex-direction: column; gap: .2rem; color: var(--text); min-width: 0;
}
a.kpi { transition: background .12s; }
a.kpi:hover { text-decoration: none; background: color-mix(in srgb, var(--card) 55%, var(--hover)); }
.kpi-label { font-size: .85rem; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: .45rem; }
.kpi-value { font-size: 1.75rem; font-weight: 600; letter-spacing: -.03em; line-height: 1.2; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.kpi-value.sm { font-size: 1.3rem; letter-spacing: -.02em; }
.kpi-note { font-size: .82rem; color: var(--muted); }
.kpi-side { position: absolute; right: 1.2rem; bottom: 1.2rem; color: var(--muted); }
.kpi-side.chev { bottom: auto; top: 1.1rem; opacity: 0; transform: translateX(-3px); transition: opacity .12s, transform .12s; }
.kpi-side.chev .icon { width: 16px; height: 16px; }
a.kpi:hover .kpi-side.chev { opacity: 1; transform: none; }
.kpi.attention .kpi-value { color: var(--danger); }
.kpi.caution .kpi-value { color: var(--warn); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex-shrink: 0; }
.dot.danger { background: var(--danger); }
.dot.warn { background: var(--warn); }
.dot.ok { background: var(--ok); }
/* The 7-day trend only shows when the tile has room for it beside the numbers. */
@container (max-width: 210px) { .kpi-side.trend { display: none; } }
@container (min-width: 211px) { .kpi:has(.trend) .kpi-value, .kpi:has(.trend) .kpi-note { padding-right: 72px; } }
.delta { font-weight: 500; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--danger); }
.spark rect { fill: var(--grid); }
.spark rect.today { fill: var(--series-1); }

.dash-row { display: grid; gap: 1.25rem; margin-bottom: 1.25rem; }
.dash-row > .card { margin-bottom: 0; }
.dash-row.two { grid-template-columns: 1.4fr 1fr; }
.dash-row.three { grid-template-columns: 1fr 1fr 1fr; }

/* Charts */
.legend { display: flex; gap: 1.4rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-bottom: 1rem; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: .45rem; vertical-align: 1px; }
.legend b { color: var(--text); margin-left: .35rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart { position: relative; }
.chart-empty { position: absolute; inset: 0 0 30px 52px; display: grid; place-items: center; color: var(--muted); font-size: .9rem; pointer-events: none; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--faint); font-size: 11px; font-family: inherit; font-variant-numeric: tabular-nums; }
.chart .s1 { fill: var(--series-1); }
.chart .s2 { fill: var(--series-2); }
.chart .s3 { fill: var(--series-3); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: var(--text); fill-opacity: .035; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--card); color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow-pop); border-radius: 8px; padding: .6rem .75rem; font-size: .82rem;
  min-width: 170px; transform: translate(-50%, -100%); white-space: nowrap; z-index: 5; font-variant-numeric: tabular-nums;
}
.tooltip b { display: block; margin-bottom: .3rem; }
.tooltip div { display: flex; justify-content: space-between; gap: 1rem; line-height: 1.6; }
.tooltip div:last-child { border-top: 1px solid var(--border); margin-top: .3rem; padding-top: .3rem; }
.tooltip i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: .4rem; vertical-align: 1px; }
.barlist { display: grid; gap: 1rem; }
.barlist-row { display: grid; grid-template-columns: 1fr auto; gap: .4rem .8rem; font-size: .9rem; }
.barlist-row b { font-variant-numeric: tabular-nums; }
.barlist-track { grid-column: 1 / -1; height: 6px; background: var(--hover); border-radius: 99px; overflow: hidden; }
.barlist-fill { height: 100%; background: var(--series-1); border-radius: 99px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  height: 34px; padding: 0 .85rem; border-radius: 8px; border: 1px solid var(--input-border); background: var(--card);
  color: var(--text); font: inherit; font-size: .93rem; font-weight: 500; cursor: pointer; white-space: nowrap;
  box-shadow: var(--shadow); transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--hover); border-color: var(--border-strong); text-decoration: none; }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-fg); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.95); }
.btn.danger-outline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--input-border)); background: var(--card); }
.btn.danger-outline:hover { background: var(--danger-soft); }
.btn.small { height: 28px; padding: 0 .65rem; font-size: .85rem; border-radius: 7px; }
.btn.block { width: 100%; }
.btn.big { height: 42px; padding: 0 1.2rem; font-size: 1rem; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 1rem; padding: .35rem .45rem; border-radius: 7px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--hover); color: var(--danger); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; min-width: 0; }
.field > span { font-weight: 500; font-size: .875rem; color: var(--text-2); }
.field small { color: var(--muted); }
.req { color: var(--danger); margin-left: 2px; }
input, select, textarea {
  font: inherit; font-size: .95rem; padding: .5rem .7rem; min-height: 36px; border: 1px solid var(--input-border); border-radius: 8px;
  background: var(--card); color: var(--text); width: 100%; min-width: 0; box-shadow: var(--shadow);
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
/* Dropdowns: our own chevron with breathing room, instead of the browser arrow pressed against the edge. */
select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding-right: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a8a93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7rem center; background-size: 16px;
}
select::-ms-expand { display: none; }
select:disabled { cursor: not-allowed; opacity: .7; }
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
input:disabled { background: var(--hover); color: var(--muted); box-shadow: none; }
input[type="checkbox"], input[type="radio"] { min-height: 0; box-shadow: none; width: 15px; height: 15px; }
.check { display: flex; align-items: center; gap: .5rem; cursor: pointer; margin-bottom: 1rem; font-size: .93rem; color: var(--text-2); }
.check input { width: 15px; accent-color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 1rem; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
.form-grid .check { grid-column: 1 / -1; }
.form-section { font-size: .95rem; margin: .6rem 0 1rem; padding-top: 1.1rem; border-top: 1px solid var(--border); }
details.more { margin-top: .4rem; border-top: 1px solid var(--border); padding-top: .9rem; }
details.more summary { cursor: pointer; color: var(--text-2); font-weight: 500; margin-bottom: .9rem; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .8rem; }
.input-row { display: flex; gap: .5rem; align-items: flex-end; }
.input-row .field { margin-bottom: 0; }
.input-row .btn { height: 36px; }
.input-row + * { margin-top: 1rem; }
.grow { flex: 1; }
.filters { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; padding: 1rem 1.4rem; }
.filters .field, .filters .check { margin-bottom: 0; }
.filters .check { padding-bottom: .55rem; }
.filters .btn { height: 36px; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th {
  text-align: left; font-size: .8rem; color: var(--muted); font-weight: 500; padding: .55rem .75rem;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table td small.muted { font-size: .82rem; }
.table td > b:first-child { white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table tfoot td { border-bottom: 0; border-top: 1px solid var(--border-strong); font-weight: 500; }
.table.clickable tbody tr { cursor: pointer; transition: background .1s; }
.table.clickable tbody tr:hover { background: color-mix(in srgb, var(--card) 40%, var(--hover)); }
/* Tables that sit directly in a card run edge to edge, so row hovers and rules meet the card border. */
.card > .table, .card > .table-scroll { margin-left: -1.4rem; margin-right: -1.4rem; width: calc(100% + 2.8rem); }
.card > .table-scroll > .table { width: 100%; }
.card > .table th:first-child, .card > .table td:first-child,
.card > .table-scroll > .table th:first-child, .card > .table-scroll > .table td:first-child { padding-left: 1.4rem; }
.card > .table th:last-child, .card > .table td:last-child,
.card > .table-scroll > .table th:last-child, .card > .table-scroll > .table td:last-child { padding-right: 1.4rem; }
.card > .table:last-child, .card > .table-scroll:last-child { margin-bottom: -.5rem; }
.card > .table thead th, .card > .table-scroll > .table thead th { background: color-mix(in srgb, var(--card) 50%, var(--bg)); border-top: 1px solid var(--border); }
.card > .table:first-child thead th, .card > .table-scroll:first-child > .table thead th { border-top: 0; }
.card > .table:first-child, .card > .table-scroll:first-child { margin-top: -1.25rem; }
.card > .table:first-child thead th:first-child, .card > .table-scroll:first-child > .table thead th:first-child { border-top-left-radius: var(--radius); }
.card > .table:first-child thead th:last-child, .card > .table-scroll:first-child > .table thead th:last-child { border-top-right-radius: var(--radius); }
tr.cancelled td { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--faint); }
tr.cancelled td .badge { text-decoration: none; }
.table-scroll { overflow-x: auto; }
/* Medicines & Stock: a medicine row opens to show its batches */
.chev-cell { width: 28px; padding-right: 0 !important; color: var(--faint); }
.chev-cell .icon { width: 15px; height: 15px; transition: transform .15s; display: block; }
.drug-row.open .chev-cell .icon { transform: rotate(90deg); color: var(--text); }
.drug-row.open td { border-bottom-color: transparent; }
.table.clickable tbody tr.batch-row { cursor: default; }
.table.clickable tbody tr.batch-row:hover { background: none; }
.batch-row > td { padding: 0 .75rem 1.1rem 2.6rem; }
.batch-panel { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: .4rem 1rem .9rem; }
.batch-panel .table th { background: none; }
.batch-panel .actions { margin-top: .8rem; }
.table.entry td { padding: .45rem .3rem; }
.table.entry input, .table.entry select { padding: .35rem .5rem; min-height: 32px; }
.table.entry select { padding-right: 1.8rem; background-position: right .45rem center; background-size: 14px; }
.w-num { width: 70px; }
.w-money { width: 95px; }
.w-batch { width: 110px; }
td .qty { width: 80px; text-align: right; }
.split { margin-top: .2rem; }
.mrp-hint { margin-top: .15rem; line-height: 1.2; }

/* Status: a coloured dot and label, no filled chip. */
.badge {
  display: inline-flex; align-items: center; gap: .4rem; font-size: .82rem; font-weight: 500; color: var(--muted);
  white-space: nowrap; vertical-align: middle; text-decoration: none;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.danger { color: var(--danger); }
.badge.warn { color: var(--warn); }
.badge.ok { color: var(--ok); }
.badge.brand { color: var(--brand-ink); }
.alert {
  padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .93rem;
  border: 1px solid transparent; color: var(--text-2);
}
.alert.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 22%, transparent); color: var(--danger); }
.alert.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.alert.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info-ink) 15%, transparent); color: var(--info-ink); }

.tabs { display: flex; gap: 1.5rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); }
.tabs a { padding: .6rem 0; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--text); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ---------- Billing ---------- */
.bill-layout { display: grid; grid-template-columns: 1fr 360px; gap: 1.25rem; align-items: start; }
.bill-layout > .card { margin-bottom: 0; }
#bill-form { position: sticky; top: 72px; }
/* X-rays on a bill: one row per X-ray, under the picker. */
.xray-lines:empty { display: none; }
.xray-lines { display: grid; gap: .4rem; margin-top: .2rem; }
.xray-line {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: .5rem;
  padding: .4rem .3rem .4rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.xray-name { font-size: .92rem; line-height: 1.3; min-width: 0; }
.xray-name small { display: block; }
.xray-amount { font-variant-numeric: tabular-nums; font-weight: 500; }
.xray-line .xray-price { width: 92px; min-height: 30px; padding: .25rem .5rem; text-align: right; box-shadow: none; }
.xray-line .icon-btn { padding: .25rem .4rem; }
/* Review step before saving a bill. */
.review-who { margin: 0 0 .9rem; }
.modal .table.review td { padding: .55rem .75rem; }
.modal .table.review th:first-child, .modal .table.review td:first-child { padding-left: 0; }
.modal .table.review th:last-child, .modal .table.review td:last-child { padding-right: 0; }
.modal .table.review tfoot td { font-weight: 500; color: var(--muted); padding-top: .8rem; }
.review-total { font-size: 1.45rem; font-weight: 600 !important; letter-spacing: -.025em; color: var(--text) !important; }
/* Full / Concession / Free on the bill. */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--hover); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: block; text-align: center; padding: .38rem .3rem; border-radius: 6px; font-size: .88rem; font-weight: 500; color: var(--muted); }
.segmented input:checked + span { background: var(--card); color: var(--text); box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.segmented input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 1px; }
.concession-box { display: grid; grid-template-columns: 1fr 96px; gap: .4rem; margin-top: .4rem; }
.concession-box[hidden], #payment-field[hidden] { display: none; }
.review-off td { color: var(--ok); }
.totals { display: grid; grid-template-columns: 1fr auto; gap: .45rem 0; margin: .75rem 0 1.1rem; font-size: .95rem; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; padding-left: 1rem; text-align: right; font-variant-numeric: tabular-nums; }
.totals .sub { font-size: .85em; }
.totals .grand { font-size: 1.45rem; font-weight: 600; letter-spacing: -.025em; color: var(--text); border-top: 1px solid var(--border); padding-top: .7rem; margin-top: .3rem; }
.account { max-width: 900px; }
.account .totals { max-width: 320px; margin-left: auto; }
.account .table { margin-top: 1rem; }
.purchase-foot { display: flex; gap: 1.5rem; align-items: flex-end; margin: 1rem 0; }
.purchase-foot .field { margin-bottom: 0; }
.purchase-total { font-size: .95rem; color: var(--muted); white-space: nowrap; padding-bottom: .4rem; }
.purchase-total b { font-size: 1.45rem; letter-spacing: -.025em; color: var(--text); margin-left: .5rem; font-variant-numeric: tabular-nums; }
.downloads h2 { margin-bottom: .8rem; }

/* Drug picker dropdown */
.picker { position: relative; }
.picker-list {
  display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 20; margin-top: 6px; padding: 4px;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-pop);
  max-height: 360px; overflow-y: auto;
}
.picker-list.open { display: block; }
.picker-item {
  display: flex; justify-content: space-between; gap: 1rem; width: 100%; text-align: left; padding: .6rem .7rem;
  border: 0; background: none; font: inherit; color: var(--text); cursor: pointer; border-radius: 6px;
}
.picker-item.active, .picker-item:hover { background: var(--hover); }
.picker-empty { padding: .8rem; color: var(--muted); }

/* ---------- Invoice ---------- */
.invoice { max-width: 900px; padding: 2.4rem; }
.inv-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--text); padding-bottom: 1rem; margin-bottom: 1rem; }
.inv-brand { display: flex; gap: .9rem; align-items: flex-start; }
.inv-brand img { width: 56px; height: 56px; flex-shrink: 0; }
.inv-head h2 { font-size: 1.35rem; margin: 0 0 .2rem; letter-spacing: -.02em; }
.inv-head p, .inv-patient p { margin: .1rem 0; }
.inv-meta { text-align: right; }
.inv-meta h3 { margin: 0 0 .3rem; letter-spacing: .08em; font-size: .85rem; color: var(--muted); }
.inv-patient { display: flex; justify-content: space-between; margin-bottom: 1rem; }
.inv-table td, .inv-table th { padding: .4rem .4rem; font-size: .9rem; }
.inv-foot { display: flex; justify-content: space-between; gap: 2rem; margin-top: 1rem; align-items: flex-start; }
.gst-table { width: auto; }
.gst-table td, .gst-table th { padding: .25rem .6rem; font-size: .85rem; }
.inv-foot .totals { min-width: 260px; margin: 0; }
.inv-footer { display: flex; justify-content: space-between; margin-top: 2.5rem; color: var(--muted); }
.inv-footer .sign { border-top: 1px solid var(--muted); padding-top: .3rem; min-width: 180px; text-align: center; }

/* ---------- Modal & toast ---------- */
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(.985); } }
@keyframes fade-in { from { opacity: 0; } }
.modal-backdrop { position: fixed; inset: 0; background: rgba(12, 12, 13, .4); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 50; padding: 1rem; animation: fade-in .15s ease-out; }
.modal {
  background: var(--card); color: var(--text); border-radius: 12px; width: 100%; max-width: 480px; max-height: 92vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-pop); border: 1px solid var(--border); animation: pop-in .18s ease-out;
}
.modal.wide { max-width: 720px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.4rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 1.3rem 1.4rem; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .85rem 1.4rem; border-top: 1px solid var(--border); background: color-mix(in srgb, var(--card) 50%, var(--bg)); border-radius: 0 0 12px 12px; }
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translate(-50%, 12px); opacity: 0; transition: .2s ease-out;
  background: #18181b; color: #fafafa; padding: .7rem 1.1rem; border-radius: 9px; z-index: 100; font-size: .93rem; font-weight: 500;
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, .35), 0 0 0 1px rgba(255, 255, 255, .06); max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b42d2a; }

/* ---------- Login ---------- */
.login-wrap { flex: 1; display: flex; padding: 12px; background: var(--card); min-height: 100vh; }
.login-card { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 2rem; }
.login-art {
  position: relative; overflow: hidden; border-radius: 14px; padding: 2.6rem; display: flex; flex-direction: column; justify-content: space-between;
  color: #fafafa; background: #111113; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
}
/* A single soft light from the top edge, so the panel isn't flat black. */
.login-art::before {
  content: ""; position: absolute; inset: -40% -20% auto; height: 80%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, .07), transparent); pointer-events: none;
}
.login-art > * { position: relative; }
.login-art-logo { width: min(220px, 60%); height: auto; }
.login-art-text small { font-size: .9rem; color: #a1a1aa; font-weight: 500; }
.login-art-text p { margin: .9rem 0 0; font-size: clamp(1.8rem, 2.6vw, 2.7rem); font-weight: 500; line-height: 1.15; letter-spacing: -.035em; max-width: 520px; }
.login-art-text p span { color: #71717a; }
.login-form { align-self: center; justify-self: center; width: 100%; max-width: 360px; padding: 2rem 0; }
.login-brand { display: flex; align-items: center; gap: .75rem; }
.login-brand b { display: block; font-size: 1rem; font-weight: 600; line-height: 1.25; }
.login-brand small { display: block; color: var(--muted); font-size: .85rem; margin-top: .1rem; }
.login-emblem { display: block; flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; box-shadow: 0 0 0 1px var(--border); }
.login-form h1 { margin: 2.4rem 0 .5rem; font-size: 1.9rem; }
.login-form > .muted { margin: 0 0 2rem; font-size: .95rem; }
.login-form .btn { margin-top: .6rem; }
.password-box { position: relative; }
.password-box input { padding-right: 2.6rem; }
.password-box .icon-btn { position: absolute; right: .3rem; top: 50%; transform: translateY(-50%); }
.password-box .icon-btn:hover { color: var(--text); }
.password-box .icon { width: 17px; height: 17px; }
.login-help { margin: 1.5rem 0 0; text-align: center; font-size: .85rem; color: var(--muted); }
@media (max-width: 760px) {
  .login-wrap { padding: 10px; }
  .login-card { grid-template-columns: 1fr; gap: .5rem; align-content: start; }
  .login-art { min-height: 180px; padding: 1.4rem; gap: 1.2rem; }
  .login-art-text p { font-size: 1.4rem; }
  .login-form { padding: 1.4rem .6rem; }
  .login-brand { display: none; }
  .login-art-logo { width: 180px; }
  .login-form h1 { margin-top: .4rem; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .dash-row.three { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1000px) {
  .bill-layout, .grid-2, .dash-row.two, .dash-row.three { grid-template-columns: 1fr; }
  #bill-form { position: static; }
}
@media (max-width: 800px) {
  .sidebar { position: fixed; left: -250px; z-index: 40; transition: left .2s; background: var(--card); }
  body.nav-open .sidebar { left: 0; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
  .menu-toggle {
    display: grid; place-items: center; position: fixed; top: 10px; left: 1rem; z-index: 30; border: 1px solid var(--border);
    border-radius: 8px; background: var(--card); color: var(--text); width: 36px; height: 36px; cursor: pointer;
  }
  .topbar { padding: 0 1rem 0 3.6rem; }
  .topbar .btn span { display: none; }
  #page { padding: 1.2rem 1rem 2rem; }
  h1 { font-size: 1.35rem; }
  .kpi { padding: .9rem 1rem; }
  .kpi-side { display: none; }
  .kpi-value { font-size: 1.3rem; }
  .kpi-value.sm { font-size: 1.1rem; }
  .stats { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .stat b { font-size: 1.2rem; }
  .form-grid, .form-grid.three, .row-2 { grid-template-columns: 1fr; }
  .card { overflow-x: auto; padding: 1rem; }
  .card > .table, .card > .table-scroll { margin-left: -1rem; margin-right: -1rem; width: calc(100% + 2rem); }
  .card > .table:first-child, .card > .table-scroll:first-child { margin-top: -1rem; }
  .card > .table th:first-child, .card > .table td:first-child,
  .card > .table-scroll > .table th:first-child, .card > .table-scroll > .table td:first-child { padding-left: 1rem; }
  .card > .table th:last-child, .card > .table td:last-child,
  .card > .table-scroll > .table th:last-child, .card > .table-scroll > .table td:last-child { padding-right: 1rem; }
  .purchase-foot { flex-direction: column; align-items: stretch; }
  .invoice { padding: 1rem; }
  .inv-head, .inv-foot { flex-direction: column; }
  .inv-meta { text-align: left; }
}

/* ---------- Print (bills): always light ---------- */
@media print {
  @page { size: A5 portrait; margin: 8mm; }
  :root, :root[data-theme="dark"] { --text: #000; --muted: #444; --card: #fff; --border: #ccc; --hover: #f2f2f2; --bg: #fff; }
  body { background: #fff; font-size: 11px; }
  .sidebar, .menu-toggle, .topbar, .no-print, .toast { display: none !important; }
  #app { display: block; }
  #page { padding: 0; max-width: none; }
  .card { box-shadow: none; padding: 0; margin: 0; border: 0; }
  .card > .table, .card > .table-scroll { margin: 0; width: 100%; }
  .invoice { max-width: none; }
  .badge::before { display: none; }
}
