/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f0f4f8;
  --card:      #ffffff;
  --border:    #e2e8f0;
  --text:      #1a202c;
  --muted:     #64748b;

  --blue:      #1d4ed8;
  --blue-bg:   #eff6ff;
  --blue-mid:  #bfdbfe;

  --green:     #15803d;
  --green-bg:  #f0fdf4;
  --green-mid: #bbf7d0;

  --amber:     #92400e;
  --amber-bg:  #fffbeb;
  --amber-mid: #fde68a;

  --red:       #991b1b;
  --red-bg:    #fef2f2;
  --red-mid:   #fecaca;

  --teal:      #0e7490;
  --teal-bg:   #ecfeff;
  --teal-mid:  #a5f3fc;

  --gray:      #475569;
  --gray-bg:   #f8fafc;

  --radius:    14px;
  --radius-sm: 8px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.site-header {
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 60%, #2563eb 100%);
  color: #fff;
  padding: 2.5rem 1.5rem 2rem;
  text-align: center;
  box-shadow: 0 4px 20px rgba(29,78,216,.3);
}

.header-inner h1 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.header-sub {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  opacity: 0.8;
  letter-spacing: 0.03em;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
}

.section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 1.25rem;
}

/* ── Inputs ───────────────────────────────────────────────────────────────── */
.inputs-card { padding: 1.75rem; }

.inputs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem 1.5rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.input-group label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--muted);
}

.input-wrap {
  display: flex;
  align-items: stretch;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--card);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-wrap:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}

.input-wrap input {
  flex: 1;
  border: none;
  outline: none;
  padding: 0.55rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  min-width: 0;
}

.input-wrap.small input { font-size: 0.95rem; }

.unit {
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  background: var(--gray-bg);
  border-left: 1.5px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  user-select: none;
}

.range-slider {
  width: 100%;
  accent-color: var(--blue);
  cursor: pointer;
  height: 4px;
  margin-top: 0.1rem;
}

/* ── Summary cards grid ───────────────────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

@media (max-width: 720px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .summary-grid { grid-template-columns: 1fr; }
}

.metric-card {
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem 1.1rem;
  box-shadow: var(--shadow);
  border-top: 4px solid transparent;
  position: relative;
  overflow: hidden;
}

/* Colors */
.mc-blue   { background: var(--blue-bg);  border-top-color: var(--blue);  }
.mc-green  { background: var(--green-bg); border-top-color: var(--green); }
.mc-amber  { background: var(--amber-bg); border-top-color: #d97706;      }
.mc-red    { background: var(--red-bg);   border-top-color: #dc2626;      }
.mc-teal   { background: var(--teal-bg);  border-top-color: var(--teal);  }
.mc-gray   { background: var(--gray-bg);  border-top-color: var(--gray);  }

.mc-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.35rem;
}

.mc-blue  .mc-label { color: var(--blue);  }
.mc-green .mc-label { color: var(--green); }
.mc-amber .mc-label { color: #b45309;      }
.mc-red   .mc-label { color: #b91c1c;      }
.mc-teal  .mc-label { color: var(--teal);  }
.mc-gray  .mc-label { color: var(--gray);  }

.mc-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 0.3rem;
}

.mc-sub {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

/* ── Writeup ──────────────────────────────────────────────────────────────── */
.writeup-card h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text);
}

.writeup-card p {
  font-size: 0.92rem;
  color: #374151;
  margin-bottom: 0.85rem;
  line-height: 1.75;
}

.writeup-card p:last-child { margin-bottom: 0; }

.writeup-card strong { font-weight: 700; }
.hi-blue   { color: var(--blue);  font-weight: 700; }
.hi-green  { color: var(--green); font-weight: 700; }
.hi-amber  { color: #b45309;      font-weight: 700; }
.hi-red    { color: #b91c1c;      font-weight: 700; }

/* ── Table ────────────────────────────────────────────────────────────────── */
.table-card { padding: 0; overflow: hidden; }

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

.toggle-group {
  display: flex;
  gap: 3px;
  background: var(--gray-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}

.toggle-btn {
  border: none;
  background: transparent;
  padding: 0.28rem 0.85rem;
  border-radius: 6px;
  font-size: 0.82rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
}

.toggle-btn.active {
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.table-wrap {
  max-height: 440px;
  overflow-y: auto;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.855rem;
}

thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

thead th {
  background: var(--gray-bg);
  padding: 0.65rem 1rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

thead th.r { text-align: right; }

tbody td {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

tbody td.r      { text-align: right; }
tbody td.c-green { color: var(--green); }
tbody td.c-amber { color: #b45309;      }

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover td { background: var(--blue-bg); }

/* ── Chart ────────────────────────────────────────────────────────────────── */
.chart-card { padding: 0; overflow: hidden; }

.chart-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.chart-controls { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.chart-area-wrap {
  display: flex;
  align-items: flex-start;
  padding: 1.25rem 1.5rem 0;
}

/* Y-axis */
.chart-yaxis {
  width: 52px;
  flex-shrink: 0;
  position: relative;
  height: 240px;
  margin-right: 6px;
}

.y-label {
  position: absolute;
  right: 0;
  font-size: 0.67rem;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
  line-height: 1;
  transform: translateY(50%);
}

/* Scrollable chart area */
.chart-scroll-wrap {
  flex: 1;
  overflow-x: auto;
  min-width: 0;
}

.chart-inner {
  position: relative;
  min-width: min-content;
}

/* Grid lines */
.grid-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: #e2e8f0;
  pointer-events: none;
  z-index: 3;
}

/* Bars */
.chart-area {
  display: flex;
  align-items: flex-end;
  height: 240px;
  gap: 2px;
  position: relative;
  z-index: 1;
}

.bar-col {
  flex: 1;
  min-width: 8px;
  display: flex;
  align-items: flex-end;
  height: 100%;
  cursor: default;
}

.bar-col.bc-monthly { min-width: 3px; }

.bar {
  width: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 3px 3px 0 0;
  overflow: hidden;
  transition: filter 0.12s;
}

.bar-col:hover .bar { filter: brightness(1.15); }

.bar-seg { min-height: 0; }
.bs-gains   { background: #16a34a; }
.bs-monthly { background: #2563eb; }
.bs-start   { background: #7c3aed; }

/* X-axis */
.chart-xaxis {
  display: flex;
  gap: 2px;
  padding-top: 0.3rem;
}

.x-label {
  flex: 1;
  min-width: 8px;
  text-align: center;
  font-size: 0.62rem;
  color: var(--muted);
  overflow: hidden;
  white-space: nowrap;
}

/* Legend */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  padding: 0.85rem 1.5rem 1.1rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.ld-start    { background: #7c3aed; }
.ld-invested { background: #2563eb; }
.ld-gains    { background: #16a34a; }

/* Hover tooltip */
.chart-tooltip {
  position: fixed;
  background: #1e293b;
  color: #fff;
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font-size: 0.8rem;
  pointer-events: none;
  z-index: 1000;
  min-width: 185px;
  box-shadow: 0 8px 28px rgba(0,0,0,.3);
  display: none;
  line-height: 1.4;
}

.chart-tooltip.visible { display: block; }

.tip-label {
  font-weight: 700;
  font-size: 0.78rem;
  color: #94a3b8;
  margin-bottom: 0.55rem;
  letter-spacing: 0.02em;
}

.tip-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.3rem;
}

.tip-row span:nth-child(2) { flex: 1; color: #cbd5e1; }
.tip-row strong { font-variant-numeric: tabular-nums; margin-left: auto; }

.tip-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.td-start   { background: #7c3aed; }
.td-monthly { background: #2563eb; }
.td-gains   { background: #16a34a; }

.tip-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.45rem;
  margin-top: 0.2rem;
  border-top: 1px solid #334155;
  font-weight: 700;
  color: #fff;
}

/* ── Disclaimer ───────────────────────────────────────────────────────────── */
.disclaimer {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.6;
  text-align: center;
  padding: 0 1rem;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .container { padding: 1rem 0.75rem 2.5rem; gap: 1rem; }
  .card { padding: 1.25rem; }
  .inputs-grid { grid-template-columns: 1fr; }
  .mc-value { font-size: 1.25rem; }
  .table-topbar { padding: 0.85rem 1rem; }
}

@media (max-width: 380px) {
  .inputs-grid { grid-template-columns: 1fr; }
}
