/* ---------- design tokens ---------- */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dde2ea;
  --text-1: #0f1419;
  --text-2: #5a6470;
  --accent: #00a989;
  --accent-2: #006f5b;
  --accent-fg: #ffffff;
  --danger: #c8362a;
  --danger-bg: #fdecea;
  --warn-bg: #fff8e6;
  --warn-border: #f0d68a;
  --shadow-sm: 0 1px 2px rgba(15, 20, 25, 0.04), 0 1px 1px rgba(15, 20, 25, 0.03);
  --shadow-md: 0 4px 14px rgba(15, 20, 25, 0.06), 0 2px 4px rgba(15, 20, 25, 0.04);
  --radius: 10px;
  --radius-sm: 6px;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
:root[data-theme="dark"] {
  --bg: #0b0d10;
  --surface: #14181d;
  --surface-2: #1d232a;
  --border: #2a323b;
  --text-1: #f0f3f7;
  --text-2: #93a0ad;
  --accent: #1fd1ad;
  --accent-2: #00a989;
  --accent-fg: #06120f;
  --danger: #ff7062;
  --danger-bg: #2a1815;
  --warn-bg: #2a2412;
  --warn-border: #4a3f1d;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 16px;
}
.topbar-meta { display: flex; align-items: center; gap: 10px; }
.ruo-pill {
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-2);
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-1);
  border-radius: var(--radius-sm);
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- layout ---------- */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.hero { margin: 8px 0 22px; }
.hero h1 {
  font-size: 26px;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  font-weight: 700;
}
.hero p { color: var(--text-2); margin: 0; }

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  background: transparent;
  border: none;
  padding: 10px 14px;
  font: inherit;
  color: var(--text-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  font-weight: 500;
  transition: color 120ms ease, border-color 120ms ease;
}
.tab:hover { color: var(--text-1); }
.tab.active {
  color: var(--text-1);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab-panel { animation: fade 200ms ease; }
.tab-panel[hidden] { display: none; }
@keyframes fade {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- grid + cards ---------- */
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 840px) {
  .grid.two { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 18px; }
.card h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.card h3 {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
}
.card .muted { color: var(--text-2); }
.muted.small { font-size: 13px; }

/* ---------- form fields ---------- */
.field {
  display: block;
  margin-bottom: 14px;
}
.label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  margin-bottom: 6px;
}
.label-row .hint { color: var(--text-2); font-size: 12px; font-weight: 400; }

input[type=number], select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-1);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input[type=number]:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.input-with-suffix {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.input-with-suffix:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.input-with-suffix input {
  border: none;
  flex: 1;
  background: transparent;
  outline: none;
  padding: 10px 12px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--text-1);
  min-width: 0;
}
.input-with-suffix .suffix {
  padding: 0 12px;
  display: flex;
  align-items: center;
  color: var(--text-2);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 500;
  border-left: 1px solid var(--border);
}
.suffix-toggle {
  display: flex;
  background: var(--surface-2);
  border-left: 1px solid var(--border);
}
.unit-btn {
  background: transparent;
  border: none;
  padding: 0 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
  min-width: 38px;
}
.unit-btn + .unit-btn { border-left: 1px solid var(--border); }
.unit-btn:hover { color: var(--text-1); }
.unit-btn.active {
  background: var(--accent);
  color: var(--accent-fg);
}

/* ---------- buttons ---------- */
.row { display: flex; }
.row.gap-sm { gap: 8px; }
.row.align-end { align-items: flex-end; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-1);
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; }

/* ---------- result KPIs ---------- */
.result-card { background: var(--surface); }
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
  font-weight: 600;
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-1);
  font-variant-numeric: tabular-nums;
}
.kpi-value.accent { color: var(--accent); }
.kpi-sub {
  font-size: 12px;
  color: var(--text-2);
}

/* ---------- syringe visual ---------- */
.syringe-vis {
  margin-top: 8px;
  padding: 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.syr-label {
  display: flex;
  flex-direction: column;
  margin-bottom: 8px;
  font-size: 14px;
}
.syr-label strong {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 16px;
  letter-spacing: -0.01em;
}
.syr-sub { color: var(--text-2); font-size: 12px; }
.syr-svg { width: 100%; height: auto; display: block; }

/* ---------- recipe ---------- */
.recipe ol {
  margin: 0;
  padding-left: 22px;
}
.recipe li {
  margin-bottom: 6px;
  font-size: 14px;
}
.recipe li strong {
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- alerts + callouts ---------- */
.alert {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  font-weight: 500;
}
.alert.error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
}
.callout {
  margin-top: 18px;
  padding: 14px 16px;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-1);
}
.callout strong { color: var(--accent-2); }
.callout.warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}
:root[data-theme="dark"] .callout.warn strong { color: #ffd166; }

/* ---------- reference tables ---------- */
.reftable {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin-bottom: 4px;
}
.reftable th, .reftable td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.reftable th {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-2);
}
.reftable td strong { font-family: var(--font-mono); }

.formula {
  background: var(--surface-2);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
  margin: 0;
}

/* ---------- guided tab ---------- */
.checks {
  display: grid;
  gap: 6px;
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-1);
  cursor: pointer;
  padding: 6px 0;
}
.check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}

.placeholder-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: left;
  background: var(--surface);
  border-style: dashed;
}
.example-box {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}
.example-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: 6px;
}
.example-box p {
  margin: 0 0 6px;
  font-size: 14px;
  line-height: 1.55;
}
.example-box p:last-child { margin-bottom: 0; }

.plan-summary {
  padding: 14px 16px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 14.5px;
  line-height: 1.55;
}
.plan-summary strong { color: var(--accent-2); }
:root[data-theme="dark"] .plan-summary strong { color: var(--accent); }
.plan-summary .summary-line + .summary-line { margin-top: 6px; }

.protocol {
  margin-top: 18px;
}
.protocol h3 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-2);
}
.protocol ol {
  margin: 0;
  padding-left: 22px;
}
.protocol li {
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1.55;
}
.protocol li strong {
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 600;
}
.protocol p { margin: 0; font-size: 14px; line-height: 1.55; }

footer {
  margin-top: 40px;
  text-align: center;
  color: var(--text-2);
  font-size: 12px;
}
footer p { margin: 0; }

/* ---------- planner alternatives table ---------- */
.alt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 4px;
}
.alt-table thead th {
  text-align: left;
  font-weight: 500;
  color: var(--text-2);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 6px 8px 6px 0;
  border-bottom: 1px solid var(--border);
}
.alt-table tbody td {
  padding: 8px 8px 8px 0;
  border-bottom: 1px solid var(--border-faint, var(--border));
}
.alt-table tbody tr:last-child td { border-bottom: 0; }
.alt-table .fit-ok { color: var(--accent); font-weight: 500; }
.alt-table .fit-tight { color: #c98a00; font-weight: 500; }
.alt-table .fit-bad { color: var(--danger, #d44); font-weight: 500; }
.alt-table .picked { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.alt-table .picked td:first-child { font-weight: 600; }

/* compact mono in tables */
.alt-table td { font-family: var(--font-mono); }
.alt-table td:first-child { font-family: var(--font-sans); }

/* ---------- focus visibility ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- shelf-life bar ---------- */
.shelf-bar {
  position: relative;
  width: 100%;
  height: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 8px;
}
.shelf-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease, background 0.2s ease;
}
.shelf-fill.tight { background: #c98a00; }
.shelf-fill.bad { background: var(--danger, #d44); }

/* ---------- cost grid ---------- */
.cost-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 4px;
}
.cost-grid > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.cost-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
}
.cost-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

/* ---------- result actions row ---------- */
.result-actions {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.btn.btn-small {
  padding: 6px 12px;
  font-size: 12.5px;
}
.copy-flash {
  background: color-mix(in srgb, var(--accent) 18%, transparent) !important;
  border-color: var(--accent) !important;
  color: var(--accent-2) !important;
}

/* ---------- inventory tab tweaks ---------- */
.row-sep {
  font-family: var(--font-mono);
  color: var(--text-2);
  font-size: 15px;
  align-self: center;
  padding: 0 4px;
}

/* ---------- suffix-toggle wide (for dose mode) ---------- */
.suffix-toggle.wide {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.suffix-toggle.wide .unit-btn {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-2);
  font-weight: 500;
}
.suffix-toggle.wide .unit-btn.active {
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: var(--accent-2);
  font-weight: 600;
}
:root[data-theme="dark"] .suffix-toggle.wide .unit-btn.active {
  color: var(--accent);
}

/* ---------- reference dynamic tables ---------- */
#refCompoundTable details {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  padding: 0;
  background: var(--surface);
  overflow: hidden;
}
#refCompoundTable details[open] {
  background: var(--surface-2);
}
#refCompoundTable summary {
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 600;
  font-size: 14.5px;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
#refCompoundTable summary::-webkit-details-marker { display: none; }
#refCompoundTable summary::after {
  content: "+";
  font-family: var(--font-mono);
  color: var(--text-2);
  font-size: 18px;
  flex-shrink: 0;
}
#refCompoundTable details[open] summary::after {
  content: "−";
}
#refCompoundTable .ref-stab {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-2);
  padding: 2px 8px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: 999px;
  margin-left: auto;
  margin-right: 12px;
}
:root[data-theme="dark"] #refCompoundTable .ref-stab { color: var(--accent); }
#refCompoundTable .ref-body {
  padding: 0 14px 14px;
  font-size: 13.5px;
  line-height: 1.6;
}
#refCompoundTable .ref-body dl {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 4px 16px;
  margin: 0 0 10px;
}
#refCompoundTable .ref-body dt {
  font-weight: 500;
  color: var(--text-2);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  align-self: center;
}
#refCompoundTable .ref-body dd { margin: 0; font-family: var(--font-mono); font-size: 13px; }
#refCompoundTable .ref-sources {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}
#refCompoundTable .ref-sources li {
  padding: 4px 0;
  font-size: 12.5px;
}
#refCompoundTable .ref-sources a {
  color: var(--accent-2);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent-2);
}
:root[data-theme="dark"] #refCompoundTable .ref-sources a {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
#refCompoundTable .ref-sources a:hover { border-bottom-style: solid; }

#refRampTable .ramp-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
#refRampTable .ramp-row:last-child { border-bottom: 0; }
#refRampTable .ramp-name { font-weight: 600; }
#refRampTable .ramp-name small { display: block; color: var(--text-2); font-weight: 400; font-size: 11.5px; margin-top: 2px; }
#refRampTable .ramp-steps {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-2);
}
#refRampTable .ramp-steps strong { color: var(--accent-2); font-weight: 600; }
:root[data-theme="dark"] #refRampTable .ramp-steps strong { color: var(--accent); }

/* ---------- print styles ---------- */
@media print {
  .topbar, .tabs, footer, .result-actions, #g_placeholder, #p_placeholder, #i_placeholder {
    display: none !important;
  }
  .tab-panel { display: block !important; page-break-after: always; }
  .tab-panel:not(.active) { display: none !important; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  body { background: white; color: black; }
  .callout { background: #f8f8f8; }
}

/* ---------- mobile syringe + tables ---------- */
@media (max-width: 540px) {
  .syr-svg { height: 50px; }
  .alt-table { font-size: 12px; }
  .alt-table thead th, .alt-table tbody td { padding-right: 4px; }
  #refCompoundTable .ref-body dl {
    grid-template-columns: 110px 1fr;
    gap: 3px 10px;
  }
  #refRampTable .ramp-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .cost-grid { grid-template-columns: 1fr 1fr; }
}
