/* CabinetCare — "the kitchen pharmacy shelf"
   Warm paper + brand-navy ink, serif leaflet voice, mono EXP stamps.
   Brand hues (Dythan #22) unchanged: navy 255, blue 262, teal 185.
   Elderly-first: 17px body, 44px+ targets, 3px focus rings, reduced-motion safe. */

:root {
  color-scheme: light;
  /* Lexend: designed from reading-proficiency research (open apertures, tall
     x-height, generous letter spacing) to cut visual stress. One family for the
     whole page keeps every label maximally legible for arm's-length reading. */
  --serif: 'Lexend', system-ui, -apple-system, sans-serif;
  --sans: 'Lexend', system-ui, -apple-system, sans-serif;
  --mono: 'Lexend', ui-monospace, monospace;

  --ink: oklch(0.27 0.05 255);
  --ink-muted: oklch(0.48 0.035 255);
  --blue: oklch(0.58 0.20 262);
  --blue-deep: oklch(0.50 0.19 262);
  --blue-tint: oklch(0.95 0.03 262);
  --teal: oklch(0.70 0.11 185);
  --teal-tint: oklch(0.955 0.035 185);
  --teal-ink: oklch(0.42 0.09 185);
  --danger: oklch(0.53 0.19 25);
  --danger-tint: oklch(0.965 0.02 25);
  --amber-ink: oklch(0.50 0.12 75);
  --amber-tint: oklch(0.965 0.035 85);

  /* Warm paper neutrals: leaflet, not hospital chrome. */
  --paper: oklch(0.972 0.011 85);
  --card: oklch(0.993 0.006 85);
  --line: oklch(0.888 0.02 85);

  /* The pharmacist counter: the one committed color surface on the page. */
  --counter-bg: oklch(0.27 0.05 255);
  --counter-line: oklch(0.36 0.05 255);
  --counter-ink: oklch(0.965 0.01 85);
  --counter-muted: oklch(0.79 0.025 255);

  --r-ctl: 12px;
  --r-panel: 18px;
  --shadow: 0 1px 2px oklch(0.27 0.05 255 / 0.05), 0 3px 10px oklch(0.27 0.05 255 / 0.05);
  --shadow-hover: 0 2px 4px oklch(0.27 0.05 255 / 0.07), 0 8px 20px oklch(0.27 0.05 255 / 0.09);
  --toast-bg: oklch(0.24 0.035 255);
  --toast-ink: oklch(0.97 0.008 85);
}

/* Dark mode (user toggle, teacher item #4): same brand hues, cream text keeps the
   warmth. Explicit [data-theme] wins; the media query is a no-JS fallback only. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) { color-scheme: dark; }
  :root:not([data-theme]) {
    --ink: oklch(0.945 0.008 85);
    --ink-muted: oklch(0.68 0.02 255);
    --blue: oklch(0.64 0.18 262);
    --blue-deep: oklch(0.72 0.17 262);
    --blue-tint: oklch(0.27 0.045 262);
    --teal: oklch(0.72 0.11 185);
    --teal-tint: oklch(0.25 0.035 185);
    --teal-ink: oklch(0.80 0.09 185);
    --danger: oklch(0.70 0.17 25);
    --danger-tint: oklch(0.26 0.045 25);
    --amber-ink: oklch(0.80 0.11 75);
    --amber-tint: oklch(0.26 0.045 85);
    --paper: oklch(0.185 0.018 255);
    --card: oklch(0.235 0.022 255);
    --line: oklch(0.335 0.025 255);
    --counter-bg: oklch(0.25 0.04 258);
    --counter-line: oklch(0.35 0.04 258);
    --counter-ink: oklch(0.955 0.008 85);
    --counter-muted: oklch(0.76 0.025 255);
    --shadow: 0 1px 2px oklch(0 0 0 / 0.3), 0 3px 12px oklch(0 0 0 / 0.35);
    --shadow-hover: 0 2px 4px oklch(0 0 0 / 0.35), 0 10px 24px oklch(0 0 0 / 0.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: oklch(0.945 0.008 85);
  --ink-muted: oklch(0.68 0.02 255);
  --blue: oklch(0.64 0.18 262);
  --blue-deep: oklch(0.72 0.17 262);
  --blue-tint: oklch(0.27 0.045 262);
  --teal: oklch(0.72 0.11 185);
  --teal-tint: oklch(0.25 0.035 185);
  --teal-ink: oklch(0.80 0.09 185);
  --danger: oklch(0.70 0.17 25);
  --danger-tint: oklch(0.26 0.045 25);
  --amber-ink: oklch(0.80 0.11 75);
  --amber-tint: oklch(0.26 0.045 85);
  --paper: oklch(0.185 0.018 255);
  --card: oklch(0.235 0.022 255);
  --line: oklch(0.335 0.025 255);
  --counter-bg: oklch(0.25 0.04 258);
  --counter-line: oklch(0.35 0.04 258);
  --counter-ink: oklch(0.955 0.008 85);
  --counter-muted: oklch(0.76 0.025 255);
  --shadow: 0 1px 2px oklch(0 0 0 / 0.3), 0 3px 12px oklch(0 0 0 / 0.35);
  --shadow-hover: 0 2px 4px oklch(0 0 0 / 0.35), 0 10px 24px oklch(0 0 0 / 0.4);
}

/* User-chosen font (Display settings). Lexend is the default in :root above;
   these repoint every family var when the reader picks another. Atkinson
   Hyperlegible is the Braille Institute's low-vision face (ships 400/700 —
   our 600 headings resolve to bold, keeping hierarchy). */
:root[data-font="atkinson"] {
  --serif: 'Atkinson Hyperlegible', system-ui, sans-serif;
  --sans: 'Atkinson Hyperlegible', system-ui, sans-serif;
  --mono: 'Atkinson Hyperlegible', ui-monospace, monospace;
}
:root[data-font="system"] {
  --serif: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

::selection { background: var(--blue); color: white; }

/* Root font-size carries the user's text-size choice (Display settings). Every
   rem in the sheet scales from here; fixed-px touch targets stay put on purpose. */
html { font-size: calc(16px * var(--text-scale, 1)); }

body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
  font-size: 1.0625rem;
}

@media (prefers-reduced-motion: no-preference) {
  body, .topbar, .panel, .med-card, .add-panel, .med-form input, .med-form textarea,
  .med-form select, .step-btn, .chip, .btn-primary, .btn-ghost, .logo, .counter {
    transition: background-color 200ms ease, border-color 200ms ease, color 200ms ease, box-shadow 200ms ease;
  }
}

/* ---------- Header ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1.75rem;
  /* Translucent frosted bar — the paper shows through as you scroll, matching the
     considered feel of the login screen. Solid fallback where blur is unsupported. */
  background: var(--paper);
  background: color-mix(in oklch, var(--paper) 80%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Two wordmark files: navy on light, white on dark — swapped by theme so the
   logo always reads cleanly without a chip behind it. */
.logo {
  height: 42px;
  width: auto;
  display: block;
}
.logo-dark { display: none; }
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .logo-light { display: none; }
  :root:not([data-theme]) .logo-dark { display: block; }
}

/* Two tidy clusters, not five loose pills: a utility group (Display + theme) sits
   in a soft pill container, a hairline apart from the account control. */
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }

.topbar-utility {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem;
  background: color-mix(in oklch, var(--card) 70%, transparent);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.theme-toggle {
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.45rem 0.9rem;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.theme-toggle:hover { background: var(--paper); color: var(--blue); }

/* ---------- Account menu ---------- */

.account-menu { position: relative; }

.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.3rem 0.75rem 0.3rem 0.35rem;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}
.account-btn:hover,
.account-btn[aria-expanded="true"] { border-color: var(--blue); }

.avatar {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--teal);
  color: var(--counter-bg);
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}
.account-name {
  max-width: 11ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.caret { font-size: 0.7rem; color: var(--ink-muted); }
.account-btn[aria-expanded="true"] .caret { color: var(--blue); }

.account-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(300px, calc(100vw - 2rem));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-hover);
  padding: 0.5rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
@media (prefers-reduced-motion: no-preference) {
  .account-panel { animation: panel-in 180ms cubic-bezier(0.22, 1, 0.36, 1); }
}

/* The verbose profile line (name, age, allergies) now reads as the menu header,
   where it has room, instead of sprawling across the bar. */
.profile-chip {
  padding: 0.7rem 0.85rem;
  background: var(--teal-tint);
  border: 1px solid var(--teal);
  color: var(--teal-ink);
  border-radius: var(--r-ctl);
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.4;
}
.account-actions { display: flex; flex-direction: column; gap: 0.15rem; }
.account-actions .menu-item { min-height: 44px; }

/* ---------- Display settings ---------- */

.display-menu { position: relative; }

.icon-btn {
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 0.95rem;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.icon-btn span { font-weight: 700; letter-spacing: -0.01em; }
.icon-btn:hover,
.icon-btn[aria-expanded="true"] { border-color: var(--blue); color: var(--blue); }

.display-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(320px, calc(100vw - 2rem));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-hover);
  padding: 1.15rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}
@media (prefers-reduced-motion: no-preference) {
  .display-panel { animation: panel-in 180ms cubic-bezier(0.22, 1, 0.36, 1); }
}
.display-panel.hidden { display: none; }

.display-group { display: flex; flex-direction: column; gap: 0.55rem; }
.display-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-muted);
}

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
.seg-btn {
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 500;
  min-height: 44px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.seg-btn:hover { border-color: var(--blue); }
.seg-btn[aria-pressed="true"] {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
  font-weight: 600;
}
:root[data-theme="dark"] .seg-btn[aria-pressed="true"] { color: oklch(0.16 0.03 262); }

.font-options { display: flex; flex-direction: column; gap: 0.45rem; }
.font-btn {
  text-align: left;
  font-size: 1.05rem;
  font-weight: 600;
  min-height: 52px;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}
.font-btn small { font-size: 0.78rem; font-weight: 400; color: var(--ink-muted); }
.font-btn:hover { border-color: var(--blue); }
.font-btn[aria-pressed="true"] {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1.5px var(--blue);
}

@media (max-width: 640px) {
  .display-menu { position: static; }
  .display-panel {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    top: auto;
    width: auto;
  }
}

/* ---------- Page frame ---------- */

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.75rem;
}

/* The shelf head: a greeting and one plain sentence of cabinet health.
   Deliberately NOT a metric card row. */
.shelf-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem 2rem;
  flex-wrap: wrap;
  padding: 2.4rem 0 1.7rem;
}

.shelf-head-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.greeting {
  font-family: var(--serif);
  font-size: clamp(2rem, 4.2vw, 2.7rem);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.015em;
}

.status {
  margin-top: 0.45rem;
  font-size: 1.06rem;
  color: var(--ink-muted);
  max-width: 62ch;
}
.status b {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.98em;
  color: var(--ink);
}
.status em { font-style: normal; font-weight: 600; }
.status em.bad { color: var(--danger); }
.status em.warn { color: var(--amber-ink); }

.layout {
  display: grid;
  grid-template-columns: 1fr 355px;
  gap: 2rem;
  align-items: start;
  padding-bottom: 1rem;
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- The pharmacist counter (assistant) ---------- */

.counter {
  background: var(--counter-bg);
  border: 1px solid var(--counter-line);
  border-radius: var(--r-panel);
  padding: 1.9rem 1.7rem;
  color: var(--counter-ink);
  box-shadow: var(--shadow);
  position: sticky;
  top: 88px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
@media (max-width: 980px) {
  .counter { position: static; }
}

.counter h2 {
  font-family: var(--serif);
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.counter-copy {
  color: var(--counter-muted);
  font-size: 1rem;
  line-height: 1.55;
}

.counter .btn-big { width: 100%; }
.counter .btn-primary:disabled { background: var(--counter-line); color: var(--counter-muted); cursor: wait; }

.counter-help {
  color: var(--counter-muted);
  font-size: 0.88rem;
  text-align: center;
}

/* ---------- Inventory: cards live straight on the paper ---------- */

.medicine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 1.05rem;
}

.med-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem 1.15rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--card);
  box-shadow: var(--shadow);
}
@media (prefers-reduced-motion: no-preference) {
  .med-card {
    animation: card-in 460ms cubic-bezier(0.22, 1, 0.36, 1) backwards;
    animation-delay: min(calc(var(--i, 0) * 45ms), 540ms);
    transition: box-shadow 200ms ease, border-color 200ms ease, transform 200ms ease;
  }
  .med-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
}
@media (prefers-reduced-motion: reduce) {
  .med-card:hover { box-shadow: var(--shadow-hover); }
}

/* Expiry triage, glanceable at arm's length: expired cards get a full red border
   and a wash; expiring-soon cards a full amber border. (Never a side stripe.) */
.med-card[data-status="expired"] { border-color: var(--danger); background: var(--danger-tint); }
.med-card[data-status="soon"] { border-color: var(--amber-ink); }

/* The label: medicine names set in serif, like the front of the box. */
.med-card h3 {
  font-family: var(--serif);
  font-size: 1.24rem;
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: -0.005em;
  padding-right: 2.1rem;
}

.cat {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-muted);
}

/* The EXP stamp. */
.expiry { font-size: 0.88rem; font-weight: 500; padding: 0.2rem 0.6rem; border-radius: 7px; width: fit-content; }
.expiry b { font-family: var(--mono); font-weight: 600; font-size: 0.94em; }
.expiry.ok { background: var(--teal-tint); color: var(--teal-ink); }
.expiry.soon { background: var(--amber-tint); color: var(--amber-ink); }
.expiry.expired { background: var(--danger); color: white; }
:root[data-theme="dark"] .expiry.expired { background: var(--danger); color: oklch(0.18 0.02 25); }

.med-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem 0.9rem;
  color: var(--ink-muted);
  font-size: 0.88rem;
}
.med-meta .qty { font-family: var(--mono); font-weight: 500; font-size: 0.85rem; }
.med-meta .loc::before { content: "· "; }

.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag {
  font-size: 0.8rem;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink-muted);
  padding: 0.14rem 0.6rem;
  border-radius: 999px;
}
.med-card[data-status="expired"] .tag { background: var(--card); }

/* Per-card "more options" menu */
.card-menu { position: absolute; top: 0.55rem; right: 0.55rem; }
.menu-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.menu-btn:hover,
.menu-btn[aria-expanded="true"] {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
}
.menu-dropdown {
  position: absolute;
  top: 2.5rem;
  right: 0;
  min-width: 150px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  box-shadow: var(--shadow-hover);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  z-index: 5;
}
.menu-dropdown.hidden { display: none; }
.menu-item {
  font-family: var(--sans);
  font-size: 0.95rem;
  text-align: left;
  min-height: 42px;
  padding: 0.5rem 0.8rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.menu-item:hover { background: var(--paper); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-tint); }

/* Scan-photo source menu: a small popup rather than one native file input, since
   Android's default photo picker (shown when a file input has no `capture`) only
   offers existing photos and drops the camera option entirely. */
.scan-menu { position: relative; }
.scan-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 210px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-hover);
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  z-index: 50;
}
.scan-dropdown.hidden { display: none; }

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--ink-muted);
  padding: 3.5rem 1rem;
}
.empty-title {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.4rem;
}

/* ---------- Add-medicine inline panel ---------- */

.add-panel {
  border: 1.5px solid var(--blue);
  border-radius: var(--r-panel);
  background: var(--card);
  padding: 1.7rem 1.6rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-hover);
}
@media (prefers-reduced-motion: no-preference) {
  .add-panel { animation: panel-in 240ms cubic-bezier(0.22, 1, 0.36, 1); }
}
@keyframes panel-in {
  from { opacity: 0; transform: translateY(-6px); }
}
.add-panel.hidden { display: none; }

.add-panel h3 {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 1.3rem;
}

.telegram-code {
  font-family: var(--mono);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--blue);
  background: var(--teal-tint);
  border: 1.5px dashed var(--blue);
  border-radius: var(--r-ctl);
  padding: 0.9rem 1.2rem;
  text-align: center;
  margin: 1rem 0 0.5rem;
}

.med-form { display: flex; flex-direction: column; gap: 1.6rem; }

.field { display: flex; flex-direction: column; gap: 0.45rem; min-width: 0; }

.q { font-size: 1.05rem; font-weight: 600; color: var(--ink); }
.q em { font-weight: 400; font-style: normal; color: var(--ink-muted); font-size: 0.95rem; }

.help { font-size: 0.9rem; color: var(--ink-muted); }

.suggest-hint { color: var(--teal-ink); font-weight: 500; }
.suggest-hint.hidden { display: none; }

.confirm-unrecognized {
  flex-direction: row;
  align-items: flex-start;
  gap: 0.6rem;
  background: var(--amber-tint);
  border: 1px solid var(--amber-ink);
  border-radius: var(--r-ctl);
  padding: 0.75rem 0.9rem;
}
.confirm-unrecognized.hidden { display: none; }

.expiry-warning {
  color: var(--amber-ink);
  font-weight: 600;
  margin-top: 0.4rem;
}
.expiry-warning.hidden { display: none; }
.confirm-row { display: flex; align-items: flex-start; gap: 0.6rem; }
.confirm-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-height: 0;
  margin-top: 0.15rem;
  flex-shrink: 0;
  accent-color: var(--amber-ink);
}
.confirm-row span { font-size: 0.95rem; color: var(--amber-ink); }

.med-form input,
.med-form textarea,
.med-form select {
  font-family: var(--sans);
  font-size: 1.1rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  background: var(--paper);
  color: var(--ink);
  width: 100%;
  min-width: 0;
  min-height: 48px;
}
.med-form input:focus-visible,
.med-form textarea:focus-visible,
.med-form select:focus-visible,
.chip:focus-visible,
.step-btn:focus-visible,
button:focus-visible {
  outline: 3px solid oklch(0.58 0.20 262 / 0.45);
  outline-offset: 1px;
  border-color: var(--blue);
}

/* Quantity stepper */
.qty-row { display: flex; align-items: stretch; gap: 0.5rem; }
.step-btn {
  width: 52px;
  min-height: 48px;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  cursor: pointer;
  flex: none;
}
.step-btn:hover { border-color: var(--blue); color: var(--blue); }
#qty-input { width: 90px; flex: none; text-align: center; font-family: var(--mono); font-size: 1.05rem; }
.qty-row select { flex: 1; min-width: 110px; }

/* Symptom chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  font-family: var(--sans);
  font-size: 1rem;
  min-height: 42px;
  padding: 0.4rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.chip:hover { border-color: var(--blue); }
.chip.on {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
  font-weight: 500;
}
.chip.on::before { content: "✓ "; }

/* Divider before the long-term chip: a different kind of answer (why you have it),
   not one more symptom. */
.chip-divider {
  flex-basis: 100%;
  height: 1px;
  background: var(--line);
  margin: 0.15rem 0.25rem;
}
.chip-long-term {
  border-style: dashed;
  color: var(--ink-muted);
}
.chip-long-term.on {
  background: var(--amber-tint);
  border-color: var(--amber-ink);
  border-style: solid;
  color: var(--amber-ink);
  font-weight: 500;
}
.chip-long-term.on::before { content: "✓ "; }

/* Optional details */
.more { border-top: 1px solid var(--line); padding-top: 1rem; }
.more summary {
  font-size: 1rem;
  font-weight: 600;
  color: var(--blue-deep);
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.more-inner { display: flex; flex-direction: column; gap: 1.4rem; padding-top: 1.1rem; }

.form-error { color: var(--danger); font-size: 0.95rem; min-height: 1.1rem; }

.form-actions { display: flex; justify-content: flex-end; gap: 0.75rem; flex-wrap: wrap; }

/* ---------- Buttons ---------- */

.btn-primary {
  background: var(--blue);
  color: white;
  border: none;
  padding: 0.65rem 1.3rem;
  border-radius: var(--r-ctl);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
  min-height: 44px;
}
.btn-primary:hover { background: var(--blue-deep); }
:root[data-theme="dark"] .btn-primary { color: oklch(0.16 0.03 262); }
:root[data-theme="dark"] .btn-primary:hover { color: oklch(0.16 0.03 262); }
.btn-primary:active, .btn-ghost:active, .theme-toggle:active, .menu-btn:active, .step-btn:active {
  transform: scale(0.97);
}
.btn-big { font-size: 1.08rem; padding: 0.8rem 1.6rem; min-height: 52px; }

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--line);
  padding: 0.65rem 1.2rem;
  border-radius: var(--r-ctl);
  font-size: 1rem;
  font-family: var(--sans);
  cursor: pointer;
  min-height: 44px;
}
.btn-ghost:hover { color: var(--ink); border-color: var(--ink-muted); }
.btn-ghost:disabled { color: var(--ink-muted); cursor: wait; opacity: 0.7; }

/* ---------- Footer & toast ---------- */

.foot {
  text-align: center;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-muted);
  padding: 3rem 1rem 2rem;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 0.98rem;
  line-height: 1.45;
  padding: 0.85rem 1.4rem;
  border-radius: var(--r-panel);
  box-shadow: 0 4px 16px oklch(0 0 0 / 0.3);
  z-index: 100;
  max-width: min(90vw, 26rem);
  width: max-content;
  text-align: left;
  overflow-wrap: break-word;
}
.toast.hidden { display: none; }

/* ---------- Live camera capture modal (desktop "Take a photo") ---------- */
.camera-modal {
  position: fixed;
  inset: 0;
  background: oklch(0.1 0.02 255 / 0.88);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 1.5rem;
}
.camera-modal.hidden { display: none; }
.camera-frame {
  max-width: min(90vw, 640px);
  width: 100%;
  border-radius: var(--r-panel);
  overflow: hidden;
  background: black;
  box-shadow: var(--shadow-hover);
}
.camera-frame video { width: 100%; display: block; }
.camera-actions { display: flex; gap: 0.8rem; }

/* ---------- Welcome walkthrough modal (one-time, first sign-in) ---------- */
.welcome-modal {
  position: fixed;
  inset: 0;
  background: oklch(0.1 0.02 255 / 0.62);
  z-index: 220;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.welcome-modal.hidden { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .welcome-modal:not(.hidden) .welcome-card {
    animation: panel-in 240ms cubic-bezier(0.22, 1, 0.36, 1);
  }
}
.welcome-card {
  background: var(--card);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-hover);
  padding: 2rem 2rem 1.7rem;
  width: min(92vw, 720px);
  max-height: 92vh;
  overflow-y: auto;
  text-align: center;
}
.welcome-eyebrow {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--teal-ink);
}
.welcome-title {
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0.5rem 0 0.35rem;
}
.welcome-sub {
  color: var(--ink-muted);
  font-size: 1.02rem;
  line-height: 1.5;
  max-width: 46ch;
  margin: 0 auto 1.4rem;
}
.welcome-video-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--r-ctl);
  overflow: hidden;
  background: var(--counter-bg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.welcome-video-frame video { width: 100%; height: 100%; display: block; object-fit: cover; }
.welcome-play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: clamp(62px, 12vw, 82px);
  height: clamp(62px, 12vw, 82px);
  border: none;
  cursor: pointer;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--blue);
  box-shadow: 0 14px 36px oklch(0.58 0.20 262 / 0.5);
  transition: transform 200ms ease, background-color 200ms ease;
}
:root[data-theme="dark"] .welcome-play { color: oklch(0.16 0.03 262); }
.welcome-play svg { width: 40%; height: 40%; margin-left: 6%; }
.welcome-play:hover { transform: scale(1.07); background: var(--blue-deep); }
.welcome-play:focus-visible { outline: 3px solid white; outline-offset: 3px; }
.welcome-play.hidden { display: none; }
.welcome-actions { margin-top: 1.4rem; display: flex; justify-content: center; }
.welcome-actions .btn-big { min-width: 210px; }

@media (max-width: 640px) {
  .welcome-card { padding: 1.5rem 1.2rem 1.3rem; }
  .welcome-title { font-size: 1.45rem; }
}

/* ---------- Scan-in-progress overlay ---------- */
.scan-loading {
  position: fixed;
  inset: 0;
  background: oklch(0.1 0.02 255 / 0.55);
  z-index: 210;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.scan-loading.hidden { display: none; }
.scan-loading-card {
  background: var(--card);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-hover);
  padding: 2rem 2.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  text-align: center;
  max-width: min(90vw, 320px);
}
.scan-loading-card p { font-weight: 600; font-size: 1.1rem; color: var(--ink); }
.scan-loading-sub { font-weight: 400 !important; font-size: 0.92rem !important; color: var(--ink-muted) !important; }
.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid var(--line);
  border-top-color: var(--blue);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--line); }
}

.profile-chip.hidden,
#logout-btn.hidden,
#telegram-link-btn.hidden,
.account-btn.hidden,
.account-panel.hidden,
.page.hidden { display: none; }

/* ---------- Accounts: login / signup / onboarding ---------- */

.auth-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 74px);
  padding: 2.5rem 1.5rem 3.5rem;
}
.auth-gate.hidden { display: none; }

/* One contained split panel on the paper: a navy brand story beside the form,
   so the screen reads as a considered surface, not a lone card in empty space. */
.auth-shell {
  width: 100%;
  max-width: 940px;
  display: grid;
  grid-template-columns: 1.02fr 1fr;
  background: var(--card);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-hover);
  overflow: hidden;
}

/* Left: the one committed navy surface, shared with the pharmacist counter. */
.auth-brand {
  background: var(--counter-bg);
  color: var(--counter-ink);
  padding: 2.7rem 2.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 2rem;
  min-width: 0;
}
.auth-brand-mark { width: 200px; max-width: 100%; height: auto; display: block; }
.auth-brand-body { display: flex; flex-direction: column; gap: 1.6rem; }
.auth-brand-head {
  font-family: var(--serif);
  font-size: clamp(1.55rem, 2.4vw, 2rem);
  font-weight: 600;
  line-height: 1.18;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.auth-points { list-style: none; display: flex; flex-direction: column; gap: 1rem; }
.auth-points li {
  position: relative;
  padding-left: 2.1rem;
  font-size: 1.02rem;
  line-height: 1.4;
  color: var(--counter-muted);
}
.auth-points li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0.02em;
  width: 1.5rem;
  height: 1.5rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--teal);
  color: var(--counter-bg);
  font-size: 0.85rem;
  font-weight: 700;
}
.auth-brand-foot { font-size: 0.85rem; color: var(--counter-muted); }

/* Right: the form, vertically centered and comfortably narrow. */
.auth-panel {
  padding: 2.9rem 2.7rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--card);
  min-width: 0;
}
.auth-card { width: 100%; max-width: 384px; margin: 0 auto; }

.auth-title {
  font-family: var(--serif);
  font-size: 1.78rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.14;
  margin-bottom: 0.4rem;
}
.auth-sub {
  color: var(--ink-muted);
  font-size: 1.02rem;
  line-height: 1.5;
  margin-bottom: 1.8rem;
}

.auth-form { display: flex; flex-direction: column; gap: 1.15rem; }
.auth-form .field { gap: 0.4rem; }

/* The inputs the old screen never styled — they fell back to browser defaults
   and looked half-finished. Same input language as the add-medicine form. */
.auth-form input {
  font-family: var(--sans);
  font-size: 1.05rem;
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  background: var(--paper);
  color: var(--ink);
  width: 100%;
  min-height: 52px;
}
.auth-form input::placeholder { color: var(--ink-muted); opacity: 0.75; }
.auth-form input:focus-visible {
  outline: 3px solid oklch(0.58 0.20 262 / 0.4);
  outline-offset: 1px;
  border-color: var(--blue);
}
.auth-form .form-error:empty { display: none; }
.auth-form .btn-big { width: 100%; margin-top: 0.6rem; }

.auth-info {
  font-size: 0.95rem;
  color: var(--teal-ink);
  background: var(--teal-tint);
  border: 1px solid var(--teal);
  border-radius: var(--r-ctl);
  padding: 0.7rem 0.9rem;
}
.auth-info.hidden { display: none; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin: 1.4rem 0;
  color: var(--ink-muted);
  font-size: 0.85rem;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.btn-google {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  font-size: 1.02rem;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
  min-height: 52px;
}
.btn-google:hover { border-color: var(--blue); color: var(--blue); }

.auth-switch {
  margin-top: 1.6rem;
  text-align: center;
  font-size: 0.95rem;
  color: var(--ink-muted);
}

.link-btn {
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--blue);
  background: none;
  border: none;
  padding: 0.3rem;
  cursor: pointer;
  min-height: 44px;
}
.link-btn:hover { color: var(--blue-deep); text-decoration: underline; }

/* Stack the split on tablet/phone: navy header with the headline, form below. */
@media (max-width: 760px) {
  .auth-shell { grid-template-columns: 1fr; max-width: 470px; }
  .auth-brand { padding: 1.9rem 1.7rem; gap: 1rem; }
  .auth-brand-head { font-size: 1.4rem; }
  .auth-points, .auth-brand-foot { display: none; }
  .auth-panel { padding: 2.1rem 1.7rem; }
  .auth-card { max-width: none; }
}

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 0.7rem 1.1rem; }
  .topbar-actions { width: 100%; flex-wrap: wrap; }
  .logo { height: 36px; }
  .profile-chip { border-radius: 12px; font-size: 0.88rem; flex: 1 1 100%; }
  .theme-toggle { flex: none; }

  .page { padding: 0 1.1rem; }
  .shelf-head { padding: 1.6rem 0 1.3rem; }
  .shelf-head-actions { width: 100%; }
  .shelf-head-actions .btn-big { flex: 1; }
  .scan-menu { flex: 1; }
  .scan-menu .btn-big { width: 100%; }
  .scan-dropdown { position: fixed; left: 1rem; right: 1rem; bottom: 1rem; top: auto; width: auto; }
  .status { font-size: 1rem; }
  .counter { padding: 1.5rem 1.3rem; }
  .add-panel { padding: 1.3rem 1.15rem; }
  .medicine-grid { grid-template-columns: 1fr; }
  .foot { padding-bottom: 5.5rem; }
}
