:root {
  color-scheme: dark;
  --bg: #08090c;
  --surface: #0e1017;
  --card: rgba(14, 18, 28, 0.92);
  --card-hover: rgba(18, 22, 34, 0.96);
  --line: rgba(140, 160, 200, 0.1);
  --line-strong: rgba(140, 160, 200, 0.18);
  --text: #e8edf6;
  --text-secondary: #a8b2c8;
  --text-muted: #7b86a0;
  --accent: #3ee8c8;
  --accent-dim: rgba(62, 232, 200, 0.12);
  --accent-glow: rgba(62, 232, 200, 0.06);
  --compare: #f0945e;
  --compare-dim: rgba(240, 148, 94, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --font: "Space Grotesk", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

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

html, body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
select { appearance: none; -webkit-appearance: none; }

[x-cloak], [x-show="false"] { display: none !important; }

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

/* ─── Banner ─── */
.legal-banner {
  background: #12141a;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.legal-banner__inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0.55rem 1.5rem;
  text-align: center;
  color: #b0b8cc;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.03em;
}

/* ─── Header ─── */
.shell-header {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(20px) saturate(1.4);
  background: rgba(8, 9, 12, 0.78);
  border-bottom: 1px solid var(--line);
}
.shell-header__inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
}
.shell-brand__title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

/* ─── Tab bar ─── */
.shell-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,0.02);
}
.shell-tab {
  padding: 0.6rem 1.1rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: all 160ms;
}
.shell-tab:hover { color: var(--text); }
.shell-tab--active {
  background: var(--accent-dim);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(62, 232, 200, 0.15);
}

/* ─── Layout ─── */
.app-main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
}
.workspace { animation: fadeUp 220ms ease; }
.workspace__grid {
  display: grid;
  grid-template-columns: minmax(0, 400px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}
.recon-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

/* ─── Cards ─── */
.builder-card,
.results-card,
.recon-card,
.recon-result {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  padding: 1.25rem;
}
.results-card {
  position: sticky;
  top: 5rem;
}

/* ─── Fields ─── */
.field { display: block; }
.field__label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 500;
}
.field__label--with-info {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.info-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255,255,255,0.03);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1;
  cursor: help;
  transition: border-color 140ms, color 140ms, background 140ms;
}
.info-chip:hover,
.info-chip:focus-visible {
  border-color: rgba(62, 232, 200, 0.28);
  background: rgba(62, 232, 200, 0.08);
  color: var(--accent);
  outline: none;
}
.info-chip__bubble {
  position: absolute;
  left: 50%;
  top: calc(100% + 0.7rem);
  transform: translateX(-50%) translateY(0.15rem);
  width: min(16rem, 70vw);
  padding: 0.72rem 0.8rem;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(10, 12, 18, 0.97);
  box-shadow: 0 18px 40px rgba(0,0,0,0.35);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
  text-transform: none;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 140ms, transform 140ms, visibility 140ms;
  z-index: 30;
}
.info-chip__bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  border-width: 0 6px 7px 6px;
  border-style: solid;
  border-color: transparent transparent rgba(10, 12, 18, 0.97) transparent;
}
.info-chip:hover .info-chip__bubble,
.info-chip:focus-visible .info-chip__bubble {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}
.field__control {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.025);
  padding: 0.75rem 0.95rem;
  color: var(--text);
  font-size: 1.05rem;
  outline: none;
  transition: border-color 140ms, box-shadow 140ms;
}
.field__control:focus {
  border-color: rgba(62, 232, 200, 0.4);
  box-shadow: 0 0 0 3px rgba(62, 232, 200, 0.06);
}
select.field__control {
  padding-right: 2.8rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' stroke='%239aa5bc' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
}
.field__compound { position: relative; }
.field__compound .field__control { padding-right: 3.8rem; }
.field__suffix {
  position: absolute;
  top: 50%; right: 0.85rem;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  pointer-events: none;
}
.suffix-select {
  position: absolute;
  top: 50%; right: 0.5rem;
  transform: translateY(-50%);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  padding: 0.3rem 0.4rem;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 140ms, color 140ms;
  appearance: none;
  -webkit-appearance: none;
}
.suffix-select:hover {
  border-color: var(--line-strong);
  color: var(--text-secondary);
}
.suffix-select:focus {
  border-color: rgba(62, 232, 200, 0.3);
  color: var(--text);
  outline: none;
}
.suffix-select--lg {
  font-size: 0.9rem;
  padding: 0.4rem 0.5rem;
}

.builder-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* ─── Protocol card ─── */
.protocol-card {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.015);
}
.protocol-card--compare {
  border-color: transparent;
  background: transparent;
  padding: 0;
  margin-top: 0.75rem;
}
.protocol-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.protocol-card__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}
.protocol-card__title--compare { color: var(--compare); }
.compound-badge {
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,0.03);
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.protocol-controls {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.75rem;
  grid-template-columns: 1fr;
}
.protocol-controls--dual {
  grid-template-columns: 1fr 1fr;
}

/* ─── Period rows ─── */
.period-head {
  display: grid;
  grid-template-columns: 42px 1fr 1fr 30px;
  gap: 0.55rem;
  margin-top: 0.75rem;
  padding: 0 0.15rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
}
.period-stack {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.35rem;
}
.period-row {
  display: grid;
  grid-template-columns: 42px 1fr 1fr 30px;
  gap: 0.55rem;
  align-items: center;
  padding: 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.02);
  transition: border-color 120ms;
}
.period-row:hover { border-color: var(--line-strong); }
.period-row--compare { border-color: rgba(240, 148, 94, 0.12); }
.period-row--compare:hover { border-color: rgba(240, 148, 94, 0.25); }

.period-row__index {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  border-radius: var(--radius-xs);
  background: var(--accent-dim);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
}
.period-row__index--compare {
  background: var(--compare-dim);
  color: var(--compare);
}
.period-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 120ms;
}
.period-remove:hover:not(:disabled) {
  border-color: rgba(255, 100, 120, 0.2);
  background: rgba(255, 100, 120, 0.06);
  color: #ff7e96;
}
.period-remove:disabled { opacity: 0.25; cursor: not-allowed; }

.protocol-card__actions {
  margin-top: 0.65rem;
  display: flex;
  gap: 0.75rem;
}

/* ─── Buttons ─── */
.ghost-button, .add-protocol-button, .remove-compare {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 140ms;
}
.ghost-button {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(62, 232, 200, 0.12);
}
.ghost-button:hover {
  background: rgba(62, 232, 200, 0.18);
  border-color: rgba(62, 232, 200, 0.25);
}
.ghost-button--compare {
  background: var(--compare-dim);
  color: var(--compare);
  border-color: rgba(240, 148, 94, 0.12);
}
.ghost-button--compare:hover {
  background: rgba(240, 148, 94, 0.18);
  border-color: rgba(240, 148, 94, 0.25);
}
.add-protocol-button {
  width: 100%;
  padding: 0.85rem;
  border: 1px dashed rgba(62, 232, 200, 0.2);
  background: var(--accent-glow);
  color: var(--accent);
  font-family: var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.add-protocol-button:hover {
  border-color: rgba(62, 232, 200, 0.35);
  background: var(--accent-dim);
}
.remove-compare {
  background: transparent;
  color: var(--text-muted);
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
}
.remove-compare:hover { color: #ff7e96; }

.compare-empty { margin-top: 0; }

/* ─── Chart sections ─── */
.chart-section {
  margin-bottom: 1rem;
}
.chart-section:last-of-type { margin-bottom: 0; }
.chart-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.chart-section__title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* Washout toggle */
.washout-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text-secondary);
}
.washout-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: rgba(255,255,255,0.03);
  accent-color: var(--accent);
  cursor: pointer;
}

/* Chart canvas wrapper */
.chart-canvas-wrap {
  position: relative;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(62, 232, 200, 0.03), transparent 60%),
    var(--surface);
  min-height: 200px;
}
.chart-canvas-wrap--hero {
  min-height: 280px;
}
.chart-canvas-wrap canvas {
  position: relative;
  z-index: 1;
  max-width: 100%;
}

/* ─── Reconstitution ─── */
.recon-card--inputs .field__label {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}
.recon-card--inputs .field__control {
  padding: 0.85rem 1rem;
  font-size: 1.08rem;
}
.recon-card--inputs .field__suffix {
  font-size: 0.85rem;
}
.recon-card--inputs select.field__control {
  padding-right: 3rem;
}
.field__control--lg {
  font-size: 1.3rem !important;
  font-weight: 600;
  padding: 1rem 1.1rem !important;
}
.recon-field--full {
  grid-column: 1 / -1;
}
.recon-fields {
  display: grid;
  gap: 1rem;
}
.recon-fields__group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.recon-result {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.recon-stage {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 2rem;
  align-items: center;
  padding: 1.75rem;
  border: 1px solid rgba(62, 232, 200, 0.08);
  border-radius: 20px;
  background:
    radial-gradient(circle at 15% 20%, rgba(62, 232, 200, 0.06), transparent 50%),
    var(--surface);
}

/* Vial */
.vial-visual { display: grid; justify-items: center; gap: 0.5rem; }
.vial-visual__cap {
  width: 56px;
  height: 14px;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, #1a1f2e, #0e1117);
}
.vial-visual__glass {
  position: relative;
  width: 100px;
  height: 168px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 18px;
  background: rgba(255,255,255,0.03);
}
.vial-visual__liquid {
  position: absolute;
  left: 8px; right: 8px; bottom: 8px;
  border-radius: 12px 12px 14px 14px;
  background: linear-gradient(180deg, rgba(62, 232, 200, 0.85), rgba(62, 180, 200, 0.6));
  box-shadow: 0 0 20px rgba(62, 232, 200, 0.15);
  transition: height 300ms ease;
}
.vial-visual__label {
  position: absolute;
  left: 50%; bottom: 18px;
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 0.1rem;
  width: calc(100% - 20px);
  padding: 0.5rem;
  border-radius: 12px;
  background: rgba(8, 9, 12, 0.7);
  backdrop-filter: blur(8px);
}
.vial-visual__label span { font-size: 1.05rem; font-weight: 600; }
.vial-visual__label small {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Syringe */
.syringe-visual { display: grid; gap: 0.85rem; }
.syringe-visual__tube {
  position: relative;
  overflow: hidden;
  height: 52px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  background: rgba(255,255,255,0.03);
}
.syringe-visual__fill {
  position: absolute;
  top: 4px; bottom: 4px; left: 4px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), #3ec8e8);
  box-shadow: 0 0 16px rgba(62, 232, 200, 0.2);
  transition: width 300ms ease;
}
.syringe-visual__ticks {
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(90deg, transparent, transparent 9%, rgba(255,255,255,0.1) 9%, rgba(255,255,255,0.1) 9.5%);
}
.syringe-visual__copy {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}
.syringe-visual__number {
  display: inline-block;
  min-width: 2ch;
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  background: linear-gradient(135deg, var(--accent), #80f0e0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.syringe-visual__unit {
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 500;
}

/* Recon metrics */
.recon-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}
.recon-metric {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.02);
  text-align: center;
}
.recon-metric__value {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.recon-metric__label {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
}

/* ─── Model footer (scheduler only) ─── */
.model-footer {
  margin-top: 1.25rem;
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.015);
}
.model-footer p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.7;
}

/* ─── Animations ─── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Responsive ─── */

/* Tablet — stack main grids */
@media (max-width: 1080px) {
  .workspace__grid,
  .recon-layout { grid-template-columns: 1fr; }
  .results-card { position: static; }
}

/* Small tablet / large phone */
@media (max-width: 768px) {
  .app-main { padding: 1rem 1rem 2rem; }
  .shell-header__inner { padding: 0.75rem 1rem; }
  .legal-banner__inner { padding: 0.5rem 1rem; font-size: 0.7rem; }

  .builder-card,
  .results-card,
  .recon-card,
  .recon-result { padding: 1rem; border-radius: 16px; }

  .protocol-card { padding: 0.85rem; }

  .recon-stage {
    grid-template-columns: 120px 1fr;
    gap: 1.25rem;
    padding: 1.25rem;
  }
  .vial-visual__glass { width: 85px; height: 140px; }
  .vial-visual__cap { width: 48px; height: 12px; }

  .chart-canvas-wrap { padding: 0.75rem; }
}

/* Phone */
@media (max-width: 640px) {
  html, body { font-size: 15px; }
  .app-main { padding: 0.75rem 0.75rem 2rem; }
  .legal-banner__inner { font-size: 0.65rem; padding: 0.45rem 0.75rem; }

  .shell-header__inner {
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.65rem 0.75rem;
  }
  .shell-brand__title { font-size: 1.2rem; }
  .shell-tab { padding: 0.5rem 0.75rem; font-size: 0.78rem; }

  .builder-card,
  .results-card,
  .recon-card,
  .recon-result { padding: 0.85rem; border-radius: 14px; }

  .builder-toolbar { grid-template-columns: 1fr; }
  .protocol-controls--dual { grid-template-columns: 1fr; }
  .recon-fields__group { grid-template-columns: 1fr; }

  .period-head,
  .period-row { grid-template-columns: 32px 1fr 1fr 28px; gap: 0.4rem; }
  .period-row { padding: 0.5rem; }
  .period-row__index { height: 32px; font-size: 0.82rem; }

  .chart-section__header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .chart-canvas-wrap { padding: 0.5rem; min-height: 180px; }
  .chart-canvas-wrap--hero { min-height: 220px; }

  .recon-stage {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 1.5rem;
    padding: 1.25rem 1rem;
  }
  .syringe-visual__copy { justify-content: center; }

  .recon-metrics { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
  .recon-metric { padding: 0.75rem 0.5rem; }
  .recon-metric__value { font-size: 1.25rem; }
  .recon-metric__label { font-size: 0.75rem; }

  .model-footer { padding: 0.75rem 0.85rem; }
  .model-footer p { font-size: 0.75rem; }

  .compound-badge { font-size: 0.75rem; padding: 0.25rem 0.5rem; }
}

/* Very small phone */
@media (max-width: 380px) {
  .shell-tabs { width: 100%; }
  .shell-tab { flex: 1; text-align: center; padding: 0.5rem 0.5rem; font-size: 0.72rem; }
  .recon-metrics { grid-template-columns: 1fr; }
  .period-head,
  .period-row { grid-template-columns: 28px 1fr 1fr 24px; gap: 0.3rem; }
}
