:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f2f4f7; --ink: #101828; --ink-2: #475467; --ink-3: #5d6b82;
  --line: #e4e7ec; --line-2: #d0d5dd; --accent: #1d4ed8; --accent-soft: #eef4ff; --hit: #fffaeb; --hit-line: #fec84b;
  --b-narcotic: #c01048; --b-controlled: #b54708; --b-targeted: #6938ef; --b-rx: #1d4ed8; --b-bio: #0e7490; --b-otc: #067647; --b-other: #667085;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1e222b; --ink: #f0f2f5; --ink-2: #b4bccb; --ink-3: #98a2b3;
    --line: #262b36; --line-2: #343a47; --accent: #7aa7ff; --accent-soft: #1a2540; --hit: #2a2414; --hit-line: #b8860b;
    --b-narcotic: #ff6b8d; --b-controlled: #f7a35c; --b-targeted: #a990ff; --b-rx: #7aa7ff; --b-bio: #4cc3d9; --b-otc: #4fd18b; --b-other: #98a2b3;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--sans); }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
kbd { font: 11.5px var(--mono); padding: 1px 5px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); color: var(--ink-2); }

/* ---------- header with the search box */
.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
       backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.bar, .meta, main, .foot { width: min(1040px, 100% - 32px); margin-inline: auto; }
.bar { display: flex; align-items: center; gap: 14px; padding: 14px 0 8px; }
.logo { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 650; font-size: 18px; letter-spacing: -.01em; flex: none; }
.logo svg { width: 26px; height: 26px; fill: none; stroke: var(--accent); stroke-width: 2.2; }
.logo b { color: var(--accent); font-weight: 650; }
.search { position: relative; flex: 1; min-width: 0; }
.search-icon { position: absolute; left: 15px; top: 50%; width: 19px; height: 19px; margin-top: -9.5px; fill: none; stroke: var(--ink-3); stroke-width: 2; pointer-events: none; }
#q, .ghost { font: 500 18px var(--sans); letter-spacing: 0; padding: 0 64px 0 46px; height: 50px; }
#q { position: relative; width: 100%; border: 1.5px solid var(--line-2); border-radius: var(--radius); background: transparent; color: var(--ink); outline: none;
     transition: border-color .12s, box-shadow .12s; }
.search { background: var(--surface); border-radius: var(--radius); }
#q:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
#q::placeholder { color: var(--ink-3); font-weight: 400; }
#q::-webkit-search-cancel-button { display: none; }
.ghost { position: absolute; inset: 0; display: flex; align-items: center; white-space: pre; overflow: hidden; pointer-events: none; border: 1.5px solid transparent; }
.ghost-typed { color: transparent; }
.ghost-rest { color: var(--ink-3); opacity: .75; }
.esc-hint { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.lang, .settings summary { height: 40px; min-width: 40px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface);
  font-weight: 600; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); flex: none; }
.lang:hover, .settings summary:hover { color: var(--ink); border-color: var(--ink-3); }
.settings { position: relative; flex: none; }
.settings summary { list-style: none; }
.settings summary::-webkit-details-marker { display: none; }
.settings summary svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.settings[open] summary { color: var(--accent); border-color: var(--accent); }
.settings-panel { position: absolute; right: 0; top: calc(100% + 8px); width: 300px; padding: 14px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 16px 40px -12px rgba(16, 24, 40, .25); }
.settings-title { margin: 0 0 10px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.switch { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .track { flex: none; width: 36px; height: 20px; border-radius: 999px; background: var(--line-2); position: relative; margin-top: 1px; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch small { display: block; color: var(--ink-3); font-size: 12.5px; }

.meta { display: flex; align-items: center; gap: 6px 12px; flex-wrap: wrap; min-height: 34px; padding: 0 0 8px; font-size: 13px; color: var(--ink-2); }
.meta b { color: var(--ink); font-weight: 600; }
.suggest { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; padding: 3px 11px; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip-brand { font-weight: 600; color: var(--ink); }
.suggest { flex-wrap: nowrap; overflow: hidden; mask-image: linear-gradient(90deg, #000 85%, transparent); min-width: 0; flex: 1; }
.suggest .chip { flex: none; white-space: nowrap; }

/* ---------- welcome */
main { padding: 16px 0 40px; }
.welcome { padding: 28px 0 10px; color: var(--ink-2); }
.hint { font-size: 17px; margin: 0 0 14px; color: var(--ink); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 26px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 22px; }
.legend div { margin: 0; }
.keys { font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }

/* ---------- badges: a letter code + label, never colour alone */
.badge { --c: var(--b-other); display: inline-flex; align-items: center; gap: 7px; height: 26px; padding: 0 9px 0 0; border-radius: 7px;
  background: color-mix(in srgb, var(--c) 10%, var(--surface)); color: var(--c); font-size: 12.5px; font-weight: 600; white-space: nowrap; flex: none; }
.badge b { display: inline-grid; place-items: center; min-width: 30px; height: 26px; padding: 0 6px; border-radius: 7px; background: var(--c); color: var(--surface); font-size: 12px; font-weight: 750; letter-spacing: .02em; }
.badge.sm { height: 20px; padding: 0; }
.badge.sm b { height: 20px; min-width: 24px; font-size: 11px; border-radius: 5px; }
.b-narcotic { --c: var(--b-narcotic); } .b-controlled { --c: var(--b-controlled); } .b-targeted { --c: var(--b-targeted); }
.b-rx { --c: var(--b-rx); } .b-bio { --c: var(--b-bio); } .b-otc { --c: var(--b-otc); } .b-other { --c: var(--b-other); }
@media (prefers-color-scheme: dark) { .badge b { color: #0f1115; } }

/* ---------- results: one row per formulation */
.results { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row + .row { border-top: 1px solid var(--line); }
.row-main { width: 100%; display: grid; grid-template-columns: 172px minmax(0, 1fr) auto; align-items: center; gap: 16px; padding: 8px 16px;
  background: none; border: 0; text-align: left; cursor: pointer; position: relative; }
.row-main:hover { background: var(--surface-2); }
.row.sel > .row-main { background: var(--accent-soft); }
.row.sel > .row-main::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.row-main:focus-visible { outline-offset: -2px; }
.what { min-width: 0; display: grid; gap: 2px; }
.line1 { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.brand { font-size: 18px; font-weight: 700; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand.nobrand { font-weight: 600; color: var(--ink-2); }
.star { color: #d4a017; font-size: 14px; }
.tag { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); border: 1px solid var(--line-2); border-radius: 5px; padding: 0 5px; }
.line2 { display: flex; flex-wrap: wrap; gap: 0 7px; font-size: 13px; color: var(--ink-2); min-width: 0; }
.line2 .ing { color: var(--ink-2); }
.str { font-size: 16px; font-weight: 650; color: var(--ink); white-space: nowrap; margin-left: 4px; }
.frm { font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.brand { flex: 0 1 auto; min-width: 0; }
.frm2 { display: none; }
.line2 .dot { color: var(--line-2); }
.found { color: var(--ink-2); }
.found .mono { font-size: 12.5px; }
.count { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-3); white-space: nowrap; }
.count svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; transition: transform .15s; }
.row.open .count svg { transform: rotate(90deg); }
.row.gone .brand, .row.gone .line2 { opacity: .6; }

/* ---------- details, opened in place */
.detail { padding: 2px 16px 16px 204px; display: grid; gap: 12px; }
.detail > * { min-width: 0; }
.desc { margin: 0; color: var(--ink); max-width: 72ch; }
.facts { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0; font-size: 13px; }
.facts dt { color: var(--ink-3); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.facts dd { margin: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); background: var(--surface-2); padding: 7px 10px; }
td { padding: 6px 10px; border-top: 1px solid var(--line); vertical-align: middle; }
tr.hit td { background: var(--hit); }
tr.hit td:first-child { box-shadow: inset 3px 0 0 var(--hit-line); }
tr.gone td { color: var(--ink-3); }
.c-din { width: 1%; white-space: nowrap; }
.din { display: inline-flex; align-items: center; gap: 6px; font: 600 13.5px var(--mono); background: none; border: 1px solid transparent; border-radius: 6px; padding: 2px 6px; margin-left: -6px; cursor: pointer; }
.din svg { width: 13px; height: 13px; fill: none; stroke: var(--ink-3); stroke-width: 2; opacity: 0; }
.din:hover, .din:focus-visible { border-color: var(--line-2); background: var(--surface); }
.din:hover svg, .din:focus-visible svg, tr.hit .din svg { opacity: 1; }
.c-st { white-space: nowrap; }
.st { font-size: 11.5px; font-weight: 600; margin-right: 6px; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); color: var(--ink-2); }
.st3 { text-decoration: line-through; }
.c-hc { width: 1%; text-align: right; }
.c-hc a { text-decoration: none; font-weight: 600; padding: 2px 6px; border-radius: 6px; }
.c-hc a:hover { background: var(--accent-soft); }
.more { margin: 12px 4px 0; font-size: 13px; }

/* ---------- footer, toast */
.foot { padding: 6px 0 40px; font-size: 12px; color: var(--ink-3); }
.foot p { margin: 0; max-width: 90ch; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; box-shadow: 0 10px 30px -10px rgba(0,0,0,.4); }

@media (max-width: 760px) {
  .bar { flex-wrap: wrap; gap: 10px; padding-top: 10px; }
  .logo span { display: none; }
  .search { order: 3; flex-basis: 100%; }
  .bar .logo { margin-right: auto; }
  #q, .ghost { font-size: 17px; height: 48px; padding-right: 14px; }
  .esc-hint { display: none; }
  .row-main { grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; padding: 11px 12px; }
  .row-main > .badge span { display: none; }
  .row-main > .badge { padding: 0; }
  .detail { padding: 0 12px 14px; }
  .brand { font-size: 17px; flex: none; max-width: 100%; }
  .line1 { flex-wrap: wrap; row-gap: 0; }
  .frm { display: none; }
  .frm2 { display: inline; }
  .str { font-size: 15px; }
  .c-co { display: none; }
  .settings-panel { width: min(300px, calc(100vw - 32px)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* review fixes */
.warn { color: var(--b-controlled); font-weight: 600; }
.orig { color: var(--ink); }
.orig b { font-weight: 650; }
.orig, .orig b { white-space: nowrap; }
.detail:not(.all) tr.extra { display: none; }
.show-all { justify-self: start; border: 1px solid var(--line-2); background: var(--surface); border-radius: 8px; padding: 5px 12px; font-size: 13px; font-weight: 600; color: var(--accent); cursor: pointer; }
.show-all:hover { border-color: var(--accent); }
.row-main:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
