/* ── Design tokens ─────────────────────────────────────────── */
:root {
  --bg: #0b1220;
  --bg-elev: #111a2b;
  --bg-card: #152036;
  --bg-card-2: #1a2740;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --text-mute: #64748b;
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.15);
  --orange: #ea580c;
  --sky: #38bdf8;
  --sky-dim: rgba(56, 189, 248, 0.15);
  --emerald: #34d399;
  --rose: #fb7185;
  --violet: #a78bfa;
  --heavy: #94a3b8;
  --light: #38bdf8;
  --isbl: #f59e0b;
  --tank: #38bdf8;
  --util: #a78bfa;
  --owner: #64748b;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Ambient background */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, black, transparent);
  pointer-events: none;
  z-index: 0;
}
.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(100px);
  pointer-events: none;
  z-index: 0;
}
.bg-glow-1 {
  width: 480px; height: 480px;
  top: -120px; left: 20%;
  background: rgba(245, 158, 11, 0.08);
}
.bg-glow-2 {
  width: 520px; height: 520px;
  top: 30%; right: -80px;
  background: rgba(56, 189, 248, 0.06);
}

/* Header */
.site-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.25rem 1.75rem 0.75rem;
  max-width: 1600px;
  margin: 0 auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}
.brand-mark {
  flex-shrink: 0;
  width: 44px; height: 44px;
  display: grid;
  place-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand h1 span {
  color: var(--amber);
  font-weight: 600;
}
.subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.header-badges {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.badge {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: var(--sky-dim);
  color: var(--sky);
  border: 1px solid rgba(56, 189, 248, 0.25);
}
.badge-amber {
  background: var(--amber-dim);
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.3);
}

/* Layout */
.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 280px 1fr 270px;
  gap: 1rem;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem 2rem;
  align-items: start;
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 260px 1fr;
  }
  .detail-panel { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .site-header { flex-direction: column; align-items: flex-start; }
}

/* Panels */
.panel {
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-elev) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.15rem;
}
.panel-head {
  margin-bottom: 1rem;
}
.panel-head.row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.panel-head p {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Controls */
.controls-panel {
  position: sticky;
  top: 0.75rem;
  max-height: calc(100vh - 1.5rem);
  overflow-y: auto;
}
.control-group {
  margin-bottom: 1.15rem;
}
.control-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.control-label strong {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--amber);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1e293b, #334155);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fbbf24, #f59e0b);
  border: 2px solid #0f172a;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25);
  cursor: grab;
  transition: transform 0.12s ease;
}
input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fbbf24, #f59e0b);
  border: 2px solid #0f172a;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25);
  cursor: grab;
}

.range-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 0.3rem;
  font-size: 0.65rem;
  color: var(--text-mute);
  font-family: var(--mono);
}

.cut-visual {
  display: flex;
  height: 28px;
  border-radius: 8px;
  overflow: hidden;
  margin: 0.55rem 0 0.25rem;
  border: 1px solid var(--border);
}
.cut-light, .cut-heavy {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 0.2s ease;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  min-width: 0;
}
.cut-light {
  background: linear-gradient(90deg, #0ea5e9, #38bdf8);
  color: #0c4a6e;
}
.cut-heavy {
  background: linear-gradient(90deg, #64748b, #94a3b8);
  color: #0f172a;
}
.cut-light span, .cut-heavy span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 0 4px;
}

.seg-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  background: #0f172a;
  padding: 0.3rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.seg {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.5rem 0.4rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.seg:hover { color: var(--text); }
.seg.active {
  background: linear-gradient(145deg, #f59e0b, #d97706);
  color: #0f172a;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}
.hint {
  margin: 0.45rem 0 0;
  font-size: 0.7rem;
  color: var(--text-mute);
  line-height: 1.4;
}

.btn-reset {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.65rem;
  border-radius: 10px;
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-reset:hover {
  border-style: solid;
  border-color: var(--amber);
  color: var(--amber);
  background: var(--amber-dim);
}

/* Main column */
.main-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

/* Hero cards */
.hero-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1.15fr;
  gap: 0.75rem;
}
@media (max-width: 1100px) {
  .hero-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .hero-grid { grid-template-columns: 1fr; }
}

.hero-card {
  background: linear-gradient(160deg, var(--bg-card-2) 0%, var(--bg-elev) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  min-height: 130px;
  display: flex;
  flex-direction: column;
}
.hero-card.primary {
  background:
    radial-gradient(ellipse 80% 60% at 100% 0%, rgba(245, 158, 11, 0.12), transparent 55%),
    linear-gradient(160deg, #1a2740 0%, #111a2b 100%);
  border-color: rgba(245, 158, 11, 0.25);
}
.hero-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-mute);
  margin-bottom: 0.4rem;
}
.hero-value {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.85rem;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text);
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.15rem;
}
.hero-value.sm { font-size: 1.35rem; }
.hero-value .currency {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-right: 0.15rem;
}
.hero-value .unit {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-left: 0.15rem;
}
.hero-value .sep {
  color: var(--text-mute);
  margin: 0 0.1rem;
}
.hero-card.primary .hero-value {
  color: var(--amber);
}
.hero-sub {
  margin-top: auto;
  padding-top: 0.55rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.hero-sub strong { color: var(--text); font-weight: 600; }
.hero-meta {
  margin-top: 0.35rem;
  font-size: 0.68rem;
  color: var(--text-mute);
  font-family: var(--mono);
}
.confidence-bar {
  height: 4px;
  background: #1e293b;
  border-radius: 999px;
  margin-top: 0.7rem;
  overflow: hidden;
}
.conf-fill {
  height: 100%;
  width: 55%;
  border-radius: 999px;
  background: linear-gradient(90deg, #f59e0b, #38bdf8);
  transition: width 0.3s ease;
}

/* Decision meter */
.decision-meter { margin: 0.4rem 0 0.3rem; }
.decision-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #fb7185 0%, #fbbf24 50%, #34d399 100%);
  margin-bottom: 0.45rem;
}
.decision-needle {
  position: absolute;
  top: 50%;
  left: 30%;
  width: 4px;
  height: 18px;
  margin-top: -9px;
  margin-left: -2px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(0,0,0,0.5);
  transition: left 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
}
.decision-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.62rem;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Flow diagram */
.visual-panel { overflow: hidden; }
.yield-pills {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.pill {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
}
.pill.light {
  background: var(--sky-dim);
  color: var(--sky);
  border: 1px solid rgba(56, 189, 248, 0.3);
}
.pill.heavy {
  background: rgba(148, 163, 184, 0.12);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.flow-diagram {
  background: #0a101c;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 0.5rem;
  overflow-x: auto;
}
.flow-svg {
  width: 100%;
  min-width: 700px;
  height: auto;
  display: block;
}
.flow-node rect, .flow-node ellipse {
  fill: #152036;
  stroke: var(--border-strong);
  stroke-width: 1.5;
}
.flow-node.feed rect {
  fill: rgba(245, 158, 11, 0.12);
  stroke: rgba(245, 158, 11, 0.45);
}
.prod-light {
  fill: rgba(56, 189, 248, 0.15) !important;
  stroke: rgba(56, 189, 248, 0.5) !important;
}
.prod-heavy {
  fill: rgba(148, 163, 184, 0.12) !important;
  stroke: rgba(148, 163, 184, 0.4) !important;
}
.flow-node.column rect {
  fill: rgba(167, 139, 250, 0.1);
  stroke: rgba(167, 139, 250, 0.45);
}
.flow-node.multi-prod {
  fill: rgba(52, 211, 153, 0.1) !important;
  stroke: rgba(52, 211, 153, 0.4) !important;
}
.tray {
  stroke: rgba(167, 139, 250, 0.35);
  stroke-width: 1;
}
.flow-title {
  fill: var(--text);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
}
.flow-sub {
  fill: var(--text-dim);
  font-family: var(--mono);
  font-size: 9px;
}
.flow-tiny {
  fill: var(--text-mute);
  font-family: var(--font);
  font-size: 8px;
}
.flow-callout {
  fill: var(--amber);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
}
.flow-arrow {
  fill: none;
  stroke: #475569;
  stroke-width: 2;
}
.flow-arrow.light { stroke: #38bdf8; }
.flow-arrow.heavy { stroke: #94a3b8; }
.flow-arrow.multi { stroke: #34d399; }
.flow-arrowhead {
  fill: #475569;
}
.flow-arrowhead.light { fill: #38bdf8; }
.flow-arrowhead.heavy { fill: #94a3b8; }
.flow-arrowhead.multi { fill: #34d399; }
.side-draws {
  transition: opacity 0.35s ease;
}
#twoCutProducts {
  transition: opacity 0.35s ease;
}

/* Charts */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 900px) {
  .charts-row { grid-template-columns: 1fr; }
}
.chart-panel canvas {
  width: 100% !important;
  height: auto !important;
  max-height: 240px;
  display: block;
}

/* Stacked bar */
.stacked-chart { padding-top: 0.25rem; }
.stack-bar {
  display: flex;
  height: 56px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}
.stack-bar .seg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  transition: flex 0.35s cubic-bezier(0.34, 1.1, 0.64, 1);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #0f172a;
  padding: 0 4px;
}
.stack-bar .seg span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.stack-bar .seg.isbl { background: linear-gradient(180deg, #fbbf24, #f59e0b); }
.stack-bar .seg.tank { background: linear-gradient(180deg, #7dd3fc, #38bdf8); }
.stack-bar .seg.util { background: linear-gradient(180deg, #c4b5fd, #a78bfa); }
.stack-bar .seg.owner { background: linear-gradient(180deg, #94a3b8, #64748b); color: #0f172a; }

.stack-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 1rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.legend-item .dot {
  width: 10px; height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}
.legend-item .val {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text);
  font-weight: 500;
}

/* Benchmark bars */
.bench-chart {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.bench-row {
  display: grid;
  grid-template-columns: 130px 1fr 70px;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.72rem;
}
.bench-name {
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bench-track {
  height: 18px;
  background: #0f172a;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.bench-fill {
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, #334155, #64748b);
  transition: width 0.4s ease;
  min-width: 2px;
}
.bench-fill.yours {
  background: linear-gradient(90deg, #d97706, #f59e0b);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.35);
}
.bench-fill.dru {
  background: linear-gradient(90deg, #0e7490, #38bdf8);
}
.bench-val {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text);
  text-align: right;
}

/* Findings */
.findings-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}
@media (max-width: 1000px) {
  .findings-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .findings-grid { grid-template-columns: 1fr; }
}
.finding {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
}
.finding-icon {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--amber);
  margin-bottom: 0.4rem;
}
.finding h3 {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  font-weight: 650;
}
.finding p {
  margin: 0;
  font-size: 0.74rem;
  color: var(--text-dim);
  line-height: 1.45;
}
.finding strong { color: var(--text); }

/* Detail panel */
.detail-panel {
  position: sticky;
  top: 0.75rem;
  max-height: calc(100vh - 1.5rem);
  overflow-y: auto;
}
.metric {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}
.metric.highlight {
  background: var(--amber-dim);
  margin: 0.4rem -0.5rem 0;
  padding: 0.55rem 0.5rem;
  border-radius: 8px;
  border: 1px solid rgba(245, 158, 11, 0.2);
}
.m-label {
  font-size: 0.75rem;
  color: var(--text-dim);
}
.m-value {
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--text);
  text-align: right;
}
.m-value.mono {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
}
.metric.highlight .m-value { color: var(--amber); }

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.9rem 0;
}
.section-label {
  margin: 0 0 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-mute);
}

.product-bars { display: flex; flex-direction: column; gap: 0.75rem; }
.pbar-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}
.pbar-head span:last-child {
  font-family: var(--mono);
  color: var(--text);
  font-weight: 500;
}
.pbar-track {
  height: 10px;
  background: #0f172a;
  border-radius: 999px;
  overflow: hidden;
}
.pbar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}
.pbar-fill.light { background: linear-gradient(90deg, #0ea5e9, #38bdf8); }
.pbar-fill.heavy { background: linear-gradient(90deg, #64748b, #94a3b8); }
.pbar-meta {
  margin-top: 0.25rem;
  font-size: 0.68rem;
  color: var(--text-mute);
}

.assumptions {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.55;
}
.assumptions li { margin-bottom: 0.25rem; }

.source-note {
  margin-top: 1rem;
  padding: 0.65rem 0.7rem;
  background: #0a101c;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.65rem;
  color: var(--text-mute);
  line-height: 1.45;
}

/* Footer */
.site-footer {
  position: relative;
  z-index: 1;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
}
.site-footer p {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-mute);
  line-height: 1.5;
}
.site-footer code {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-dim);
  background: var(--bg-card);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

/* Scrollbar polish */
.controls-panel::-webkit-scrollbar,
.detail-panel::-webkit-scrollbar {
  width: 6px;
}
.controls-panel::-webkit-scrollbar-thumb,
.detail-panel::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 999px;
}
