/* =============================================
   ecodemos — shared styles
   Used by all pages (landing + modules)
   ============================================= */

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

body {
  font-family: system-ui, sans-serif;
  background: #fff;
  color: #1a1a1a;
}

a {
  color: inherit;
}

/* --- Nav bar --- */
.navbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}

.nav-title {
  font-weight: 600;
  margin-right: auto;
  color: #008539;
  text-decoration: none;
}

.navbar a {
  text-decoration: none;
  color: #1a1a1a;
  font-size: 0.9rem;
}

.navbar a:hover {
  text-decoration: underline;
}

.nav-disabled {
  color: #999 !important;
  pointer-events: none;
}

/* --- Landing page --- */
.landing-page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

.landing-hero {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0 0 2.5rem;
}

.landing-eyebrow {
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b7280;
}

.landing-hero h1 {
  font-size: clamp(2.1rem, 3vw, 3.3rem);
  line-height: 1.05;
  max-width: 12ch;
}

.landing-intro {
  max-width: 62ch;
  font-size: 1.02rem;
  line-height: 1.7;
  color: #4b5563;
}

.landing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.landing-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.landing-section {
  padding-top: 2rem;
}

.landing-section--compact {
  padding-top: 1.5rem;
}

.landing-section-heading {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.landing-section-heading h2 {
  font-size: 1.2rem;
}

.landing-section-heading p {
  color: #6b7280;
  line-height: 1.6;
}

.demo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.2rem;
}

.demo-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  overflow: hidden;
  min-width: 0;
}

.demo-card-preview {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.5rem;
  min-height: 220px;
  padding: 1rem;
  text-decoration: none;
  border-bottom: 1px solid #e5e7eb;
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.92)),
    linear-gradient(135deg, #f5f5f5, #ececec 55%, #f7f7f7);
}

.demo-card-preview--ds {
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.94)),
    linear-gradient(135deg, #edf4f1, #f8faf9 48%, #e6eef7);
}

.demo-card-preview--secr {
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.94)),
    linear-gradient(135deg, #f4f5f6, #fbfbfb 48%, #eceff2);
}

.demo-card-preview--lv {
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.94)),
    linear-gradient(135deg, #f5f4ef, #fafaf7 48%, #f0f2f7);
}

.demo-card-preview-label {
  align-self: flex-start;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  font-size: 0.74rem;
  color: #6b7280;
}

.demo-card-preview strong {
  max-width: 24ch;
  font-size: 1rem;
  line-height: 1.35;
  color: #1f2937;
}

.demo-card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1rem;
}

.demo-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.demo-card-header h3 {
  font-size: 1.05rem;
}

.demo-card-tag {
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: #f3f4f6;
  font-size: 0.72rem;
  color: #6b7280;
  white-space: nowrap;
}

.demo-card-body p {
  line-height: 1.6;
  color: #4b5563;
}

.demo-card-points {
  display: grid;
  gap: 0.45rem;
  padding-left: 1rem;
  color: #374151;
}

.demo-card-points li {
  line-height: 1.45;
}

.demo-card-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: auto;
}

.demo-card-link {
  font-size: 0.9rem;
  color: #4b5563;
  text-decoration: none;
}

.demo-card-link:hover {
  text-decoration: underline;
}

.compare-grid,
.docs-link-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.docs-link-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.compare-card,
.docs-link-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 1rem;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  text-decoration: none;
}

.compare-card p,
.docs-link-card span {
  color: #4b5563;
  line-height: 1.55;
}

.docs-link-card:hover {
  border-color: #cfd5dd;
  background: #fcfcfc;
}

/* --- Module layout --- */
.module-layout {
  display: grid;
  grid-template-rows: 40vh 1fr;
  grid-template-columns: 1fr 320px;
  grid-template-areas:
    "sim     controls"
    "analytics analytics";
  height: calc(100vh - 48px); /* full height minus navbar */
  gap: 1px;
  background: #e0e0e0; /* gap colour */
}

.pane-sim        { grid-area: sim;       background: #fff; overflow: hidden; position: relative; padding: 0 0.75rem; }
.pane-controls   { grid-area: controls;  background: #fff; overflow-y: auto; padding: 1rem; }
.pane-analytics  { grid-area: analytics; background: #fff; overflow: hidden; padding: 0.75rem 1rem; }

/* --- Analytics panels --- */
.analytics-panels {
  display: flex;
  gap: 1rem;
  height: 100%;
}

.analytics-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-detection-fn { flex: 2; }
.panel-estimates    { flex: 0 0 150px; }
.panel-dhat         { flex: 1.2; }

.panel-lv-timeseries { flex: 2.1; }
.panel-lv-estimates  { flex: 0 0 190px; }
.panel-lv-phase      { flex: 1.2; }

.lv-sim-readout {
  position: absolute;
  top: 0.75rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  gap: 1.2rem;
  align-items: center;
  justify-content: flex-start;
  font-size: 0.82rem;
  color: #444;
  z-index: 5;
}

.lv-sim-readout strong {
  color: #1f1f1f;
  font-variant-numeric: tabular-nums;
}

.lv-main-chart-wrap {
  position: absolute;
  top: 2.3rem;
  left: 0.75rem;
  right: 0.75rem;
  bottom: 1.9rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.lv-autopause-hint {
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 0.45rem;
  font-size: 0.74rem;
  color: #8a5a00;
}

/* LV layout: give simulation + controls more vertical room than analytics */
.module-layout--lv {
  grid-template-rows: minmax(430px, 62vh) minmax(220px, 1fr);
}

.module-layout--lv .pane-controls {
  padding-top: 0.8rem;
  padding-bottom: 0.8rem;
}

.module-layout--lv .pane-analytics {
  padding-top: 0.55rem;
  padding-bottom: 0.55rem;
}

.module-layout--lv .panel-lv-phase {
  flex: 1;
  max-width: 420px;
}

.module-layout--lv .panel-lv-estimates {
  flex: 0 0 210px;
}

@media (max-height: 760px) {
  .module-layout--lv {
    grid-template-rows: minmax(360px, 58vh) minmax(200px, 1fr);
  }
}

/* ─── BNE module ─────────────────────────────────────────────────────────────── */

/* BNE scrolls freely — no forced viewport height */
.module-layout--bne {
  height: auto;
  min-height: 0;
  align-content: start;
  grid-template-columns: 1fr 290px;
  grid-template-rows: auto 48px auto;
  grid-template-areas:
    "sim         controls"
    "bne-metrics controls"
    "scatter     controls";
}

/* Controls column spans all rows; sticky so it stays visible while scrolling */
.module-layout--bne .pane-controls {
  grid-row: 1 / 4;
  position: sticky;
  top: 0;
  max-height: 100vh;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
  overflow-y: auto;
}

/* Scatter panel sits in the grid, below the sim + metrics rows */
.module-layout--bne .bne-analytics {
  grid-area: scatter;
  max-width: none;
  margin: 0;
  padding: 6px 8px 16px;
  background: #fff;
}

/* Sim pane: hex map left, network panel right — network gets slightly more width */
.module-layout--bne .pane-sim {
  display: grid;
  grid-template-columns: 5fr 6fr;
  grid-template-rows: 540px;
  gap: 1px;
  background: #e0e0e0;
  padding: 0;
  overflow: visible;
}

#bne-hexmap {
  background: #fff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 540px;
}

#bne-hexmap-svg {
  flex: 1;
  overflow: hidden;
}

#bne-network-panel {
  background: #fff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 540px;
}

#bne-network-view {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Metrics strip */
.pane-bne-metrics {
  grid-area: bne-metrics;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 1.8rem;
  padding: 0 1.2rem;
  font-size: 0.81rem;
  color: #555;
  border-top: 1px solid #e0e0e0;
}

.pane-bne-metrics strong {
  color: #1f1f1f;
  font-variant-numeric: tabular-nums;
}

/* Shared tab style for both layer-tabs and view-tabs */
.bne-layer-tabs,
.bne-view-tabs {
  display: flex;
  gap: 2px;
  padding: 5px 6px 0;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.bne-tab {
  padding: 2px 9px;
  font-size: 0.73rem;
  border: 1px solid #ccc;
  border-bottom: none;
  background: #f5f5f5;
  cursor: pointer;
  border-radius: 3px 3px 0 0;
  color: #555;
  line-height: 1.6;
}

.bne-tab.active {
  background: #fff;
  border-color: #777;
  color: #111;
  font-weight: 600;
}

.bne-tab:hover:not(.active) {
  background: #ececec;
}

.bne-empty {
  padding: 2rem;
  color: #888;
  font-size: 0.85rem;
  text-align: center;
}

.controls-group-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #888;
  margin: 0 0 0.4rem;
}

/* BNE legend strips (inside hex map and network panel) */
.bne-legend {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 10px;
  padding: 5px 9px 6px;
  font-size: 10px;
  color: #444;
  border-top: 1px solid #e8e8e8;
  background: #fafafa;
  min-height: 28px;
  line-height: 1.4;
}

.bne-legend b { font-weight: 600; color: #222; }

/* Colour gradient bar */
.leg-bar {
  display: inline-block;
  width: 80px;
  height: 10px;
  border: 1px solid #ccc;
  border-radius: 2px;
  vertical-align: middle;
  flex-shrink: 0;
}

/* Small coloured square swatch */
.leg-swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.18);
  vertical-align: middle;
  flex-shrink: 0;
}

/* Ring-only swatch (specialist indicator) */
.leg-ring {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid #333;
  background: transparent;
  vertical-align: middle;
  flex-shrink: 0;
}

/* Italic note — wraps to full row */
.leg-note {
  color: #777;
  font-style: italic;
  flex-basis: 100%;
  line-height: 1.5;
}

/* BNE scatter panel (below main grid) */
.bne-analytics {
  max-width: 1600px;
  margin: 0 auto;
  padding: 6px 8px 24px;
}

.bne-scatter-panel {
  background: #fff;
  padding: 10px 14px 6px;
}

#chart-bne-scatter {
  height: 240px;
  position: relative;
}

/* ─── SECR module overrides ─────────────────────────────────────────────────── */

/*
 * SECR layout — two zones:
 *
 *  TOP (viewport height, no scroll):
 *  ┌─────────────────────────┬──────────────────┐
 *  │                         │  controls        │ flex-grow (scrollable)
 *  │   sim (square, full     ├──────────────────┤
 *  │        viewport height) │  estimates       │ fixed height
 *  └─────────────────────────┴──────────────────┘
 *
 *  BELOW (scroll down to view, full width):
 *  ┌──────────────┬──────────────────────────────┐
 *  │ surface      │  D̂ convergence (1fr)         │ fixed row height
 *  └──────────────┴──────────────────────────────┘
 *  ┌─────────────────────────────────────────────┐
 *  │  capture history (full width)               │
 *  └─────────────────────────────────────────────┘
 */

/* Single-row grid: sim left, right column fills remainder */
.module-layout--secr {
  grid-template-rows: 1fr;
  grid-template-columns: calc(100vh - 48px) 1fr;
  grid-template-areas: "sim right";
}

/* Right column: controls scrolls, estimates pinned at bottom */
.module-layout--secr .pane-right {
  grid-area: right;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
  border-left: 1px solid #e0e0e0;
}

.module-layout--secr .pane-controls {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* Estimates panel — pinned below controls in the right column */
.pane-secr-estimates {
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  border-top: 1px solid #e0e0e0;
  background: #fff;
}

/* ── Analytics section (below the fold, normal document flow) ─────────────── */

.secr-analytics {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: #e0e0e0; /* gap colour between panels */
}

/* D̂ convergence — full width */
.pane-dhat {
  display: flex;
  flex-direction: column;
  background: #fff;
  padding: 0.5rem 0.75rem;
  height: 280px;
  overflow: hidden;
}

/* Capture history — full width, fixed height, chart scrolls in both axes */
.pane-captures {
  display: flex;
  flex-direction: column;
  background: #fff;
  padding: 0.5rem 0.75rem;
  height: 280px;
}

.pane-captures .chart-area {
  overflow: auto;
}

/* Detection surface — absolute overlay in bottom-left of sim pane */
.surface-overlay {
  position: absolute;
  bottom: 0.75rem;
  left: 0.75rem;
  width: 345px;
  height: 375px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid #d0d0dc;
  border-radius: 6px;
  padding: 0.4rem 0.5rem 0.3rem;
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.surface-overlay .chart-area {
  flex: 1;
  min-height: 0;
}

.panel-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #666;
  margin-bottom: 0.15rem;
  flex-shrink: 0;
}

.panel-subtitle {
  font-size: 0.68rem;
  font-weight: 400;
  color: #bbb;
  margin-bottom: 0.3rem;
  flex-shrink: 0;
}

/* Advanced disclosure section */
.controls-advanced {
  padding-top: 0.1rem;
}

.controls-advanced-summary {
  font-size: 0.8rem;
  color: #888;
  cursor: pointer;
  list-style: none;         /* hide default triangle */
  display: flex;
  align-items: center;
  gap: 0.3rem;
  user-select: none;
}

.controls-advanced-summary::-webkit-details-marker { display: none; }

.controls-advanced-summary::before {
  content: '▸';
  font-size: 0.7rem;
  transition: transform 0.15s;
}

details[open] .controls-advanced-summary::before {
  transform: rotate(90deg);
}

.controls-advanced-body {
  margin-top: 0.6rem;
}

.chart-area {
  flex: 1;
  min-height: 0;  /* required for flex children to shrink */
}

/* D3 chart shared styles */
.axis text        { font-size: 11px; fill: #555; }
.axis path,
.axis line        { stroke: #ccc; }
.chart-label      { font-size: 11px; fill: #555; }

/* --- Estimates strip --- */
.estimates-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 0.6rem;
  font-size: 0.82rem;
  align-content: start;
}

.estimates-list dt { color: #777; white-space: nowrap; }
.estimates-list dd { font-weight: 600; font-variant-numeric: tabular-nums; }

/* True value row — muted to distinguish from estimates */
.estimates-list dt.true-row { color: #b04040; }
.estimates-list dd.true-row { color: #b04040; font-weight: 500; }

/* Input parameter rows — blue, matches theoretical curve */
.estimates-list dt.input-row { color: #2255cc; }
.estimates-list dd.input-row { color: #2255cc; font-weight: 500; }

/* MLE / estimate rows — pink, matches MLE dashed curve */
.estimates-list dt.mle-row { color: #cc44aa; }
.estimates-list dd.mle-row { color: #cc44aa; font-weight: 600; }

.estimates-list dt.estimate-row { color: #2a7a2a; }
.estimates-list dd.estimate-row { color: #2a7a2a; font-weight: 600; }

/* --- Controls pane --- */
.controls-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.playback-row {
  display: flex;
  gap: 0.5rem;
}

.speed-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-label {
  font-size: 0.8rem;
  color: #777;
  white-space: nowrap;
}

.controls-divider {
  border-top: 1px solid #eee;
  margin: 0.75rem 0;
}

/* Buttons */
.btn-primary, .btn-secondary {
  border: none;
  border-radius: 5px;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: #3366cc;
  color: #fff;
  flex: 1;
}

.btn-primary:hover  { background: #2255bb; }

.btn-secondary {
  background: #f0f0f0;
  color: #333;
}

.btn-secondary:hover { background: #e0e0e0; }

/* Speed button group */
.btn-group {
  display: flex;
  border: 1px solid #ddd;
  border-radius: 5px;
  overflow: hidden;
}

.btn-speed {
  border: none;
  background: #fff;
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: inherit;
  color: #555;
  border-right: 1px solid #ddd;
}

.btn-speed:last-child { border-right: none; }
.btn-speed:hover      { background: #f5f5f5; }
.btn-speed.active     { background: #3366cc; color: #fff; }

.placeholder {
  font-size: 0.85rem;
  color: #999;
  line-height: 1.9;
}

/* Seed controls */
.seed-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.seed-input {
  width: 68px;
  padding: 0.3rem 0.4rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: inherit;
  text-align: right;
  color: #333;
}

.seed-hint {
  font-size: 0.75rem;
  color: #aaa;
  margin-top: 0.2rem;
}

/* Per-control explainer text, used in BNE controls */
.control-hint {
  font-size: 0.63rem;
  color: #bbb;
  margin: 1px 0 5px 0;
  line-height: 1.35;
}

kbd {
  font-size: 0.75rem;
  background: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 1px 5px;
}

/* Remove spinner arrows from seed number input */
.seed-input::-webkit-outer-spin-button,
.seed-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.seed-input[type=number] { -moz-appearance: textfield; }

/* Parameter slider rows */
.slider-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Checkbox toggle rows */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.82rem;
  color: #444;
  margin-bottom: 0.15rem;
}

.checkbox-row input[type="checkbox"] {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  cursor: pointer;
}

/* Detection function selector rows */
.select-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.fn-select {
  flex: 1;
  font-size: 0.82rem;
  padding: 0.2rem 0.3rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.mismatch-warning {
  font-size: 0.75rem;
  color: #b05000;
  margin: 0.2rem 0 0;
  padding: 0.25rem 0.4rem;
  background: #fff8ee;
  border-left: 3px solid #e08000;
  border-radius: 0 3px 3px 0;
}

.slider-label {
  min-width: 44px;
}

.param-slider {
  flex: 1;
  min-width: 0;
  accent-color: #3366cc;
  cursor: pointer;
}

.slider-value {
  font-size: 0.78rem;
  color: #555;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 52px;
  text-align: right;
}

/* Reset-to-defaults button — full width, sits at the bottom of the Advanced section */
.btn-reset-defaults {
  width: 100%;
  margin-top: 0.3rem;
  font-size: 0.8rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-clear-ghosts {
  width: 100%;
  margin-top: 0.3rem;
  font-size: 0.8rem;
}

@media (max-width: 1080px) {
  .demo-grid,
  .compare-grid,
  .docs-link-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .navbar {
    flex-wrap: wrap;
    row-gap: 0.6rem;
  }

  .landing-page {
    padding: 1.6rem 1rem 3rem;
  }

  .landing-hero h1 {
    max-width: none;
  }

  .demo-grid,
  .compare-grid,
  .docs-link-row {
    grid-template-columns: 1fr;
  }

  .demo-card-actions {
    flex-wrap: wrap;
  }
}
