/* ===== Reset & Variables ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef2ff;

  --blue: #3b82f6;
  --rose: #f43f5e;
  --emerald: #10b981;
  --violet: #8b5cf6;
  --amber: #f59e0b;
  --pink: #ec4899;

  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);

  --radius: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --radius-xs: 4px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: linear-gradient(135deg, var(--bg), rgba(238,242,255,0.3), var(--bg));
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Header ===== */
header {
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(226,232,240,0.6);
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
  box-shadow: 0 4px 8px rgba(99,102,241,0.25);
  flex-shrink: 0;
}

header h1 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

header .subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== Layout ===== */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px;
}

.layout {
  display: flex;
  gap: 20px;
}

/* ===== Config Panel ===== */
.config-panel {
  width: 320px;
  flex-shrink: 0;
  position: sticky;
  top: 80px;
  height: fit-content;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.config-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(226,232,240,0.6);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.config-panel h2 { display: none; }

/* ===== Config Sections ===== */
.config-section { margin-bottom: 8px; }

.config-section h3.collapsible {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
}

.config-section h3.collapsible:hover {
  box-shadow: var(--shadow-sm);
}

/* Section color themes */
.section-personal h3.collapsible {
  background: #eef2ff; color: #4338ca; border-color: #c7d2fe;
}
.section-market h3.collapsible {
  background: #ecfdf5; color: #047857; border-color: #a7f3d0;
}
.section-tax h3.collapsible {
  background: #fffbeb; color: #b45309; border-color: #fde68a;
}
.section-pension h3.collapsible {
  background: #fff1f2; color: #be123c; border-color: #fecdd3;
}
.section-sim h3.collapsible {
  background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe;
}

.section-icon {
  font-size: 0.9rem;
  flex-shrink: 0;
}

.section-label {
  flex: 1;
  text-align: left;
}

.toggle-icon {
  font-size: 0.6rem;
  opacity: 0.6;
  flex-shrink: 0;
}

.config-content {
  padding: 12px 4px 4px;
}

.config-content h4 {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin: 12px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* ===== Form Inputs ===== */
.form-group {
  margin-bottom: 12px;
}

.form-group > label {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.info-icon {
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: help;
  margin-left: 2px;
}

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

.form-row .form-group {
  flex: 1;
  min-width: 0;
}

.input-wrap {
  position: relative;
}

.input-prefix {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.85rem;
  pointer-events: none;
}

.input-suffix {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.75rem;
  pointer-events: none;
}

.form-group input[type="number"],
.form-group input[type="date"],
.form-group select {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}

.form-group input:hover,
.form-group select:hover {
  border-color: #cbd5e1;
}

.input-wrap.has-prefix input {
  padding-left: 28px;
}

.input-wrap.has-suffix input,
.input-wrap.has-suffix select {
  padding-right: 36px;
}

/* ===== Toggle Switch ===== */
.toggle-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #cbd5e1;
  border-radius: 20px;
  transition: background 0.3s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s;
  box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

.toggle-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ===== Extra Stortingen ===== */
.extra-stortingen-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.extra-storting-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.extra-storting-item input[type="date"] {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text);
  background: var(--surface);
}

.extra-storting-item input[type="number"] {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid #a7f3d0;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  color: #059669;
  background: rgba(236,253,245,0.5);
}

.extra-storting-item.negative input[type="number"] {
  color: #dc2626;
  background: rgba(254,242,242,0.5);
  border-color: #fecaca;
}

.extra-storting-item .btn-remove {
  padding: 4px 6px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.extra-storting-item .btn-remove:hover {
  background: #fef2f2;
  color: #dc2626;
}

#addExtraStorting {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s;
}

#addExtraStorting:hover {
  color: var(--primary-dark);
}

/* ===== Scenario Pills ===== */
.scenario-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.scenario-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid;
  transition: all 0.2s;
}

.scenario-pill input[type="checkbox"] {
  display: none;
}

.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.2s;
}

.pill-blue { background: #eff6ff; color: #1d4ed8; border-color: #93c5fd; }
.pill-blue .pill-dot { background: var(--blue); }
.pill-blue:has(input:not(:checked)) { background: var(--bg); color: var(--text-muted); border-color: var(--border); }
.pill-blue:has(input:not(:checked)) .pill-dot { background: #cbd5e1; }

.pill-rose { background: #fff1f2; color: #be123c; border-color: #fda4af; }
.pill-rose .pill-dot { background: var(--rose); }
.pill-rose:has(input:not(:checked)) { background: var(--bg); color: var(--text-muted); border-color: var(--border); }
.pill-rose:has(input:not(:checked)) .pill-dot { background: #cbd5e1; }

.pill-emerald { background: #ecfdf5; color: #047857; border-color: #6ee7b7; }
.pill-emerald .pill-dot { background: var(--emerald); }
.pill-emerald:has(input:not(:checked)) { background: var(--bg); color: var(--text-muted); border-color: var(--border); }
.pill-emerald:has(input:not(:checked)) .pill-dot { background: #cbd5e1; }

/* ===== Primary Button ===== */
.btn-primary {
  width: 100%;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 12px;
  box-shadow: 0 4px 12px rgba(99,102,241,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary:hover {
  box-shadow: 0 8px 20px rgba(99,102,241,0.4);
  transform: translateY(-1px);
}

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

.btn-primary:disabled {
  background: #a5b4fc;
  cursor: wait;
  transform: none;
  box-shadow: none;
}

.disclaimer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 10px;
  padding: 0 16px;
}

/* ===== Results Panel ===== */
.results-panel {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== Results Overlay ===== */
.results-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(248, 250, 252, 0.6);
  z-index: 10;
  justify-content: center;
  padding-top: 120px;
  border-radius: var(--radius);
}

.results-overlay.visible {
  display: flex;
}

.results-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ===== Summary / Stat Cards ===== */
.summary-section {
  /* No background, just a grid container */
}

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

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(226,232,240,0.6);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  transition: box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

.stat-card-bg {
  position: absolute;
  top: 0;
  right: 0;
  width: 80px;
  height: 80px;
  border-bottom-left-radius: 40px;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.stat-card:hover .stat-card-bg {
  opacity: 0.8;
}

.stat-card.box3-current .stat-card-bg { background: #eff6ff; }
.stat-card.box3-new .stat-card-bg { background: #fff1f2; }
.stat-card.bv .stat-card-bg { background: #ecfdf5; }
.stat-card.comparison .stat-card-bg { background: #f5f3ff; }

.stat-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  position: relative;
}

.stat-card.box3-current .stat-icon { background: linear-gradient(135deg, #3b82f6, #2563eb); box-shadow: 0 4px 8px rgba(59,130,246,0.25); }
.stat-card.box3-new .stat-icon { background: linear-gradient(135deg, #f43f5e, #db2777); box-shadow: 0 4px 8px rgba(244,63,94,0.25); }
.stat-card.bv .stat-icon { background: linear-gradient(135deg, #10b981, #0d9488); box-shadow: 0 4px 8px rgba(16,185,129,0.25); }
.stat-card.comparison .stat-icon { background: linear-gradient(135deg, #8b5cf6, #7c3aed); box-shadow: 0 4px 8px rgba(139,92,246,0.25); }

.stat-icon svg {
  width: 15px;
  height: 15px;
}

.stat-card h4 {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.stat-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #ecfdf5;
  color: #047857;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 20px;
  border: 1px solid #a7f3d0;
  margin-top: 8px;
}

/* ===== Chart Cards ===== */
.chart-section {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(226,232,240,0.6);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.chart-section h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}

.chart-description {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

/* ===== Tables Section ===== */
.tables-section {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(226,232,240,0.6);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.tables-section > .tables-header {
  padding: 20px 20px 12px;
}

.tables-section h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  margin-bottom: 16px;
}

.tab-button {
  padding: 8px 16px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all 0.2s;
}

.tab-button:hover {
  color: var(--text-secondary);
  background: var(--bg);
}

.tab-button.active {
  background: var(--primary-light);
  color: #4338ca;
  border-color: #c7d2fe;
  box-shadow: var(--shadow-sm);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Table Wrapper */
.table-wrapper {
  overflow-x: auto;
  max-height: 600px;
  overflow-y: auto;
}

/* Data Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  white-space: nowrap;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}

.data-table th {
  background: rgba(248,250,252,0.8);
  font-weight: 600;
  text-align: left;
  color: var(--text-secondary);
  font-size: 0.7rem;
  position: sticky;
  top: 0;
  z-index: 1;
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
}

.data-table tbody tr {
  transition: background 0.15s;
}

.data-table tbody tr:hover {
  background: rgba(238,242,255,0.3);
}

.data-table .text-right { text-align: right; }
.data-table .font-bold { font-weight: 600; }

.data-table .positive { color: #059669; }
.data-table .negative { color: var(--rose); }

.data-table .pension-row { background: rgba(16,185,129,0.04); }
.data-table .pension-row:hover { background: rgba(16,185,129,0.08); }

.data-table .totals-row {
  background: rgba(248,250,252,0.8);
  font-weight: 700;
  border-top: 2px solid var(--border);
  position: sticky;
  bottom: 0;
}

.data-table .totals-row td { border-bottom: none; }

/* Sticky columns */
.data-table th.sticky-col,
.data-table td.sticky-col {
  position: sticky;
  background-color: #ffffff !important;
  z-index: 2;
}

.data-table th.sticky-col {
  background-color: #f8fafc !important;
  z-index: 3;
}

.data-table .sticky-col-1 { left: 0; min-width: 55px; }
.data-table .sticky-col-2 { left: 55px; min-width: 55px; }
.data-table .sticky-col-3 { left: 110px; min-width: 100px; box-shadow: 2px 0 4px rgba(0,0,0,0.06); }

.data-table tbody tr:hover td.sticky-col { background-color: #eef2ff !important; }
.data-table .pension-row td.sticky-col { background-color: #ecfdf5 !important; }
.data-table .totals-row td.sticky-col { background-color: #f8fafc !important; }

/* ===== MPO Upload ===== */
.mpo-upload-area {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.mpo-upload-area .btn-secondary {
  padding: 6px 10px;
  background: var(--bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.mpo-upload-area .btn-secondary:hover { background: var(--border); }

.mpo-status { font-size: 0.75rem; }
.mpo-status.success { color: var(--emerald); font-weight: 600; }
.mpo-status.error { color: var(--rose); }

.mpo-info {
  margin-top: 8px;
  padding: 10px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text);
}

.mpo-info em { color: var(--text-muted); font-size: 0.7rem; }
.mpo-detail { color: var(--text-muted); font-size: 0.7rem; }

.field-hint {
  font-size: 0.7rem;
  font-style: italic;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== Checkbox Group (for non-pill checkboxes) ===== */
.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.checkbox-group label {
  margin: 0;
  cursor: pointer;
  font-size: 0.8rem;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .layout {
    flex-direction: column;
  }

  .config-panel {
    width: 100%;
    position: static;
    max-height: none;
  }

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

@media (max-width: 640px) {
  .container { padding: 12px; }
  .header-inner { padding: 10px 16px; }
  .stats-grid { grid-template-columns: 1fr; }
  .chart-container { height: 250px; }

  .tabs { flex-wrap: wrap; }
  .tab-button { padding: 6px 10px; font-size: 0.7rem; }
}
