:root {
  --ink: #1a2332;
  --ink-light: #334155;
  --ink-muted: #64748b;
  --ink-faint: #94a3b8;

  --accent: #1a4c7a;
  --accent2: #2b7fc4;
  --accent-light: #e8f0fe;
  --accent-glow: rgba(26, 76, 122, 0.12);

  --soil: #5c4033;
  --soil-light: #d4c5b7;
  --soil-faint: #f0ebe5;
  --sand: #e8dcc8;
  --clay: #b86f5c;
  --water: #1b7fa8;

  --bg: #f1f4f9;
  --card: #ffffff;
  --line: #e2e7ed;
  --line-light: #eef1f5;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.07), 0 1px 4px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 8px 30px rgba(15, 23, 42, 0.10), 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.18);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: radial-gradient(1400px 600px at 20% -15%, #e2eaf5 0%, var(--bg) 55%) fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.wrap {
  max-width: 1820px;
  margin: 0 auto;
  padding: 20px 22px 80px;
}

/* ─── Header ─── */
.hero {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.hero .brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hero .logo {
  font-size: 28px;
  filter: drop-shadow(0 2px 4px rgba(26, 76, 122, 0.25));
  transition: transform 0.2s ease;
}

.hero .logo:hover {
  transform: scale(1.05) rotate(-5deg);
}

.hero h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.5px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 50%, #3a9bd5 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.2px;
}

/* ─── Data Toolbar ─── */
.toolbar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.toolbar:focus-within {
  box-shadow: var(--shadow-md);
}

.toolbar .ctl {
  min-width: 100px;
}

.toolbar .ctl.wide {
  min-width: 240px;
  flex: 1;
}

label {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-muted);
  margin: 0 0 3px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.drop {
  border: 2px dashed var(--line);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  text-align: center;
  color: var(--ink-faint);
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
  background: var(--soil-faint);
  user-select: none;
  min-width: 140px;
}

.drop:hover, .drop.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow), inset 0 0 20px rgba(26, 76, 122, 0.04);
  transform: scale(1.01);
}

.drop:active {
  transform: scale(0.98);
}

/* ─── HYPROP tab ─── */
.hyprop-tab {
  display: inline-block;
  margin: 14px 0 0 8px;
  padding: 5px 18px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  position: relative;
  top: 1px;
  letter-spacing: 0.3px;
}

/* ─── Control Band ─── */
.band {
  display: flex;
  gap: 10px;
  align-items: stretch;
  flex-wrap: wrap;
  margin-top: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0 var(--radius-lg) var(--radius-lg) var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-md);
}

.gbox {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 9px 10px 10px;
  margin: 0;
  min-inline-size: auto;
  background: linear-gradient(180deg, #fcfdfe 0%, var(--card) 100%);
  transition: border-color 0.2s ease;
}

.gbox:hover {
  border-color: #d0d8e2;
}

.gbox > legend {
  font-size: 10.5px;
  color: var(--accent);
  padding: 0 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* Panels are drag-resizable by the user via a grip on the right edge (added by
   assets/resize.js). overflow stays visible so dropdowns inside don't get clipped. */
.gbox {
  min-width: 190px;
  position: relative;
}
.rsz-handle {
  position: absolute;
  top: 0;
  right: -1px;
  width: 9px;
  height: 100%;
  cursor: col-resize;
  z-index: 5;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.rsz-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 2px;
  transform: translateY(-50%);
  width: 3px;
  height: 30px;
  border-radius: 3px;
  background: var(--line);
  transition: background 0.15s ease;
}
.rsz-handle:hover::after, .gbox.rsz-active .rsz-handle::after { background: var(--accent); }

/* panel header (replaces the old <legend>) */
.gbox-h {
  font-size: 10.5px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 0 0 7px;
}

.gb-model {
  flex: 0 0 auto;
}

.gb-params {
  flex: 0 0 auto;
}

.gb-stats {
  flex: 1 1 168px;
  min-width: 158px;
}

/* ─── Sidebar ─── */
.sidecol {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 168px;
  flex: 0 0 auto;
}

.sidebtn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #f8f9fb 0%, #f1f3f6 100%);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-weight: 600;
  font-size: 12px;
  color: var(--ink-light);
  cursor: default;
  line-height: 1.3;
  transition: all 0.15s ease;
}

.sidebtn .ic {
  font-size: 16px;
}

.sidebtn.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-light) 0%, #dce8f5 100%);
  color: var(--accent);
}

.optrow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.metric-row {
  margin-top: 4px;
}

/* ─── Buttons ─── */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-light);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn:active {
  transform: translateY(0);
}

.btn.tiny {
  padding: 5px 10px;
  font-size: 11.5px;
}

.btn.ghost {
  background: #f3f6fa;
  color: var(--ink-light);
  border-color: transparent;
}

.btn.ghost:hover {
  background: #e8eef5;
  color: var(--accent);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  color: #fff;
  border: none;
  box-shadow: 0 4px 14px rgba(26, 76, 122, 0.35);
  transition: all 0.2s ease;
}

.btn.primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(26, 76, 122, 0.40);
}

.btn.primary:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(26, 76, 122, 0.30);
}

.btn.big {
  padding: 11px 38px;
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius-md);
  letter-spacing: 0.2px;
}

.btn:disabled, .btn.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.6);
  transform: none !important;
  box-shadow: none !important;
}

.btn.primary:not(:disabled) {
  animation: readyPulse 2.5s ease-in-out infinite;
}

@keyframes readyPulse {
  0%, 100% {
    box-shadow: 0 4px 14px rgba(26, 76, 122, 0.35);
  }
  50% {
    box-shadow: 0 4px 24px rgba(26, 76, 122, 0.55), 0 0 0 4px var(--accent-glow);
  }
}

/* ─── Model-Selection Matrix ─── */
.matrix {
  border-collapse: collapse;
}

.matrix th {
  font-size: 10px;
  color: var(--ink-muted);
  font-weight: 600;
  padding: 3px 5px;
  text-align: center;
  border-bottom: 2px solid var(--line-light);
}

.matrix td {
  padding: 3px 5px;
  text-align: center;
}

.matrix .rowlabel {
  text-align: left;
  font-size: 11.5px;
  white-space: nowrap;
  padding-right: 8px;
  font-weight: 500;
  color: var(--ink-light);
}

.radio {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--ink-faint);
  background: var(--card);
  cursor: pointer;
  vertical-align: middle;
  transition: all 0.15s ease;
}

.radio:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.radio.sel {
  border-color: var(--accent);
  background: radial-gradient(circle at 40% 35%, #2b7fc4 30%, var(--accent) 55%, #0d2f4a 100%);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.radio.disabled {
  border-color: var(--line);
  background: #f5f7fa;
  cursor: not-allowed;
  box-shadow: none;
}

.model-caption {
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--ink-muted);
  font-weight: 500;
}

/* ─── Parameter Tables ─── */
.ptable {
  border-collapse: collapse;
  width: auto;          /* natural width so inputs aren't squeezed/truncated */
}

.ptable th {
  font-size: 10px;
  color: var(--ink-muted);
  font-weight: 600;
  padding: 3px 8px;
  border-bottom: 2px solid var(--line-light);
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.ptable td {
  padding: 3px 8px;
  border-bottom: 1px solid var(--line-light);
  font-size: 12px;
}

.pname {
  font-weight: 600;
  color: var(--ink);
  font-family: "JetBrains Mono", "Consolas", "Courier New", monospace;
  font-size: 12px;
}

.punit {
  color: var(--ink-faint);
  font-size: 10.5px;
}

.pci {
  color: var(--ink-muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-family: "JetBrains Mono", "Consolas", "Courier New", monospace;
}

input.pin {
  width: 72px;
  padding: 3px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 12px;
  font-family: "JetBrains Mono", "Consolas", "Courier New", monospace;
  color: var(--ink);
  background: var(--card);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input.pin:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  outline: none;
}

/* compact parameter tables. NB: dcc.Input renders a wrapper
   <div class="dash-input-container pin"> around the real <input>, so width must
   be set on the WRAPPER (.pin) and the inner input made to fill it — otherwise the
   wrapper shrink-wraps to the text and clips the value. */
.ptable td, .ptable th { padding: 2px 3px; font-size: 11px; }
.ptable .pname { font-size: 11.5px; }
.ptable .pin { width: 60px; }
.ptable .pbound { width: 50px; }
.ptable .pin, .ptable .pbound { display: inline-flex; }
.ptable .pin > input, .ptable .pbound > input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  font-size: 11px;
  padding: 2px 4px;
}
.ptable .pbound > input { color: var(--ink-muted); background: var(--bg, #fbfdff); }
/* hide number-spinner arrows so the value isn't truncated */
.ptable .pin > input::-webkit-outer-spin-button,
.ptable .pin > input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ptable .pin > input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.ptable .pci { font-size: 10.5px; color: var(--ink-muted); overflow-wrap: break-word; }
.ptable .punit { font-size: 10.5px; }
.pcheck { transform: scale(0.85); }

/* fit-progress bar + Cancel button (shown during a background fit) */
.fit-prog {
  width: 280px;
  max-width: 80%;
  height: 10px;
  margin: 10px auto 2px;
  border: none;
  border-radius: 6px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.18);
  appearance: none;
  -webkit-appearance: none;
}
.fit-prog::-webkit-progress-bar { background: rgba(255, 255, 255, 0.18); border-radius: 6px; }
.fit-prog::-webkit-progress-value {
  background: linear-gradient(90deg, #2e86c1, #17a2a8);
  border-radius: 6px;
  transition: width 0.3s ease;
}
.fit-prog::-moz-progress-bar { background: #2e86c1; border-radius: 6px; }
.cancel-btn {
  margin-top: 14px;
  background: rgba(255, 255, 255, 0.12) !important;
  color: #fff !important;
  border: 1px solid rgba(255, 255, 255, 0.5) !important;
}
.cancel-btn:hover { background: rgba(231, 76, 60, 0.85) !important; border-color: transparent !important; }
/* the restore-session upload wraps a button — keep it inline like the others */
.restore-up { display: inline-block; }

.pcheck input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ─── Statistical Analysis ─── */
.sa-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 1px 0;
  font-size: 11px;
}

.sa-row + .sa-row {
  border-top: 1px solid var(--line-light);
}

/* branch sub-headers (θ / K) inside the stats panel */
.sa-sub {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  margin: 9px 0 3px;
  padding-bottom: 2px;
  border-bottom: 1.5px solid var(--accent-light);
}
.sa-sub:first-child { margin-top: 0; }
.sa-sub + .sa-row { border-top: none; }

/* model picker in the stats panel (only visible with >1 model) */
.stats-msel { font-size: 12px; }

.sa-l {
  color: var(--ink-muted);
  font-weight: 500;
}

.sa-v {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.card-title {
  font-size: 11px;
  color: var(--accent);
  padding: 0 0 6px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--accent-light);
  margin-bottom: 6px;
}

hr {
  border: none;
  border-top: 1px solid var(--line-light);
  margin: 8px 0;
}

/* ─── Fit Bar ─── */
.fitbar {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin: 18px 0 0;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.fitbar .compare {
  flex: 1;
  min-width: 240px;
  max-width: 580px;
}

.status {
  color: #1b7a3d;
  font-size: 13px;
  min-height: 18px;
  font-weight: 500;
  padding: 2px 0;
}

.status:empty::before {
  content: "Ready";
  color: var(--ink-faint);
  font-weight: 400;
}

/* ─── Mode Selector ─── */
.mode-sel {
  display: flex;
  gap: 18px;
  margin-bottom: 10px;
  font-size: 12.5px;
}

.mode-sel label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  color: var(--ink-light);
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.mode-sel label:has(input:checked) {
  background: var(--accent-light);
  color: var(--accent);
}

.mode-sel input {
  accent-color: var(--accent);
}

.kmodel-row {
  margin-top: 10px;
  /* fill the panel's width (set by the model matrix) WITHOUT widening it: width:0
     keeps the row out of the panel's shrink-to-fit calc, min-width:100% then makes
     it span the matrix width so the K cards wrap within it instead of stretching
     the whole panel and pushing the statistics box onto a new row. */
  width: 0;
  min-width: 100%;
}

.kmodel-row > label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-muted);
  margin: 0 0 5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* Conductivity multi-select: a 3-column grid of toggle-cards that lines up under
   the model matrix (same look as the SWRC selector). The native checkbox is
   hidden — a selected card fills with the accent colour, like the matrix cells. */
.kmodel-sel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.kmodel-sel label {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 32px;
  margin: 0;
  padding: 4px 5px;
  font-size: 9.5px;
  line-height: 1.15;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink-light);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  overflow-wrap: break-word;
  word-break: break-word;
  transition: all 0.15s ease;
}
.kmodel-sel label:hover { border-color: #c3cfdd; background: #f4f8fc; }
.kmodel-sel label:has(input:checked) {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
/* hide the native checkbox; selection is shown by the filled card */
.kmodel-sel input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* ─── Plot Toggle Tabs ─── */
.ptabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin: 18px 0 0;
  flex-wrap: wrap;
  padding: 0 4px;
}

.ptab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-muted);
  border: 1px solid transparent;
  border-bottom: none;
  cursor: pointer;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: all 0.15s ease;
  margin-bottom: -1px;
}

.ptab:hover {
  color: var(--accent);
  background: rgba(26, 76, 122, 0.04);
}

.ptab:has(.ptab-cb:checked) {
  background: var(--card);
  border-color: var(--line);
  border-bottom-color: var(--card);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 -2px 6px rgba(15, 23, 42, 0.04);
}

.ptab-cb {
  accent-color: var(--accent);
}

/* ─── Plots ─── */
.empty {
  text-align: center;
  color: var(--ink-faint);
  padding: 60px 20px;
  font-size: 15px;
  font-weight: 500;
}

.plot-grid {
  display: grid;
  gap: 16px;
  align-items: center;
  margin-top: 16px;
  justify-content: start;
}

/* per-sample plot row: square plots + legend wrap to the next line when they
   don't fit, top-aligned so nothing drifts out of alignment. */
.plot-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
  margin-top: 16px;
}

.plot-cell {
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 8px 10px;
  animation: fadeUp 0.35s ease both;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.plot-cell:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.sname {
  font-weight: 700;
  font-size: 13px;
  padding: 6px 10px 3px;
  color: var(--ink);
  letter-spacing: -0.2px;
}

/* ─── Legend Panel ─── */
.legend-panel {
  align-self: center;
  min-width: 155px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.legend-panel:hover {
  box-shadow: var(--shadow-md);
}

.leg-title {
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent);
  margin-bottom: 8px;
  border-bottom: 2px solid var(--accent-light);
  padding-bottom: 5px;
}

.leg-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  padding: 3px 0;
  color: var(--ink-light);
  white-space: nowrap;
}

.leg-swatch {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex: 0 0 auto;
  min-width: 30px;
}
.leg-mark {
  font-size: 11px;
  line-height: 1;
  font-weight: 700;
}

.sw {
  display: inline-block;
  flex: 0 0 20px;
  width: 20px;
  height: 3px;
  border-radius: 2px;
}

.sw.dot {
  height: 12px;
  width: 12px;
  flex: 0 0 12px;
  border: 2px solid #2e6fb0;
  border-radius: 50%;
  background: transparent;
}

.sw.band {
  height: 13px;
  width: 20px;
  background: rgba(22, 58, 92, 0.15);
  border-radius: 3px;
}

#plots h3 {
  margin: 28px 4px 10px;
  font-size: 17px;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.3px;
}

/* ─── Dash DataTable ─── */
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner table {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
}

.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner td,
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner th {
  padding: 8px 12px !important;
  font-size: 13px !important;
}

/* ─── Overlay / Modal ─── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.62);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.fit-modal {
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: 32px 48px 28px;
  text-align: center;
  box-shadow: var(--shadow-xl);
  animation: pop 0.25s ease;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

@keyframes pop {
  from {
    transform: scale(0.90);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.fit-modal .drop-icon {
  font-size: 36px;
  margin-bottom: 6px;
  animation: bob 2.4s ease-in-out infinite;
  display: block;
}

@keyframes bob {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--line-light);
  border-top-color: var(--accent);
  border-right-color: var(--accent2);
  border-radius: 50%;
  margin: 6px auto 14px;
  animation: spin 1.5s linear infinite;
  /* promote to its own GPU layer so it stays smooth while the CPU fits */
  will-change: transform;
  transform: translateZ(0);
}

@keyframes spin {
  from { transform: rotate(0deg) translateZ(0); }
  to { transform: rotate(360deg) translateZ(0); }
}

.fit-modal h3 {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
}

.fit-modal p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 1.4;
}

.fit-modal .fit-detail {
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 6px;
}

/* ─── Dropdown Overrides ─── */
.Select-control {
  border-radius: var(--radius-sm) !important;
  border-color: var(--line) !important;
  min-height: 32px !important;
  transition: border-color 0.15s ease, box-shadow 0.15s ease !important;
}

.Select-control:hover {
  border-color: var(--accent) !important;
}

.is-focused .Select-control {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px var(--accent-glow) !important;
}

.Select-placeholder,
.Select--single > .Select-control .Select-value {
  line-height: 32px !important;
  font-size: 12.5px !important;
}

.Select-menu-outer {
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-md) !important;
  border: 1px solid var(--line) !important;
  margin-top: 2px !important;
}

.Select-option {
  padding: 6px 12px !important;
  font-size: 12.5px !important;
}

.Select-option.is-focused {
  background: var(--accent-light) !important;
  color: var(--accent) !important;
}

.Select-arrow {
  border-color: var(--ink-faint) transparent transparent !important;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--ink-faint);
}

/* ─── Toast Notifications ─── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease both;
  max-width: 380px;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast.info {
  border-left: 4px solid var(--accent2);
}

.toast.success {
  border-left: 4px solid #1b7a3d;
}

.toast.error {
  border-left: 4px solid #c0392b;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: none;
  }
  to {
    opacity: 0;
    transform: translateX(30px);
  }
}

/* ─── Footer ─── */
.footer {
  margin-top: 40px;
  padding: 18px 22px 22px;
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-faint);
  border-top: 1px solid var(--line-light);
}

.footer-main {
  max-width: 760px;
  margin: 0 auto 9px;
  line-height: 1.55;
  color: var(--ink-muted);
}
.footer-main b { color: var(--accent); }

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}
.footer .foot-sep { color: var(--line); }
.footer .foot-copy { color: var(--ink-faint); }

.footer a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

.footer a:hover {
  text-decoration: underline;
  color: var(--accent2, #2e7bc4);
}

/* ─── Responsive tweaks ─── */
@media (max-width: 1100px) {
  .band {
    flex-direction: column;
  }

  .sidecol {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidecol .sidebtn {
    flex: 1;
    min-width: 140px;
  }

  .optrow {
    flex: 1;
    min-width: 200px;
  }

  .gb-model {
    flex: 1;
  }
}

/* ─────────────────────────────────────────────────────────────
   Modern polish pass — motion, focus, micro-interactions
   ───────────────────────────────────────────────────────────── */
:root { --ease: cubic-bezier(0.22, 0.61, 0.36, 1); }

/* Accessible, modern keyboard focus rings */
a:focus-visible, button:focus-visible, input:focus-visible,
.radio:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 3px;
  border-radius: 5px;
}

/* Buttons: springier lift, refined shadows */
.btn { transition: transform .16s var(--ease), box-shadow .22s var(--ease),
                   background .2s var(--ease), border-color .16s var(--ease), filter .16s var(--ease); }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); transition-duration: .05s; }
.btn.primary:hover { box-shadow: 0 7px 22px rgba(26, 76, 122, 0.44); filter: brightness(1.05); }
.btn.primary:active { box-shadow: 0 3px 10px rgba(26, 76, 122, 0.34); }
.btn.big { letter-spacing: 0.2px; }

/* Cards & panels: gentle depth on hover, smooth */
.gbox, .toolbar, .fitbar, .legend-panel {
  transition: box-shadow .28s var(--ease), border-color .2s var(--ease);
}
.gbox:hover { box-shadow: var(--shadow-md); }

/* Selection matrix: highlight the row you're hovering */
.matrix tr { transition: color .15s var(--ease); }
.matrix tr:hover .rowlabel { color: var(--accent); }
.radio { transition: border-color .15s var(--ease), background .15s var(--ease), transform .12s var(--ease); }
.radio:hover { transform: scale(1.18); }

/* Parameter / leaderboard rows: subtle hover */
.ptable tbody tr { transition: background .14s var(--ease); }
.ptable tbody tr:hover { background: var(--line-light); }

/* Inputs & dropdowns: refined focus ring */
input.pin { transition: border-color .16s var(--ease), box-shadow .16s var(--ease); }
input.pin:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px var(--accent-glow); outline: none; }
.Select-control { transition: border-color .16s var(--ease), box-shadow .16s var(--ease) !important; }
.is-focused:not(.is-open) > .Select-control {
  border-color: var(--accent2) !important;
  box-shadow: 0 0 0 3px var(--accent-glow) !important;
}

/* Gentle entrance for the control band on load */
.toolbar, .band { animation: fadeUp .4s var(--ease) both; }

/* Honor reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Fix: button hover "lift" caused a flicker (the translate moved the button
   off the cursor, toggling :hover). Use shadow/brightness only — no transform. */
.btn:hover, .btn:active, .btn.primary:hover, .btn.primary:active { transform: none !important; }
.btn:hover { border-color: var(--accent2); }
.btn.primary:hover { filter: brightness(1.06); box-shadow: 0 7px 22px rgba(26,76,122,0.44); }

/* Fix: the Fit button had an infinite "readyPulse" glow animation that read as
   flashing. Disable it — keep a calm static shadow. */
.btn.primary, .btn.primary:not(:disabled) { animation: none !important; }

/* Fix: in the 180px sidebar the 3-option Fit-metric radio (nRMSE/NSE/NLL)
   overflowed and the 3rd option (NLL) was hidden behind the next panel.
   Allow wrapping + let the sidebar grow a little so all options show. */
.mode-sel { flex-wrap: wrap !important; gap: 6px 10px !important; }
.metric-row .mode-sel label { padding: 3px 7px; }
.sidecol { width: 168px; }

/* ── Fix: open dropdown menus were rendering BEHIND the panels below them
   (e.g. the "samples" menu hidden under the Optimization Parameters block),
   so options couldn't be clicked. Layer the regions + lift menus on top. ── */
.Select-menu-outer, .Select-menu, .VirtualizedSelectOption,
.dash-dropdown .Select-menu-outer { z-index: 9999 !important; }
.Select.is-open, .dash-dropdown .Select.is-open { z-index: 9999 !important; position: relative; }

/* stacking order: earlier regions sit above later ones so a downward menu shows */
.toolbar { position: relative; z-index: 60; }
.band    { position: relative; z-index: 50; }
.fitbar  { position: relative; z-index: 40; }

/* never clip an open menu */
.toolbar, .band, .fitbar, .sidecol, .gbox, .ctl, .ctl.wide,
.optrow, .metric-row, .compare { overflow: visible; }

/* ─── Info icon + hover tooltip (top-right of each box) ─── */
.gbox, .sidecol { position: relative; }
.info {
  position: absolute;
  top: 9px;
  right: 11px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  font-style: normal;
  color: #406A93;
  background: linear-gradient(180deg, #f3f8fc 0%, #dde9f4 100%);
  border: 1px solid #c7d8e8;
  box-shadow: 0 1px 2px rgba(30, 60, 90, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.7);
  cursor: help;
  user-select: none;
  z-index: 5;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}
.info:hover, .info:focus {
  background: linear-gradient(180deg, #2e7bc4 0%, #1b4f72 100%);
  border-color: #1b4f72;
  color: #fff;
  box-shadow: 0 3px 9px rgba(27, 79, 114, 0.38);
  transform: translateY(-1px);
  outline: none;
}
.info::after {
  content: attr(data-tip);
  position: absolute;
  top: 130%;
  right: 0;
  width: 240px;
  padding: 9px 11px;
  background: #1f2d3d;
  color: #eef3f8;
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
  text-transform: none;
  border-radius: 7px;
  box-shadow: 0 8px 22px rgba(20, 35, 55, 0.28);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-3px);
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
  z-index: 200;
  pointer-events: none;
}
.info:hover::after, .info:focus::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ─── Comparison cells in the model matrix ─── */
.radio.cmp {
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px currentColor;
}

/* ─── Ctrl+click hint in the fit bar ─── */
.compare-hint {
  font-size: 12px;
  color: var(--ink-light, #55606f);
  padding: 0 6px;
  white-space: nowrap;
}
.compare-hint b { color: var(--accent, #1b4f72); }

/* ─── Model-comparison table ─── */
.cmp-head { display: flex; align-items: center; gap: 8px; position: relative; }
.cmp-head .info { position: static; margin-left: 2px; }
.cmp-table {
  border-collapse: collapse;
  width: 100%;
  margin-top: 6px;
  font-size: 13px;
  background: var(--card, #fff);
  border-radius: var(--radius-md, 10px);
  overflow: hidden;
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.08));
}
.cmp-table th {
  text-align: right;
  padding: 9px 12px;
  background: #eef2f7;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #44525f;
  border-bottom: 1px solid #dde4ec;
}
.cmp-table th:first-child, .cmp-table th:nth-child(2) { text-align: left; }
.cmp-table td {
  padding: 8px 12px;
  text-align: right;
  border-bottom: 1px solid #eef1f5;
  font-variant-numeric: tabular-nums;
}
.cmp-table tr:last-child td { border-bottom: none; }
.cmp-table tr:hover td { background: #f6f9fc; }
.cmp-table .cmp-sid { text-align: left; color: #6b7785; }
.cmp-table .mcell { text-align: left; display: flex; align-items: center; gap: 8px; }
.cmp-table tr.cmp-base td { font-weight: 600; background: #f4f8fc; }
.mchip {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: 0 0 12px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.12);
}

/* ─── Reorganised data toolbar ─── */
.toolbar { padding-right: 38px; align-items: stretch; gap: 14px; }

.drop {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 168px;
  padding: 10px 18px;
}
.drop-inner { display: flex; align-items: center; gap: 11px; }
.up-ic {
  font-size: 22px;
  line-height: 1;
  color: var(--accent, #1b4f72);
  transition: transform 0.2s ease;
}
.drop:hover .up-ic { transform: translateY(-2px); }
.up-txt { text-align: left; font-size: 11.5px; line-height: 1.3; color: var(--ink-faint); }
.up-txt b { font-size: 13px; color: var(--accent, #1b4f72); }

.tb-group {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 9px 12px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md, 9px);
  background: linear-gradient(180deg, #fcfdfe 0%, #f6f9fb 100%);
  position: relative;
}
.tb-group .ctl { min-width: 84px; }
.tb-tag {
  position: absolute;
  top: -8px;
  left: 11px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent, #1b4f72);
  background: var(--card, #fff);
  padding: 1px 7px;
  border-radius: 5px;
  border: 1px solid var(--line);
}

/* ─── Learner mode ─── */
.learner-chk { margin-top: 10px; font-size: 12.5px; font-weight: 600; color: var(--accent, #1b4f72); }
.learner-chk label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; text-transform: none; letter-spacing: 0; font-size: 12.5px; color: var(--accent, #1b4f72); }
.learner-row { margin-top: 8px; padding: 10px 12px; border: 1px dashed var(--line, #d5dbe3); border-radius: 10px; background: linear-gradient(180deg,#fbfdff,#f4f8fc); }
.learner-hint { font-size: 11.5px; line-height: 1.5; color: var(--ink-light, #55606f); margin-bottom: 8px; }

/* ── New: parameter/stat warnings + derived-quantity CIs + diagnostics ── */
.pwarn { color: #c77400; cursor: help; font-weight: 700; }
.pname.at-bound { color: #b26a00; }
.sa-ci { color: var(--muted); font-size: 0.8em; margin-left: 6px; white-space: nowrap; }
.sa-v.diag-warn, .diag-warn { color: #c0392b; font-weight: 600; }

/* ── #14 Responsive / mobile: stack the toolbar & band, shrink the square
   plots to the viewport width (Plotly graphs are responsive:true so they
   follow their container). ── */
@media (max-width: 760px) {
  .wrap { padding: 12px 10px; max-width: 100%; }
  .hero { flex-wrap: wrap; gap: 6px; }
  .hero h1 { font-size: 1.2rem; }
  .subtitle { font-size: 0.8rem; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .tb-group, .toolbar .drop, .toolbar .ctl { width: 100%; }
  .fitbar { flex-wrap: wrap; gap: 6px; }
  .fitbar .btn { flex: 1 1 auto; }
  .ptabs { flex-wrap: wrap; }
  .plot-row { flex-direction: column; align-items: center; }
  .plot-cell { width: 92vw; max-width: 440px; }
  .plot-cell .dash-graph, .plot-cell .js-plotly-plot,
  .plot-cell > div:last-child {
    width: 92vw !important; max-width: 440px !important;
    height: 92vw !important; max-height: 440px !important;
  }
  .legend-panel { width: 92vw; max-width: 440px; }
}
