/* ============================================================================
   PenToPill — design system
   ----------------------------------------------------------------------------
   Built for a pharmacist standing at a counter with a customer waiting: a phone
   or tablet held one-handed, under hard fluorescent light, often with wet or
   gloved hands. That sets the rules the rest of this file follows.

     Colour carries clinical meaning ONLY. Teal / amber / red mean high /
     check-carefully / low confidence and nothing else, so a coloured thing on
     screen is always a thing to think about. Commercial information — price,
     savings, cheapest — is deliberately monochrome and typographic, because a
     green price tag next to a green confidence band would teach the eye to read
     "cheap" as "safe".

     Touch targets are 44px minimum. Prices are tabular so a column of them can
     be scanned rather than read.

   One token block. There is no second :root further down overriding this one.
   ========================================================================= */

:root {
  /* --- Brand ramp: clinical teal --- */
  --teal-50:  #eef6f4;
  --teal-100: #d7ebe7;
  --teal-200: #a8d4cd;
  --teal-500: #12857c;
  --teal-600: #0f766e;
  --teal-700: #0b5a54;
  --teal-900: #0a3d39;

  /* --- Neutrals: warm greys, so white paper under warm shop light matches --- */
  --ink:      #14231e;
  --ink-2:    #33453e;
  --muted:    #5d6d66;
  --muted-2:  #84968f;
  --line:     #e2e9e5;
  --line-2:   #cfd9d4;
  --surface:  #ffffff;
  --surface-2:#f1f4f2;
  --bg:       #f6f8f7;

  /* --- Clinical signal --- */
  --high:     #0f766e;  --high-bg:   #e4f2ef;  --high-line:   #9ecec7;
  --medium:   #a1560a;  --medium-bg: #fdf3e4;  --medium-line: #eabe86;
  --low:      #b3261e;  --low-bg:    #fceceb;  --low-line:    #eaa9a4;
  --danger:   #b3261e;

  /* --- Aliases kept so existing markup keeps working --- */
  --primary:      var(--teal-600);
  --primary-dark: var(--teal-700);
  --primary-tint: var(--teal-50);

  /* --- Space: 4px base --- */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 24px; --s7: 32px; --s8: 44px;

  /* --- Radius --- */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius:    14px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  /* --- Elevation. Shallow and tight; this is a tool, not a showcase. --- */
  --shadow-sm: 0 1px 2px rgba(16, 40, 34, .06);
  --shadow:    0 1px 3px rgba(16, 40, 34, .05), 0 8px 22px -14px rgba(16, 40, 34, .22);
  --shadow-lg: 0 2px 6px rgba(16, 40, 34, .06), 0 22px 44px -22px rgba(16, 40, 34, .28);
  --ring: 0 0 0 4px rgba(15, 118, 110, .16);

  /* --- Type ---
     Arabic is listed in the same stack rather than swapped in, so a mixed
     "Bactroban باكتروبان" string renders both scripts without a font swap
     mid-line. SF Arabic / Geeza Pro cover Apple, Segoe UI + Tahoma cover
     Windows, Noto covers Android and Linux. All system fonts: the app has to
     work in a pharmacy with no connection. */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
          "SF Arabic", "Geeza Pro", "Noto Naskh Arabic", "Noto Sans Arabic",
          Tahoma, Arial, sans-serif;
  --font-ar: "SF Arabic", "Geeza Pro", "Noto Naskh Arabic", "Noto Sans Arabic",
             "Segoe UI", Tahoma, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --text-xs: .78rem;
  --text-sm: .86rem;
  --text-md: .95rem;
  --text-lg: 1.06rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;

  --tap: 44px;   /* minimum comfortable touch target */
}

/* ============================================================================
   Base
   ========================================================================= */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(1100px 460px at 12% -10%, #edf5f3 0%, transparent 62%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--teal-700); text-decoration: none; }
a:hover { text-decoration: underline; }

:where(a, button, input, select, textarea):focus-visible {
  outline: 3px solid var(--teal-200);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

h1, h2, h3 { margin: 0 0 var(--s1); line-height: 1.25; }
h1 { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -.022em; }
h2 { font-size: var(--text-lg); font-weight: 650; letter-spacing: -.012em; margin-bottom: var(--s3); }
h3 { font-size: var(--text-md); font-weight: 650; }
p  { margin: 0 0 var(--s3); }

.sub { color: var(--muted); font-size: var(--text-md); margin: 0 0 var(--s5); }

/* Arabic drug names sit inside Latin sentences everywhere in this app. <bdi>
   plus explicit isolation stops the bidi algorithm from dragging a trailing
   "2%" or "·" to the wrong side of the name. */
.ar, bdi.ar {
  font-family: var(--font-ar);
  unicode-bidi: isolate;
  direction: rtl;
  font-size: 1.02em;   /* Arabic runs optically smaller at the same px size */
  line-height: 1.7;
}

/* Any field that may hold either script — raw prescription text, drug names
   typed by a pharmacist — decides its own direction from its first strong
   character rather than inheriting the page's. */
.bidi-auto { unicode-bidi: isolate; }

/* ============================================================================
   Layout
   ========================================================================= */

.wrap { max-width: 1080px; margin: 0 auto; padding: var(--s5) var(--s4) 64px; }
.narrow { max-width: 460px; }

.grid { display: grid; gap: var(--s4); }
@media (min-width: 760px) {
  .grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--s5);
}
.card + .card { margin-top: var(--s4); }
a.card { display: block; transition: transform .16s ease, box-shadow .16s ease; }
a.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); text-decoration: none; }
a.card h2 { color: var(--teal-700); }

.section-title {
  display: flex; align-items: baseline; gap: var(--s2);
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); margin: 0 0 var(--s3);
}

footer.foot {
  text-align: center; color: var(--muted); font-size: var(--text-xs);
  padding: var(--s7) 0 var(--s3); line-height: 1.6;
}

/* ============================================================================
   Top bar
   ========================================================================= */

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(180deg, var(--teal-500) 0%, var(--teal-600) 100%);
  color: #eafcf8;
  box-shadow: 0 1px 0 rgba(255,255,255,.10) inset, 0 6px 20px -14px rgba(8,60,55,.7);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 var(--s4);
  min-height: 60px; display: flex; align-items: center; gap: var(--s4);
}
.brand {
  display: flex; align-items: center; gap: var(--s2);
  font-weight: 700; font-size: var(--text-lg); color: #fff; letter-spacing: -.01em;
}
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 32px; height: 32px; border-radius: var(--radius-sm); background: #fff;
  color: var(--teal-600); display: grid; place-items: center; flex: none;
}
/* The mark inherits `color`, so the same SVG is a teal glyph on this white
   chip and a white glyph on the teal auth chip. */
.brand .logo .mark { width: 22px; height: 22px; display: block; }

/* Wordmark. "To" drops a weight and a little contrast so the three words read
   as three; at one uniform weight "PenToPill" collapses into "pen-top-ill". */
.wordmark { letter-spacing: -.015em; white-space: nowrap; }
.wordmark .wm-to { font-weight: 500; opacity: .68; }

.nav { display: flex; gap: var(--s1); align-items: center; margin-left: auto; }
.nav-user { display: flex; gap: var(--s2); align-items: center; margin-left: var(--s3); }
.nav a {
  color: #d6f2ec; padding: 10px var(--s3); border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-weight: 600; transition: background .14s;
  display: inline-flex; align-items: center; min-height: 40px;
}
.nav a:hover { background: rgba(255,255,255,.13); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.20); color: #fff; }
.nav-user form { margin: 0; }
.nav-user .who {
  color: #bfe6df; font-size: var(--text-xs);
  padding-left: var(--s3); border-left: 1px solid rgba(255,255,255,.22);
}
.nav .btn-signout {
  background: transparent; color: #d6f2ec;
  border-color: rgba(255,255,255,.32); min-height: 40px; padding: 8px var(--s3);
}
.nav .btn-signout:hover { background: rgba(255,255,255,.13); filter: none; }

/* Mobile: the nav collapses to a scrollable strip under the brand. A hamburger
   would hide Scan behind a tap, and Scan is the whole job. */
@media (max-width: 759px) {
  .topbar-inner { flex-wrap: wrap; gap: var(--s2); padding: var(--s2) var(--s3); min-height: 0; }
  .brand { font-size: var(--text-md); }
  .nav {
    order: 3; width: 100%; gap: var(--s1); margin-left: 0;
    overflow-x: auto; scrollbar-width: none; padding-bottom: 2px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: none; }
  .nav-user { margin-left: auto; }
  .nav-user .who {
    border-left: none; padding-left: 0;
    white-space: nowrap; max-width: 38vw; overflow: hidden; text-overflow: ellipsis;
  }
  .nav-user .btn-signout { min-height: 36px; padding: 6px var(--s3); font-size: var(--text-sm); }
}

/* ============================================================================
   Buttons — 44px minimum, always
   ========================================================================= */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); padding: 11px var(--s4);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-weight: 650; letter-spacing: -.005em;
  background: var(--surface-2); color: var(--ink);
  cursor: pointer; text-align: center;
  transition: filter .12s ease, background .14s ease, transform .04s ease;
}
.btn:hover { filter: brightness(.97); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(180deg, var(--teal-500) 0%, var(--teal-600) 100%);
  color: #fff;
  box-shadow: 0 1px 2px rgba(8,60,55,.24), inset 0 1px 0 rgba(255,255,255,.14);
}
.btn-primary:hover { background: linear-gradient(180deg, var(--teal-600) 0%, var(--teal-700) 100%); filter: none; }
.btn-ghost { background: transparent; border-color: var(--line-2); }
.btn-ghost:hover { background: var(--surface-2); filter: none; }
.btn-danger { background: transparent; border-color: var(--low-line); color: var(--low); }
.btn-danger:hover { background: var(--low-bg); filter: none; }
.btn-block { width: 100%; }
.btn-lg { min-height: 52px; padding: 14px var(--s5); font-size: var(--text-lg); border-radius: var(--radius); }
.btn-sm { min-height: 36px; padding: 6px var(--s3); font-size: var(--text-sm); font-weight: 600; }

/* ============================================================================
   Forms
   ========================================================================= */

label { font-weight: 650; font-size: var(--text-sm); display: block; margin-bottom: var(--s1); }

input[type=text], input[type=email], input[type=password], input[type=search],
input[type=number], textarea, select {
  width: 100%; min-height: var(--tap); padding: 11px var(--s3);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  font: inherit; font-size: 16px;   /* 16px stops iOS zooming the page on focus */
  background: #fff; color: var(--ink);
  transition: border-color .14s, box-shadow .14s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--teal-600); box-shadow: var(--ring);
}
select {
  appearance: none; padding-right: 38px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' stroke='%235d6d66' stroke-width='1.6' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 14px center;
}
.field { margin-bottom: var(--s4); }
.field .hint { color: var(--muted); font-size: var(--text-xs); margin-top: var(--s1); }
.field .err  { color: var(--danger); font-size: var(--text-xs); margin-top: var(--s1); font-weight: 600; }

/* ============================================================================
   Badges & chips
   ========================================================================= */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  padding: 3px 9px; border-radius: var(--radius-xs);
  white-space: nowrap;
}
.badge.high   { background: var(--high-bg);   color: var(--high); }
.badge.medium { background: var(--medium-bg); color: var(--medium); }
.badge.low,
.badge.none   { background: var(--low-bg);    color: var(--low); }
.badge.status { background: var(--teal-50);   color: var(--teal-700); }
.badge.muted  { background: var(--surface-2); color: var(--muted); }

.pill-row { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ============================================================================
   Price — monochrome on purpose. See the note at the top of this file.
   ========================================================================= */

.price {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  font-weight: 700; color: var(--ink);
  white-space: nowrap;
}
.price .cur { font-size: .74em; font-weight: 600; color: var(--muted); margin-right: 2px; }
.price-lg { font-size: var(--text-xl); letter-spacing: -.02em; }
.price-none { color: var(--muted); font-weight: 600; }

/* Ink-filled, so it reads as an editorial label and never as a safety colour. */
.chip-cheapest {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--ink); color: #fff;
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em;
  padding: 3px 7px; border-radius: var(--radius-xs); white-space: nowrap;
}
.saving {
  font-size: var(--text-xs); font-weight: 650; color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 2px 7px; border-radius: var(--radius-xs); white-space: nowrap;
}

/* Dataset prices are a reference, not a live price list. Said once per screen,
   quietly, but never omitted — a pharmacist quoting a stale price to a customer
   is a real problem and this data is open, not EDA-official. */
.price-caveat {
  display: flex; gap: var(--s2); align-items: flex-start;
  font-size: var(--text-xs); color: var(--muted); line-height: 1.5;
}

/* ============================================================================
   Alerts
   ========================================================================= */

.alert {
  padding: var(--s3) var(--s4); border-radius: var(--radius-sm);
  margin-bottom: var(--s4); font-size: var(--text-md);
  border: 1px solid transparent;
}
.alert-info  { background: var(--teal-50);   color: var(--teal-700); border-color: var(--teal-100); }
.alert-warn  { background: var(--medium-bg); color: var(--medium);   border-color: var(--medium-line); }
.alert-error { background: var(--low-bg);    color: var(--low);      border-color: var(--low-line); }

/* ============================================================================
   Stats & tables
   ========================================================================= */

.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: var(--s4) var(--s5); box-shadow: var(--shadow-sm);
}
.stat .n {
  font-size: 1.7rem; font-weight: 800; letter-spacing: -.025em;
  font-variant-numeric: tabular-nums; line-height: 1.15;
}
.stat .l { color: var(--muted); font-size: var(--text-sm); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-md); }
th, td { text-align: left; padding: var(--s3); border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  color: var(--muted); font-size: var(--text-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }

/* A dispensing record on a phone. Sideways-scrolling a table means the drug
   name scrolls out of view while you read its price, so below the breakpoint
   each row becomes its own labelled block instead. */
@media (max-width: 640px) {
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr {
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    padding: var(--s2) var(--s3); margin-bottom: var(--s2); background: var(--surface);
  }
  /* Block, not flex. A flex cell turns every child into its own column, which
     split the Arabic name away from the Latin one it belongs under. As a block,
     short values sit inline after the label and block children (the Arabic name)
     drop to the line below where they belong. */
  /* Label above value, both plain blocks.
     Two cleverer layouts were tried and both break on real cells. A flex row
     turns every child into its own column, splitting the Arabic name away from
     the Latin one. A hanging indent (text-indent + padding) drags inline-block
     children — status badges, the Continue button — left across their own
     label. Stacking costs a line per field and survives any content. */
  .table-stack td { border-bottom: none; padding: 3px 0; }
  .table-stack td::before {
    content: attr(data-label);
    display: block; margin-bottom: 1px;
    color: var(--muted); font-size: 10px;
    font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  }
  .table-stack td[data-label=""]::before { display: none; }
  .table-stack td:empty { display: none; }
  .table-stack td.num { text-align: left; }
}

/* ============================================================================
   Capture
   ========================================================================= */

.capture-stage {
  position: relative; background: #0d1a17; border-radius: var(--radius);
  overflow: hidden; min-height: 240px; max-height: 62vh;
  display: grid; place-items: center;
  outline: 2px dashed transparent; outline-offset: -6px;
  transition: outline-color .15s;
}
.capture-stage.is-empty { aspect-ratio: 3 / 4; }
.capture-stage.drop-active { outline-color: var(--teal-600); }

/* NEVER `cover` here — that crops. The pharmacist must see the WHOLE
   prescription to confirm the redaction covers the patient name and that the
   full script is in frame. `contain` for video; intrinsic-ratio scaling for the
   canvas (object-fit does not apply to canvas painting). */
.capture-stage video, .capture-stage img {
  width: 100%; height: 100%; object-fit: contain; background: #000;
}
.capture-stage canvas {
  display: block; max-width: 100%; max-height: 62vh;
  width: auto; height: auto; touch-action: none; cursor: crosshair;
}
.capture-stage .overlay {
  position: absolute; inset: 14px; border: 2px dashed rgba(255,255,255,.5);
  border-radius: var(--radius-sm); pointer-events: none;
}
.capture-stage .hint {
  position: absolute; bottom: var(--s3); left: var(--s3); right: var(--s3);
  text-align: center; color: #eafcf8; font-size: var(--text-sm);
  background: rgba(0,0,0,.42); padding: 6px var(--s3); border-radius: var(--radius-xs);
}
.capture-actions { display: flex; gap: var(--s2); margin-top: var(--s3); flex-wrap: wrap; }
.capture-actions .btn { flex: 1 1 128px; }
.capture-meta { margin-top: var(--s1); text-align: right; min-height: 1em; }

.privacy-note {
  display: flex; gap: var(--s2); align-items: flex-start;
  font-size: var(--text-sm); color: var(--muted); margin-top: var(--s3); line-height: 1.5;
}

.how-list { margin: var(--s4) 0 0; padding: 0; list-style: none; counter-reset: step; }
.how-list li {
  counter-increment: step; position: relative; padding: 7px 0 7px 34px;
  color: var(--muted); font-size: var(--text-sm);
}
.how-list li::before {
  content: counter(step); position: absolute; left: 0; top: 7px;
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--teal-50); color: var(--teal-700); font-size: .72rem; font-weight: 800;
}

/* ============================================================================
   Review / confirm
   ========================================================================= */

/* The summary rail: progress and running total, the two things a pharmacist
   glances at between lines. Sticks under the top bar so the total stays
   visible while scrolling a long prescription. */
.rx-summary {
  position: sticky; top: 60px; z-index: 15;
  background: rgba(255,255,255,.94);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--s3) var(--s4); margin-bottom: var(--s4);
  display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap;
}
.rx-summary .progress-bar { flex: 1 1 220px; margin: 0; }
.rx-summary .basket { margin-left: auto; text-align: right; }
.rx-summary .basket .l {
  font-size: 10px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); display: block;
}
.rx-summary .basket .partial { font-size: var(--text-xs); color: var(--medium); font-weight: 600; }

.progress-bar { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s4); }
.progress-bar .track {
  flex: 1; height: 8px; border-radius: 4px; background: var(--surface-2);
  overflow: hidden; border: 1px solid var(--line);
}
.progress-bar .track > span {
  display: block; height: 100%; background: var(--teal-600);
  transition: width .25s ease;
}

.line-card {
  border: 1px solid var(--line); border-left: 5px solid var(--line-2);
  border-radius: var(--radius); background: var(--surface);
  box-shadow: var(--shadow-sm); margin-bottom: var(--s4); overflow: hidden;
  transition: box-shadow .16s;
}
.line-card:not(.confirmed):hover { box-shadow: var(--shadow); }
.line-card.band-high { border-left-color: var(--high); }
.line-card.band-medium { border-left-color: var(--medium); }
.line-card.band-low, .line-card.band-none { border-left-color: var(--low); }
/* A hand-added line has no confidence to report — it was never read, so it is
   not "low". Colour in this file means clinical confidence and nothing else, so
   a manual line stays neutral rather than borrowing the red that means "check
   this against the paper". */
.line-card.band-manual { border-left-color: var(--line-2); }
.line-card.confirmed { border-left-color: var(--high); background: var(--high-bg); }

.line-head {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line);
}
.line-head .idx {
  width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2);
  display: grid; place-items: center; font-weight: 800; font-size: var(--text-xs);
  flex: none; margin-top: 1px; color: var(--ink-2);
}
.line-head .raw { font-weight: 700; min-width: 0; word-break: break-word; }
.line-head .raw small {
  display: block; font-weight: 400; color: var(--muted);
  font-size: var(--text-xs); margin-top: 2px; line-height: 1.45;
}
.line-head .spacer { margin-left: auto; }
.line-body { padding: var(--s2) var(--s4) var(--s4); }

/* --- Candidate rows --- */
.candidate {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--s1) var(--s3);
  align-items: start;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: var(--s3); margin-top: var(--s2);
  cursor: pointer; background: var(--surface);
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.candidate:hover { border-color: var(--teal-200); background: var(--teal-50); }
.candidate.is-selected {
  border-color: var(--teal-600); background: var(--teal-50);
  box-shadow: 0 0 0 1px var(--teal-600) inset;
}
.candidate.discontinued { opacity: .6; }

.candidate .cname {
  font-weight: 700; font-size: var(--text-lg); letter-spacing: -.01em;
  display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap;
}
.candidate .cname .ar { font-weight: 600; color: var(--ink-2); }
.candidate .cmeta {
  color: var(--muted); font-size: var(--text-sm); margin-top: 2px; line-height: 1.45;
}
.candidate .cmeta .mfr { text-transform: capitalize; }

.candidate .cprice {
  grid-column: 2; grid-row: 1;
  text-align: right; display: flex; flex-direction: column;
  align-items: flex-end; gap: var(--s1);
}
.candidate .cscore {
  font-size: var(--text-xs); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.candidate .barlt {
  height: 4px; border-radius: 2px; background: var(--surface-2);
  overflow: hidden; grid-column: 1 / -1; margin-top: var(--s1);
}
.candidate .barlt > span { display: block; height: 100%; background: var(--teal-200); }

/* Validation conflicts — dose/form disagrees with the read. Safety-critical:
   must be impossible to miss next to a confident-looking name. */
.candidate .cwarn {
  grid-column: 1 / -1;
  margin-top: var(--s1); font-size: var(--text-xs); line-height: 1.4;
  color: var(--medium); background: var(--medium-bg);
  border-left: 3px solid var(--medium-line);
  border-radius: var(--radius-xs); padding: 4px var(--s2);
}
.candidate .cwarn.strength_clash {
  color: var(--low); background: var(--low-bg);
  border-left-color: var(--low); font-weight: 650;
}

/* --- Alternatives panel --- */
.alt-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 1px dashed var(--line-2); border-radius: var(--radius-sm);
  color: var(--teal-700); font: inherit; font-size: var(--text-sm); font-weight: 650;
  padding: 8px var(--s3); min-height: 38px; cursor: pointer; margin-top: var(--s2);
  transition: background .14s, border-color .14s;
}
.alt-toggle:hover { background: var(--teal-50); border-color: var(--teal-200); }
.alt-toggle[aria-expanded="true"] { background: var(--teal-50); border-style: solid; border-color: var(--teal-200); }
.alt-toggle .chev { transition: transform .16s; font-size: .8em; }
.alt-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }

.alt-panel {
  margin-top: var(--s2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface-2); overflow: hidden;
}
.alt-panel .alt-head {
  display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap;
  padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line);
  font-size: var(--text-xs); color: var(--muted);
}
.alt-panel .alt-head strong { color: var(--ink); }
.alt-row {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line);
  background: var(--surface); cursor: pointer; min-height: var(--tap);
  transition: background .12s;
  width: 100%; border-left: 0; border-right: 0; border-top: 0;
  font: inherit; text-align: left; color: inherit;
}
.alt-row:last-child { border-bottom: none; }
.alt-row:hover { background: var(--teal-50); }
.alt-row.is-selected {
  background: var(--teal-50);
  box-shadow: inset 3px 0 0 var(--teal-600);
}
.alt-row .an { font-weight: 650; min-width: 0; }
.alt-row .an .ar { font-weight: 600; color: var(--ink-2); margin-left: 6px; }
.alt-row .am { color: var(--muted); font-size: var(--text-xs); display: block; margin-top: 1px; }
.alt-row .ap { margin-left: auto; text-align: right; display: flex; align-items: center; gap: var(--s2); }
.alt-empty, .alt-loading { padding: var(--s3); color: var(--muted); font-size: var(--text-sm); background: var(--surface); }

/* --- Counter lookup --------------------------------------------------------
   Reuses the review screen's .candidate / .alt-* furniture so a product reads
   the same wherever it appears. The one difference is that nothing here is
   selectable, so the interactive affordances come back off: a pointer cursor
   and a hover highlight on a row that does nothing is a promise the page
   cannot keep. */
.lookup-input { width: 100%; }
.lookup-status { margin-top: var(--s2); min-height: 1.2em; }
.lookup-results { margin-top: var(--s2); }
.lookup-item + .lookup-item { margin-top: var(--s4); }
.lookup-item .candidate { cursor: default; }
.lookup-item .candidate:hover { border-color: var(--line); background: var(--surface); }
.alt-row.is-static { cursor: default; }
.alt-row.is-static:hover { background: var(--surface); }

/* --- Stored prescription photo --- */
.rx-photo-img {
  display: block; max-width: 100%; height: auto;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2);
}

/* --- "or" divider, between a primary action and its fallback --- */
.or-rule {
  display: flex; align-items: center; gap: var(--s3);
  margin: var(--s4) 0; color: var(--muted-2);
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .08em;
}
.or-rule::before, .or-rule::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* --- Dose correction --- */
.dose-edit {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: var(--s3); margin-bottom: var(--s3);
}
.dose-grid { display: grid; gap: var(--s2); grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 760px) { .dose-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.dose-grid label { font-weight: 650; color: var(--muted); margin: 0; font-size: var(--text-xs); }
.dose-grid .dose-input {
  width: 100%; margin-top: 3px; min-height: 40px; padding: 8px var(--s2);
  border: 1px solid var(--line-2); border-radius: var(--radius-xs);
  font: inherit; font-size: 16px; background: #fff; color: var(--ink);
}

/* --- Manual search --- */
.manual { position: relative; margin-top: var(--s2); }
.manual-results {
  position: absolute; z-index: 20; left: 0; right: 0; margin-top: var(--s1);
  background: #fff; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); max-height: 300px; overflow-y: auto;
}
.manual-results > div {
  padding: var(--s3); cursor: pointer; border-bottom: 1px solid var(--surface-2);
  min-height: var(--tap); display: flex; align-items: center; gap: var(--s3);
}
.manual-results > div:last-child { border-bottom: none; }
.manual-results > div:hover { background: var(--teal-50); }
.manual-results .mr-main { min-width: 0; flex: 1; }
.manual-results small { color: var(--muted); display: block; font-size: var(--text-xs); }

.line-tools {
  display: flex; gap: var(--s2); align-items: center;
  margin-top: var(--s3); flex-wrap: wrap;
}
.line-tools .confirm-btn { flex: 1 1 180px; }
.line-tools .discard-btn { color: var(--danger); border-color: var(--line-2); }
.selection-note { font-size: var(--text-xs); color: var(--muted); flex-basis: 100%; }

.chosen-note {
  display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap;
  color: var(--teal-700); font-weight: 650; padding: var(--s1) 2px;
}
.chosen-note .price { color: var(--ink); }

.unvalidated-flag {
  display: inline-block; font-size: var(--text-xs); font-weight: 650;
  color: var(--medium); background: var(--medium-bg);
  border-left: 3px solid var(--medium-line);
  border-radius: var(--radius-xs); padding: 2px var(--s2);
}

.detail-row {
  display: flex; gap: var(--s4); flex-wrap: wrap;
  color: var(--muted); font-size: var(--text-sm); margin-top: var(--s1);
}
.detail-row b { color: var(--ink); font-weight: 650; }

.add-line-row {
  display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
  margin: var(--s1) 0 var(--s5);
}

/* ============================================================================
   Auth
   ========================================================================= */

.auth-body {
  min-height: 100vh; display: grid; place-items: start center;
  background: radial-gradient(900px 420px at 50% -10%, #e8f3f0 0%, transparent 62%), var(--bg);
}
.auth-shell { width: 100%; max-width: 27rem; padding: 7vh var(--s5) var(--s7); }
.auth-brand {
  display: flex; align-items: center; justify-content: center; gap: 11px;
  font-weight: 750; font-size: 1.35rem; color: var(--teal-700); letter-spacing: -.02em;
}
.auth-brand .logo {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(180deg, var(--teal-500), var(--teal-600));
  color: #fff;
  box-shadow: 0 4px 14px -4px rgba(15,118,110,.6);
}
.auth-brand .logo .mark { width: 27px; height: 27px; display: block; }
.auth-tagline { text-align: center; color: var(--muted); margin: var(--s3) 0 var(--s6); font-size: var(--text-md); }
.auth-card { box-shadow: var(--shadow-lg); padding: var(--s6); }
.auth-card h2 { margin-bottom: var(--s5); }
.auth-note { text-align: center; color: var(--muted); font-size: var(--text-sm); margin-top: var(--s4); }
.auth-foot { text-align: center; color: var(--muted); font-size: var(--text-xs); margin-top: var(--s7); line-height: 1.6; }

.invite-fresh { border: 1px solid var(--teal-600); background: var(--teal-50); }
.copy-row { display: flex; gap: var(--s2); margin-top: var(--s3); }
.copy-row input { flex: 1; font-family: var(--font-mono); font-size: var(--text-xs); background: #fff; }

/* ============================================================================
   Utilities
   ========================================================================= */

.muted { color: var(--muted); }
.tiny { font-size: var(--text-xs); }
.mono { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.spacer-t { margin-top: var(--s5); }
.flex { display: flex; gap: var(--s2); align-items: center; }
.flex-between { display: flex; gap: var(--s3); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ============================================================================
   Small screens
   ========================================================================= */

@media (max-width: 759px) {
  .wrap { padding: var(--s4) var(--s3) 56px; }
  h1 { font-size: var(--text-xl); }
  .card { padding: var(--s4); }
  .auth-shell { padding-top: 4vh; }

  .rx-summary { top: 0; padding: var(--s3); gap: var(--s3); }
  .rx-summary .basket { margin-left: auto; }

  .line-head { padding: var(--s3); flex-wrap: wrap; }
  .line-head .spacer { display: none; }
  .line-head .raw { flex: 1 1 0; min-width: 0; }
  /* The badge takes its own line rather than squeezing the prescription text
     into a narrow column on a 375px screen. The zero-height ::after is the line
     break; giving the badge itself flex-basis:100% would stretch it into a
     banner and push it past the card edge by its own indent. */
  .line-head::after { content: ""; order: 2; flex-basis: 100%; height: 0; }
  .line-head .band-badge { order: 3; margin-left: 38px; }
  .line-body { padding: var(--s2) var(--s3) var(--s3); }

  /* Already the second item in the top nav — no need for it twice. */
  .hide-sm { display: none !important; }

  /* Compact variants go back to full size on touch. These are in-content
     actions a pharmacist hits repeatedly, sometimes with gloves on.
     Sign-out stays small on purpose: it is a rare action sitting in the
     chrome, and growing it steals a row of vertical space on every screen. */
  .btn-sm, .alt-toggle { min-height: var(--tap); }

  /* An empty stage does not need to fill the screen. Letting it run to its full
     3:4 box pushed "Scan prescription" below the fold on a phone, so the one
     button the whole screen exists for was never visible on arrival. Drop the
     ratio rather than capping the height — capping it against a fixed ratio
     shrinks the width too, leaving the stage floating in the middle of its card. */
  .capture-stage.is-empty { aspect-ratio: auto; min-height: 240px; max-height: 40vh; }

  /* Price moves under the name rather than squeezing it into a narrow column. */
  .candidate { grid-template-columns: 1fr; }
  .candidate .cprice {
    grid-column: 1; grid-row: auto;
    flex-direction: row; align-items: center; justify-content: flex-start;
    gap: var(--s2); margin-top: var(--s1);
  }
  .candidate .cname { font-size: var(--text-md); }

  .line-tools .confirm-btn { flex: 1 1 100%; }
  .alt-row { flex-wrap: wrap; }
  .alt-row .ap { margin-left: 0; width: 100%; justify-content: flex-start; }
}

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

/* ============================================================================
   Print — the dispensing record and the counter label
   ========================================================================= */

@media print {
  .topbar, .nav, .foot, .btn, .rx-summary, .alt-toggle, .alt-panel { display: none !important; }
  body { background: #fff; }
  .wrap { max-width: none; padding: 0; }
  .card { box-shadow: none; border-color: #bbb; }
}
