@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700&family=Spectral:wght@400;600&display=swap");

:root {
  --bg: #0f1418;
  --panel: #151c22;
  --panel-soft: #1c2430;
  --accent: #ff7a59;
  --accent-2: #4fd1c5;
  --accent-3: #f1c40f;
  --accent-4: #7c9df5;
  --text: #f5f5f5;
  --muted: #8899a6;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: rgba(0, 0, 0, 0.45);
  --table-border: rgba(255, 255, 255, 0.1);
  --table-border-header: rgba(255, 255, 255, 0.15);
  --warning-color: #ffa500;
  --ember-color: #fb923c;
  --scale: 0.9;
  --inv-scale: 1.1111;  /* 1 / 0.9 */
  --full-vh: calc(100vh * var(--inv-scale));
}

* { box-sizing: border-box; }

html {
  background: radial-gradient(circle at 15% 20%, #1d2a32 0%, #0f1418 45%, #0b1014 100%);
  overflow: hidden;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

.app {
  transform: scale(var(--scale));
  transform-origin: 0 0;
  width: calc(100vw * var(--inv-scale));
  height: calc(100vh * var(--inv-scale));
  display: grid;
  grid-template-columns: 180px 1fr;
}

nav {
  background: linear-gradient(180deg, #0e1317 0%, #121a20 100%);
  padding: 20px 10px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

nav h1 {
  font-size: 19px;
  margin: 0 0 4px 4px;
  font-weight: 700;
}

nav h1 span { color: var(--accent); }

.nav-subtitle {
  font-size: 10px;
  color: var(--muted);
  margin: 0 0 16px 4px;
  letter-spacing: 0.5px;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 9px 12px;
  margin-bottom: 3px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-item.active, .nav-item:hover {
  background: rgba(255, 122, 89, 0.12);
  color: var(--accent);
}

/* --- Nav bottom: locale toggle + auth --- */
.nav-bottom {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Locale toggle */
.nav-locale {
  display: flex;
  gap: 2px;
  margin-bottom: 8px;
  background: rgba(255,255,255,0.04);
  border-radius: 6px;
  padding: 2px;
}
.locale-btn {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 0;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.5px;
}
.locale-btn.active {
  background: rgba(255, 122, 89, 0.18);
  color: var(--accent);
}
.locale-btn:hover:not(.active) {
  color: var(--fg);
}

/* Auth buttons */
.nav-auth { margin-top: 4px; }
.nav-auth-buttons {
  display: flex;
  gap: 4px;
}
.auth-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  padding: 5px 0;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.auth-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.auth-btn.auth-register {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}
.auth-btn.auth-register:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.auth-btn.active {
  background: rgba(255, 122, 89, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* Logged-in state */
.nav-auth-user {
  text-align: center;
}
.auth-user-name {
  font-size: 12px;
  color: var(--fg);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.auth-btn.auth-logout {
  width: 100%;
  font-size: 11px;
  border-color: var(--border);
  color: var(--muted);
}
.auth-btn.auth-delete-account {
  width: 100%;
  font-size: 10px;
  border-color: rgba(220, 60, 60, 0.3);
  color: #dc3c3c;
  margin-top: 8px;
  margin-bottom: 4px;
}
.auth-btn.auth-delete-account:hover {
  border-color: #dc3c3c;
  background: rgba(220, 60, 60, 0.1);
}

/* Auth form (animated expand) */
.auth-form-wrapper {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.45s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease, margin 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  margin-top: 0;
}
.auth-form-wrapper.open {
  max-height: 220px;
  min-height: 190px;
  opacity: 1;
  margin-top: 8px;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.auth-form input {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 5px;
  outline: none;
  transition: border-color 0.15s;
}
.auth-form input:focus {
  border-color: var(--accent);
}
.auth-form input::placeholder {
  color: var(--muted);
  opacity: 0.6;
}
.auth-submit {
  background: var(--accent);
  color: #fff;
  border: 0;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 0;
  border-radius: 5px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.auth-submit:hover { opacity: 0.85; }
.auth-cancel {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 11px;
  padding: 4px 0;
  cursor: pointer;
  transition: color 0.15s;
}
.auth-cancel:hover { color: var(--fg); }
.auth-error {
  font-size: 11px;
  color: #ff5959;
  min-height: 0;
  transition: min-height 0.15s;
  text-align: center;
}

main {
  padding: 20px 24px 16px;
  overflow-y: auto;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  position: relative;
  z-index: 1;
}

#header-glow {
  position: fixed;
  top: 0;
  left: 180px;
  right: 0;
  height: 100vh;
  z-index: 9999;
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: 0.52;
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,0.6) 30%, rgba(0,0,0,0.2) 65%, rgba(0,0,0,0) 100%);
  mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,0.6) 30%, rgba(0,0,0,0.2) 65%, rgba(0,0,0,0) 100%);
  background:
    radial-gradient(ellipse 650px 420px at 20% 15%, rgba(79,209,197,0.45) 0%, transparent 70%),
    radial-gradient(ellipse 550px 370px at 70% 10%, rgba(124,157,245,0.4) 0%, transparent 70%),
    radial-gradient(ellipse 480px 320px at 50% 25%, rgba(255,122,89,0.32) 0%, transparent 70%),
    radial-gradient(ellipse 420px 310px at 35% 5%,  rgba(150,115,230,0.22) 0%, transparent 70%),
    radial-gradient(ellipse 380px 270px at 80% 20%, rgba(241,196,15,0.22) 0%, transparent 70%);
  background-size: 220% 220%;
  animation: glowDrift 20s ease-in-out infinite alternate;
  will-change: background-position;
}

@keyframes glowDrift {
  0%   { background-position: 30% 20%, 70% 10%, 50% 30%, 20% 15%, 80% 25%; }
  25%  { background-position: 48% 10%, 52% 25%, 35% 15%, 58% 5%,  62% 20%; }
  50%  { background-position: 60% 25%, 38% 15%, 58% 10%, 30% 20%, 48% 10%; }
  75%  { background-position: 35% 15%, 65% 20%, 45% 25%, 50% 10%, 75% 15%; }
  100% { background-position: 25% 22%, 75% 8%,  55% 22%, 40% 15%, 65% 25%; }
}

header .title { font-size: 20px; font-weight: 700; }
header .subtitle { font-family: "Spectral", serif; color: var(--muted); font-size: 13px; margin-top: 3px; }

.section { display: none; }
.section.active { display: block; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  align-items: start;
}

.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 18px;
  border-radius: 10px;
  box-shadow: 0 8px 20px var(--shadow);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  border-color: rgba(79, 209, 197, 0.25);
  box-shadow:
    0 8px 20px var(--shadow),
    0 0 8px rgba(79, 209, 197, 0.12),
    0 0 30px rgba(79, 209, 197, 0.06);
}

.card.wide { grid-column: span 2; }
.card.tall { min-height: 400px; }

/* EMTR/PTR compute banner — slim, full-width */
.emtr-compute-banner { padding: 12px 18px !important; }
.emtr-compute-row {
  display: flex;
  align-items: center;
  gap: 16px;
}
.emtr-compute-text {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.emtr-progress-bar {
  width: 100px;
  flex-shrink: 0;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}
.emtr-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 2px;
}
.emtr-progress-bar.loading .emtr-progress-fill {
  width: 30%;
  background: var(--accent);
  animation: emtr-progress-slide 1.5s ease-in-out infinite;
}
.emtr-progress-bar.done .emtr-progress-fill {
  width: 100%;
  background: var(--accent-2);
  animation: none;
  transition: width 0.3s ease;
}
@keyframes emtr-progress-slide {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(200%); }
  100% { transform: translateX(400%); }
}

.card h3 {
  margin: 0 0 10px 0;
  font-size: 15px;
  font-weight: 600;
}

.card-note {
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 12px 0;
}

.form-group { margin-bottom: 12px; }

.form-row {
  display: flex;
  gap: 14px;
}

.form-row .form-group { flex: 1; }

label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input, select, textarea {
  width: 100%;
  background: var(--panel-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}

/* Fix Safari select height — Safari ignores padding on selects */
select:not([multiple]) {
  height: 36px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238899a6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-2);
}

input::placeholder { color: var(--muted); opacity: 0.5; }

/* Hide number input spinners globally */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}

textarea { min-height: 50px; resize: vertical; }
select[multiple] { min-height: 105px; }

/* Simulation tab layout - Run Config fixed 420px (matches Parameters left column) */
#overview .grid {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 4.5fr) minmax(0, 5.5fr);
  gap: 16px;
  align-items: stretch;
  min-height: calc(var(--full-vh) - 160px);
}

/* Consistent overflow clipping across all tab sections */
.section { overflow-x: clip; }

#overview .card {
  display: flex;
  flex-direction: column;
  min-height: 0 !important;
}

#overview .card:first-child {
  contain: size;
  overflow: hidden;
}

#overview .card:first-child > .button-row {
  margin-top: 16px;
}

#overview .card:first-child .run-config-overflow {
  overflow-y: auto;
  min-height: 0;
  scrollbar-width: thin;
}

#overview .card .results-list,
#overview .card .sim-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  max-height: none;
}

/* Compact result rows in Simulation Latest Results */
#overview .results-list .list-item {
  padding: 0 12px;
  border-bottom: none;
}

#overview .results-list .list-item .result-section {
  margin-top: 12px;
  padding-top: 8px;
  line-height: 1.6;
  margin-bottom: 1px;
  font-size: 12px;
}

#overview .results-list .list-item:first-child .result-section {
  margin-top: 2px;
  padding-top: 2px;
  border-top: none;
}

#overview .results-list .list-item .result-note {
  display: block;
  margin-bottom: 5px;
}

#overview .results-list .list-item .result-row {
  padding: 3px 0;
  line-height: 1.3;
}

/* Analysis tab layout */
#analysis .grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
}



#analysis .card.wide {
  grid-column: span 2;
}

#analysis .indicators-poverty-row,
#analysis .poverty-gap-row {
  grid-column: span 2;
  display: flex;
  gap: 16px;
  align-items: stretch;
}

#analysis .card {
  display: flex;
  flex-direction: column;
  min-height: auto;
}

#analysis .card .chart-container {
  flex: 1;
  min-height: 240px;
}

#analysis .results-list {
  max-height: none;
  overflow-y: visible;
}

#analysis .tall-list {
  max-height: none;
}

.analysis-section-header {
  grid-column: span 2;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 20px 0 4px 0;
  border-bottom: 1px solid var(--border);
}

/* Parameters tab layout - side by side columns */
#parameters .grid {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  min-height: calc(var(--full-vh) - 160px);
}

#parameters .left-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#parameters .left-column .card:last-child {
  flex: 1;
  display: flex;
  flex-direction: column;
}

#parameters .left-column .card:last-child #preset-list {
  flex: 1;
  overflow-y: auto;
}

#preset-list.preset-list-collapsed {
  max-height: 160px;
}

#preset-list.preset-list-expanded {
  max-height: none;
}

#parameters .card.wide {
  grid-column: span 1;
}

button.primary {
  background: var(--accent);
  border: none;
  color: #0b0f12;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s ease;
}

button.secondary {
  background: transparent;
  color: var(--accent-2);
  border: 1px solid var(--accent-2);
  padding: 8px 14px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s ease;
}

button.primary:hover { background: #ff9577; }
button.secondary:hover { background: rgba(79, 209, 197, 0.1); }

.button-row { display: flex; gap: 8px; margin-top: 10px; }

.icon-btn {
  background: var(--panel-soft);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: var(--accent);
  color: #000;
}

.tag {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11px;
  background: rgba(79, 209, 197, 0.12);
  color: var(--accent-2);
  font-weight: 500;
}

/* Config summary (replaces run-id-row) */
.run-config-summary {
  margin-bottom: 12px;
  padding: 8px 10px;
  background: var(--panel-soft);
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 12px;
}
.config-row {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 6px;
  padding: 1px 0;
}
.config-label { color: var(--muted); }
.config-value { font-weight: 600; color: var(--fg); }
.config-placeholder { color: var(--muted); font-style: italic; }

/* Inline year-mismatch warning */
.sim-warning {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(241, 196, 15, 0.08);
  border: 1px solid rgba(241, 196, 15, 0.3);
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
}
.sim-warning .sim-warning-title {
  font-weight: 600;
  color: var(--accent-3);
  margin-bottom: 4px;
}
.sim-warning ul {
  margin: 4px 0 8px 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 11px;
}
.sim-warning .sim-warning-hint {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 10px;
}
.sim-warning .button-row {
  margin-top: 0;
}

/* Simulation list entries */
.sim-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  flex: 1;
}
.sim-entry {
  position: relative;
  padding: 8px 30px 8px 10px;
  background: var(--panel-soft);
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  transition: border-color 0.15s, background 0.15s;
}
.sim-delete {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.sim-entry:hover .sim-delete {
  opacity: 1;
}
.sim-delete:hover {
  color: #ff5959;
}
.sim-entry.pending .sim-delete,
.sim-entry.running .sim-delete { font-size: 14px; }
.sim-entry.done:hover { border-color: var(--accent); }
.sim-entry.active {
  border-color: var(--accent);
  background: rgba(255, 122, 89, 0.08);
}
.sim-entry .sim-meta { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* Sim-entry queue states */
.sim-entry.running {
  background: rgba(255, 255, 255, 0.03);
  cursor: default;
}
.sim-entry.pending {
  background: rgba(255, 255, 255, 0.02);
  opacity: 0.6;
  cursor: default;
}
.sim-entry.error {
  border-color: #ff5959;
  background: rgba(255, 89, 89, 0.08);
  cursor: default;
}
.sim-entry-progress {
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 1.5px;
  overflow: hidden;
  margin-top: 6px;
}
.sim-entry-progress .bar {
  height: 100%;
  border-radius: 1.5px;
}
.sim-entry.done .sim-entry-progress .bar {
  width: 100%;
  background: var(--accent-2);
}
.sim-entry.running .sim-entry-progress .bar {
  width: 30%;
  background: var(--accent);
  animation: progress-slide 1.2s ease-in-out infinite;
}
.sim-entry.pending .sim-entry-progress .bar {
  width: 0;
}
.sim-entry.error .sim-entry-progress .bar {
  width: 100%;
  background: #ff5959;
}

/* Export multi-select list */
.export-multi-list {
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.export-multi-item {
  padding: 8px 10px;
  background: var(--panel-soft);
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.export-multi-item:hover { border-color: var(--accent); }
.export-multi-item.selected { border-color: var(--accent-2); background: rgba(76, 175, 80, 0.10); }
.export-multi-item .em-meta { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.table th, .table td {
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.table th { font-weight: 600; color: var(--muted); }
.table input { padding: 5px 7px; font-size: 12px; transition: all 0.15s ease; }
.table input:focus { outline: none; border-color: var(--accent-2); }

/* Parameter table container */
#param-table {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 10px;
  min-height: 200px;
}

#parameters > .grid > .card.tall {
  display: flex;
  flex-direction: column;
  max-height: calc(var(--full-vh) - 160px);
}

#param-table .table th {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

/* Charts – dedicated wrapper prevents Chart.js resize loop */
.chart-container {
  position: relative;
  width: 100%;
  height: 240px;
  overflow: hidden;
  background: #0b1014;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.chart-subtitle {
  font-size: 11px;
  color: var(--muted);
  margin: -4px 0 6px 0;
  line-height: 1.4;
}

.chart-container.chart-tall {
  height: 340px;
}

#household .chart-container.chart-tall,
#multiyear .chart-container.chart-tall {
  height: 408px;
}

#household .chart-container.chart-decomp {
  height: 530px;
}

.chart-container.chart-xl {
  height: 500px;
  min-height: 500px;
}

#analysis .card .chart-container.chart-xl {
  height: auto;
  min-height: 500px;
}


#analysis .chart-container.chart-ventile {
  height: 480px;
  min-height: 480px;
}

/* Lists */
.list, .results-list {
  overflow-y: auto;
}

.list { max-height: 180px; }
.results-list { max-height: 320px; }
.tall-list { max-height: 400px; }

.list-item {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.5;
}

.list-item:last-child { border-bottom: none; }
.list-item.placeholder { color: var(--muted); font-style: italic; }

.badge {
  font-size: 10px;
  background: rgba(255, 255, 255, 0.08);
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--muted);
  margin-left: 5px;
}

/* Analysis tabs */
.analysis-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 0;
}

.analysis-tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 16px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s ease;
}

.analysis-tab.active {
  background: var(--accent-2);
  color: #000;
  border-color: var(--accent-2);
}

.analysis-tab:hover:not(.active) {
  border-color: var(--accent-2);
  color: var(--accent-2);
}

.analysis-panel {
  padding-top: 6px;
  padding-bottom: 2px;
}

/* Analysis mode card visibility */
.single-run-card, .compare-run-card {
  transition: opacity 0.15s ease;
}

#analysis.compare-mode .single-run-card {
  display: none !important;
}

#analysis.compare-mode .compare-run-card {
  display: block !important;
}

#analysis.compare-mode .compare-run-card.indicators-poverty-row,
#analysis.compare-mode .compare-run-card.poverty-gap-row {
  display: flex !important;
}

#analysis:not(.compare-mode) .compare-run-card {
  display: none !important;
}

/* Full-height panels in compare mode — no scroll truncation */
#analysis.compare-mode .compare-run-card .results-list,
#analysis.compare-mode .compare-run-card .tall-list {
  max-height: none;
  overflow-y: visible;
}

/* Highlighted "All" row in decile summary (both single-run and compare) */
.decile-summary-compare tbody tr:first-child,
#decile-summary-table tbody tr:first-child {
  background: rgba(79, 209, 197, 0.12);
  font-weight: 600;
  color: var(--accent-2);
}

/* Center spanning group headers (Disp. Income, Income Share, etc.) */
.decile-summary-compare th[colspan],
.compact-indicators th[colspan],
.compact-poverty th[colspan] {
  text-align: center;
}

/* Guide Section */
.guide-container { max-width: 1400px; }

.guide-grid {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 20px;
}

.guide-left,
.guide-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guide-left .card,
.guide-right .card { padding: 20px; }

.guide-left .card:has(> details.guide-details) {
  cursor: pointer;
}

.guide-left .card:hover summary h3,
.guide-left .card:hover > .guide-section > h3 {
  color: var(--accent-2);
}

.guide-left .card:hover .guide-title,
.guide-right .card:hover .guide-title {
  color: var(--accent-2);
}

.guide-right .card {
  position: sticky;
  top: 10px;
  max-height: calc(var(--full-vh) - 30px);
  overflow-y: auto;
}

.guide-right .guide-title {
  font-size: 16px;
  margin: 0 0 16px 0;
  color: var(--accent);
}

.guide-right .guide-section h3 { font-size: 14px; }
.guide-right .guide-section { margin-bottom: 20px; padding-bottom: 14px; }
.guide-right .module-grid { grid-template-columns: 1fr; }

.guide-title {
  font-size: 22px;
  margin: 0 0 20px 0;
  color: var(--accent);
  transition: color 0.3s ease;
}

.guide-section {
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.guide-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

/* Collapsible guide sections */
details.guide-details summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
details.guide-details summary::-webkit-details-marker { display: none; }

details.guide-details summary::before {
  content: "▶";
  font-size: 10px;
  color: var(--muted);
  transition: transform 0.2s;
  display: inline-block;
  width: 14px;
  flex-shrink: 0;
}
details.guide-details[open] summary::before {
  transform: rotate(90deg);
}
details.guide-details[open] summary {
  margin-bottom: 12px;
}
details.guide-details summary h3 {
  margin: 0;
  display: inline;
}

.guide-section h3 {
  font-size: 16px;
  margin: 0 0 18px 0;
  color: var(--text);
  transition: color 0.3s ease;
}

.guide-section p {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  margin: 0 0 10px 0;
}

.guide-section p strong { color: var(--text); }

.guide-steps {
  padding-left: 22px;
  margin: 0;
}

.guide-steps li {
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.guide-steps li strong { color: var(--text); }

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.info-item {
  background: var(--panel-soft);
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.info-item > strong:first-child {
  display: block;
  font-size: 12px;
  color: var(--accent-2);
  margin-bottom: 4px;
}

.info-item p strong {
  color: var(--text);
  font-weight: 600;
}

.info-item p {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.module-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 10px;
}

.module-grid .module-box.benefit {
  grid-row: 1 / 3;
  grid-column: 2;
}

.module-box {
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.module-box.tax { background: rgba(255, 89, 89, 0.08); }
.module-box.benefit { background: rgba(79, 209, 197, 0.08); }
.module-box.fee { background: rgba(241, 196, 15, 0.08); }

.module-box h4 {
  font-size: 11px;
  margin: 0 0 8px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.module-box.tax h4 { color: #ff5959; }
.module-box.benefit h4 { color: var(--accent-2); }
.module-box.fee h4 { color: var(--accent-3); }

.module-box .module-item {
  font-size: 11px;
  padding: 3px 0;
  color: var(--muted);
  border: none;
}

.module-box .module-item strong {
  color: var(--text);
  margin-right: 3px;
}

.guide-tab-link { cursor: pointer; }
.guide-tab-link:hover { opacity: 0.7; }

/* Quick Start box bullets: tight within, spaced between */
.guide-section .qs-boxes li {
  margin-bottom: 7px;
  padding-bottom: 0;
}
.guide-section .qs-boxes li:last-child {
  margin-bottom: 0;
}

/* Quick Start box flex weights */
.qs-baseline { flex: 0.80; }
.qs-reform { flex: 1.45; }
.qs-household { flex: 1.35; }
.qs-boxes { display: flex; gap: 10px; margin-top: 8px; }

/* Guide subheading */
.guide-h4 { margin: 28px 0 8px; font-size: 13px; }

/* Standard bullet list */
.guide-list { margin: 0 0 12px 5px; font-size: 12px; line-height: 1.8; }

/* Nested sub-list */
.guide-list-nested { margin: 4px 0 4px 8px; font-size: 11.5px; line-height: 1.7; color: var(--muted); }

/* Info box variants */
.guide-infobox {
  background: rgba(79, 209, 197, 0.05);
  border-left: 3px solid var(--accent-2);
  border-radius: 4px;
  padding: 12px;
  margin: 12px 0 36px;
  font-size: 12px;
}
.guide-infobox--warning {
  background: rgba(255, 165, 0, 0.05);
  border-left-color: var(--warning-color);
}
.guide-infobox--blue {
  background: rgba(99, 102, 241, 0.05);
  border-left-color: #6366f1;
}
.guide-infobox--ember {
  background: rgba(251, 146, 60, 0.07);
  border-left-color: var(--ember-color);
}
.guide-infobox--accent {
  background: linear-gradient(135deg, rgba(79, 209, 197, 0.08), rgba(79, 209, 197, 0.04));
  border-left: 3px solid var(--accent-2);
  border-radius: 6px;
  padding: 12px;
  margin: 16px 0 36px;
}

/* Guide table */
.guide-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 32px; }
.guide-table th { text-align: left; padding: 8px; border-bottom: 1px solid var(--table-border-header); background: rgba(79, 209, 197, 0.1); }
.guide-table td { padding: 8px; border-bottom: 1px solid var(--table-border); }
.guide-table tr:last-child td { border-bottom: none; }
.table-section-header td { font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--accent-2); background: rgba(79, 209, 197, 0.06); }

/* Code box */
.guide-codebox {
  margin: 8px 0 28px 8px;
  font-size: 11.5px;
  line-height: 1.7;
  font-family: var(--font-mono, monospace);
  background: var(--panel-soft, #1a2332);
  padding: 10px 14px;
  border-radius: 6px;
  overflow-x: auto;
}

/* Footnote */
.guide-footnote { font-size: 11px; color: var(--muted); margin-top: 4px; margin-bottom: 28px; }

/* Module sub-bullet list */
.guide-module-details { margin: 4px 0 8px 8px; font-size: 11.5px; line-height: 1.7; color: var(--muted); }

/* Scope tags */
.guide-scope-tag { font-size: 11px; font-weight: 600; }
.scope-individual { color: var(--accent-4); }
.scope-household { color: var(--accent-2); }

/* Income concept checkboxes */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  background: var(--panel-soft);
  border-radius: 4px;
}

.checkbox-label:hover {
  background: rgba(255, 255, 255, 0.08);
}

.checkbox-label input[type="checkbox"] {
  width: 12px;
  height: 12px;
  margin: 0;
  accent-color: var(--accent);
}

.income-options {
  border-top: none;
  padding-top: 0;
}

/* Comparison tables for Analysis tab */
.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.compare-table th,
.compare-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.compare-table th:first-child,
.compare-table td:first-child {
  text-align: left;
  font-weight: 500;
}

.compare-table th {
  font-weight: 600;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.compare-table .positive {
  color: #4fd1c5;
}

.compare-table .negative {
  color: #ff5959;
}

.compare-table .neutral {
  color: var(--muted);
}

.compare-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.compare-table tr.section-header-row td {
  background: rgba(79, 209, 197, 0.12);
  font-size: inherit;
  padding: 8px 10px;
  color: var(--accent-2);
}

/* Decile summary compare table */
.decile-summary-compare {
  table-layout: auto;
  font-size: 11px;
}
.decile-summary-compare th,
.decile-summary-compare td {
  white-space: nowrap;
}
.decile-summary-compare th.group-border,
.decile-summary-compare td.group-border {
  border-left: 1px solid var(--border);
}

/* Compact indicators table for compare mode */
.compact-indicators {
  font-size: 11px;
}

/* Compact poverty tables for compare mode */
.compact-poverty {
  font-size: 11px;
}
.compact-poverty th,
.compact-poverty td {
  white-space: nowrap;
}
.compact-poverty th.group-border,
.compact-poverty td.group-border {
  border-left: 1px solid var(--border);
}
/* Center and bold all sub-column headers (Base, Ref, Δ) in compact poverty tables */
.compact-poverty thead th:not(:first-child) {
  text-align: center;
  font-weight: 600;
}

/* Fiscal aggregate tables — consistent column widths + group separators */
.fiscal-module-table {
  table-layout: fixed;
}

/* Single-run fiscal table (6 cols: Module | Total | HH Count | IND Count | HH Avg | IND Avg) */
.fiscal-module-table.fiscal-single col:nth-child(1) { width: 34%; }
.fiscal-module-table.fiscal-single col:nth-child(2) { width: 14%; }
.fiscal-module-table.fiscal-single col:nth-child(3) { width: 13%; }
.fiscal-module-table.fiscal-single col:nth-child(4) { width: 13%; }
.fiscal-module-table.fiscal-single col:nth-child(5) { width: 13%; }
.fiscal-module-table.fiscal-single col:nth-child(6) { width: 13%; }

/* Separators: between Total & HH Count (col 3), between IND Count & HH Avg (col 5) */
.fiscal-module-table.fiscal-single th:nth-child(3),
.fiscal-module-table.fiscal-single td:nth-child(3),
.fiscal-module-table.fiscal-single th:nth-child(5),
.fiscal-module-table.fiscal-single td:nth-child(5) {
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  padding-left: 12px;
}

/* Compare-run fiscal table (7 cols: Module | BL Total | Δ Total | Δ HH Count | Δ IND Count | Δ HH Avg | Δ IND Avg) */
/* Module col matches single-run (34%) so Baseline Total aligns with Total column */
.fiscal-module-table.fiscal-compare col:nth-child(1) { width: 34%; }
.fiscal-module-table.fiscal-compare col:nth-child(2) { width: 11%; }
.fiscal-module-table.fiscal-compare col:nth-child(3) { width: 11%; }
.fiscal-module-table.fiscal-compare col:nth-child(4) { width: 11%; }
.fiscal-module-table.fiscal-compare col:nth-child(5) { width: 11%; }
.fiscal-module-table.fiscal-compare col:nth-child(6) { width: 11%; }
.fiscal-module-table.fiscal-compare col:nth-child(7) { width: 11%; }

/* Separators: between Δ Total & Δ HH Count (col 4), between Δ IND Count & Δ HH Avg (col 6) */
.fiscal-module-table.fiscal-compare th:nth-child(4),
.fiscal-module-table.fiscal-compare td:nth-child(4),
.fiscal-module-table.fiscal-compare th:nth-child(6),
.fiscal-module-table.fiscal-compare td:nth-child(6) {
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  padding-left: 12px;
}

/* Data section - synthetic data generation */
#data .data-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  align-items: start;
}

.data-left-column,
.data-right-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.data-left-column .card,
.data-right-column .card {
  margin: 0;
}

/* Progress bar */
.progress-bar-container {
  width: 100%;
  height: 24px;
  background: var(--panel-soft);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-2) 0%, #38c7b6 100%);
  border-radius: 12px;
  transition: width 0.3s ease;
}

.progress-bar.error {
  background: linear-gradient(90deg, #ff5959 0%, #ff7a59 100%);
}

.progress-stage {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

/* Synthetic result display */
.synth-result {
  margin-top: 16px;
  padding: 12px;
  background: var(--panel-soft);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.result-header {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
}

.result-header.success { color: var(--accent-2); }
.result-header.failed { color: #ff5959; }

.result-details {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.synth-result-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.result-stat {
  background: var(--panel);
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 13px;
}

.result-stat.success { color: var(--accent-2); }
.result-stat.warning { color: var(--accent-3); }

.synth-result-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.synth-result-section h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.synth-result-section h5 {
  margin: 8px 0 6px 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-2);
}

.result-meta {
  font-size: 11px;
  color: var(--muted);
  margin: 4px 0;
}

.comparison-group {
  margin-bottom: 12px;
}

.comparison-table.compact {
  font-size: 11px;
  width: 100%;
}

.comparison-table.compact th,
.comparison-table.compact td {
  padding: 4px 8px;
}

.comparison-table .diff {
  font-family: monospace;
  text-align: right;
}

.comparison-table tr.good { background: rgba(79, 209, 197, 0.08); }
.comparison-table tr.good .diff { color: var(--accent-2); }

.comparison-table tr.ok { background: rgba(241, 196, 15, 0.05); }
.comparison-table tr.ok .diff { color: var(--accent-3); }

.comparison-table tr.bad { background: rgba(255, 89, 89, 0.08); }
.comparison-table tr.bad .diff { color: #ff5959; }

.comparison-table .status {
  text-align: center;
  font-size: 14px;
}

.comparison-table tr.good .status { color: var(--accent-2); }
.comparison-table tr.bad .status { color: #ff5959; }

/* Advanced options toggle */
.advanced-toggle {
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  padding: 8px 0;
  margin-top: 8px;
  border-top: 1px solid var(--border);
  user-select: none;
}

.advanced-toggle:hover {
  color: var(--accent-2);
}

.toggle-icon {
  display: inline-block;
  transition: transform 0.2s;
  margin-right: 6px;
}

.toggle-icon.expanded {
  transform: rotate(90deg);
}

.advanced-options {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

/* Dataset list */
.dataset-list {
  max-height: 400px;
  overflow-y: auto;
}

.dataset-item {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
}

.dataset-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.dataset-item:last-child {
  border-bottom: none;
}

.dataset-item.selected {
  background: rgba(79, 209, 197, 0.1);
  border-left: 3px solid var(--accent-2);
}

.dataset-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dataset-year {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.btn-delete {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.btn-delete:hover {
  background: rgba(255, 89, 89, 0.15);
  color: #ff5959;
}

.dataset-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.dataset-badges {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.dataset-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
}

.dataset-badge.calibrated {
  background: rgba(79, 209, 197, 0.15);
  color: var(--accent-2);
}

.dataset-badge.validated {
  background: rgba(79, 209, 197, 0.15);
  color: var(--accent-2);
}

.dataset-badge.failed {
  background: rgba(255, 89, 89, 0.15);
  color: #ff5959;
}

.dataset-badge.default {
  background: rgba(156, 136, 255, 0.15);
  color: #9c88ff;
}

.dataset-badge.partial {
  background: rgba(178, 204, 68, 0.15);
  color: #b2cc44;
}

.dataset-badge.uprated {
  background: rgba(255, 177, 66, 0.15);
  color: #ffb142;
}

.protected-icon {
  font-size: 12px;
  padding: 4px;
  cursor: default;
}

/* Validation benchmarks */
.validation-header {
  padding: 12px;
  background: var(--panel-soft);
  border-radius: 6px;
  margin-bottom: 12px;
}

.validation-header.passed {
  border-left: 3px solid var(--accent-2);
}

.validation-header.failed {
  border-left: 3px solid #ff5959;
}

.validation-status {
  font-weight: 600;
  font-size: 14px;
}

.validation-status.passed { color: var(--accent-2); }
.validation-status.failed { color: #ff5959; }

.validation-year {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.benchmark-list {
  max-height: 350px;
  overflow-y: auto;
}

.benchmark-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.benchmark-item:last-child {
  border-bottom: none;
}

.benchmark-name {
  font-size: 12px;
  color: var(--text);
  flex: 1;
}

.benchmark-values {
  display: flex;
  gap: 16px;
  font-size: 11px;
  color: var(--muted);
}

.benchmark-expected,
.benchmark-actual {
  min-width: 80px;
  text-align: right;
}

.benchmark-status {
  width: 20px;
  text-align: center;
  font-weight: 600;
}

.benchmark-status.pass { color: var(--accent-2); }
.benchmark-status.fail { color: #ff5959; }

/* StatsFin status panel */
.statfin-status {
  padding: 10px;
  background: var(--panel-soft);
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.statfin-status-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.statfin-status-icon {
  font-size: 14px;
}

.statfin-status.cached .statfin-status-icon {
  color: var(--accent-2);
}

.statfin-status.missing .statfin-status-icon {
  color: var(--accent-3);
}

/* Statistics tabs and panels */
.stats-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.stats-tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.15s ease;
}

.stats-tab.active {
  background: var(--accent-2);
  color: #000;
  border-color: var(--accent-2);
}

.stats-tab:hover:not(.active) {
  border-color: var(--accent-2);
  color: var(--accent-2);
}

.stats-panel {
  padding: 12px 0;
}

#stats-employment {
  margin-bottom: 20px;
}

.stats-section {
  margin-bottom: 20px;
}

.stats-section h4 {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 8px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

/* Income tab: sections stack vertically, inner card grids use 2 columns */
#stats-income-grid {
  display: block;
}

#stats-income-grid .stats-grid {
  grid-template-columns: repeat(2, 1fr);
}

.stat-card {
  background: var(--panel-soft);
  padding: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.stat-card .stat-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.stat-card .stat-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.stat-card .stat-subvalue {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

/* Comparison table */
.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.comparison-table th,
.comparison-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}

.comparison-table th:first-child,
.comparison-table td:first-child {
  text-align: left;
}

.comparison-table th {
  font-weight: 600;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 10px;
  text-transform: uppercase;
}

.comparison-table .deviation-ok {
  color: var(--accent-2);
}

.comparison-table .deviation-warning {
  color: var(--accent-3);
  background: rgba(241, 196, 15, 0.1);
}

.comparison-table .deviation-error {
  color: #ff5959;
  background: rgba(255, 89, 89, 0.1);
}

/* Distribution table */
.distribution-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.distribution-table th,
.distribution-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}

.distribution-table th:first-child,
.distribution-table td:first-child {
  text-align: left;
}

.distribution-table th {
  font-weight: 600;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

/* Improved Results Display Styling */
.result-section {
  display: block;
  font-size: 11px;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.result-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.result-note {
  font-size: 9px;
  color: var(--muted);
  text-transform: none;
  font-weight: normal;
  letter-spacing: 0;
}

.result-row {
  display: block;
  padding: 3px 0;
  font-size: 12px;
}

.result-row strong {
  color: var(--text);
}

/* Value change highlighting for Analysis tab toggles */
.value-changed {
  animation: highlightChange 2s ease-out;
  border-radius: 3px;
}

@keyframes highlightChange {
  0% { background-color: rgba(79, 209, 197, 0.3); }
  100% { background-color: transparent; }
}

.value-increased {
  color: var(--accent-2) !important;
}

.value-decreased {
  color: #ff5959 !important;
}


/* ── Household Explorer ── */

/* Layout wrapper for household section */
#household .hh-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Prevent page-level scroll on Household tab until content needs it.
   JS adds .hh-needs-scroll when a card overflows or charts are shown. */
main:has(> #household.active:not(.has-charts):not(.hh-needs-scroll)) {
  overflow-y: hidden;
}

.hh-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.hh-section {
  margin-bottom: 12px;
}

.hh-section h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hh-row-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 8px;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--border);
}

.form-row-compact {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.form-group-sm {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 80px;
  flex: 1;
}

.form-group-sm label {
  font-size: 10px;
  color: var(--muted);
  padding-left: 4px;
}

.form-group-sm input,
.form-group-sm select {
  padding: 4px 6px;
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
}

.form-group-sm select:not([multiple]) {
  height: 28px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238899a6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 24px;
}

.form-group-sm input:focus,
.form-group-sm select:focus {
  border-color: var(--accent);
  outline: none;
}

.hh-adult-row,
.hh-child-row {
  padding: 8px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 6px;
  margin-bottom: 6px;
}

/* Daycare warning for children age 6+ */
.hh-daycare-warning {
  color: #f1c40f;
  font-size: 11px;
  margin-top: 4px;
  padding: 4px 8px;
  background: rgba(241, 196, 15, 0.1);
  border-radius: 4px;
}

/* Income Breakdown table styling */
.hh-trajectory-table {
  font-size: 13px;
}

.hh-trajectory-table td {
  padding: 6px 8px;
}

.hh-main-row td {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.hh-main-row.hh-benefit-row td:first-child strong {
  color: #4fd1c5;
}

.hh-main-row.hh-tax-row td:first-child strong {
  color: #ff5959;
}

.hh-main-row.hh-fee-row td:first-child strong {
  color: #ff7a59;
}

.hh-main-row.hh-disposable-row td {
  background: rgba(79, 209, 197, 0.08);
}

.hh-main-row.hh-vat-row td:first-child strong {
  color: #ff7a59;
}

.hh-main-row.hh-extended-row td {
  background: rgba(79, 209, 197, 0.12);
}

.hh-sub-row td {
  border-top: none !important;
}

.hh-top-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

/* 3-panel grid layout for household explorer */
/* Panels: Household & Members | Settings | Income Breakdown */
.hh-four-panel-grid {
  display: grid;
  grid-template-columns: 1.8fr 0.8fr 1.4fr;
  gap: 16px;
}

/* Narrow fields (Age, Disabled, Church) in single-row adult layout */
.hh-sm-narrow {
  min-width: 52px !important;
  flex: 0.5 !important;
}

/* Age input: narrow in adult main row only (not sub-rows like Months unemp.) */
input.hh-adult-age {
  width: 44px !important;
  max-width: 44px !important;
}
.form-group-sm:has(.hh-adult-age) {
  min-width: 0 !important;
  flex: 0 0 auto !important;
}

/* Compact fields (Gross €/mo) — tighter to leave room for Extra + tags */
.hh-sm-compact {
  min-width: 56px !important;
  flex: 0.55 !important;
}
/* Sex field: very narrow since labels are just F/M */
.hh-sm-sex {
  min-width: 36px !important;
  flex: 0.3 !important;
}
.form-group-sm:has(.hh-adult-sex) {
  flex: 0.3 !important;
  min-width: 36px !important;
}

/* Gross €/mo: slightly tighter than other compact fields */
.form-group-sm:has(.hh-adult-earnings) {
  flex: 0.46 !important;
  min-width: 50px !important;
}

/* Status field — wider to fit "Employed, Private" etc */
.hh-sm-status {
  min-width: 90px !important;
  flex: 0.85 !important;
}

/* Extra options toggle button */
.hh-extra-toggle {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.hh-extra-toggle:hover {
  background: rgba(255,255,255,0.14);
  color: var(--fg);
}
.hh-extra-toggle.expanded {
  background: rgba(79,209,197,0.15);
  border-color: rgba(79,209,197,0.3);
  color: var(--fg);
}
.hh-extra-arrow {
  display: inline-block;
  transition: transform 0.2s;
  font-size: 10px;
}
.hh-extra-toggle.expanded .hh-extra-arrow {
  transform: rotate(90deg);
}
.hh-extra-toggle-group {
  min-width: 100px !important;
  flex: 0.8 !important;
}
.hh-extra-toggle-group > label + * {
  /* Button + tags row */
}
.hh-extra-btn-row {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  height: 26px;
  overflow: visible;
}
.hh-extra-tags {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px 3px;
  align-content: center;
  min-height: 24px;
}
.hh-extra-tag {
  font-size: 9px;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(79,209,197,0.18);
  color: #4fd1c5;
  white-space: nowrap;
  line-height: 1.3;
}

/* Lock extra-options-row fields to fixed widths so layout doesn't shift when pension appears */
.hh-extra-options-row > .form-group-sm {
  flex: 0 0 auto !important;
}
.hh-extra-options-row > .hh-sm-narrow {
  width: 60px;
}
.hh-extra-options-row > .form-group-sm:has(.hh-adult-spouse) {
  width: 90px;
}
.hh-extra-options-row > .hh-widow-pension-group {
  flex: 1 1 0 !important;
}

/* Extra options row 2: lives-with-parents combined dropdown, parental leave wider */
.hh-lives-with-parents-group {
  min-width: 52px !important;
  flex: 0.55 !important;
}
.form-group-sm:has(.hh-adult-parental-days) {
  min-width: 70px !important;
  flex: 0.65 !important;
}

/* Responsive: 2x2 on medium screens */
@media (max-width: 1200px) {
  .hh-four-panel-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Responsive: 1 column on small screens */
@media (max-width: 768px) {
  .hh-four-panel-grid {
    grid-template-columns: 1fr;
  }
}

#hh-charts-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-top: 16px;
  align-items: stretch;
}

#hh-charts-container > .card {
  display: flex;
  flex-direction: column;
  min-height: auto;
}

#hh-charts-container > .card .chart-container {
  flex: 1 0 auto;
}

/* Placeholder for empty chart data */
.chart-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
  background: rgba(255,255,255,0.02);
  border-radius: 6px;
}

/* Progress bar for budget constraint calculation */
.progress-bar-container {
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar-indeterminate {
  height: 100%;
  width: 30%;
  background: var(--accent);
  border-radius: 2px;
  animation: progress-slide 1.2s ease-in-out infinite;
}

@keyframes progress-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

/* Checkbox styling for household forms */
.checkbox-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
}

.checkbox-group input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Preset editing banner */
.preset-editing-banner {
  background: rgba(255,122,89,0.12);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 12px;
}

.preset-editing-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.preset-editing-info {
  flex: 1;
}

.preset-editing-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Taller preset action buttons */
button.preset-btn {
  padding: 8px 14px;
  font-size: 12px;
  min-width: auto;
}

/* Taller chart canvases for budget constraint / METR (legacy, use .chart-container.chart-tall) */

/* Small button variant for add/remove */
button.small {
  padding: 4px 10px;
  font-size: 12px;
  min-width: auto;
}

/* Headline cards row for overview KPIs */
.headline-cards {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.headline-card {
  flex: 1;
  min-width: 140px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  text-align: center;
}

.headline-card .hc-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.headline-card .hc-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--fg);
  margin-top: 4px;
}

.headline-card .hc-delta {
  font-size: 13px;
  margin-top: 2px;
}

.headline-card .hc-delta.positive { color: var(--accent); }
.headline-card .hc-delta.negative { color: #ff5959; }

/* Analysis section toggle buttons */
.analysis-section {
  margin-bottom: 16px;
}

.analysis-section summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 0;
  color: var(--accent);
  list-style: none;
}

.analysis-section summary::before {
  content: "▸ ";
}

.analysis-section[open] summary::before {
  content: "▾ ";
}


/* Export tab — balanced layout for export, history, and audit */
#exports .grid {
  display: grid;
  grid-template-columns: 1.7fr 1.15fr 1.15fr;
  gap: 16px;
  align-items: stretch;
}

/* Multiyear tab — data tables (matches compare-table styling) */
.my-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.my-table th,
.my-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
.my-table th {
  font-weight: 600;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.my-table th:first-child,
.my-table td:first-child {
  text-align: left;
}
.my-table .my-table-label {
  font-weight: 500;
  white-space: nowrap;
}
.my-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}
.my-table .my-row-benefit .my-table-label { color: #4fd1c5; }
.my-table .my-row-tax .my-table-label { color: #ff5959; }
.my-table .my-row-fee .my-table-label { color: #ff7a59; }
.my-table .my-row-disposable { background: rgba(79, 209, 197, 0.08); }
.my-table .my-row-disposable .my-table-label { font-weight: 600; }
.my-table .my-row-change td { font-size: 11px; color: rgba(255,255,255,0.4); padding-top: 2px; padding-bottom: 2px; border-bottom: none; }
.my-table .my-row-change .my-table-label { padding-left: 16px; font-weight: 400; }
.my-table .my-section-header td { background: rgba(79, 209, 197, 0.12); color: var(--accent-2); font-size: inherit; padding: 8px 10px; }

/* Multiyear tab — 3-card settings row */
.my-settings-grid {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr 2fr;
  gap: 16px;
  align-items: stretch;
}
@media (max-width: 1200px) {
  .my-settings-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .my-settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  nav {
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 10px;
  }
  nav h1 { grid-column: 1 / -1; margin-bottom: 8px; }
  .nav-subtitle { grid-column: 1 / -1; margin-bottom: 4px; }
  .nav-item { text-align: center; }
  .nav-bottom {
    grid-column: 1 / -1;
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }
  .nav-locale { margin-bottom: 0; flex-shrink: 0; }
  .nav-auth { flex: 1; min-width: 0; }
  .nav-auth-buttons { justify-content: flex-end; }
  .auth-form-wrapper.open { max-height: 160px; }
  .auth-form { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .auth-form input { flex: 1; min-width: 100px; }
  .auth-submit { flex: 0 0 auto; padding: 7px 14px; }
  .auth-cancel { flex: 0 0 auto; }
  main { padding: 14px 10px; }
  #header-glow { left: 0; }
  .grid { grid-template-columns: 1fr; }
  .card.wide { grid-column: span 1; }
  .info-grid, .module-grid { grid-template-columns: 1fr; }
  #data .data-grid { grid-template-columns: 1fr; }
  .guide-grid { grid-template-columns: 1fr; }
  .guide-right .card { position: static; max-height: none; }
  .guide-right .module-grid { grid-template-columns: 1fr; }
  .hh-form-grid { grid-template-columns: 1fr; }
  .hh-top-grid { grid-template-columns: 1fr; }
  .hh-four-panel-grid { grid-template-columns: 1fr; }
  #hh-charts-container { grid-template-columns: 1fr; }
  .headline-cards { flex-direction: column; }
}

/* Large screens (27" iMac, external monitors): remove the 0.9 scale
   that's needed on 14" laptops. Threshold: viewport height > 1100px. */
@media (min-height: 1100px) {
  :root {
    --scale: 1;
    --inv-scale: 1;
    --full-vh: 100vh;
  }
}

/* ── Parameter group section badges & tooltips ──────────────────────── */
.param-group-header {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 20px;
}

.param-group-badges {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.param-year-badge {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--accent-4);
  background: rgba(124, 157, 245, 0.10);
  border: 1px solid rgba(124, 157, 245, 0.18);
  border-radius: 3px;
  padding: 1px 5px;
  white-space: nowrap;
  line-height: 1.4;
}

.param-info-icon {
  position: relative;
  top: -1px;
  display: inline-flex;
  vertical-align: middle;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: rgba(136, 153, 166, 0.35);  /* --muted at 35% opacity via color, not element opacity */
  font-size: 0;
  cursor: help;
  flex-shrink: 0;
  transition: color 0.15s;
}

.param-info-icon::before {
  content: "";
  width: 12px;
  height: 12px;
  background: currentColor;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4'/%3E%3Cpath d='M12 8h.01'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4'/%3E%3Cpath d='M12 8h.01'/%3E%3C/svg%3E");
  mask-size: contain;
}

.param-info-icon:hover {
  color: rgba(79, 209, 197, 0.7);  /* --accent-2 at 70% */
}

.param-info-tooltip {
  position: fixed;
  width: 280px;
  padding: 10px 12px;
  background: #1e2d3d;
  border: 1px solid rgba(79, 209, 197, 0.4);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(0, 0, 0, 0.4);
  color: #e0e8f0;
  font-size: 13px;
  font-weight: 400;
  font-style: normal;
  font-family: "Space Grotesk", sans-serif;
  line-height: 1.55;
  letter-spacing: normal;
  text-transform: none;
  white-space: normal;
  overflow-wrap: break-word;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease 0s;
  z-index: 10000;
  isolation: isolate;
}

/* Invisible bridge so the cursor can travel from the ? icon to the tooltip without
   leaving the :hover zone.  Covers the 8px gap above the tooltip. */
.param-info-tooltip::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 0;
  width: 100%;
  height: 12px;            /* slightly larger than the 8px gap */
}

/* Decorative arrow pointing up from the tooltip */
.param-info-tooltip::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  margin-left: -5px;
  border: 5px solid transparent;
  border-bottom-color: #1e2d3d;
}

.param-info-icon:hover .param-info-tooltip {
  opacity: 1;
  pointer-events: auto;
  transition-delay: 0.4s;
}

/* Flip arrow when tooltip opens above the icon */
.param-info-tooltip.tooltip-above::after {
  bottom: auto;
  top: 100%;
  border-bottom-color: transparent;
  border-top-color: #1e2d3d;
}
.param-info-tooltip.tooltip-above::before {
  bottom: auto;
  top: 100%;
}

/* ── Contextual help tooltip variants ──────────────────────────────── */

/* h3 title icons — same size, slight spacing */
h3 .param-info-icon {
  margin-left: 4px;
}

/* Wider tooltip for card-level help (vs 280px default for field labels) */
.param-info-tooltip.tooltip-wide {
  width: 360px;
}

/* Click-to-pin: persistent tooltip visibility */
.param-info-tooltip.tooltip-pinned {
  opacity: 1;
  pointer-events: auto;
}

/* Left-aligned variant: arrow shifts left instead of centered */
.param-info-tooltip.tooltip-left::after {
  left: 7px;
  margin-left: 0;
}

/* Proper inline alignment when ? icon is inside a <label> */
label .param-info-icon {
  display: inline-flex;
  vertical-align: middle;
  margin-left: 4px;
}

/* Ensure cards with tooltips don't clip them */
.card[data-has-tooltip] {
  overflow: visible;
}

/* Compact variant for Household tab dense layout */
.form-group-sm .param-info-icon {
  width: 11px;
  height: 11px;
  margin-left: 2px;
}
.form-group-sm .param-info-icon::before {
  width: 10px;
  height: 10px;
}

/* ── Legal hover-over links (NOTICE / LICENSE in Guide) ── */
.legal-hover-link {
  position: relative;
  color: var(--accent-2);
  cursor: help;
  border-bottom: 1px dotted rgba(79, 209, 197, 0.4);
}
.legal-hover-content {
  position: fixed;
  width: 420px;
  max-height: none;
  overflow-y: visible;
  padding: 14px 16px;
  background: #1e2d3d;
  border: 1px solid rgba(79, 209, 197, 0.4);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(0, 0, 0, 0.4);
  color: #e0e8f0;
  font-size: 12.5px;
  font-weight: 400;
  font-family: "Space Grotesk", sans-serif;
  line-height: 1.55;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
  z-index: 10000;
  isolation: isolate;
}
.legal-hover-link:hover .legal-hover-content,
.legal-hover-link:focus .legal-hover-content {
  opacity: 1;
  pointer-events: auto;
}

/* ── Export-to-PNG button ──────────────────────────────── */
.card-export-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.35;
  transition: opacity 0.15s, background 0.15s, border-color 0.15s;
}
.card-export-btn svg {
  width: 14px; height: 14px;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.card:hover .card-export-btn { opacity: 0.6; }
.card-export-btn:hover {
  opacity: 1;
  background: rgba(79,209,197,0.10);
  border-color: rgba(79,209,197,0.25);
  color: var(--accent-2);
}
.card:has(canvas) .card-export-btn,
.card:has(table) .card-export-btn { display: flex; }
#guide .card-export-btn, #overview .card-export-btn,
#parameters .card-export-btn, #data .card-export-btn,
#exports .card-export-btn { display: none !important; }
.card-export-btn.card-export-btn-detailed { right: 40px; }
.card-export-btn.exporting {
  opacity: 1; color: var(--accent-2);
  animation: exportPulse 1s ease-in-out infinite;
}
@keyframes exportPulse { 0%,100%{opacity:.6} 50%{opacity:1} }
