/* Ensure [hidden] always wins over any display property in author styles */
[hidden] { display: none !important; }

/* ── CSS Custom Properties ───────────────────────────────────────────────── */
:root {
  --bg-page:         #f0f4f8;
  --bg-card:         #ffffff;
  --bg-input:        #f7fafc;
  --bg-input-focus:  #ffffff;
  --bg-hover:        #edf2f7;

  --text-primary:    #1a202c;
  --text-secondary:  #4a5568;
  --text-muted:      #718096;
  --text-hint:       #a0aec0;
  --heading:         #1a365d;

  --border:          #e2e8f0;
  --border-focus:    #4299e1;
  --focus-ring:      rgba(66, 153, 225, 0.2);

  --blue-primary:    #2b6cb0;
  --blue-medium:     #4299e1;
  --blue-light:      #bee3f8;
  --blue-xlight:     #ebf8ff;

  --green-badge:     #48bb78;
  --green-dark:      #276749;
  --green-light:     #c6f6d5;

  --red-badge:       #fc8181;
  --red-dark:        #c53030;
  --red-light:       #fed7d7;
  --red-bg:          #fff5f5;

  --purple-bg:       #faf5ff;

  --orange-badge:    #dd6b20;
  --orange-light:    #feebc8;
  --orange-bg:       #fffaf0;
  --amber-text:      #744210;

  --table-head-bg:   #2b6cb0;
  --table-head-txt:  #ffffff;
  --table-border:    #edf2f7;
  --table-hover:     #ebf8ff;
  --row-pre-ret-bg:  #f7fafc;
  --row-pre-ret-txt: #718096;
  --row-shortfall:   #fff5f5;
  --row-conversion:  #faf5ff;
  --row-irmaa:       #fffaf0;

  --shadow-sm:  0 2px 10px rgba(0, 0, 0, 0.07);
  --shadow-md:  0 2px 12px rgba(0, 0, 0, 0.08);

  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23718096' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
}

[data-theme="dark"] {
  --bg-page:         #0f172a;
  --bg-card:         #1e293b;
  --bg-input:        #334155;
  --bg-input-focus:  #3d4f65;
  --bg-hover:        #293548;

  --text-primary:    #f1f5f9;
  --text-secondary:  #cbd5e1;
  --text-muted:      #94a3b8;
  --text-hint:       #64748b;
  --heading:         #93c5fd;

  --border:          #334155;
  --border-focus:    #60a5fa;
  --focus-ring:      rgba(96, 165, 250, 0.2);

  --blue-primary:    #3b82f6;
  --blue-medium:     #60a5fa;
  --blue-light:      #1e3a5f;
  --blue-xlight:     #172036;

  --green-badge:     #34d399;
  --green-dark:      #6ee7b7;
  --green-light:     #064e3b;

  --red-badge:       #f87171;
  --red-dark:        #fca5a5;
  --red-light:       #450a0a;
  --red-bg:          #1f0f0f;

  --purple-bg:       #1e1b4b;

  --orange-badge:    #f6ad55;
  --orange-light:    #7b341e;
  --orange-bg:       #2d1a0a;
  --amber-text:      #fbd38d;

  --table-head-bg:   #1e3a5f;
  --table-head-txt:  #e2e8f0;
  --table-border:    #334155;
  --table-hover:     #172036;
  --row-pre-ret-bg:  #1a2234;
  --row-pre-ret-txt: #64748b;
  --row-shortfall:   #1f0f0f;
  --row-conversion:  #1a1730;
  --row-irmaa:       #2d1e0f;

  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 2px 12px rgba(0, 0, 0, 0.5);

  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2394a3b8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  padding: 2rem 2.5rem;
  transition: background 0.2s, color 0.2s;
}

/* Full-width page shell */
.page-wrap {
  max-width: 1600px;
  margin: 0 auto;
}

/* Narrow centred form */
.form-section {
  max-width: 960px;
  margin: 0 auto;
}

/* Results go full page-wrap width */
.results-section {
  margin-top: 2.5rem;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  margin-bottom: 2.5rem;
}

.header-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.header-text {
  flex: 1;
  text-align: center;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--heading);
  letter-spacing: -0.5px;
}

header p {
  margin-top: 0.5rem;
  color: var(--text-secondary);
  font-size: 1rem;
}

/* ── Theme toggle ─────────────────────────────────────────────────────────── */
.theme-toggle {
  display: flex;
  gap: 0;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  align-self: flex-start;
  background: var(--bg-input);
}

.theme-btn {
  padding: 0.45rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-right: 1.5px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}

.theme-btn:last-child {
  border-right: none;
}

.theme-btn:hover:not(.active) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.theme-btn.active {
  background: var(--blue-primary);
  color: #fff;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 2rem;
  margin-bottom: 1.5rem;
}

.card h2 {
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--blue-primary);
  border-bottom: 2px solid var(--blue-light);
  padding-bottom: 0.6rem;
  margin-bottom: 1.5rem;
}

/* ── Form ─────────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

/* Taxable brokerage cluster — groups balance + cost basis with a titled frame */
.field-cluster {
  grid-column: span 2;
  background: var(--blue-xlight);
  border: 1.5px solid var(--blue-light);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}

.field-cluster-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--blue-primary);
  margin-bottom: 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.field-cluster-title::before {
  content: "";
  display: inline-block;
  width: 3px;
  height: 13px;
  background: var(--blue-primary);
  border-radius: 2px;
  flex-shrink: 0;
}

.field-cluster-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.field-cluster-3 {
  grid-column: 1 / -1;   /* spans full width of the 3-col form grid */
}

.field-cluster-grid-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

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

label span.hint {
  font-weight: 400;
  color: var(--text-hint);
  font-size: 0.8rem;
}

input[type="number"],
input[type="text"] {
  height: 2.75rem;
  padding: 0 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-input);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.2s;
  width: 100%;
}

input[type="number"]:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
  background: var(--bg-input-focus);
}

.input-prefix {
  position: relative;
}

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

.input-prefix input {
  padding-left: 1.75rem;
}

.input-suffix {
  position: relative;
}

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

.input-suffix input {
  padding-right: 2rem;
}

/* Filing status toggle */
.filing-toggle {
  display: flex;
  gap: 0;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  width: fit-content;
}

.filing-toggle input[type="radio"] {
  display: none;
}

.filing-toggle label {
  padding: 0.6rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-input);
  cursor: pointer;
  border: none;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}

.filing-toggle label:first-of-type {
  border-right: 1.5px solid var(--border);
}

.filing-toggle input[type="radio"]:checked + label {
  background: var(--blue-primary);
  color: #fff;
}

/* Select */
select {
  height: 2.75rem;
  padding: 0 2rem 0 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-input) var(--select-arrow) no-repeat right 0.75rem center;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.2s;
}

select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
  background-color: var(--bg-input-focus);
}

/* Force select option background in dark mode */
[data-theme="dark"] select option {
  background: #1e293b;
  color: #f1f5f9;
}

.bracket-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  line-height: 1.4;
}

.ss-options {
  display: flex;
  gap: 0.75rem;
}

.ss-option {
  flex: 1;
}

.ss-option input[type="radio"] {
  display: none;
}

.ss-option label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 0.5rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: var(--bg-input);
  transition: all 0.15s;
  font-size: 0.875rem;
  text-align: center;
  gap: 0.2rem;
}

.ss-option label .age {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--blue-primary);
}

.ss-option label .desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

.ss-option input[type="radio"]:checked + label {
  border-color: var(--border-focus);
  background: var(--blue-xlight);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.submit-btn {
  width: 100%;
  height: 3.25rem;
  background: linear-gradient(135deg, #2b6cb0, #4299e1);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: opacity 0.15s, transform 0.1s;
  margin-top: 0.5rem;
}

.submit-btn:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

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

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  margin-top: 0.5rem;
}

.form-actions .submit-btn {
  flex: 1;
  width: auto;
  margin-top: 0;
}

.btn-clear {
  flex-shrink: 0;
  height: 3.25rem;
  padding: 0 1.5rem;
  background: transparent;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-clear:hover {
  background: var(--red-bg);
  border-color: var(--red-badge);
  color: var(--red-dark);
}

/* ── Access gate ──────────────────────────────────────────────────────────── */

.access-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-page);
  z-index: 1000;
  padding: 1rem;
}

.access-gate-box {
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.access-gate-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.5rem;
}

.access-gate-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin: 0 0 1.5rem;
}

.access-gate-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  height: 2.75rem;
  padding: 0 1rem;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-size: 0.875rem;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  background: var(--bg-input);
  color: var(--text-primary);
  letter-spacing: 0.04em;
  transition: border-color 0.15s, box-shadow 0.15s;
  margin-bottom: 0.75rem;
}

.access-gate-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
  background: var(--bg-input-focus);
}

.access-gate-error {
  font-size: 0.8rem;
  color: var(--red-dark);
  background: var(--red-light);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  margin-bottom: 0.75rem;
}

.access-gate-btn {
  display: block;
  width: 100%;
  height: 2.75rem;
  border: none;
  border-radius: 9px;
  background: var(--blue-primary);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.access-gate-btn:hover:not(:disabled) { background: #2c5282; }
.access-gate-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Profile bar ──────────────────────────────────────────────────────────── */

.profile-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  background: var(--bg-card);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  padding: 0.75rem 1.25rem;
  margin-bottom: 1.25rem;
}

.profile-load-group,
.profile-save-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.profile-bar-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--blue-primary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.profile-load-group select {
  height: 2.1rem;
  padding: 0 1.75rem 0 0.65rem;
  font-size: 0.85rem;
  min-width: 200px;
  max-width: 280px;
}

.profile-save-group input[type="text"] {
  height: 2.1rem;
  padding: 0 0.65rem;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 0.85rem;
  background: var(--bg-input);
  color: var(--text-primary);
  width: 220px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.profile-save-group input[type="text"]:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
  background: var(--bg-input-focus);
}

.btn-pill {
  height: 2.1rem;
  padding: 0 1rem;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-family: inherit;
}

.btn-pill:hover { background: var(--bg-hover); border-color: var(--text-muted); }

.btn-pill.btn-primary {
  background: var(--blue-primary);
  color: #fff;
  border-color: var(--blue-primary);
}
.btn-pill.btn-primary:hover { background: #2c5282; border-color: #2c5282; }

.btn-pill.btn-danger {
  color: var(--red-dark);
  border-color: var(--red-light);
}
.btn-pill.btn-danger:hover { background: var(--red-bg); border-color: var(--red-badge); }

.profile-toast {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  transition: opacity 0.2s;
}
.toast-ok  { background: var(--green-light); color: var(--green-dark); }
.toast-err { background: var(--red-light);   color: var(--red-dark);   }

.btn-change-key {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-family: inherit;
  white-space: nowrap;
  transition: color 0.15s;
}
.btn-change-key:hover { color: var(--text-secondary); }

/* Divider between load and save groups */
.profile-load-group::after {
  content: "";
  display: block;
  width: 1px;
  height: 1.5rem;
  background: var(--border);
  margin-left: 0.75rem;
}

/* ── Results section ──────────────────────────────────────────────────────── */

.results-header {
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}

.results-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.results-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
  padding-top: 0.2rem;
}

.results-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--heading);
}

.disclaimer {
  font-size: 0.78rem;
  color: var(--text-hint);
  margin-top: 0.4rem;
  font-style: italic;
}

/* Summary cards grid — fills page width */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.sum-card {
  background: var(--bg-card);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.25rem;
}

.sum-card.span2 {
  grid-column: span 2;
  min-width: 0;
}

.sum-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.sum-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.sum-sub {
  display: block;
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.status-ok   { border-left: 4px solid var(--green-badge); }
.status-fail { border-left: 4px solid var(--red-badge);   }
.status-ok   .sum-value { color: var(--green-dark); }
.status-fail .sum-value { color: var(--red-dark);   }

/* Recommendations */
.recommendations-box {
  background: var(--bg-card);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}

.rec-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--blue-primary);
  margin-bottom: 0.6rem;
}

.recommendations-box ul {
  list-style: disc;
  padding-left: 1.25rem;
}

.recommendations-box li {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  line-height: 1.5;
}

/* Section label */
.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--blue-primary);
  margin-bottom: 0.6rem;
}

/* Column toggles */
.col-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.toggle-label {
  font-weight: 600;
  color: var(--blue-primary);
}

.col-toggles label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-secondary);
}

/* Table */
.table-scroll {
  overflow-x: auto;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 2rem;
}

#planTable {
  border-collapse: collapse;
  font-size: 0.75rem;
  white-space: nowrap;
  width: 100%;
  background: var(--bg-card);
}

#planTable thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--table-head-bg);
  color: var(--table-head-txt);
}

#planTable th {
  padding: 0.55rem 0.75rem;
  text-align: right;
  font-weight: 600;
  letter-spacing: 0.03em;
}

#planTable th:first-child,
#planTable td:first-child {
  text-align: center;
  position: sticky;
  left: 0;
  z-index: 1;
  background: inherit;
}

#planTable thead th:first-child { background: var(--table-head-bg); }

#planTable td {
  padding: 0.45rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--table-border);
  color: var(--text-primary);
}

#planTable tbody tr:hover { background: var(--table-hover) !important; }

/* Row color coding */
.pre-ret        { background: var(--row-pre-ret-bg); color: var(--row-pre-ret-txt); }
.row-shortfall  { background: var(--row-shortfall); }
.row-conversion { background: var(--row-conversion); }
.row-irmaa      { background: var(--orange-bg); }

/* Cell value colors */
.shortfall { color: var(--red-dark);   font-weight: 600; }
.surplus   { color: var(--green-dark); font-weight: 600; }

/* Tax-optimization column value badges */
.irmaa-none { color: var(--text-muted); }
.irmaa-warn { color: var(--orange-badge); font-weight: 600; }
.irmaa-high { color: var(--red-dark);    font-weight: 700; }
.ltcg-ok    { color: var(--green-dark);  font-weight: 600; }
.ltcg-mid   { color: var(--orange-badge); font-weight: 600; }
.ltcg-high  { color: var(--red-dark);    font-weight: 700; }
.ss-tier1   { color: var(--orange-badge); font-weight: 600; }
.ss-tier2   { color: var(--red-dark);    font-weight: 700; }

/* Summary card variants */
.sum-card-warn {
  border-left: 4px solid var(--orange-badge);
}
.sum-card-ok {
  border-left: 4px solid var(--green-badge);
}
.sum-ok { color: var(--green-dark); }

/* Tax optimization note badges in Notes column */
.tax-opt-badge {
  display: inline-block;
  font-size: 0.68rem;
  background: var(--orange-light);
  color: var(--amber-text);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
  white-space: normal;
  line-height: 1.4;
  vertical-align: middle;
}

/* Notes column — single line, truncated; full text visible via row title tooltip */
.col-notes {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-cell {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ── Charts ───────────────────────────────────────────────────────────────── */

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.chart-card {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 1.25rem 1.5rem 1rem;
}

.chart-card.chart-full {
  grid-column: 1 / -1;
}

.chart-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--blue-primary);
  margin-bottom: 0.75rem;
}

.chart-wrap {
  position: relative;
  height: 280px;
}

.chart-card.chart-full .chart-wrap {
  height: 320px;
}

/* ── Ideal Retirement Age trigger button ─────────────────────────────────── */

.ideal-trigger-btn {
  display: block;
  width: 100%;
  max-width: 960px;
  margin: 0.75rem auto 0;
  height: 3rem;
  background: var(--bg-card);
  color: var(--blue-primary);
  border: 2px solid var(--blue-primary);
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}

.ideal-trigger-btn:hover {
  background: var(--blue-primary);
  color: #fff;
}

.ideal-trigger-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* ── Ideal Retirement Age results section ───────────────────────────────────  */

.ideal-age-section {
  margin-top: 2rem;
  max-width: 960px;
  margin-left: auto;
  margin-right: auto;
}

.ideal-card {
  background: var(--bg-card);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 1.75rem 2rem;
  border-top: 4px solid var(--blue-primary);
}

/* Minimum portfolio constraint badge */
.ideal-constraint-badge {
  display: inline-block;
  background: var(--blue-primary);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  margin-bottom: 0.75rem;
  letter-spacing: 0.01em;
}

/* Not-found variant */
.ideal-not-found { border-top-color: var(--red-badge); }
.ideal-nf-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--red-dark);
  margin-bottom: 0.75rem;
}

/* Header row: hero age + score badge */
.ideal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
}

.ideal-hero {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ideal-hero-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.ideal-hero-age {
  font-size: 4rem;
  font-weight: 800;
  color: var(--blue-primary);
  line-height: 1;
}

.ideal-cmp {
  font-size: 0.82rem;
  font-weight: 600;
  margin-top: 0.2rem;
}
.ideal-earlier { color: var(--green-dark); }
.ideal-later   { color: var(--red-dark);   }
.ideal-same    { color: var(--text-muted); }

/* Score badge */
.ideal-score-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 90px;
  border-radius: 12px;
  padding: 0.75rem 1.1rem;
  gap: 0.1rem;
}

.score-high { background: var(--green-light); color: var(--green-dark); }
.score-med  { background: #fef3c7; color: #92400e; }
.score-low  { background: var(--red-light);   color: var(--red-dark);   }

[data-theme="dark"] .score-med { background: #451a03; color: #fcd34d; }

.isb-num  { font-size: 2rem; font-weight: 800; line-height: 1; }
.isb-lbl  { font-size: 0.65rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.75; }
.isb-tier { font-size: 0.78rem; font-weight: 700; }

/* Explanation paragraph */
.ideal-explanation {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1.25rem;
}

/* Metrics grid */
.ideal-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.ideal-metric {
  background: var(--bg-input);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
}

.im-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.im-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.im-sub {
  display: block;
  font-size: 0.68rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

/* Sub-sections (failure table, risks) */
.ideal-sub {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 1rem;
}

.ideal-sub-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--blue-primary);
  margin-bottom: 0.6rem;
}

.ideal-fail-intro {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

/* Failure analysis table */
.failure-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.failure-table th {
  text-align: left;
  padding: 0.35rem 0.65rem;
  background: var(--bg-input);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.failure-table td {
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: top;
}

.failure-table tr:last-child td { border-bottom: none; }

.fl-age    { white-space: nowrap; font-weight: 600; color: var(--text-primary); width: 110px; }
.fl-reason { white-space: nowrap; color: var(--red-dark); width: 220px; }
.fl-detail { line-height: 1.4; }

/* Risks list */
.ideal-risks {
  list-style: disc;
  padding-left: 1.25rem;
}

.ideal-risks li {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  line-height: 1.5;
}

.ideal-risk-item {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  body { padding: 1.5rem 1rem; }
  .form-grid   { grid-template-columns: 1fr 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card.chart-full { grid-column: 1; }
}

@media (max-width: 520px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full-width { grid-column: 1; }
  .field-cluster { grid-column: 1; }
  .field-cluster-grid { grid-template-columns: 1fr; }
  .field-cluster-grid-3 { grid-template-columns: 1fr; }
  .header-inner { flex-direction: column-reverse; align-items: center; }
  .header-text  { text-align: center; width: 100%; }
}

/* ── Print styles ─────────────────────────────────────────────────────────── */

@media print {
  @page { size: landscape; margin: 1cm; }

  body { padding: 0; background: #fff; color: #000; }

  .form-section,
  .profile-bar,
  .col-toggles,
  .submit-btn,
  .btn-clear,
  .results-actions,
  .theme-toggle { display: none !important; }

  .page-wrap       { max-width: 100%; }
  .results-section { margin-top: 0; }

  .summary-grid        { break-inside: avoid; }
  .sum-card            { box-shadow: none; border: 1px solid #e2e8f0; background: #fff; color: #000; }
  .recommendations-box { box-shadow: none; border: 1px solid #e2e8f0; break-inside: avoid; background: #fff; }

  .table-scroll { overflow: visible; box-shadow: none; border-radius: 0; }
  #planTable    { font-size: 0.6rem; background: #fff; }
  #planTable thead { position: static; background: #2b6cb0; color: #fff; }
  #planTable td { color: #000; border-bottom: 1px solid #e2e8f0; }
  #planTable th,
  #planTable td { display: table-cell !important; }

  .section-label + .charts-grid { break-before: page; }
  .charts-grid { grid-template-columns: 1fr 1fr; }
  .chart-card  { break-inside: avoid; box-shadow: none; border: 1px solid #e2e8f0; background: #fff; }
  .chart-card.chart-full { grid-column: 1 / -1; }
  .chart-wrap            { height: 200px; }
  .chart-card.chart-full .chart-wrap { height: 240px; }
}

/* ── Year Snapshot Modal ─────────────────────────────────────────────────── */

body.modal-open { overflow: hidden; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
}

.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.18s ease;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.5rem 0.9rem;
  border-bottom: 1.5px solid var(--border);
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--heading);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-body {
  padding: 1rem 1.5rem 1.5rem;
  overflow-y: auto;
}

/* Spend banner */
.snap-spend {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  background: var(--blue-xlight);
  border: 1.5px solid var(--blue-light);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  margin-bottom: 1rem;
}
.snap-spend-label { font-size: 0.78rem; font-weight: 600; color: var(--blue-primary); text-transform: uppercase; letter-spacing: 0.04em; }
.snap-spend-val   { font-size: 1.25rem; font-weight: 700; color: var(--heading); }
.snap-spend-sub   { font-size: 0.82rem; color: var(--text-muted); }

/* Sections */
.snap-section { margin-bottom: 1rem; }
.snap-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.snap-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.865rem;
}
.snap-table tr { border-bottom: 1px solid var(--table-border); }
.snap-table tr:last-child { border-bottom: none; }
.snap-table tr:empty { display: none; }

.snap-label {
  padding: 0.32rem 0.5rem 0.32rem 0;
  color: var(--text-secondary);
  width: 60%;
}
.snap-val {
  padding: 0.32rem 0 0.32rem 0.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--text-primary);
}

.snap-table tr.snap-divider { background: var(--bg-hover); }
.snap-table tr.snap-divider .snap-label,
.snap-table tr.snap-divider .snap-val { font-weight: 700; color: var(--text-primary); }

.snap-sub       { color: var(--text-muted); font-size: 0.82rem; }
.snap-pos       { color: var(--green-dark); }
.snap-neg       { color: var(--red-dark); }
.snap-warn      { color: var(--orange-badge); }
.snap-conversion { color: var(--blue-primary); font-weight: 600; }

/* Notes */
.snap-notes-section { margin-top: 0.5rem; }
.snap-note-item {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin: 0.35rem 0 0;
  padding: 0.35rem 0.6rem;
  background: var(--bg-hover);
  border-radius: 5px;
  border-left: 3px solid var(--blue-medium);
}
.snap-note {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0.5rem 0 0;
  font-style: italic;
}

/* Clickable rows hint */
#tableBody tr:hover { background: var(--table-hover); }

@media (max-width: 520px) {
  .modal-box { border-radius: 8px; }
  .modal-header { padding: 0.9rem 1rem 0.75rem; }
  .modal-body { padding: 0.75rem 1rem 1.25rem; }
  .snap-spend { flex-wrap: wrap; gap: 0.4rem; }
}

/* ── What-If Scenarios ───────────────────────────────────────────────────── */

.whatif-list { margin-bottom: 0.85rem; }

.whatif-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  margin: 0 0 0.5rem;
}

.whatif-chip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background: var(--orange-bg);
  border: 1.5px solid var(--orange-light);
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  margin-bottom: 0.45rem;
}

.whatif-chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--orange-badge);
  flex-shrink: 0;
}

.whatif-chip-label {
  flex: 1;
  font-size: 0.865rem;
  color: var(--amber-text);
  font-weight: 500;
}

.whatif-chip-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.2rem;
  border-radius: 3px;
  flex-shrink: 0;
  transition: color 0.15s;
}
.whatif-chip-delete:hover { color: var(--red-dark); }

.btn-add-event {
  background: none;
  border: 1.5px dashed var(--border);
  border-radius: 6px;
  color: var(--blue-primary);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
  cursor: pointer;
  width: 100%;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
}
.btn-add-event:hover { background: var(--blue-xlight); border-color: var(--blue-medium); }

.whatif-add-form {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: 8px;
}

.whatif-fields { margin-top: 0.75rem; }

.whatif-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
}
.whatif-fields-grid-1 { grid-template-columns: 1fr; max-width: 280px; }

.whatif-form-btns {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
  align-items: center;
}

/* Scenario rows in table */
.row-scenario { background: var(--orange-bg) !important; }
.row-scenario:hover { background: var(--orange-light) !important; }

/* Snapshot modal — scenario section */
.snap-scenario-section { margin-bottom: 1rem; }
.snap-scenario-note {
  border-left-color: var(--orange-badge) !important;
  background: var(--orange-bg) !important;
  color: var(--amber-text) !important;
}

@media (max-width: 520px) {
  .whatif-fields-grid { grid-template-columns: 1fr; }
}
