/* FeeLedger — Achromatic Ledger App Stylesheet
   Tokens follow the dealt achromatic-ledger sheet:
   - Ground: cool ledger blue-grey (#f2f4f7)
   - Cards: pure #ffffff, 1px hairline #e2e5ea, zero resting shadow
   - Chrome: neutral ink (#0a0a0a), near-black primary CTA (#141414)
   - One chart hue: #1d5fbf on the active data series and focus controls */

:root {
  color-scheme: light;
  --ground: #f2f4f7;
  --surface: #ffffff;
  --raised: #e8ecf0;
  --active: #e5e8ed;
  --border: #e2e5ea;
  --rule: #eef0f3;
  --control: #d0d5dd;
  --text: #0a0a0a;
  --muted: #595e66;
  --faint: #616770;
  --accent: #1d5fbf;
  --primary: #141414;
  --primary-ink: #ffffff;
  --positive: #2e7d32;
  --negative: #c4242a;
  --warning: #92400e;
  --pill-positive-bg: #dcfae5;
  --pill-positive-ink: #04250e;
  --pill-negative-bg: #ffedea;
  --pill-negative-ink: #831c1e;
  --pill-warning-bg: #fffbeb;
  --pill-warning-ink: #92400e;
  --pill-neutral-bg: #eeeeee;
  --pill-neutral-ink: #3d3d3d;

  --chart-1: #1d5fbf;
  --chart-2: #8a8a8a;
  --chart-3: #141414;
  --chart-muted: #9ca3af;
  --chart-mark: #0a0a0a;
  --chart-span: 0.06;
  --grid: #eef0f3;
  --axis-ink: #595e66;
  --ink: #0a0a0a;

  --font: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --fs-title: 1.5rem;
  --fs-section: 1rem;
  --fs-kpi: 1.6875rem;
  --fs-body: 0.875rem;
  --fs-small: 0.75rem;

  --sidebar-width: 248px;
  --pad: 20px;
  --gap: 12px;
  --card-pad: 16px;
  --radius-card: 8px;
  --radius-control: 6px;
  --control-height: 36px;
  --row-height: 44px;
  --nav-row: 32px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --t-press: 120ms;
  --t-hover: 150ms;
  --t-ui: 200ms;

  accent-color: var(--accent);
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.45;
  text-align: start;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p, figure, ul, ol, dl, dd { margin: 0; }
h1, h2, th { text-wrap: balance; }
p { text-wrap: pretty; }
.prose p, .prose li { max-width: 72ch; }
ul[class], ol[class] { padding: 0; list-style: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num, table, .kpi-value, .money-figure, .tabular { font-variant-numeric: tabular-nums; }

/* ---------- shell: open-plane sidebar + fluid canvas ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100svh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100svh;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 20px 12px 16px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--ground);
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 6px;
  font-weight: 600;
  font-size: 0.9375rem;
  letter-spacing: -0.01em;
}
.brand-mark { width: 22px; height: 22px; flex: none; }
.scope-pill {
  margin: 2px 8px 10px;
  padding: 6px 10px;
  border-radius: var(--radius-control);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: var(--fs-small);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.scope-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--positive);
  flex: none;
}
.sidebar .group-label {
  margin: 18px 8px 4px;
  font-size: var(--fs-small);
  color: var(--faint);
  font-weight: 500;
}
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--nav-row);
  padding: 5px 10px;
  border-radius: var(--radius-control);
  color: var(--muted);
  font-size: var(--fs-body);
  font-weight: 400;
  transition: background-color var(--t-hover) ease, color var(--t-hover) ease;
}
.nav-item:hover { background: var(--raised); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--active); color: var(--text); font-weight: 500; }
.nav-item .nav-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.nav-item .nav-left span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item svg { width: 16px; height: 16px; flex: none; stroke-width: 1.5; }
.nav-tag { font-size: var(--fs-small); color: var(--faint); font-variant-numeric: tabular-nums; flex: none; }
.sidebar .bottom {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.mobile-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 48px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--control);
  border-radius: var(--radius-control);
  background: var(--surface);
  cursor: pointer;
  font-size: var(--fs-small);
  font-weight: 500;
}
.sidebar-close { display: none; }

.canvas {
  min-width: 0;
  padding: var(--pad);
  max-width: 1260px;
}

/* ---------- title row ---------- */
.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: var(--fs-small);
  color: var(--muted);
}
.breadcrumbs a:hover { color: var(--text); text-decoration: underline; }
.title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.title-row h1 {
  font-size: var(--fs-title);
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.title-row .sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: var(--fs-body);
  max-width: 68ch;
}
.title-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.stamp {
  color: var(--faint);
  font-size: var(--fs-small);
  white-space: nowrap;
}

/* ---------- grids and panels ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap);
}
.grid.top { align-items: start; }
.span-12 { grid-column: span 12; }
.span-8 { grid-column: span 8; }
.span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; }
.span-5 { grid-column: span 5; }
.span-4 { grid-column: span 4; }

.stack { display: grid; gap: var(--gap); align-content: start; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--card-pad);
  min-width: 0;
}
.panel > header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-bottom: 14px;
}
.panel h2 {
  font-size: var(--fs-section);
  line-height: 1.3;
  font-weight: 600;
}
.panel .meta {
  color: var(--faint);
  font-size: var(--fs-small);
}

/* ---------- KPI strip (4 columns, 1px dividers, no tinted tiles) ---------- */
.kpis {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}
.kpi { padding: 12px var(--card-pad); min-width: 0; }
.kpi + .kpi { border-left: 1px solid var(--border); }
.kpi-label { font-size: var(--fs-small); color: var(--muted); }
.kpi-value {
  margin-top: 4px;
  font-size: var(--fs-kpi);
  line-height: 1.15;
  font-weight: 500;
  letter-spacing: -0.015em;
}
.kpi-value.money { font-weight: 700; }
.kpi-value small {
  font-size: 0.55em;
  color: var(--muted);
  font-weight: 400;
  margin-left: 2px;
}
.delta {
  margin-top: 4px;
  font-size: var(--fs-small);
  color: var(--muted);
}
.delta .up, .pos-text { color: var(--positive); }
.delta .down, .neg-text { color: var(--negative); }

/* ---------- calculator form & controls (brand-consistent-forms + webmcp) ---------- */
.calc-form { display: grid; gap: 10px; }
form:tool-form-active {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-control);
}
button:tool-submit-active {
  outline: 2px solid var(--negative);
  outline-offset: 2px;
}
.field { display: grid; gap: 6px; }
.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.field label, .field-label {
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--text);
}
.input, select.input {
  width: 100%;
  height: var(--control-height);
  padding: 0 10px;
  border: 1px solid var(--control);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-size: var(--fs-body);
}
.input-prefix-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.input-prefix {
  position: absolute;
  left: 10px;
  color: var(--muted);
  pointer-events: none;
}
.input.has-prefix { padding-left: 24px; text-align: right; font-variant-numeric: tabular-nums; }
.input.num-input { text-align: right; font-variant-numeric: tabular-nums; }

.segmented {
  display: inline-flex;
  width: 100%;
  padding: 2px;
  border-radius: var(--radius-control);
  background: var(--raised);
}
.segmented button {
  flex: 1;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-small);
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--t-hover) ease, color var(--t-hover) ease;
}
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.preset-btn {
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  cursor: pointer;
  transition: background-color var(--t-hover) ease, color var(--t-hover) ease;
}
.preset-btn:hover, .preset-btn[aria-pressed="true"] {
  background: var(--raised);
  color: var(--text);
  border-color: var(--control);
}

.check-list { display: grid; gap: 8px; padding-top: 2px; }
.check-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-body);
  color: var(--text);
  cursor: pointer;
}
.check-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}
.range-input {
  width: 100%;
  cursor: pointer;
}

/* Progressive enhancement fallback for older browsers without CSS accent-color (flat colors only) */
@supports not (accent-color: var(--accent)) {
  .check-item input[type="checkbox"].visually-hidden {
    position: absolute;
    clip-path: inset(50%);
    overflow: hidden;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    white-space: nowrap;
  }
  .check-item input[type="checkbox"] + span::before {
    content: "";
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-right: 8px;
    border: 2px solid var(--control);
    background: var(--surface);
    border-radius: 4px;
    vertical-align: middle;
  }
  .check-item input[type="checkbox"]:checked + span::before {
    background: var(--accent);
    border-color: var(--accent);
  }
  .range-input {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 999px;
    background: var(--raised);
  }
  .range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--control-height);
  padding: 0 14px;
  border-radius: var(--radius-control);
  border: 1px solid var(--control);
  background: var(--surface);
  font-size: var(--fs-body);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--t-hover) ease, transform var(--t-press) var(--ease-out);
}
.btn:hover { background: var(--raised); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.primary:hover { background: #262626; }
.btn.full { width: 100%; }

/* ---------- fee waterfall & key-value rows ---------- */
.rows { display: grid; }
.kv-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  padding: 8px 0;
  font-variant-numeric: tabular-nums;
}
.kv-row + .kv-row { border-top: 1px solid var(--rule); }
.kv-row .kv-label { color: var(--muted); }
.kv-row .kv-val { font-weight: 500; text-align: right; }
.kv-row.total-row .kv-label { color: var(--text); font-weight: 600; }
.kv-row.total-row .kv-val { font-weight: 700; font-size: 1rem; }

/* ---------- charts ---------- */
.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-bottom: 10px;
}
.chart-head h2 { font-size: var(--fs-section); font-weight: 600; }
.chart { position: relative; min-width: 0; }
.chart-note {
  margin-top: 8px;
  font-size: var(--fs-small);
  color: var(--muted);
}
@media (max-width: 480px) {
  .chart-legend {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 4px 12px !important;
  }
  .chart-legend li { white-space: normal !important; }
}

/* ---------- responsive tables (sticky header + container query stacked view) ---------- */
.table-wrap {
  overflow: auto;
  max-inline-size: 100%;
  container-type: inline-size;
}
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}
thead th {
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
  background: var(--surface);
  height: 36px;
  padding: 0 12px;
  text-align: left;
  font-weight: 400;
  font-size: var(--fs-small);
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
  vertical-align: baseline;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr.is-active td { background: var(--active); }
th.n, td.n { text-align: right; }
td.money { font-weight: 700; }
td .sub {
  display: block;
  font-size: var(--fs-small);
  color: var(--muted);
  font-weight: 400;
}
.row-link { font-weight: 500; color: var(--text); }
.row-link:hover { text-decoration: underline; }

.pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: var(--fs-small);
  font-weight: 500;
  white-space: nowrap;
  flex: none;
  background: var(--pill-neutral-bg);
  color: var(--pill-neutral-ink);
}
.pill.pos { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.pill.neg { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.pill.warn { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }

@container (width < 520px) {
  table.stackable, table.stackable thead, table.stackable tbody, table.stackable tr, table.stackable th, table.stackable td {
    display: block;
  }
  table.stackable thead { display: none; }
  table.stackable tbody tr {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }
  table.stackable tbody tr:last-child { border-bottom: 0; }
  table.stackable td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 4px 0;
    border-bottom: 0;
    text-align: right;
  }
  table.stackable td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: var(--fs-small);
    font-weight: 400;
    text-align: left;
  }
  table.stackable td:first-child {
    display: block;
    text-align: left;
    padding-bottom: 6px;
  }
  table.stackable td:first-child::before { display: none; }
  table.stackable td:first-child .sub { margin-top: 2px; }
}

/* ---------- contextual affiliate recommendation panel & hub links ---------- */
.partner-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}
.partner-copy { max-width: 68ch; }
.partner-copy h2 { font-size: var(--fs-section); font-weight: 600; margin-bottom: 4px; }
.partner-copy p { color: var(--muted); font-size: var(--fs-body); }
.partner-meta { margin-top: 6px; font-size: var(--fs-small); color: var(--faint); }

.link-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 16px;
}
.dir-cols {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px 20px;
}
.dir-col h3 {
  font-size: var(--fs-body);
  font-weight: 600;
  margin-bottom: 8px;
}
.hub-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
  font-size: var(--fs-body);
}
.hub-link:hover .hub-name { text-decoration: underline; }
.hub-meta { font-size: var(--fs-small); color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- FAQ list ---------- */
.faq-list { display: grid; gap: 14px; }
.faq-item { padding-bottom: 12px; border-bottom: 1px solid var(--rule); }
.faq-item:last-child { padding-bottom: 0; border-bottom: 0; }
.faq-item h3 { font-size: var(--fs-body); font-weight: 600; margin-bottom: 4px; }
.faq-item p { color: var(--muted); font-size: var(--fs-body); max-width: 72ch; }

/* ---------- footer ---------- */
.site-footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  font-size: var(--fs-small);
  color: var(--muted);
}
.footer-links { display: flex; flex-wrap: wrap; gap: 16px; }
.footer-links a:hover { color: var(--text); text-decoration: underline; }

/* ---------- responsive breakpoints ---------- */
@media (max-width: 1020px) {
  .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; }
  .link-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dir-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .mobile-bar { display: flex; position: sticky; top: 0; z-index: 10; }
  .sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100svh;
    z-index: 30;
    border-right: 0;
    background: var(--surface);
    transform: translateX(-100%);
    transition: transform var(--t-ui) var(--ease-out);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-flex; margin-left: auto; }
  .canvas { padding: 16px; }
  .title-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .kpis { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi + .kpi { border-left: 0; }
  .kpi:nth-child(n + 3) { border-top: 1px solid var(--border); }
  .kpi:nth-child(2n) { border-left: 1px solid var(--border); }
  .field-row { grid-template-columns: minmax(0, 1fr); }
  .link-grid { grid-template-columns: minmax(0, 1fr); }
  .dir-cols { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation: none !important; }
}
