:root {
  --bg: #0f1a17;
  --bg-raised: #16241f;
  --bg-card: #1b2c26;
  --line: #2a4038;
  --text: #e8f2ee;
  --text-dim: #9db8af;
  --accent: #4fd1a5;
  --accent-dark: #2e8f70;
  --sev-contra: #ff5d5d;
  --sev-major: #ff9f43;
  --sev-moderate: #ffd54f;
  --sev-minor: #6ec6ff;
  --radius: 14px;
  --tabbar-h: 62px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
}

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, #12241e, var(--bg-raised));
  border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) 0 0;
}
.topbar-inner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.logo {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent); color: #06231a;
  font-size: 22px; font-weight: 700;
}
.topbar h1 { font-size: 19px; letter-spacing: 0.3px; }
.tagline { font-size: 12px; color: var(--text-dim); }

/* Disclaimer */
.disclaimer {
  position: relative;
  margin: 10px 12px 0;
  padding: 10px 34px 10px 12px;
  background: #3a2b12;
  border: 1px solid #6b4d1c;
  color: #ffd98a;
  border-radius: 10px;
  font-size: 12.5px;
}
.disclaimer button {
  position: absolute; top: 4px; right: 6px;
  background: none; border: none; color: #ffd98a;
  font-size: 20px; cursor: pointer; padding: 4px;
}

/* Tabs */
.tab { display: none; padding: 12px; }
.tab.active { display: block; }

.searchwrap { position: sticky; top: 66px; z-index: 10; padding: 2px 0 10px; background: var(--bg); }
input[type="search"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}
input[type="search"]:focus { border-color: var(--accent-dark); }

/* Browse-mode toggle (Category / A–Z) */
.view-toggle { display: flex; gap: 6px; margin-top: 8px; }
.vt-btn {
  flex: 1; padding: 8px 10px; font-size: 13px; font-weight: 600;
  color: var(--text-dim); background: var(--bg-card);
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-family: inherit;
}
.vt-btn.active { color: #06231a; background: var(--accent); border-color: var(--accent); }

/* Drug list */
.drug-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }

/* Therapeutic group sections (browse view) */
.group { list-style: none; }
.group-header {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; cursor: pointer; color: var(--text);
  font-size: 14.5px; font-weight: 600; text-align: left; font-family: inherit;
}
.group-header:active { background: #223830; }
.group-name { flex: 1; }
.group-count {
  font-size: 12px; font-weight: 600; color: var(--text-dim);
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 9px;
}
.group-chevron { color: var(--accent); font-size: 13px; transition: transform 0.15s ease; }
.group.open .group-chevron { transform: rotate(90deg); }
.group-drugs { margin-top: 8px; padding-left: 0; }
/* `hidden` must beat the .drug-list `display:flex` rule (equal specificity) */
.group-drugs[hidden] { display: none; }
.drug-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
}
.drug-item:active { background: #223830; }
.drug-name { font-weight: 600; font-size: 15.5px; }
.drug-sub { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.species-tags { display: flex; gap: 4px; flex-shrink: 0; }
.species-tag {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: #23433a; color: var(--accent); font-weight: 600;
}
.empty { color: var(--text-dim); text-align: center; padding: 28px 10px; font-size: 14px; }

/* Severity badges */
.badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; color: #10100e;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.sev-contraindicated { background: var(--sev-contra); }
.sev-major { background: var(--sev-major); }
.sev-moderate { background: var(--sev-moderate); }
.sev-minor { background: var(--sev-minor); }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

/* Mix check */
.suggestions { margin-bottom: 10px; }
.suggestions:empty { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #23433a; color: var(--text);
  border: 1px solid var(--accent-dark);
  border-radius: 999px; padding: 7px 12px;
  font-size: 14px; cursor: pointer;
}
.chip b { color: var(--accent); font-weight: 700; }
.mix-card { margin-bottom: 10px; border-left: 4px solid var(--line); }
.mix-card.sev-b-contraindicated { border-left-color: var(--sev-contra); }
.mix-card.sev-b-major { border-left-color: var(--sev-major); }
.mix-card.sev-b-moderate { border-left-color: var(--sev-moderate); }
.mix-card.sev-b-minor { border-left-color: var(--sev-minor); }
.mix-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.mix-pair { font-weight: 700; font-size: 15px; }
.mix-title { font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; }
.mix-effect { font-size: 14px; margin-bottom: 6px; }
.mix-action { font-size: 13px; color: var(--text-dim); }
.mix-action b { color: var(--accent); }
.mix-ok {
  background: #14311f; border: 1px solid #2c5a3c; color: #a5e8b6;
  border-radius: var(--radius); padding: 12px 14px; font-size: 13.5px; margin-bottom: 10px;
}
.mix-note { font-size: 12px; color: var(--text-dim); padding: 4px 2px 16px; }

/* Detail sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 40;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-width: 640px; margin: 0 auto;
  max-height: 86vh; overflow-y: auto;
  background: var(--bg-raised);
  border: 1px solid var(--line); border-bottom: none;
  border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(24px + env(safe-area-inset-bottom));
}
.sheet-grab {
  width: 42px; height: 4px; border-radius: 4px;
  background: var(--line); margin: 4px auto 14px;
}
.sheet h2 { font-size: 20px; }
.sheet .drug-sub { margin-bottom: 10px; }
.sheet h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--accent); margin: 16px 0 6px;
}
.sheet p, .sheet li { font-size: 14px; }
.contra-list { list-style: none; }
.contra-list li {
  padding: 8px 10px 8px 30px; position: relative;
  background: #2c1d1d; border: 1px solid #4a2b2b;
  border-radius: 10px; margin-bottom: 6px;
}
.contra-list li::before { content: "⛔"; position: absolute; left: 8px; top: 8px; font-size: 13px; }
.int-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 9px 10px; background: var(--bg-card);
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px;
  cursor: pointer; font-size: 14px;
}
.sheet-close {
  position: absolute; top: 10px; right: 12px;
  background: var(--bg-card); border: 1px solid var(--line);
  color: var(--text-dim); font-size: 16px; line-height: 1;
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
}

/* About */
.about h2 { margin-bottom: 8px; }
.data-stamp {
  display: inline-block; margin-bottom: 12px;
  padding: 5px 11px; border-radius: 999px;
  background: #23433a; color: var(--accent);
  font-size: 12.5px; font-weight: 600;
}
.data-stamp b { color: var(--text); }
.about h3 { margin: 14px 0 6px; font-size: 14px; color: var(--accent); }
.about p, .about li { font-size: 13.5px; color: var(--text); }
.legend { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.legend .badge { margin-right: 6px; }
.donate-cta {
  display: flex; align-items: center; gap: 12px;
  text-decoration: none; margin: 8px 0 4px;
  padding: 12px 14px; border-radius: 12px;
  background: linear-gradient(135deg, #2a3f5f, #3a2f5a);
  border: 1px solid #4a5a80;
}
.donate-cta:active { filter: brightness(1.1); }
.donate-heart { font-size: 22px; flex-shrink: 0; }
.donate-text { font-size: 12.5px; color: var(--text); line-height: 1.4; }
.donate-text strong { display: block; color: #ffd98a; font-size: 13.5px; margin-bottom: 1px; }
.donate-text b { color: var(--accent); }
.donate-arrow { margin-left: auto; color: var(--accent); font-size: 15px; font-weight: 700; flex-shrink: 0; white-space: nowrap; }
.fineprint { margin-top: 14px; font-size: 12px; color: var(--text-dim); }

/* Site-wide footer (bottom of every tab) */
.site-footer { padding: 16px 12px 8px; margin-top: 10px; border-top: 1px solid var(--line); }
.footer-credit { text-align: center; font-size: 12.5px; color: var(--text-dim); margin-bottom: 10px; }
.footer-credit strong { color: var(--text); }
.footer-credit a { color: var(--accent); text-decoration: none; font-weight: 600; }
.site-footer .donate-cta { margin: 0; }
code { background: #10201b; padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }

/* Provenance badges (FDA-label vs extra-label vs draft) */
.prov-badge {
  display: inline-block; vertical-align: middle;
  font-size: 9.5px; font-weight: 800; letter-spacing: 0.4px;
  padding: 2px 6px; border-radius: 5px; margin-left: 7px;
  text-transform: uppercase;
}
.prov-extra { background: #4a3512; color: #ffcf7a; border: 1px solid #6b4d1c; }
.prov-draft { background: #4a1f24; color: #ff9aa6; border: 1px solid #7a2c34; }
.prov-banner {
  border-radius: 10px; padding: 9px 12px; margin: 10px 0 4px; font-size: 12.5px;
}
.prov-banner-extra { background: #3a2b12; border: 1px solid #6b4d1c; color: #ffd98a; }
.prov-banner-draft { background: #3a1a1f; border: 1px solid #7a2c34; color: #ffb3bd; }
.stamp-draft { color: #ff9aa6; }
.rx-prov {
  border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 12.5px;
}
.rx-prov-extra { background: #3a2b12; border: 1px solid #6b4d1c; color: #ffd98a; }
.rx-prov-draft { background: #3a1a1f; border: 1px solid #7a2c34; color: #ffb3bd; }

/* Rx Check */
.rx-intro { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }
.rx-intro strong { color: var(--sev-moderate); }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-dim); margin-bottom: 10px; flex: 1; }
.field select, .field input {
  padding: 11px 12px; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; width: 100%;
}
.field-row { display: flex; gap: 10px; }
.field-row .field:last-child { flex: 0 0 40%; }
.btn-primary {
  display: block; width: 100%; padding: 13px; margin-top: 6px;
  background: var(--accent); color: #06231a;
  border: none; border-radius: 12px;
  font-size: 15px; font-weight: 700; cursor: pointer;
}
.rx-card { margin-top: 12px; border-left: 4px solid var(--line); }
.rx-card p { font-size: 13.5px; margin-bottom: 6px; }
.rx-head { font-weight: 700; font-size: 15px; margin-bottom: 8px; }
.rx-ok { border-left-color: #45d06f; }
.rx-ok .rx-head { color: #7fe8a2; }
.rx-warn { border-left-color: var(--sev-moderate); }
.rx-warn .rx-head { color: var(--sev-moderate); }
.rx-fail { border-left-color: var(--sev-contra); background: #2c1d1d; }
.rx-fail .rx-head { color: var(--sev-contra); }
.rx-info { border-left-color: var(--sev-minor); }
.rx-info .rx-head { color: var(--sev-minor); }
.rx-nodata { border-left-color: var(--text-dim); }
.dose-line { margin-bottom: 6px; }
.dose-src { display: block; font-size: 11.5px; color: var(--text-dim); font-style: italic; }
#handout-btn { margin-top: 18px; }

/* Owner handout */
.handout {
  position: fixed; inset: 0; z-index: 100; overflow-y: auto;
  background: #f4f1ea; color: #1c1b18;
}
.handout-bar {
  position: sticky; top: 0; display: flex; justify-content: space-between; gap: 10px;
  padding: 10px 14px; background: #e7e2d6; border-bottom: 1px solid #cfc8b8;
}
.handout-bar button {
  padding: 9px 16px; border-radius: 10px; border: 1px solid #cfc8b8;
  background: #fff; color: #1c1b18; font-size: 14px; font-weight: 600; cursor: pointer;
}
.handout-bar .btn-primary { background: #2e8f70; color: #fff; border: none; width: auto; margin: 0; display: inline-block; }
.handout-page { max-width: 640px; margin: 0 auto; padding: 22px 20px 60px; }
.handout-page h1 { font-size: 24px; margin-bottom: 2px; }
.h-brand { font-weight: 400; color: #6b675c; font-size: 18px; }
.h-sub { color: #6b675c; font-size: 13px; margin-bottom: 18px; }
.handout-page h2 { font-size: 15px; margin: 16px 0 6px; color: #2e8f70; }
.handout-page p, .handout-page li { font-size: 14px; line-height: 1.55; margin-bottom: 6px; }
.handout-page ul { padding-left: 20px; }
.h-tip { background: #fdf6dd; border: 1px solid #e8d98f; border-radius: 8px; padding: 8px 10px; }
.h-foot { margin-top: 20px; font-size: 12px; color: #6b675c; border-top: 1px solid #cfc8b8; padding-top: 10px; }

@media print {
  body > *:not(#handout) { display: none !important; }
  body { background: #fff; padding: 0; max-width: none; }
  .handout { position: static; background: #fff; }
  .handout-bar { display: none; }
}

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-width: 640px; margin: 0 auto;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--bg-raised);
  border-top: 1px solid var(--line);
}
.tabbtn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; color: var(--text-dim);
  font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.tabbtn.active { color: var(--accent); }
.tabicon { font-size: 20px; }
