/* ==========================================================================
   Battery Sizing — design system
   Dark by default (matches the cockpit-style tooling engineers use next to
   FTMS); a light theme is available through the toggle in the top bar.
   ========================================================================== */

:root {
  color-scheme: dark;

  --bg:            #0a0e14;
  --surface:       #111823;
  --surface-2:     #16202d;
  --surface-3:     #1d2937;
  --border:        #22303f;
  --border-strong: #31435a;

  --text:          #e8eef6;
  --text-muted:    #8fa0b4;
  --text-faint:    #7f93a9;

  --accent:        #3d9bff;
  --accent-fill:   #1f6fd1;   /* carries white text at 4.9:1; --accent is for text and rings */
  --accent-soft:   rgba(61, 155, 255, 0.14);
  --ok:            #34d399;
  --ok-soft:       rgba(52, 211, 153, 0.14);
  --warn:          #f5b544;
  --warn-soft:     rgba(245, 181, 68, 0.15);
  --danger:        #fb7185;
  --danger-soft:   rgba(251, 113, 133, 0.15);

  /* Lift systems keep the same colours everywhere: bars, tables, charts. */
  --vertical:      #a78bfa;
  --horizontal:    #22d3ee;
  --reserve:       #f5b544;
  --free:          #243244;

  --radius:   10px;
  --radius-s: 7px;
  --gap:      14px;

  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg:            #eef2f7;
  --surface:       #ffffff;
  --surface-2:     #f5f8fc;
  --surface-3:     #e9eff7;
  --border:        #d7e0ec;
  --border-strong: #bccbdd;
  --text:          #0f1a26;
  --text-muted:    #53657b;
  --text-faint:    #5a6c82;
  --accent:        #1668d6;
  --accent-fill:   #1668d6;
  --accent-soft:   rgba(22, 104, 214, 0.1);
  --ok:            #0f9d64;
  --ok-soft:       rgba(15, 157, 100, 0.12);
  --warn:          #b4740b;
  --warn-soft:     rgba(180, 116, 11, 0.14);
  --danger:        #d23c53;
  --danger-soft:   rgba(210, 60, 83, 0.12);
  --vertical:      #7c4ddb;
  --horizontal:    #0a91ab;
  --reserve:       #b4740b;
  --free:          #dbe4ef;
  --shadow: 0 8px 24px rgba(15, 26, 38, 0.12);
}

* { box-sizing: border-box; }

/* `hidden` has to beat the display rules of .app/.gate/.overlay below. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  overflow-x: hidden;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* Every figure in the app is tabular so columns stay aligned while typing. */
.num, input[type="number"], table td, .kpi-value, .chip-value {
  font-variant-numeric: tabular-nums;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- App shell ---------------------------------------------------------- */

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--accent), #7c4ddb);
  color: #fff;
}
.brand-name { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--text-faint); }

.topbar-spacer { flex: 1 1 auto; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
#config-select { width: 230px; max-width: 100%; }

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 380px;
  gap: var(--gap);
  padding: var(--gap);
  overflow: hidden;
}
.column {
  display: flex; flex-direction: column; gap: var(--gap);
  overflow-y: auto; padding-right: 2px;
  min-width: 0;   /* keep a wide table inside its column instead of widening the page */
}
.card { min-width: 0; }
.column > .card { flex: none; }   /* the column scrolls; its cards never shrink and clip */
.column::-webkit-scrollbar { width: 9px; }
.column::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 6px; }
.column::-webkit-scrollbar-track { background: transparent; }

/* --- Cards -------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card-title { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); }
.card-head .spacer { flex: 1; }
.card-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.card-body.tight { padding: 8px; }
.card-body.flush { padding: 0; }

/* --- Controls ----------------------------------------------------------- */

button, .btn {
  font: inherit;
  font-weight: 550;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  padding: 7px 12px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  transition: background 120ms ease, border-color 120ms ease, opacity 120ms ease;
  white-space: nowrap;
}
button:hover:not(:disabled), .btn:hover { background: var(--border); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.btn-primary { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(0.9); background: var(--accent-fill); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-icon { padding: 5px; border-radius: 6px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 6px 9px;
  width: 100%;
  min-width: 0;
}
input:hover, select:hover { border-color: var(--border-strong); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); cursor: pointer; }
select { cursor: pointer; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; text-align: right; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > label { font-size: 11px; color: var(--text-muted); font-weight: 550; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.input-unit { position: relative; display: flex; align-items: center; }
.input-unit > input { padding-right: 34px; }
.input-unit > span {
  position: absolute; right: 9px;
  font-size: 11px; color: var(--text-faint); pointer-events: none;
}

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 2px;
  gap: 2px;
}
.segmented button {
  background: transparent; border: none; color: var(--text-muted);
  padding: 4px 10px; font-size: 12px; border-radius: 5px;
}
.segmented button[aria-pressed="true"] { background: var(--accent-fill); color: #fff; }
.segmented.compact button { padding: 2px 6px; font-size: 11px; }

/* --- Chips and badges --------------------------------------------------- */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.chip-value { color: var(--text); font-weight: 600; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 650; letter-spacing: 0.03em;
  padding: 3px 9px; border-radius: 99px; text-transform: uppercase;
}
.badge.ok     { background: var(--ok-soft);     color: var(--ok); }
.badge.warn   { background: var(--warn-soft);   color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info   { background: var(--accent-soft); color: var(--accent); }
.badge.muted  { background: var(--surface-3);   color: var(--text-muted); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.vertical   { background: var(--vertical); }
.dot.horizontal { background: var(--horizontal); }
.dot.reserve    { background: var(--reserve); }
.dot.free       { background: var(--free); border: 1px solid var(--border-strong); }

/* --- Lists -------------------------------------------------------------- */

.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: none; border-left: none; border-right: none; border-top: none;
  width: 100%; text-align: left; border-radius: 0;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface-2); }
.list-item[aria-current="true"] { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .meta { font-size: 11px; color: var(--text-faint); }

/* --- Tables ------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  padding-left: 5px;
  padding-right: 5px;
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-faint);
  text-align: right;
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th:first-child, thead th.left { text-align: left; }
tbody td {
  padding: 4px 4px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}
tbody td:first-child, tbody td.left { text-align: left; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.is-disabled { opacity: 0.42; }
/* A check was followed to this row: flash it so the eye lands on it. */
tbody tr.is-flagged td { animation: row-flag 1600ms ease-out; }
@keyframes row-flag {
  0%, 35% { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); }
}
tbody tr.is-reserve td { background: color-mix(in srgb, var(--reserve) 7%, transparent); }
tbody td input, tbody td select { padding: 4px 6px; background: transparent; border-color: transparent; }
tbody td select { min-width: 82px; }
tbody td.name-cell select { min-width: 100%; font-size: 11.5px; margin-top: 2px; }
tbody td input:hover, tbody td select:hover { background: var(--surface-2); border-color: var(--border); }
tbody td input:focus { background: var(--surface-2); border-color: var(--accent); }
td.calc { color: var(--text-muted); font-family: var(--mono); font-size: 12px; }
td.name-cell input { font-weight: 550; text-align: left; }
.col-narrow { width: 40px; }
.col-name { min-width: 112px; }
/* Row actions: four compact targets, sized so the row still fits. */
tbody td .btn-icon.btn-sm { padding: 3px 4px; font-size: 11px; line-height: 1; }

/* The row actions stay reachable even when the table has to scroll. */
thead th:last-child, tbody td:last-child {
  position: sticky;
  right: 0;
  background: var(--surface);
  box-shadow: -7px 0 7px -7px rgba(0, 0, 0, 0.5);
}
thead th:last-child { background: var(--surface-2); z-index: 2; }
tbody tr:hover td:last-child { background: var(--surface-2); }
tbody tr.is-reserve td:last-child {
  background: color-mix(in srgb, var(--reserve) 7%, var(--surface));
}

/* --- KPIs --------------------------------------------------------------- */

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpi {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 9px 11px;
}
.kpi-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.kpi-value { font-size: 21px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.kpi-value small { font-size: 12px; font-weight: 550; color: var(--text-muted); margin-left: 3px; }
.kpi-note { font-size: 11px; color: var(--text-faint); }

/* --- Range hero -------------------------------------------------------- */

.range-hero { display: flex; flex-direction: column; gap: 2px; }
.range-hero-label {
  font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-faint);
}
.range-hero-value {
  display: flex; align-items: baseline; gap: 4px;
  font-size: 34px; font-weight: 650; letter-spacing: -0.025em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.range-hero-value small { font-size: 15px; font-weight: 550; color: var(--text-muted); }
.range-hero-figures { display: flex; flex-wrap: wrap; gap: 4px 28px; }
.config-name { width: 200px; }
.range-hero-note { font-size: 11.5px; color: var(--text-faint); }
.range-plan {
  display: grid; grid-template-columns: auto 1fr; gap: 3px 12px;
  margin: 10px 0 0; padding-top: 9px; border-top: 1px solid var(--border);
  font-size: 12px;
}
.range-plan dt { color: var(--text-muted); }
.range-plan dd { margin: 0; text-align: right; color: var(--text); }

/* Draft against the saved version, shown only while there are unsaved edits. */
.baseline {
  border: 1px solid var(--border); border-radius: var(--radius-s);
  background: var(--surface-2); padding: 8px 10px 4px;
}
.baseline-title {
  font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-faint); margin-bottom: 2px;
}
.baseline-table { font-size: 12px; }
.baseline-table thead th { position: static; background: none; padding: 4px 0 4px 8px; }
.baseline-table tbody td { padding: 3px 0 3px 8px; }
.baseline-table tbody td:first-child, .baseline-table thead th:first-child { padding-left: 0; }
.baseline-table tbody tr:last-child td { border-bottom: none; }
.baseline-table tbody tr:hover { background: none; }
.baseline-table tr td:last-child, .baseline-table tr th:last-child {
  position: static; background: none; box-shadow: none;
}
.baseline-table tr:not(.is-changed) td { color: var(--text-faint); }
.baseline-delta { font-family: var(--mono); font-weight: 600; }

details.detail > summary {
  cursor: pointer; font-size: 12px; color: var(--text-muted); padding: 2px 0;
  list-style-position: inside;
}
details.detail > summary:hover { color: var(--text); }
details.detail[open] > summary { margin-bottom: 8px; }

/* --- Energy bar --------------------------------------------------------- */

.energy-bar {
  display: flex;
  height: 30px;
  border-radius: 7px;
  overflow: hidden;
  background: var(--free);
  border: 1px solid var(--border);
}
.energy-seg {
  display: grid; place-items: center;
  font-size: 10.5px; font-weight: 650; color: #06101c;
  min-width: 0; overflow: hidden;
  transition: width 200ms ease;
}
.energy-seg.vertical   { background: var(--vertical); }
.energy-seg.horizontal { background: var(--horizontal); }
.energy-seg.reserve    { background: var(--reserve); }
.energy-seg.over       { background: var(--danger); color: #fff; }
.energy-bar { position: relative; }
.energy-limit {
  position: absolute; top: -1px; bottom: -1px; width: 2px;
  background: var(--text); opacity: 0.85;
}
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11.5px; color: var(--text-muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* --- Headroom bars ------------------------------------------------------ */

.meter { display: flex; flex-direction: column; gap: 3px; }
.meter-head { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-muted); }
.meter-head b { color: var(--text); font-weight: 600; }
.meter-track {
  position: relative; height: 7px; border-radius: 4px;
  background: var(--free); overflow: hidden;
}
.meter-fill { height: 100%; border-radius: 4px; background: var(--ok); transition: width 200ms ease; }
.meter-fill.warn   { background: var(--warn); }
.meter-fill.danger { background: var(--danger); }
.meter-limit { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text-faint); }

/* --- Validation --------------------------------------------------------- */

.messages { display: flex; flex-direction: column; gap: 7px; }
.message {
  display: flex; gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-s);
  font-size: 12.5px;
  border: 1px solid transparent;
  line-height: 1.4;
}
.message.error   { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.message.warning { background: var(--warn-soft);   border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.message.info    { background: var(--surface-2);   border-color: var(--border); color: var(--text-muted); }
.message .icon { flex: none; font-weight: 700; }
.message-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.message-head {
  display: flex; gap: 8px; align-items: baseline;
  font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted);
}
.message-target { margin-left: auto; color: var(--accent); text-transform: none; letter-spacing: 0; }
button.message.is-link {
  width: 100%; text-align: left; font-weight: 400; white-space: normal;
  align-items: flex-start; color: var(--text); cursor: pointer;
}
button.message.is-link.error:hover   { border-color: color-mix(in srgb, var(--danger) 60%, transparent); background: var(--danger-soft); }
button.message.is-link.warning:hover { border-color: color-mix(in srgb, var(--warn) 60%, transparent); background: var(--warn-soft); }
button.message.is-link.info:hover    { border-color: var(--border-strong); background: var(--surface-2); }
button.message.is-link:hover .message-target { text-decoration: underline; }
.message.error .icon   { color: var(--danger); }
.message.warning .icon { color: var(--warn); }
.message.info .icon    { color: var(--accent); }

/* --- Charts ------------------------------------------------------------- */

.chart { width: 100%; display: block; }
.chart text { fill: var(--text-faint); font-size: 10px; font-family: var(--sans); }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 4; opacity: 0.6; }
.chart .bar-vertical   { fill: var(--vertical); }
.chart .bar-horizontal { fill: var(--horizontal); }
.chart .bar-reserve    { fill: var(--reserve); }
.chart .bar-label      { fill: var(--text-muted); }

/* --- Drawer / modal ----------------------------------------------------- */

.overlay {
  position: fixed; inset: 0;
  background: rgba(4, 8, 13, 0.6);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  padding: 24px;
  z-index: 50;
}
.overlay[hidden] { display: none; }
.dialog {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: min(880px, 100%);
  max-height: min(86vh, 900px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.dialog.narrow { width: min(480px, 100%); }
.dialog-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.dialog-head h2 { font-size: 15px; }
.dialog-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.dialog-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2);
}

/* --- Toasts ------------------------------------------------------------- */

.toasts {
  position: fixed; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 100; max-width: 380px;
}
.toast {
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-s);
  padding: 10px 13px;
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toast-in 160ms ease;
}
.toast { display: flex; align-items: center; gap: 12px; transition: opacity 200ms ease; }
.toast-action { margin-left: auto; }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* --- Sign-in gate ------------------------------------------------------- */

.gate {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #17263a, var(--bg));
  padding: 24px;
}
.gate-card {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 30px;
  width: min(430px, 100%);
  text-align: center;
  display: flex; flex-direction: column; gap: 14px; align-items: center;
}
.gate-card h1 { font-size: 19px; }
.gate-card p { color: var(--text-muted); margin: 0; font-size: 13.5px; }

/* --- Phase guide ------------------------------------------------------- */

.phase-guide { border-top: 1px solid var(--border); padding: 9px 12px; font-size: 12.5px; }
.phase-guide > summary { cursor: pointer; color: var(--text-muted); font-size: 12px; }
.phase-guide > summary:hover { color: var(--text); }
.phase-guide dl {
  display: grid; grid-template-columns: max-content minmax(0, 68ch);
  gap: 6px 16px; margin: 10px 0 2px;
}
.phase-guide dt { font-weight: 650; color: var(--text); }
.phase-guide dd { margin: 0; color: var(--text-muted); line-height: 1.45; }
@media (max-width: 860px) {
  .phase-guide dl { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .phase-guide dd { margin-bottom: 6px; }
}

/* --- Keyboard shortcuts ---------------------------------------------- */

.shortcut-list { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0; align-items: center; }
.shortcut-list dt { display: flex; gap: 4px; }
.shortcut-list dd { margin: 0; color: var(--text-muted); }
kbd {
  font: 600 11.5px var(--sans); min-width: 22px; text-align: center;
  padding: 2px 6px; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  box-shadow: inset 0 -1px 0 var(--border-strong);
}

/* --- Misc --------------------------------------------------------------- */

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.empty {
  padding: 22px 14px; text-align: center; color: var(--text-faint); font-size: 12.5px;
}
.divider { height: 1px; background: var(--border); }
.hidden { display: none !important; }
.spin { animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.source-note {
  font-size: 11.5px; color: var(--text-faint);
  border-left: 2px solid var(--border-strong); padding-left: 9px;
}

/* --- Responsive --------------------------------------------------------- */

/* Pack current is the first column to go: the results panel already shows the
   peak, and dropping it keeps the whole row visible on a 1440 px laptop. */
@media (max-width: 1520px) {
  .col-optional { display: none; }
}

@media (max-width: 1400px) {
  .workspace { grid-template-columns: 270px minmax(0, 1fr) 340px; }
}
/* Below 1150 px the page scrolls instead of the columns. Setup stays in view
   as a sticky left rail (a first-time user must pick packs there first); the
   mission and the results share the right side. */
@media (max-width: 1150px) {
  .app { height: auto; min-height: 100vh; }
  .workspace {
    grid-template-columns: 270px minmax(0, 1fr);
    overflow: visible; align-items: start;
  }
  .column { overflow: visible; }
  .column.left {
    grid-column: 1; grid-row: 1 / span 2;
    position: sticky; top: var(--gap);
    max-height: calc(100vh - 2 * var(--gap)); overflow-y: auto;
  }
  .column.center { grid-column: 2; grid-row: 1; }
  .column.right  { grid-column: 2; grid-row: 2; }
}
@media (max-width: 860px) {
  .column.left, .column.center, .column.right {
    grid-column: auto; grid-row: auto; position: static; max-height: none;
  }
  .topbar { gap: 8px; }
  .topbar-spacer { display: none; }
  .brand-sub { display: none; }
  #config-switcher { order: 5; width: 100%; }
  #config-select { flex: 1 1 auto; width: auto; }
  .workspace { grid-template-columns: minmax(0, 1fr); overflow-y: auto; }
  .app { height: auto; min-height: 100vh; }
  .column { overflow: visible; }
  .column.right { order: -1; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  tbody tr.is-flagged td { animation: none; outline: 2px solid var(--accent); outline-offset: -2px; }
}
