/* ==========================================================================
   Adhi Siddha Varma Clinic — built on the layered web style guide
   Layers (art → streaks → grain → scrim → glass → content), seams not edges,
   light DM Sans headings, Geist body, Geist Mono for data, motion with manners.
   ========================================================================== */

/* ---------- Bundled fonts (work offline; files in /fonts, OFL licences alongside) ---------- */
@font-face { font-family: "DM Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/dm-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "DM Sans"; font-style: normal; font-weight: 500; font-display: swap; src: url("/fonts/dm-sans-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Geist"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/geist-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Geist"; font-style: normal; font-weight: 500; font-display: swap; src: url("/fonts/geist-sans-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Geist Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/geist-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Geist Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("/fonts/geist-mono-latin-500-normal.woff2") format("woff2"); }

/* ---------- Colour stories: one dominant hue family + one accent ---------- */
:root, [data-story="tulsi"] {
  --deep: #0e2a1e;   /* forest */
  --mid: #1c5a40;
  --accent: #2e9a68; /* tulsi green */
  --glow: #f2bd6b;   /* turmeric */
  --tint: #e5f3eb;
  --dusk: rgba(8, 28, 18, 0.28);
}
[data-story="cobalt"] { --deep: #001f5d; --mid: #133daf; --accent: #1a52dc; --glow: #f3b6a4; --tint: #e6f0ff; --dusk: rgba(37, 19, 41, 0.2); }
[data-story="teal"]   { --deep: #04262b; --mid: #0f6e64; --accent: #19a58e; --glow: #ffd9a0; --tint: #e2f6f1; --dusk: rgba(4, 30, 40, 0.25); }
[data-story="ember"]  { --deep: #2a0a24; --mid: #8a1f45; --accent: #e2553a; --glow: #ffc56b; --tint: #fdeceb; --dusk: rgba(40, 8, 30, 0.25); }
[data-story="moss"]   { --deep: #1d2a14; --mid: #4f6b2c; --accent: #8a9e3f; --glow: #f4e2b8; --tint: #f2f1e3; --dusk: rgba(30, 25, 10, 0.2); }

:root {
  --ink: #16181c;
  --muted: #5b6577;
  --line: #e3e7ef;
  --page: #f8f9f7;
  --card: #ffffff;
  --field: #ffffff;
  --warn: #a5650f;
  --warn-bg: #fdf1dc;
  --bad: #b3261e;
  --bad-bg: #fbe5e3;
  --wa: #1f9d55;
  --ease-swoop: cubic-bezier(0.2, 0.85, 0.45, 0.95);
  --ease-fly: cubic-bezier(0.2, 0.7, 0.1, 1);
  --font-head: "DM Sans", system-ui, sans-serif;
  --font-body: Geist, system-ui, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, Consolas, monospace;
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #eef1f6; --muted: #9aa4b5; --line: #262b35; --page: #0d0f13; --card: #14171d; --field: #0f1216;
    --warn: #e8b05a; --warn-bg: #33270f; --bad: #f08a80; --bad-bg: #3a1a18; --wa: #3ccf7e;
  }
}
:root[data-theme="dark"] {
  --ink: #eef1f6; --muted: #9aa4b5; --line: #262b35; --page: #0d0f13; --card: #14171d; --field: #0f1216;
  --warn: #e8b05a; --warn-bg: #33270f; --bad: #f08a80; --bad-bg: #3a1a18; --wa: #3ccf7e;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font-family: var(--font-body); font-size: 14.5px; letter-spacing: -0.2px; line-height: 1.6; }
h1, h2, h3 { font-family: var(--font-head); font-weight: 400; letter-spacing: -0.025em; line-height: 1.12; margin: 0; }
h2 { font-size: 20px; margin-bottom: 12px; }
h3 { font-size: 16px; font-weight: 500; margin-bottom: 8px; }
a { color: inherit; }
.mono, code { font-family: var(--font-mono); font-size: 12.5px; letter-spacing: 0; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
[hidden] { display: none !important; }

/* ---------- Shared layer stack ---------- */
.layered { position: relative; isolation: isolate; overflow: hidden; color: #fff; }
.layered > .art { position: absolute; inset: -10%; z-index: -4;
  background:
    radial-gradient(60% 45% at 78% 28%, color-mix(in srgb, var(--glow) 70%, transparent) 0%, transparent 60%),
    radial-gradient(50% 60% at 18% 85%, color-mix(in srgb, var(--accent) 80%, transparent) 0%, transparent 70%),
    radial-gradient(80% 60% at 50% 0%, var(--mid) 0%, transparent 70%),
    var(--deep);
  animation: art-in 1.6s var(--ease-swoop) both, sway 18s ease-in-out 1.6s infinite; }
/* OLD: concentric rings
.layered > .streaks { position: absolute; inset: -30% -20% -10% -20%; z-index: -3; opacity: .5; mix-blend-mode: screen; pointer-events: none;
  background: repeating-radial-gradient(ellipse 120% 55% at 60% 120%, transparent 0 14px, color-mix(in srgb, #fff 18%, transparent) 15px, transparent 17px);
  transform: rotate(-8deg); animation: art-in 2s var(--ease-swoop) .15s both, drift 40s linear infinite alternate; } */
/* OLD (v2): flowing contour lines
.layered > .streaks { ... transform: rotate(-6deg); ... }
.layered > .streaks path { stroke-dasharray: 1700; stroke-dashoffset: 1700; animation: draw 2.6s ... calc(var(--i) * 45ms) forwards; } */
/* OLD (v3): one large leaf skeleton (SVG drawn by JS), drawn in from the midrib
.layered > .streaks { position: absolute; inset: -6%; z-index: -3; opacity: .75; mix-blend-mode: screen; pointer-events: none;
  color: color-mix(in srgb, var(--glow) 40%, #fff); animation: drift 48s ease-in-out infinite alternate; }
.layered > .streaks svg { width: 100%; height: 100%; display: block; }
.layered > .streaks path { vector-effect: non-scaling-stroke; stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: draw 1.4s var(--ease-swoop) calc(var(--o) * 90ms) forwards; }
.layered > .streaks .v1 { stroke-width: 1.8; stroke-opacity: .6; animation-duration: 1.8s; }
.layered > .streaks .v2 { stroke-width: 1.2; stroke-opacity: .48; }
.layered > .streaks .v3 { stroke-width: .85; stroke-opacity: .34; }
.layered > .streaks .v4 { stroke-width: .6; stroke-opacity: .26; }
.calm .layered > .streaks path { animation: none; stroke-dashoffset: 0; } */

/* NEW (v4): an evenly repeated geometric leaf-vein tile across the whole page.
   One 160px tile holds two small leaves: a straight midrib with right-angled veins and tiny forks,
   the second mirrored and offset, so the leaves alternate direction like a herringbone.
   The tile is a mask, so its colour comes from CSS variables: light on the dark layered areas,
   ink-coloured and fainter on the page between cards. */
/* OLD (v4a): separate sprig motifs in a 160px tile; read as wallpaper and was too strong (opacity .13)
:root { --veins: url("data:image/svg+xml;utf8,<svg ... width='160' height='160'> two mirrored sprigs </svg>"); --veins-size: 160px; } */
/* NEW (v4b): a continuous lattice. Each 96px tile carries one stretch of a diagonal midrib that joins
   the next tile's, so the whole page is crossed by parallel leaf ribs. Every 24px along a rib, two
   right-angled veins branch forward with a tiny fork, like nerve endings. Spread evenly, very faint. */
/* OLD (v4b): continuous 96px lattice; too small and dense
:root { --veins: url("data:image/svg+xml;utf8,<svg ... width='96' height='96'> diagonal rib + 24px veins </svg>"); --veins-size: 96px; } */
/* NEW (v4c): large, well-spaced geometric leaves. A 420px tile holds two faceted leaves
   (the second mirrored and offset): midrib + stem, four pairs of right-angled veins tapering
   toward base and tip, a fork on every vein, and a straight-edged outline through the vein tips. */
:root {
  --veins: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='420' height='420' fill='none' stroke='black' stroke-linecap='round' stroke-linejoin='round'><g><path stroke-width='1.4' d='M24 396L260 160'/><path stroke-width='1' d='M84 336V298M84 336H122M128 292V236M128 292H184M172 248V196M172 248H224M216 204V172M216 204H248'/><path stroke-width='.7' d='M84 315l-13-13M105 336l13 13M128 261l-20-20M159 292l20 20M172 219l-18-18M201 248l18 18M216 186l-11-11M234 204l11 11'/><path stroke-width='.8' d='M40 380L84 298L128 236L172 196L216 172L260 160L248 204L224 248L184 292L122 336Z'/></g><g transform='translate(420 -160) scale(-1 1)'><path stroke-width='1.4' d='M24 396L260 160'/><path stroke-width='1' d='M84 336V298M84 336H122M128 292V236M128 292H184M172 248V196M172 248H224M216 204V172M216 204H248'/><path stroke-width='.7' d='M84 315l-13-13M105 336l13 13M128 261l-20-20M159 292l20 20M172 219l-18-18M201 248l18 18M216 186l-11-11M234 204l11 11'/><path stroke-width='.8' d='M40 380L84 298L128 236L172 196L216 172L260 160L248 204L224 248L184 292L122 336Z'/></g></svg>");
  --veins-size: 420px;
}
.layered > .streaks { position: absolute; inset: 0; z-index: -3; pointer-events: none; opacity: .14;
  background-color: color-mix(in srgb, var(--glow) 35%, #fff);
  -webkit-mask: var(--veins) 0 0 / var(--veins-size) var(--veins-size) repeat; mask: var(--veins) 0 0 / var(--veins-size) var(--veins-size) repeat;
  animation: veins-in 1.6s ease both; } /* not "fade": that ends at opacity 1 and overrode the faint .07 */
.calm .layered > .streaks { animation: none; }
@keyframes veins-in { from { opacity: 0; } } /* no "to": settles at the element's own opacity */

/* The same tile, fainter, over the whole page background (shows between cards) */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: .05;
  background-color: var(--ink);
  -webkit-mask: var(--veins) 0 0 / var(--veins-size) var(--veins-size) repeat; mask: var(--veins) 0 0 / var(--veins-size) var(--veins-size) repeat; }
.layered > .grain { position: absolute; inset: 0; z-index: -2; opacity: .22; mix-blend-mode: overlay; pointer-events: none; background-image: var(--grain); }
.layered > .scrim { position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(180deg, transparent 35%, color-mix(in srgb, var(--mid) 55%, transparent) 72%, var(--mid) 100%), linear-gradient(108deg, var(--dusk) 0%, transparent 93%); }

/* ---------- Glass ---------- */
.glass { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.2); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 15px; border-radius: 10px; font: 500 14px var(--font-head); letter-spacing: -0.02em;
  text-decoration: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; white-space: nowrap;
  transition: transform .2s var(--ease-swoop), border-color .2s, background-color .2s; }
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 85%, #000); }
.btn.light { background: #fff; color: var(--deep); border-color: #fff; }
.btn.glassy { background: color-mix(in srgb, var(--deep) 45%, transparent); color: #fff; border: 1px solid rgba(255,255,255,.22); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.btn.glassy:hover { border-color: rgba(255,255,255,.5); }
.btn.wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); border-color: var(--line); }
.twinkle { width: 7px; height: 7px; border-radius: 50%; background: var(--glow); animation: twinkle 2.4s ease-in-out infinite; }

/* ---------- Auth screen ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.auth .scrim { background: linear-gradient(180deg, transparent 30%, color-mix(in srgb, var(--deep) 60%, transparent) 100%), linear-gradient(108deg, var(--dusk) 0%, transparent 93%); }
.auth-wrap { width: min(980px, 100%); display: grid; grid-template-columns: 1.1fr 1fr; gap: 48px; align-items: center; }
.auth-copy .kicker { display: flex; align-items: center; gap: 10px; font: 13px var(--font-mono); letter-spacing: .12em; text-transform: uppercase; opacity: .85; animation: fade 1s ease both; }
.auth-copy h1 { font-size: clamp(38px, 5.5vw, 64px); max-width: 12ch; margin: 18px 0 14px; animation: drop 1.05s var(--ease-swoop) .35s both; }
.auth-copy p { font-size: 17px; max-width: 40ch; opacity: .85; margin: 0; animation: drop 1.05s var(--ease-swoop) .5s both; }
.auth-card { border-radius: 18px; padding: 26px; animation: fly-in .95s var(--ease-fly) .2s both; }
.auth-card h2 { font-size: 24px; }
.auth-card label { color: rgba(255,255,255,.8); }
.auth-card input { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.25); color: #fff; }
.auth-card input::placeholder { color: rgba(255,255,255,.5); }
.auth-card input:focus { border-color: var(--glow); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--glow) 30%, transparent); }
.auth-card .err { background: rgba(179,38,30,.35); border: 1px solid rgba(255,255,255,.2); color: #fff; padding: 8px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 13.5px; }
.auth-card .check { color: rgba(255,255,255,.85); }
/* OLD: spinning round orb
.orb { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff, var(--accent) 60%, var(--deep)); animation: spin 42s linear infinite; flex: none; } */
/* NEW: leaf-sprout mark on a glass tile; leaves sway slowly, like a plant in a breeze */
.mark { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: 10px;
  background: linear-gradient(140deg, color-mix(in srgb, var(--accent) 85%, transparent), color-mix(in srgb, var(--deep) 70%, transparent));
  border: 1px solid rgba(255,255,255,.25); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18); }
.mark svg { width: 24px; height: 24px; overflow: visible; }
.mark .leaf { transform-box: view-box; transform-origin: 16px 19px; animation: leaf-sway 6s ease-in-out infinite; }
.mark .leaf.l { fill: var(--glow); }
.mark .leaf.r { fill: #fff; opacity: .92; animation-delay: -3s; transform-origin: 16px 15.5px; }
.auth-copy .kicker .mark { width: 28px; height: 28px; border-radius: 9px; }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; animation: fly-in-left .95s var(--ease-fly) both; }
.side .scrim { background: linear-gradient(180deg, transparent 0%, color-mix(in srgb, var(--deep) 70%, transparent) 60%, var(--deep) 100%), linear-gradient(108deg, var(--dusk) 0%, transparent 93%); }
.side .art { animation: art-in 1.6s var(--ease-swoop) both; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand b { font: 500 15px var(--font-head); letter-spacing: -0.01em; line-height: 1.25; display: block; }
.brand small { font: 11px var(--font-mono); letter-spacing: .1em; text-transform: uppercase; opacity: .7; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid transparent; background: none; color: rgba(255,255,255,.82);
  font: 14px var(--font-body); text-align: left; cursor: pointer; transition: background-color .25s, border-color .25s, color .25s; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item[aria-current="page"] { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.22); color: #fff; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.nav-item svg { width: 17px; height: 17px; flex: none; opacity: .9; }
.nav-item .count { margin-left: auto; font: 11px var(--font-mono); padding: 1px 7px; border-radius: 99px; background: color-mix(in srgb, var(--glow) 85%, transparent); color: var(--deep); }
.side-foot { margin-top: auto; padding: 12px; border-radius: 12px; font-size: 13px; }
.side-foot .who { font-weight: 500; }
.side-foot .role { font: 11px var(--font-mono); text-transform: uppercase; letter-spacing: .08em; opacity: .7; }
.side-foot .row { margin-top: 8px; }

main { min-width: 0; }

/* Page hero: the full layer stack, fading into the page colour (a seam, not an edge) */
.page-hero { padding: 34px 36px 64px; }
.page-hero .scrim { background: linear-gradient(180deg, transparent 0%, color-mix(in srgb, var(--mid) 30%, transparent) 45%, color-mix(in srgb, var(--page) 70%, transparent) 88%, var(--page) 100%), linear-gradient(108deg, var(--dusk) 0%, transparent 93%); }
.page-hero .eyebrow { font: 12px var(--font-mono); letter-spacing: .12em; text-transform: uppercase; opacity: .8; animation: fade .8s ease both; display: flex; align-items: center; gap: 10px; }
.page-hero h1 { font-size: clamp(30px, 3.6vw, 44px); margin: 10px 0 6px; max-width: 22ch; animation: drop 1.05s var(--ease-swoop) .15s both; }
.page-hero p { margin: 0; opacity: .85; max-width: 60ch; animation: drop 1.05s var(--ease-swoop) .3s both; }
.page-hero .actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; animation: drop 1.05s var(--ease-swoop) .45s both; }
.page-hero .stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 22px; animation: drop 1.05s var(--ease-swoop) .45s both; }
.stat { border-radius: 14px; padding: 14px 16px; }
.stat .n { font: 400 30px var(--font-head); letter-spacing: -0.03em; display: flex; align-items: center; gap: 10px; }
.stat .l { font: 11px var(--font-mono); letter-spacing: .08em; text-transform: uppercase; opacity: .8; }

.content { padding: 0 36px 60px; margin-top: -30px; position: relative; }
.content > * { animation: rise .7s var(--ease-swoop) both; }
.content > *:nth-child(2) { animation-delay: .08s; }
.content > *:nth-child(3) { animation-delay: .16s; }

/* Data refresh on the same page: entrances do not replay, ambient motion keeps going */
.calm .page-hero > :not(.art):not(.streaks):not(.grain):not(.scrim), .calm .content > * { animation: none; }
.calm .page-hero > .art { animation: sway 18s ease-in-out infinite; }
.calm .page-hero > .streaks { animation: drift 40s linear infinite alternate; }

/* Calm sections between rich ones */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.empty { color: var(--muted); padding: 22px 0; text-align: center; }

/* Tables scroll inside their own card, never the page */
.tablewrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font: 500 11px var(--font-mono); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td a { text-decoration: none; font-weight: 500; }
td a:hover { color: var(--accent); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font: 500 11.5px var(--font-body); background: var(--tint); color: color-mix(in srgb, var(--accent) 70%, var(--deep)); white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.dim { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--muted); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge:not(.warn):not(.bad):not(.dim) { background: color-mix(in srgb, var(--accent) 22%, transparent); color: color-mix(in srgb, var(--accent) 55%, #fff); } }

.pulse-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--glow); position: relative; display: inline-block; flex: none; }
.pulse-dot::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--glow); animation: ping 1.8s cubic-bezier(0,0,.2,1) infinite; }

/* ---------- Forms ---------- */
label { display: block; font: 500 12px var(--font-body); color: var(--muted); margin-bottom: 5px; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--field); color: var(--ink); font: 14px var(--font-body); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
textarea { min-height: 66px; resize: vertical; }
.field { margin-bottom: 12px; min-width: 0; }
.fg { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--ink); }
.check input { width: auto; }
.section-title { font: 500 11px var(--font-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin: 18px 0 10px; display: flex; align-items: center; gap: 10px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.hint { font-size: 12.5px; color: var(--muted); margin: 4px 0 10px; }

.rx-row { display: grid; grid-template-columns: minmax(0, 2fr) repeat(2, minmax(0, 1fr)) minmax(0, 1.2fr) minmax(0, 1.2fr) minmax(0, .7fr) minmax(0, .8fr) auto; gap: 6px; margin-bottom: 6px; align-items: center; }
.rx-row input, .rx-row select { padding: 7px 8px; font-size: 13px; }
.rx-head { font: 500 10.5px var(--font-mono); color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Modal (glass over a dimmed page) ---------- */
.modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
  background: color-mix(in srgb, var(--deep) 55%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fade .25s ease both; }
.modal-card { width: 100%; max-width: 820px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 24px; animation: drop .5s var(--ease-swoop) both; box-shadow: 0 30px 60px -30px rgba(0,0,0,.5); }
.modal-card.narrow { max-width: 520px; }
.modal-card h2 { font-size: 24px; }

/* ---------- Visit cards ---------- */
.visit { border-left: 3px solid var(--accent); }
.kv { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 6px 0; }
.kv span b { font: 500 11px var(--font-mono); color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-right: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Story picker */
.stories { display: flex; gap: 8px; flex-wrap: wrap; }
.story { font: 13px var(--font-body); padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; display: flex; align-items: center; gap: 8px; }
.story[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.sw { width: 14px; height: 14px; border-radius: 50%; }

/* Toast */
#toast { position: fixed; bottom: 22px; left: 50%; translate: -50% 0; z-index: 50; max-width: min(560px, calc(100% - 32px)); padding: 11px 16px; border-radius: 12px; color: #fff; font-size: 14px;
  background: color-mix(in srgb, var(--deep) 88%, transparent); border: 1px solid rgba(255,255,255,.18); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  opacity: 0; transform: translateY(10px); transition: opacity .3s var(--ease-swoop), transform .3s var(--ease-swoop); pointer-events: none; }
#toast.show { opacity: 1; transform: none; }
#toast.error { background: color-mix(in srgb, #7a1712 90%, transparent); }

.loading { padding: 40px 0; text-align: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; display: inline-block; }

#print { display: none; }

/* ---------- Keyframes ---------- */
@keyframes fly-in { from { opacity: 0; translate: 0 -80px; } to { opacity: 1; translate: 0 0; } }
@keyframes fly-in-left { from { opacity: 0; translate: -40px 0; } to { opacity: 1; translate: 0 0; } }
@keyframes drop   { from { opacity: 0; transform: translateY(-18px); } to { opacity: 1; transform: none; } }
@keyframes rise   { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes art-in { from { opacity: 0; transform: scale(1.08); } to { opacity: 1; } }
@keyframes fade   { from { opacity: 0; } to { opacity: 1; } }
@keyframes sway   { 0%, 100% { rotate: -0.5deg; } 50% { rotate: 0.5deg; } }
@keyframes drift  { from { translate: -2% 0; } to { translate: 2% -2%; } }
@keyframes spin   { to { transform: rotate(360deg); } }
@keyframes twinkle{ 0%, 100% { opacity: .85; transform: scale(1); } 50% { opacity: 1; transform: scale(1.18); } }
@keyframes ping   { 75%, 100% { opacity: 0; transform: scale(2.4); } }
@keyframes draw   { to { stroke-dashoffset: 0; } }
@keyframes leaf-sway { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ---------- Small screens ---------- */
/* ---------- Mobile app shell ---------- */
.appbar { display: none; }
.nav-item .label-short { display: none; }

/* OLD: on small screens the sidebar became a horizontally scrolling strip at the top
@media (max-width: 900px) {
  .side { position: relative; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 10px 12px; gap: 4px; scrollbar-width: none; }
  .side::-webkit-scrollbar { display: none; }
  .side .brand { padding: 0 8px 0 4px; flex: none; }
  .side .brand div { display: none; }
  .nav-item { width: auto; flex: none; padding: 8px 11px; }
  .nav-item .label-long { display: none; }
  .side-foot { margin: 0 0 0 auto; padding: 0; background: none; border: 0; backdrop-filter: none; flex: none; }
  .side-foot .who, .side-foot .role { display: none; }
  .side-foot .row { margin: 0; }
} */
/* NEW: phones and portrait tablets get an app layout: glass top bar + bottom tab bar */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .appbar { display: flex; position: sticky; top: 0; z-index: 25; align-items: center; gap: 10px;
    padding: calc(8px + env(safe-area-inset-top)) 14px 8px; color: #fff;
    background: color-mix(in srgb, var(--deep) 82%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(255,255,255,.12); }
  .appbar b { font: 500 15px var(--font-head); letter-spacing: -0.01em; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .appbar .btn { min-height: 36px; }
  .side { position: fixed; left: 0; right: 0; bottom: 0; top: auto; height: auto; z-index: 25; flex-direction: row; align-items: stretch; justify-content: space-around; gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); animation: none; border-top: 1px solid rgba(255,255,255,.14); }
  .side .scrim { background: color-mix(in srgb, var(--deep) 75%, transparent); }
  .side .brand, .side-foot { display: none; }
  .nav-item { flex: 1 1 0; min-width: 0; flex-direction: column; justify-content: center; gap: 3px; padding: 6px 2px; min-height: 52px; border-radius: 12px; font-size: 11px; text-align: center; }
  .nav-item svg { width: 21px; height: 21px; }
  .nav-item .label-long { display: none; }
  .nav-item .label-short { display: block; }
  .nav-item .count { position: absolute; margin: 0; top: 3px; left: 50%; transform: translateX(6px); font-size: 10px; padding: 0 6px; }
  .nav-item { position: relative; }
  main { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  #toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .page-hero { padding: 24px 16px 54px; }
  .page-hero .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content { padding: 0 16px 40px; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .auth-wrap { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .rx-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding: 8px; border: 1px solid var(--line); border-radius: 10px; }
  .rx-row input[name="med"] { grid-column: 1 / -1; }
  .rx-head { display: none; }
}

/* Phones: thumb-sized controls, no iOS zoom on focus, tables as cards, forms as full-screen sheets */
@media (max-width: 640px) {
  input, select, textarea { font-size: 16px; padding: 11px 12px; }
  .btn { min-height: 42px; padding: 9px 14px; }
  .btn.sm { min-height: 36px; padding: 6px 11px; }
  .page-hero h1 { font-size: 30px; }
  .page-hero .actions .btn { flex: 1 1 auto; }
  .card { padding: 16px; border-radius: 14px; }
  .fg { grid-template-columns: minmax(0, 1fr); }
  .rx-row input[name="med"] { grid-column: 1 / -1; }

  /* tables -> stacked cards; labels come from the header row (added by labelTables() in app.js) */
  .tablewrap { overflow: visible; margin: 0; }
  table.stackable, table.stackable tbody, table.stackable tr, table.stackable td { display: block; width: 100%; }
  table.stackable thead, table.stackable tr:has(> th) { display: none; }
  table.stackable tr { border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; background: var(--card); }
  table.stackable td { border: 0; padding: 6px 0; display: flex; gap: 14px; justify-content: space-between; align-items: center; text-align: right; min-height: 34px; }
  table.stackable td::before { content: attr(data-label); font: 500 10.5px var(--font-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); text-align: left; flex: none; }
  table.stackable td:not([data-label])::before, table.stackable td[data-label=""]::before { content: none; }
  table.stackable td:not([data-label]) { justify-content: flex-end; }
  table.stackable td > .row { justify-content: flex-end; }
  table.stackable td.empty { justify-content: center; }

  /* modals become bottom sheets that fill the screen; Save stays visible */
  /* OLD: .modal { padding: 0; align-items: flex-end; }  (a tall sheet overflowed upward and its top couldn't be scrolled to) */
  .modal { padding: calc(28px + env(safe-area-inset-top)) 0 0; align-items: flex-start; }
  .modal-card, .modal-card.narrow { max-width: none; min-height: calc(100% - 0px); margin-top: auto; border-radius: 20px 20px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); }
  .modal-card form > .row:last-child { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); margin: 8px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--card); border-top: 1px solid var(--line); z-index: 2; }
  .modal-card form > .row:last-child .btn.primary { flex: 1; }
}

/* Installed app (no browser chrome): honour the notch at the top on wide screens too */
@media (display-mode: standalone) and (min-width: 901px) {
  .side { padding-top: calc(18px + env(safe-area-inset-top)); }
}

/* ---------- Print: prescription only ---------- */
@media print {
  body { background: #fff; color: #000; }
  #app, .modal, #toast { display: none !important; }
  #print { display: block; padding: 8px 20px; font: 13px/1.5 Geist, system-ui, sans-serif; color: #000; }
  #print h1 { font: 400 26px "DM Sans", sans-serif; margin: 0; }
  #print table { border: 1px solid #999; margin-top: 6px; }
  #print th, #print td { border: 1px solid #999; color: #000; padding: 5px 8px; }
  #print hr { border: 0; border-top: 2px solid #000; }
}
