/* ── Budget Modeller ─────────────────────────────────────────────────────── */

/* ── Miller Table ── */
.miller-table {
  display: grid;
  grid-template-columns:
    minmax(150px, 0.8fr)   /* goals */
    minmax(200px, 1.5fr)   /* portfolios */
    minmax(170px, 1fr)     /* config */
    minmax(150px, 1fr);    /* donut */
  gap: 10px;
  min-width: 680px;
  margin-bottom: 24px;
  height: 360px;
  position: relative;
}
.miller-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08),0 1px 4px rgba(0,0,0,0.04);
  position: relative;
  transition: box-shadow 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.miller-col::after {
  content:'';position:absolute;inset:0;border-radius:inherit;
  background:linear-gradient(180deg,color-mix(in srgb,var(--accent) 4%,transparent) 0%,transparent 35%);
  opacity:0;transition:opacity 0.25s ease;pointer-events:none;z-index:0;
}
.miller-col:hover { box-shadow: 0 6px 28px rgba(0,0,0,0.12),0 2px 6px rgba(0,0,0,0.06); border-color: var(--border2); }
.miller-col:hover::after { opacity:1; }
/* Staggered fade-in for columns when a goal is selected */
@keyframes miller-col-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.miller-col-fade { opacity: 0; animation: miller-col-in 0.55s cubic-bezier(0.22,1,0.36,1) forwards; }
.miller-col-goals {
  /* sized by grid-template-columns */
}
.miller-col-portfolios {
  /* sized by grid-template-columns */
}
.miller-col-config {
  /* sized by grid-template-columns */
}
/* Vertical divider — hidden (columns are now separate floating panels) */
.miller-vdivider {
  display: none;
}
.miller-col-header {
  padding: 10px 16px;
  flex-shrink: 0;
  /* Fixed two-row height so header never resizes when sub-labels appear */
  height: 56px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  transition: box-shadow 0.2s;
}
/* Header hover: shadow + accent text */
.miller-col:hover .miller-col-header { }
.miller-col:hover .miller-col-label,
.miller-col:hover .miller-sub-label { color: var(--accent); }
.miller-col-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text3);
  transition: color 0.2s;
}
.miller-col-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* Goals column — scrollbar hidden until hover */
.miller-col-goals .miller-col-body { scrollbar-width: none; }
.miller-col-goals .miller-col-body::-webkit-scrollbar { width: 0; }
.miller-col-goals:hover .miller-col-body { scrollbar-width: thin; }
.miller-col-goals:hover .miller-col-body::-webkit-scrollbar { width: 6px; }
.miller-col-goals:hover .miller-col-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.miller-col-goals:hover .miller-col-body::-webkit-scrollbar-track { background: transparent; }

/* Tabular-nums for all numeric values in the miller table */
.miller-config-value,
.modeller-budget-input,
.miller-port-budget-input,
.miller-port-budget-ro,
.miller-donut-centre-value,
.miller-goal-count {
  font-variant-numeric: tabular-nums;
}

/* Goals column */
.miller-goal-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border-bottom: none;
  position: relative;
}
/* Shorter sub-divider — inset from both sides to differentiate from header line */
.miller-goal-row::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 24px;
  right: 24px;
  height: 1px;
  background: var(--border);
}
.miller-goal-row:last-child::after { display: none; }
.miller-goal-row:hover:not(.disabled) { background: var(--surface-hover); }
.miller-goal-row.active {
  background: var(--accent-bg);
  color: var(--accent);
}
.miller-goal-row.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.miller-goal-dot {
  font-size: 10px;
  color: var(--text3);
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}
.miller-goal-row.active .miller-goal-dot { color: var(--accent); }
.miller-goal-name {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.miller-goal-row.active .miller-goal-name { color: var(--accent); font-weight: 600; }
.miller-goal-count {
  font-size: 10px;
  color: var(--text3);
  background: var(--bg2);
  padding: 1px 7px;
  border-radius: 8px;
  font-weight: 500;
  flex-shrink: 0;
}
.miller-goal-row.active .miller-goal-count {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: var(--accent);
}

/* Portfolios column — sub-column grid: lock | name | budget | action */
/* Shared 4-column grid for header + rows — ensures perfect alignment */
.miller-port-grid {
  display: grid;
  grid-template-columns: 28px 1fr 80px 22px;
  gap: 0 6px;
  align-items: center;
}
.miller-port-count-label {
  font-weight: 400;
  opacity: 0.7;
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0;
}
.miller-port-sub-header {
  padding-top: 6px;
}
.miller-sub-label {
  font-size: 9px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text3);
  opacity: 0.6;
}
.miller-port-hdr-lock { text-align: center; }
.miller-port-hdr-budget { text-align: right; }

.miller-port-list {
  padding: 4px 0;
}
.miller-port-row {
  display: grid;
  grid-template-columns: 28px 1fr 80px 22px;
  gap: 0 6px;
  align-items: center;
  padding: 7px 16px;
  transition: background 0.12s;
  border-bottom: none;
  position: relative;
}
/* Shorter sub-divider — inset from both sides */
.miller-port-row::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 24px;
  right: 24px;
  height: 1px;
  background: var(--border);
}
.miller-port-row:last-child::after { display: none; }
.miller-port-row:hover { background: var(--surface-hover); }
.miller-port-row.excluded {
  opacity: 0.4;
}
.miller-port-row.excluded:hover { opacity: 0.55; }
.miller-port-lock {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 3px 0;
  color: var(--text3);
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
  text-align: center;
}
.miller-port-lock:hover { color: var(--accent); background: var(--accent-bg); }
.miller-port-lock.active { color: var(--accent); }
/* Lock spacer removed — grid handles alignment */
.miller-port-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
/* Editable budget input in portfolio rows */
.miller-port-budget-input {
  width: 100%;
  text-align: right;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text2);
  font-size: 11px;
  font-family: 'DM Mono', monospace;
  font-weight: 500;
  padding: 3px 6px;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  box-sizing: border-box;
}
.miller-port-budget-input:hover { border-color: var(--border); background: var(--bg2); }
.miller-port-budget-input:focus { outline: none; border-color: var(--accent); background: var(--bg2); color: var(--text); }
.miller-port-budget-input.locked { color: var(--accent); border-color: var(--accent-border); background: var(--bg2); }
.miller-port-budget-input::-webkit-inner-spin-button,
.miller-port-budget-input::-webkit-outer-spin-button { -webkit-appearance: none; }
/* Read-only budget for excluded rows */
.miller-port-budget-ro {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--text2);
  white-space: nowrap;
  text-align: right;
}
.miller-port-budget-ro.muted { color: var(--text3); }
.miller-port-remove {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text3);
  padding: 2px 0;
  border-radius: 4px;
  line-height: 1;
  text-align: center;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}
.miller-port-row:hover .miller-port-remove { opacity: 1; }
.miller-port-remove:hover { color: var(--red); background: color-mix(in srgb, var(--red) 10%, transparent); }
.miller-port-add {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  width: 22px;
  text-align: center;
  transition: background 0.12s;
  flex-shrink: 0;
  font-weight: 600;
}
.miller-port-add:hover { background: var(--accent-bg); }

/* Config column */
.miller-config-inner {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.miller-config-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.miller-config-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text3);
}
.miller-config-value {
  font-family: 'DM Mono', monospace;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
/* Column footer — bottom-aligned button area */
.miller-col-footer {
  flex-shrink: 0;
  padding: 12px 16px;
  margin-top: auto;
  display: flex;
  justify-content: flex-end;
}
.miller-col-footer .btn {
  width: auto;
}
.miller-config-inner .modeller-run-btn {
  margin-top: auto;
  align-self: flex-start;
}
.miller-config-inner .modeller-ref-pills {
  gap: 4px;
  flex-wrap: nowrap;
}

/* Placeholder state for empty columns */
.miller-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  height: 100%;
}
.miller-placeholder-icon {
  font-size: 20px;
  opacity: 0.3;
  margin-bottom: 8px;
}
.miller-placeholder-text {
  font-size: 12px;
  color: var(--text3);
  line-height: 1.5;
}

/* ── Donut chart column ── */
.miller-col-donut {
  /* sized by grid-template-columns */
}
.miller-donut-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 0;
}
.miller-donut-fade {
  transition: opacity 0.2s ease;
}
.miller-donut-fade.fading { opacity: 0; }
.miller-donut-footer {
  justify-content: flex-end !important;
}
.miller-donut-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 12px;
  position: relative;
}
.miller-donut-chart-area { position: relative; width: 100%; max-width: 210px; }
.miller-donut-svg { width: 100%; height: auto; display: block; overflow: visible; }
.miller-donut-segment {
  transition: stroke-width 0.15s ease, opacity 0.15s ease;
}
.miller-donut-hit {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  cursor: pointer;
  z-index: 1;
}
.miller-donut-centre {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.miller-donut-centre-label {
  font-size: 10px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.miller-donut-centre-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  font-family: var(--font-mono);
}
/* ── Donut tooltip ── */
.miller-donut-tooltip {
  pointer-events: none;
  z-index: 999;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: var(--shadow-xl);
  min-width: 120px;
  transition: opacity 0.15s;
  opacity: 0;
}
.miller-donut-tooltip.visible { opacity: 1; }
.miller-donut-tt-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.miller-donut-tt-swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}
.miller-donut-tt-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.miller-donut-tt-value {
  font-size: 10px;
  color: var(--text2);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.miller-donut-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  opacity: 0.4;
}
.miller-donut-empty .miller-donut-chart-area { max-width: 120px; }
.miller-donut-empty .miller-donut-centre { pointer-events: none; }
.miller-donut-empty-label {
  font-size: 10px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Ref period segmented control (same pattern as opt-seg-control) ── */
.modeller-seg-control {
  position: relative;
  display: flex;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface2);
  overflow: hidden;
  height: 28px;
}
.modeller-seg-thumb {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 25%;
  background: var(--accent);
  pointer-events: none;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.15s;
  will-change: transform;
}
.modeller-seg-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  position: relative;
  z-index: 1;
  background: none;
  border: none;
  padding: 0;
  font-family: var(--font-ui);
  transition: color 0.12s;
}
.modeller-seg-item:hover { color: var(--text); }
.modeller-seg-item.active { color: #fff; font-weight: 600; }

/* Custom date inputs */
.modeller-custom-dates {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
}
.modeller-date-input {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg2);
  color: var(--text);
  font-size: 11px;
  font-family: inherit;
}
.modeller-date-input:focus { outline: none; border-color: var(--accent); }
.modeller-date-sep { color: var(--text3); font-size: 11px; }

/* Total budget input */
.modeller-budget-input-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg2);
  padding: 0 10px;
  gap: 4px;
  transition: border-color 0.15s;
}
.modeller-budget-input-wrap:focus-within { border-color: var(--accent); }
.modeller-budget-prefix { color: var(--text3); font-size: 12px; }
.modeller-budget-input {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-family: 'DM Mono', monospace;
  padding: 5px 0;
  width: 110px;
  outline: none;
}
.modeller-budget-input::-webkit-inner-spin-button,
.modeller-budget-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.modeller-run-btn { padding: 8px 20px; }

/* Lock warning */
.modeller-lock-warning {
  font-size: 11px;
  color: var(--amber);
  padding: 5px 0 8px;
}


/* Suggested value highlight */
.modeller-suggested { color: var(--green); font-weight: 500; font-family: 'DM Mono', monospace; }

/* Override input */
.modeller-override-input {
  width: 82px;
  text-align: right;
  background: var(--bg2);
  border: 1px solid var(--accent-border);
  border-radius: 5px;
  color: var(--accent);
  font-size: 12px;
  font-family: 'DM Mono', monospace;
  font-weight: 500;
  padding: 4px 7px;
}
.modeller-override-input:focus { outline: none; border-color: var(--accent); }
.modeller-override-input::-webkit-inner-spin-button,
.modeller-override-input::-webkit-outer-spin-button { -webkit-appearance: none; }

/* Engine signal badges */
.modeller-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.modeller-badge-high { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }
.modeller-badge-med { background: color-mix(in srgb, var(--amber) 15%, transparent); color: var(--amber); }
.modeller-badge-low { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }
.modeller-badge-learning { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }

/* Trend indicators */
.modeller-trend-up { color: var(--green); font-size: 10px; cursor: default; }
.modeller-trend-down { color: var(--red); font-size: 10px; cursor: default; }
.modeller-trend-flat { color: var(--text3); font-size: 11px; cursor: default; }

/* Anomaly warning icon */
.modeller-anomaly-icon {
  color: var(--amber);
  font-size: 11px;
  cursor: default;
  vertical-align: middle;
}

/* IS split label */
.modeller-is-label {
  font-size: 9px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Efficiency Curve Chart ── */
.modeller-chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  margin-bottom: 20px;
  overflow: hidden;
  animation: mFadeUp 0.4s both;
  animation-delay: 0.16s;
  transition: box-shadow 0.2s, border-color 0.2s;
}
.modeller-chart-section:hover { box-shadow: var(--shadow-xl); border-color: var(--border2); }
.modeller-chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modeller-chart-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text3);
}
/* ── Curve Y-axis toggle (Revenue / ROAS) ── */
.curve-y-toggle {
  position: relative;
  display: flex;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface2);
  overflow: hidden;
  height: 24px;
}
.curve-y-thumb {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 50%;
  background: var(--accent);
  pointer-events: none;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  will-change: transform;
}
.curve-y-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  position: relative;
  z-index: 1;
  background: none;
  border: none;
  padding: 0 12px;
  font-family: var(--font-ui);
  transition: color 0.12s;
}
.curve-y-toggle-3 .curve-y-thumb { width: 33.333%; }
.curve-y-btn:hover { color: var(--text); }
.curve-y-btn.active { color: #fff; font-weight: 600; }
.modeller-chart-legend {
  margin-bottom: 8px;
  padding: 12px 20px 0;
  font-size: 12px;
  color: var(--text2);
  min-height: 33px;
}
.modeller-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--text3);
  font-weight: 500;
}
.modeller-legend-swatch {
  width: 14px;
  height: 3px;
  border-radius: 2px;
}
.modeller-legend-dash {
  background: none !important;
  border-top: 2px dashed;
  height: 0;
}
.modeller-chart-gain {
  font-size: 11px;
  font-weight: 600;
  color: var(--green);
  background: color-mix(in srgb, var(--green) 12%, transparent);
  padding: 2px 8px;
  border-radius: 10px;
}
.modeller-chart-wrap {
  position: relative;
  padding: 0 0 12px;
}
.modeller-chart-wrap canvas {
  display: block;
  width: 100%;
  height: 240px;
}
.modeller-chart-crosshair {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  overflow: visible;
}
.modeller-chart-tooltip {
  display: none;
  position: absolute;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  pointer-events: none;
  min-width: 160px;
  z-index: 20;
  box-shadow: var(--shadow-lg);
  font-size: 12px;
}
.modeller-tt-budget {
  font-size: 11px;
  color: var(--text3);
  margin-bottom: 4px;
  font-family: 'DM Mono', monospace;
}
.modeller-tt-row {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.6;
  color: var(--text2);
}
.modeller-tt-row strong {
  color: var(--text);
  font-family: 'DM Mono', monospace;
}
.modeller-tt-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.modeller-tt-gain {
  font-size: 11px;
  color: var(--green);
  margin-top: 4px;
  font-weight: 500;
}

/* ── Curve Explain (LLM-powered) ─────────────────────────────────────────── */
.curve-explain-btn {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text3);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.curve-explain-btn:hover,
.curve-explain-btn.active {
  color: var(--accent);
  background: rgba(var(--accent-ch), 0.08);
}

.curve-explain-panel {
  padding: 0 20px 16px;
  border-top: 1px solid var(--border);
}

.curve-explain-phases {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.curve-explain-phase {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
}

.curve-explain-phase-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.curve-explain-phase-icon { font-size: 13px; }
.curve-explain-phase-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex: 1;
}
.curve-explain-phase-range {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--text3);
  background: var(--surface3);
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
}
.curve-explain-phase-body {
  font-size: 12px;
  line-height: 1.65;
  color: var(--text2);
}
.curve-explain-phase-body strong {
  color: var(--text);
  font-weight: 600;
}

/* Loading skeleton */
.curve-explain-loading {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}
.curve-explain-skeleton {
  height: 64px;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: ai-skeleton-shimmer 1.5s ease-in-out infinite;
}
.curve-explain-skeleton.short { height: 48px; width: 75%; }
.curve-explain-loading-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
}

/* Error / fallback states */
.curve-explain-error {
  font-size: 11px;
  color: var(--red);
  padding: 8px 12px;
  background: rgba(var(--red-ch), 0.06);
  border-radius: 8px;
  border: 1px solid rgba(var(--red-ch), 0.15);
  margin-top: 14px;
}
.curve-explain-no-key {
  font-size: 11px;
  color: var(--text3);
  font-style: italic;
  padding: 4px 0;
  margin-top: 14px;
}
.curve-explain-empty {
  font-size: 11px;
  color: var(--text3);
  margin-top: 14px;
}

/* Reasoning box (inherits ai-reasoning-box styles from portfolios.css) */
.modeller-reasoning { margin-top: 20px; }

/* Apply row */
.modeller-apply-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 0;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}
.modeller-apply-summary {
  font-size: 12px;
  color: var(--text3);
}
.modeller-apply-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.modeller-apply-btn { padding: 9px 20px; font-size: 12px; }
.modeller-step-btn { padding: 9px 16px; font-size: 12px; }

/* ── Stepped transition modal ── */
.stepped-modal { max-width: 520px; width: 90%; }
.stepped-days-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.stepped-days-input {
  width: 60px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  text-align: center;
}
.stepped-days-input:focus {
  outline: none;
  border-color: var(--accent);
}
.stepped-preview-table {
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 4px;
}
.stepped-preview-table .mpred-table { width: 100%; }
.stepped-schedule-preview {
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   POST-MODEL VISUAL COMPONENTS — Hero · Flow · Marginal ROAS · Waterfall
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── Fade-up animation ── */
@keyframes mFadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes mBarGrow { from { width: 0 !important; } }
@keyframes mWfBarIn {
  from { transform: scaleY(0); opacity: 0; }
  to   { transform: scaleY(1); opacity: 1; }
}

/* ── Hero Strip ── */
.modeller-hero {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  background: var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  animation: mFadeUp 0.4s ease both;
  transition: box-shadow 0.2s;
}
.modeller-hero:hover { box-shadow: var(--shadow-lg); }
.modeller-hero-cell {
  background: var(--surface);
  padding: 18px 16px;
  position: relative;
  overflow: hidden;
}
.modeller-hero-cell.accent {
  background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 70%, #000) 100%);
}
.modeller-hero-cell.accent::before {
  content: '';
  position: absolute; right: -20px; top: -20px;
  width: 100px; height: 100px;
  background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}
.modeller-hero-label {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text3); margin-bottom: 6px;
}
.modeller-hero-cell.accent .modeller-hero-label,
.modeller-hero-cell.accent .modeller-hero-sub { color: rgba(255,255,255,0.7); }
.modeller-hero-cell.accent .modeller-hero-value { color: #fff; }

.modeller-hero-value {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 24px; font-weight: 700;
  color: var(--text); line-height: 1;
}
.modeller-hero-sub {
  font-size: 11px; color: var(--text3); margin-top: 5px;
}
.modeller-hero-delta.up   { color: var(--green); font-weight: 600; }
.modeller-hero-delta.down { color: var(--red); font-weight: 600; }
.modeller-hero-cell.accent .modeller-hero-delta { color: #fff; }

/* ── Ceiling Warning ── */
.modeller-ceiling-note {
  font-size: 12px;
  color: var(--amber);
  padding: 8px 16px;
  margin-top: 8px;
  border-radius: var(--radius);
  background: oklch(from var(--amber) l c h / 0.08);
  text-align: center;
}

/* ── Mid Row Layout ── */
.modeller-mid-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

/* ── Bottom Row (Chart + Waterfall) ── */
/* bottom-row removed — chart + waterfall are now stacked full-width */

/* ── Budget Reallocation Flow ── */
.modeller-flow {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: mFadeUp 0.4s ease 0.08s both;
  transition: box-shadow 0.2s, border-color 0.2s;
}
.modeller-flow:hover { box-shadow: var(--shadow-xl); border-color: var(--border2); }
.modeller-flow-header {
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modeller-flow-title {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text3);
}
.modeller-flow-legend {
  display: flex; gap: 16px;
}
.modeller-flow-legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text3);
}
.modeller-flow-legend-swatch {
  width: 20px; height: 4px; border-radius: 2px;
}
.modeller-flow-body {
  padding: 8px 0;
  max-height: 378px;
  overflow-y: auto;
}
.modeller-flow-cols {
  display: grid;
  grid-template-columns: minmax(0,2fr) minmax(0,1fr) minmax(0,2fr) minmax(0,1fr) minmax(0,1fr);
  gap: 8px; align-items: center;
  padding: 0 16px 8px;
  border-bottom: 1px solid var(--border);
}
.modeller-flow-col-label {
  font-size: 9px; font-weight: 600;
  letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text3);
}
.modeller-flow-row {
  display: grid;
  grid-template-columns: minmax(0,2fr) minmax(0,1fr) minmax(0,2fr) minmax(0,1fr) minmax(0,1fr);
  gap: 8px; align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.modeller-flow-row:last-child { border-bottom: none; }
.modeller-flow-row.locked { opacity: 0.6; }

.modeller-flow-name-wrap {
  display: flex; align-items: center; gap: 8px;
  min-width: 0; overflow: hidden;
}
.modeller-flow-name-inner {
  min-width: 0; overflow: hidden;
}
.modeller-flow-name {
  font-size: 12px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.modeller-flow-type {
  font-size: 10px; color: var(--text3); margin-top: 1px;
}
.modeller-flow-lock {
  background: none; border: none; cursor: pointer;
  font-size: 12px; padding: 3px 5px; color: var(--text3);
  border-radius: 4px; transition: color 0.15s, background 0.15s;
  line-height: 1; flex-shrink: 0;
}
.modeller-flow-lock:hover { color: var(--accent); background: var(--accent-bg); }
.modeller-flow-lock.active { color: var(--accent); }

.modeller-flow-track {
  position: relative; height: 32px;
  display: flex; align-items: center;
}
.modeller-flow-bg {
  position: absolute; top: 50%; transform: translateY(-50%);
  left: 0; right: 0; height: 6px;
  background: var(--border); border-radius: 4px;
}
.modeller-flow-current {
  position: absolute; top: 50%; transform: translateY(-50%);
  left: 0; height: 6px;
  background: var(--text3); opacity: 0.45;
  border-radius: 4px; z-index: 1;
  animation: mBarGrow 0.8s cubic-bezier(.34,1.2,.64,1) 0.3s both;
}
.modeller-flow-delta {
  position: absolute; top: 50%; transform: translateY(-50%);
  height: 8px; border-radius: 2px; z-index: 2;
  animation: mBarGrow 0.8s cubic-bezier(.34,1.2,.64,1) 0.45s both;
}
.modeller-flow-delta.increase {
  background: var(--green);
  box-shadow: 0 0 6px color-mix(in srgb, var(--green) 50%, transparent);
}
.modeller-flow-delta.decrease {
  background: var(--red); opacity: 0.85;
  box-shadow: 0 0 5px color-mix(in srgb, var(--red) 40%, transparent);
}
.modeller-flow-tick {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  width: 2px; height: 16px; z-index: 3;
  background: var(--border2); border-radius: 1px;
}
.modeller-flow-delta-label {
  position: absolute; bottom: calc(50% + 8px);
  font-family: 'DM Mono', monospace; font-size: 10px; font-weight: 700;
  white-space: nowrap; font-variant-numeric: tabular-nums;
  transform: translateX(-50%); z-index: 4;
}
.modeller-flow-delta-label.increase { color: var(--green); }
.modeller-flow-delta-label.decrease { color: var(--red); }

.modeller-flow-amount {
  font-family: 'DM Mono', monospace; font-size: 12px;
  color: var(--text); text-align: right;
}
.modeller-flow-amount.left { text-align: left; }
.modeller-flow-pill {
  font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 500;
  padding: 3px 8px; border-radius: 8px; text-align: center;
  white-space: nowrap;
}
.modeller-flow-pill.up   { background: color-mix(in srgb, var(--green) 12%, transparent); color: var(--green); }
.modeller-flow-pill.down { background: color-mix(in srgb, var(--red) 10%, transparent); color: var(--red); }
.modeller-flow-pill.flat { background: var(--surface2); color: var(--text3); }

/* ── Marginal ROAS Panel ── */
.modeller-mroas {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex; flex-direction: column;
  animation: mFadeUp 0.4s ease 0.12s both;
  transition: box-shadow 0.2s, border-color 0.2s;
}
.modeller-mroas:hover { box-shadow: var(--shadow-xl); border-color: var(--border2); }
.modeller-mroas-header {
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modeller-mroas-title {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text3);
}
.modeller-mroas-subtitle {
  font-size: 10px; color: var(--text3); font-weight: 500;
}
.modeller-mroas-body {
  padding: 10px 16px;
  flex: 1; display: flex; flex-direction: column; gap: 8px;
  max-height: 340px; overflow-y: auto;
}
.modeller-mroas-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--surface2); border: 1px solid var(--border);
  position: relative; overflow: hidden;
  transition: border-color 0.2s;
  flex-shrink: 0;
}
.modeller-mroas-card:hover { border-color: var(--accent-border); }
.modeller-mroas-card::after {
  content: ''; position: absolute;
  left: 0; top: 0; bottom: 0; width: 3px;
}
.modeller-mroas-card.high::after  { background: var(--green); }
.modeller-mroas-card.mid::after   { background: var(--amber); }
.modeller-mroas-card.low::after   { background: var(--red); opacity: 0.7; }

.modeller-mroas-top {
  display: flex; align-items: center; justify-content: space-between;
}
.modeller-mroas-name {
  font-size: 13px; font-weight: 600; color: var(--text);
}
.modeller-mroas-tag {
  font-size: 10px; font-weight: 600; letter-spacing: 0.04em;
  padding: 2px 8px; border-radius: 6px;
}
.modeller-mroas-tag.scale  { background: color-mix(in srgb, var(--green) 10%, transparent); color: var(--green); border: 1px solid color-mix(in srgb, var(--green) 22%, transparent); }
.modeller-mroas-tag.hold   { background: var(--amber-bg); color: var(--amber); border: 1px solid color-mix(in srgb, var(--amber) 20%, transparent); }
.modeller-mroas-tag.reduce { background: color-mix(in srgb, var(--red) 10%, transparent); color: var(--red); border: 1px solid color-mix(in srgb, var(--red) 20%, transparent); }

.modeller-mroas-gauge {
  height: 6px; background: var(--surface3);
  border-radius: 6px; overflow: hidden;
}
.modeller-mroas-fill {
  height: 100%; border-radius: 6px;
  animation: mBarGrow 0.8s cubic-bezier(.34,1.2,.64,1) 0.4s both;
}
.modeller-mroas-fill.high { background: linear-gradient(90deg, var(--green), color-mix(in srgb, var(--green) 80%, #fff)); box-shadow: 0 0 8px color-mix(in srgb, var(--green) 30%, transparent); }
.modeller-mroas-fill.mid  { background: linear-gradient(90deg, var(--amber), color-mix(in srgb, var(--amber) 80%, #fff)); }
.modeller-mroas-fill.low  { background: linear-gradient(90deg, var(--red), color-mix(in srgb, var(--red) 80%, #fff)); opacity: 0.7; }

.modeller-mroas-meta {
  display: flex; align-items: center; gap: 8px;
}
.modeller-mroas-value {
  font-family: 'DM Mono', monospace; font-size: 14px; font-weight: 500; color: var(--text);
}
.modeller-mroas-value.high { color: var(--green); }
.modeller-mroas-value.mid  { color: var(--amber); }
.modeller-mroas-value.low  { color: var(--red); }
.modeller-mroas-desc {
  font-size: 10px; color: var(--text3);
}

/* ── Revenue Uplift Waterfall ── */
.modeller-wf {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  margin-bottom: 20px;
  animation: mFadeUp 0.4s ease 0.24s both;
}
.modeller-wf-header {
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modeller-wf-title {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text3);
}
.modeller-wf-delta-label {
  font-size: 11px; color: var(--text3);
  font-family: 'DM Mono', monospace;
}

/* ── HTML waterfall chart ── */
.modeller-wf-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 24px 20px 16px;
  height: 220px;
}
.wf-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  position: relative;
}
.wf-col-total { flex: 1.3; }
.wf-value {
  font-family: 'DM Mono', monospace;
  font-size: 10px; font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  margin-bottom: 4px;
  flex-shrink: 0;
}
.wf-val-up { color: var(--green); }
.wf-val-down { color: var(--red); }
.wf-val-opt { color: var(--accent); }
.wf-bar-area {
  flex: 1;
  width: 100%;
  position: relative;
  max-width: 72px;
}
.wf-bar {
  position: absolute;
  bottom: 0;
  left: 8%;
  right: 8%;
  border-radius: 3px;
  animation: mWfBarIn 0.4s ease both;
}
.wf-bar-current {
  background: var(--surface2);
  border: 1px solid var(--border2);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.wf-bar-up {
  background: var(--green);
  opacity: 0.85;
}
.wf-bar-down {
  background: var(--red);
  opacity: 0.65;
}
.wf-bar-optimised {
  background: var(--accent);
  opacity: 0.9;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.wf-roas {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 13px; font-weight: 700;
  color: var(--text);
  opacity: 0.85;
}
.wf-bar-optimised .wf-roas {
  color: rgba(255,255,255,0.9);
}
.wf-roas-label {
  font-size: 8px; color: var(--text3);
  opacity: 0.7;
}
.wf-bar-optimised .wf-roas-label {
  color: rgba(255,255,255,0.7);
}
.wf-connector {
  position: absolute;
  left: -4px;
  width: calc(100% + 8px);
  height: 0;
  border-top: 1px dashed var(--border2);
}
.wf-label {
  font-size: 10px;
  color: var(--text3);
  text-align: center;
  margin-top: 6px;
  flex-shrink: 0;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wf-col-delta {
  animation: mWfColIn 0.35s ease both;
  cursor: default;
}
.wf-col-delta:hover .wf-bar {
  opacity: 1;
  filter: brightness(1.1);
}
@keyframes mWfColIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Waterfall tooltip (matches efficiency chart tooltip) ── */
.wf-tooltip {
  display: none;
  position: absolute;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  pointer-events: none;
  min-width: 160px;
  z-index: 20;
  box-shadow: var(--shadow-lg);
  font-size: 12px;
}
.wf-tt-name {
  font-size: 11px; font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.wf-tt-row {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.6;
  color: var(--text2);
}
.wf-tt-label {
  font-size: 11px; color: var(--text3);
}
.wf-tt-row strong {
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 11px;
}
.wf-tt-up { color: var(--green) !important; }
.wf-tt-down { color: var(--red) !important; }

/* ── Prediction Tracking Card ─────────────────────────────────────────────── */
.mpred-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
  animation: mFadeUp 0.4s ease both;
}
.mpred-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.15s;
}
.mpred-header:hover {
  background: var(--bg3);
}
.mpred-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.mpred-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text3);
  white-space: nowrap;
}
.mpred-date {
  font-size: 12px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mpred-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.mpred-summary {
  font-size: 12px;
  font-family: 'DM Mono', monospace;
  color: var(--text2);
  white-space: nowrap;
}
.mpred-chevron {
  font-size: 12px;
  color: var(--text3);
  transition: transform 0.2s;
}
.mpred-card.open .mpred-chevron {
  transform: rotate(90deg);
}
.mpred-clear {
  font-size: 11px;
  color: var(--text3);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.mpred-clear:hover {
  color: var(--red);
}
.mpred-details {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 16px;
}
.mpred-card.open .mpred-details {
  max-height: 500px;
  padding: 0 16px 14px;
}
.mpred-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.mpred-table th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text3);
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.mpred-table th.num,
.mpred-table td.num {
  text-align: right;
  font-family: 'DM Mono', monospace;
}
.mpred-table td {
  padding: 6px 8px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.mpred-table tbody tr:last-child td {
  border-bottom: none;
}
.mpred-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mpred-err.up { color: var(--green); }
.mpred-err.down { color: var(--red); }
.mpred-note {
  font-size: 11px;
  color: var(--text3);
  margin-top: 8px;
}

/* ── NuPhy — flatten modeller gradients ── */
.theme-nuphy .modeller-mroas-fill.high{background:var(--green);box-shadow:none}
.theme-nuphy .modeller-mroas-fill.mid{background:var(--amber)}
.theme-nuphy .modeller-mroas-fill.low{background:var(--red)}
