/* Keel Money — the app layer on top of the Keel UI kit (./keel/keel-ui.css).
   Everything here is Money-specific (Today band, What-if Simulator, public-mode switch, charts,
   auth card, toast) and uses kit tokens only (var(--k-*)): Archivo, square corners, 2px rules,
   the Money accents (--k-app / --k-app-deep / --k-app-tint) and Ocean primary actions. */

body { background: var(--k-bg); }
#main:focus { outline: none; }
.mn-noscript { padding: 32px; font-family: var(--k-font); }
.mn-contents { display: contents; }
/* The Settings form wraps two blocks in a display:contents <form>, so the kit's phone rule for direct grid
   children (.k-grid > .k-block) misses them; give them the same full width and 16px gutter. */
@container k-page (max-width: 720px) {
  .k-grid > .mn-contents > .k-block { grid-column: 1 / -1; padding: 18px 16px; }
}
.mn-loading { padding: 24px 32px; }

/* ── Planning-only banner + public-mode switch (Apps B 1a) ───────────────────────────────── */
.mn-banner { gap: 6px 14px; }
.mn-banner--today .k-banner-title { color: var(--k-text); }
.mn-banner--today .mn-banner-text { color: var(--k-muted); }
.mn-pub {
  margin-left: auto; min-height: 44px; padding: 6px 12px; gap: 10px;
  font-family: var(--k-font); font-size: var(--k-fs-13); color: var(--k-text);
  background: var(--k-raised); border: 1px solid var(--k-divider); cursor: pointer;
}
button.mn-pub { border: 1px solid var(--k-divider); padding: 6px 12px; }
.mn-pub:hover { border-color: color-mix(in srgb, var(--k-text) 45%, transparent); }
.mn-pub:focus-visible { outline: 2px solid var(--k-focus); outline-offset: 2px; }

/* ── Shared bits ─────────────────────────────────────────────────────────────────────────── */
.mn-toggle { min-height: 44px; }
.mn-toggles { flex-direction: row; flex-wrap: wrap; gap: 4px 24px; }
.mn-card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.mn-after-list { margin-top: 12px; }
.mn-result { display: flex; flex-direction: column; gap: 8px; }
.mn-result:empty { display: none; }
.mn-dialog-more { padding-top: 12px; border-top: 1px solid var(--k-divider); }
.mn-details { border-top: 1px solid var(--k-divider); padding-top: 4px; }
.mn-details > summary { display: flex; align-items: center; gap: 12px; min-height: 44px; font-weight: 600; cursor: pointer; list-style: none; }
.mn-details > summary::-webkit-details-marker { display: none; }
/* flex on <summary> drops the native disclosure triangle: a +/− in the Money deep shows open/closed. */
.mn-details > summary::after { content: "+"; margin-left: auto; font-size: var(--k-fs-20); font-weight: 800; line-height: 1; color: var(--k-app-deep); }
.mn-details[open] > summary::after { content: "−"; }
.mn-details > summary:focus-visible { outline: 2px solid var(--k-focus); outline-offset: 2px; }
.mn-details[open] > summary { margin-bottom: 8px; }
.mn-milestones { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; }
.mn-token {
  display: block; padding: 8px 10px; font-family: var(--k-font-mono); font-size: var(--k-fs-13);
  overflow-wrap: anywhere; background: var(--k-raised); color: var(--k-text);
}
.mn-empty-cell { padding: 16px 8px; color: var(--k-muted); font-weight: 400; }
.k-table td.mn-empty-cell { font-weight: 400; }
.k-table .k-btn-ghost { white-space: nowrap; }
.k-table tr.mn-target, .k-table tr.mn-target:hover { background: var(--k-app-tint); box-shadow: inset 4px 0 0 var(--k-app-deep); }
.mn-num-input { width: 112px; margin-left: auto; text-align: right; }
.mn-role { min-width: 128px; }
.mn-plan-table .mn-row-actions { flex-wrap: nowrap; }
.mn-dialog-error { margin: 12px 0 0; }

/* ── Tables on phones: low-priority columns fold into a second line under the name ──────── */
.mn-sub { display: none; }
@container k-page (max-width: 720px) {
  .k-table.mn-ptable .mn-lo { display: none; }
  .k-table .mn-sub {
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px;
    font-size: var(--k-fs-12-5); font-weight: 400; line-height: 1.4; color: var(--k-muted);
  }
  .k-table .mn-sub .k-btn-group { flex-basis: 100%; }
  .mn-plan-table .mn-num-input { width: 96px; }
}
/* Chips and segmented options at 44px (the kit's are 40px; kit request filed). */
.mn-page .k-chip, .mn-page .k-seg-opt { min-height: 44px; }
.k-table .mn-email { display: block; overflow-wrap: anywhere; }
/* 44px targets for the kit's small row buttons (36px) and note actions (40px), at every width. */
.mn-page .k-btn-sm, .mn-page .k-note .k-btn { min-height: 44px; }
/* Cells holding a row action drop their block padding, so the 44px button sets the row height (about 45px)
   instead of button + padding (60px). */
.k-table td:has(> .k-btn, > .k-btn-group) { padding-block: 0; }
/* Bordered inline inputs keep a small gap so their box doesn't touch the row rules (rows about 53px). */
.k-table td:has(> .k-input, > .k-select) { padding-block: 4px; }
/* Names and bank descriptors (AMAZON.COM*RT4KL01Z2, 80-character bill names) may break anywhere, so they wrap
   inside their column instead of pushing amounts, status and row actions past the table edge. */
.k-table td.mn-wrap { overflow-wrap: anywhere; min-width: 6em; }
/* Kit list rows get the same guard (kit request: .k-list-title { overflow-wrap: anywhere }), so a bill named
   GOOGLE*CLOUDSTORAGE1234 wraps inside its row instead of printing over the yearly cost or the due day. */
.mn-page .k-list-title { overflow-wrap: anywhere; }
/* Reports category and merchant names are short words: break only a word too long for the column, so the
   lead column keeps its natural width and "Entertainment" never splits mid-word. */
.k-table td.mn-brk { overflow-wrap: break-word; }
/* Reports with a year selected put the form in four columns above the table. Between the kit's 720px phone
   breakpoint and about 900px a quarter of the page is too narrow for the Period control, and its selected
   "Year" wrapped onto a second line: use two columns there. */
@container k-page (min-width: 721px) and (max-width: 900px) {
  .mn-report-form .k-form--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.mn-bills-table { container: mn-bills / inline-size; }
/* Side-by-side tables (Bills span 8, Debts span 7) fold by their own width too, so mid-width windows
   (760–1024px) get the folded rows instead of a sideways-scrolling table. Debts folds below 520px, so an
   iPad-portrait Debts block (about 420px) keeps "Payoff (current)" and "Not modelled" in view. */
.mn-debts-table { container: mn-debts / inline-size; }
@container mn-bills (max-width: 659px) {
  .k-table.mn-ptable .mn-lo { display: none; }
  .k-table .mn-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; font-size: var(--k-fs-12-5); font-weight: 400; line-height: 1.4; color: var(--k-muted); }
  .k-table .mn-sub .k-btn-group { flex-basis: 100%; }
}
@container mn-debts (max-width: 519px) {
  .k-table.mn-ptable .mn-lo { display: none; }
  .k-table .mn-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; font-size: var(--k-fs-12-5); font-weight: 400; line-height: 1.4; color: var(--k-muted); }
}
.mn-progress { display: inline-block; width: 72px; margin: 0 8px 0 0; vertical-align: middle; }
.mn-used { font-size: var(--k-fs-12); color: var(--k-muted); }
.mn-legend-end { margin-left: auto; }
.mn-goal-cards .k-card { min-height: 100%; }

/* ── Toast (role=status) ─────────────────────────────────────────────────────────────────── */
.mn-toast {
  position: fixed; left: 16px; bottom: 16px; z-index: 1000; max-width: min(480px, calc(100vw - 32px));
  padding: 12px 16px; font-family: var(--k-font); font-size: var(--k-fs-14); line-height: 1.5;
  background: var(--k-tone-ink-bg); color: var(--k-tone-ink-fg); border-left: 4px solid var(--k-app);
  box-shadow: var(--k-shadow-md);
}
.mn-toast--error { background: var(--k-tone-safety-bg); color: var(--k-tone-safety-fg); border-left-color: var(--k-tone-safety-edge); }

/* ── SVG line chart (balance / cash-flow forecast) ───────────────────────────────────────── */
.mn-chart-wrap { display: flex; flex-direction: column; gap: 6px; }
.mn-chart { display: block; width: 100%; height: 180px; }
.mn-chart .mn-area { fill: var(--k-app-tint); }
.mn-chart .mn-line { fill: none; stroke: var(--k-app-deep); stroke-width: 2.5; }
.mn-chart .mn-zero { stroke: var(--k-error); stroke-width: 1; }
.mn-chart .mn-buffer { stroke: var(--k-muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.mn-chart .mn-low { stroke: var(--k-caution); stroke-width: 2; stroke-dasharray: 2 3; }
.mn-chart-x { display: flex; justify-content: space-between; font-size: var(--k-fs-11); color: var(--k-muted); }

/* ── Today (Apps B 1a desktop, Money Routes 1k phone) ────────────────────────────────────── */
@container k-page (min-width: 721px) {
  /* Desktop Today has no page header in the design; the h1 stays for assistive tech. */
  .mn-today > .k-head {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .mn-today .mn-kpiband { padding: 0; background: var(--k-app-tint); }
  .mn-today .mn-kpiband .k-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; }
  .mn-today .mn-kpiband .k-kpi { gap: 4px; padding: 24px 32px; border-top: 0; border-right: 1px solid var(--k-divider); }
  .mn-today .mn-kpiband .k-kpi:last-child { border-right: 0; }
  .mn-today .mn-kpiband .k-kpi-label, .mn-today .mn-kpiband .k-kpi-delta { font-size: var(--k-fs-12); }
  .mn-today .mn-kpiband .k-kpi-value { font-size: 34px; }

  .mn-today .mn-rows { gap: 0; padding: 0; }
  .mn-today .mn-plan-bars { border-right: 2px solid var(--k-divider); }
  .mn-today .mn-rows .k-block-head { padding: 14px 32px; border-bottom: 2px solid var(--k-divider); }
  .mn-today .mn-rows .k-block-title {
    font-size: var(--k-fs-15); font-weight: 800; letter-spacing: 0; text-transform: none; color: var(--k-text);
  }
  .mn-today .mn-rows .k-hbars { gap: 0; }
  .mn-today .mn-rows .k-hbar {
    grid-template-columns: 140px minmax(0, 1fr) 150px; gap: 14px; min-height: 46px; padding: 12px 32px;
    border-bottom: 1px solid var(--k-divider); font-size: var(--k-fs-14);
  }
  .mn-today .mn-rows .k-hbar-track { background: var(--k-surface); }
  .mn-today .mn-rows .k-hbar-value { text-align: right; }
  .mn-today .mn-rows .k-list { border-top: 0; }
  .mn-today .mn-rows .k-list-row { min-height: 46px; padding: 12px 32px; }
  .mn-today .mn-rows .k-list-main { flex-direction: row; align-items: center; gap: 10px; }
  .mn-today .mn-rows .k-list-title { flex: 1; font-size: var(--k-fs-14); font-weight: 400; }
  .mn-today .mn-rows .k-list-meta { font-size: var(--k-fs-12); }
  .mn-today .mn-rows .k-list-value { min-width: 80px; font-weight: 800; }
  .mn-today .mn-rows-cta { padding: 16px 32px; }
}
@container k-page (max-width: 720px) {
  .mn-today .mn-kpiband { order: -3; }
  .mn-today .mn-bills { order: -2; }
  .mn-today .mn-public-note { order: -1; }
  .mn-today #mn-kpi-bills { display: none; }
  .mn-rows-cta { padding-top: 12px; }
}

/* ── What-if Simulator (Apps B 1b) ───────────────────────────────────────────────────────── */
.mn-sim { display: grid; grid-template-columns: 420px minmax(0, 1fr); border-bottom: 2px solid var(--k-divider); }
.mn-sim--empty { display: block; padding: 8px 4px; }
.mn-sim-left { display: flex; flex-direction: column; gap: 18px; min-width: 0; padding: 28px 32px; border-right: 2px solid var(--k-divider); }
.mn-sim-right { display: flex; flex-direction: column; gap: 18px; min-width: 0; padding: 28px 32px; }
.mn-sim-title { margin: 0; font-size: var(--k-fs-30); line-height: 1.12; letter-spacing: -0.02em; text-wrap: balance; }
.mn-sim-info { margin: 0; padding: 12px 14px; font-size: var(--k-fs-13); background: var(--k-surface); color: var(--k-text); }
.mn-sim-range { gap: 8px; }
.mn-range-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.mn-range-head .k-label { font-size: var(--k-fs-13); font-weight: 800; color: var(--k-text); }
.mn-range-head .k-range-value { font-size: var(--k-fs-13); font-weight: 800; }
.mn-range-scale { display: flex; justify-content: space-between; font-size: var(--k-fs-11); color: var(--k-muted); }
.mn-sim-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 2px solid var(--k-divider); }
.mn-sim-kpis > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 16px; border-right: 1px solid var(--k-divider); }
.mn-sim-kpis > div:last-child { border-right: 0; }
.mn-sim-v { font-size: var(--k-fs-30); font-weight: 800; line-height: 1.2; letter-spacing: -0.02em; color: var(--k-c, var(--k-text)); overflow-wrap: anywhere; }
.mn-sim-h { margin: 0; font-size: var(--k-fs-13); font-weight: 600; letter-spacing: 0; line-height: 1.4; }
.mn-sim-chart {
  display: flex; align-items: flex-end; gap: 3px; height: 240px; padding-left: 4px;
  border-bottom: 2px solid var(--k-divider); border-left: 2px solid var(--k-divider);
}
.mn-sim-pair { display: flex; flex: 1; align-items: flex-end; gap: 1px; min-width: 0; height: 100%; }
.mn-sim-bar { flex: 1; min-width: 0; height: var(--k-h, 0%); background: var(--k-c, var(--k-app)); }
@container k-page (max-width: 720px) {
  .mn-sim { grid-template-columns: minmax(0, 1fr); }
  .mn-sim-left { padding: 20px 16px; border-right: 0; border-bottom: 2px solid var(--k-divider); }
  .mn-sim-right { padding: 20px 16px; }
  .mn-sim-title { font-size: var(--k-fs-24); }
  .mn-sim-kpis > div { padding: 12px 10px; }
  .mn-sim-v { font-size: var(--k-fs-20); }
  .mn-sim-chart { gap: 2px; height: 180px; }
}

/* ── Sign in / create account (Keel Public 2a / 2b) ──────────────────────────────────────── */
.mn-auth { display: grid; place-items: start center; padding: 40px 16px 64px; }
.mn-auth-card { display: flex; flex-direction: column; gap: 16px; width: min(420px, 100%); padding: 24px; background: var(--k-bg); border: 1px solid var(--k-divider); }
.mn-auth .k-lockup { padding-bottom: 14px; border-bottom: 2px solid var(--k-divider); }
.mn-auth-app { font-size: var(--k-fs-14); font-weight: 600; }
.mn-auth-title { margin: 0; font-size: var(--k-fs-36); letter-spacing: var(--k-tracking-h1); }
.mn-auth .k-input { background: var(--k-surface); }
.mn-auth-switch { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 0; font-size: var(--k-fs-14); color: var(--k-text-2); }

/* ── Print: Reports "Export PDF" ─────────────────────────────────────────────────────────── */
@media print {
  .mn-pub, .mn-toast, .mn-report-form, .k-table .k-btn, .mn-card-actions { display: none !important; }
  .mn-reports .k-grid > .k-block { grid-column: 1 / -1; }
}

#mn-sim-results { display: flex; flex-direction: column; gap: 18px; }
.k-form-wrap + .k-form-wrap { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--k-divider); }
/* Visually hidden headers/captions are position:absolute; anchor them inside the scrolling table so they
   don't widen the page on phones (kit request: .k-table-wrap { position: relative }). */
.k-table-wrap { position: relative; }
@container k-page (max-width: 720px) {
  /* Phone Today (Money Routes 1k) carries the Money-tone planning banner. */
  .mn-banner--today { --k-tone-bg: var(--k-tone-money-bg); --k-tone-fg: var(--k-tone-money-fg); }
  .mn-banner--today .k-banner-title, .mn-banner--today .mn-banner-text { color: inherit; }
}
