/* Debt snowball vs avalanche calculator: page layout on top of the shared /style.css.
   Kept in this folder so the shared stylesheet stays untouched. Same layout as the other calculators:
   graph and answer on the left, a short inputs panel on the right (stacked on phones).
   Everything is scoped to body.db. */

/* Debt colours: one fixed order, the same set as the rebalancing page (checked for colour-blind separation). */
.db {
  --c1: #b07d1a; --c2: #3f5f8a; --c3: #bd3c1c; --c4: #1f4732;
  --c5: #6e4a6b; --c6: #6d7a2c; --c7: #a35a4a; --c8: #7a5a32;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .db {
    --c1: #c9a159; --c2: #8ea2c0; --c3: #d4735b; --c4: #94c4a1;
    --c5: #b897b5; --c6: #b3c06d; --c7: #d99a88; --c8: #c7a275;
  }
}
:root[data-theme="dark"] .db {
  --c1: #c9a159; --c2: #8ea2c0; --c3: #d4735b; --c4: #94c4a1;
  --c5: #b897b5; --c6: #b3c06d; --c7: #d99a88; --c8: #c7a275;
}

.db .hero-head { display: block; padding-block: 26px 6px; }
.db .hero-head h1 { font-size: var(--step-3); max-width: none; margin-top: 6px; }
.db .workspace { display: grid; grid-template-columns: minmax(0, 1fr) 410px; gap: 28px 40px; align-items: start; padding-top: 18px; }
.db .stage { position: sticky; top: 12px; display: grid; min-width: 0; }
.db .answer { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 4px 18px; }
.db .answer .label { flex-basis: 100%; }
.db .answer .big { font-size: clamp(2.8rem, 2rem + 2.6vw, 4.2rem); }
.db .answer .big { color: var(--gold); }
.db .answer .big.is-even { color: var(--ink); }
.db .answer-line { padding-bottom: 6px; max-width: 50ch; }
.db .landscape { padding-top: 14px; }
.db .legend-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 24px; padding-top: 10px; }
.db .legend { display: flex; flex-wrap: wrap; gap: 4px 16px; pointer-events: none; font-size: 0.86rem; }
.db .legend span { display: inline-flex; align-items: center; gap: 7px; }
.db .legend-note { font-size: 0.8rem; }
.db .dc { width: 11px; height: 11px; border-radius: 2px; display: inline-block; flex: none; }

/* Stats under the graph */
.db .stats { margin-top: 22px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 640px) { .db .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .db .stat:nth-child(3) { padding-left: 0; border-left: 0; } .db .stat:nth-child(n+3) { border-top: 1px solid var(--line); } }
.db .stat { align-content: start; }
.db .stat .sub { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.db .stat-gold .v { color: var(--gold); }
.db .stat-slate .v { color: var(--slate); }
.db .stat-rust .v { color: var(--rust); }

/* Inputs panel */
.db .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px 18px; display: grid; gap: 4px; min-width: 0; }
.db .panel-head { display: grid; gap: 10px; padding-bottom: 12px; }
.db .panel-head h2 { font-size: 1.45rem; }
.db .panel-head .btn-row { flex-wrap: nowrap; }
.db .panel-head .inline-field { flex: 1; min-width: 0; }
.db .panel-head .inline-field select { width: 100%; }
.db .simple { display: grid; grid-template-columns: minmax(0, 1fr); border-top: 1px solid var(--ink); }
.db .simple .col { border: 0; margin: 0; padding: 14px 0; display: grid; gap: 10px; align-content: start; min-width: 0; }
.db .simple .col + .col { border-top: 1px solid var(--line); }
.db .simple .col:last-child { padding-bottom: 4px; }
.db .simple legend { float: left; width: 100%; padding: 0; font-family: var(--font-display); font-size: 1.05rem; }
.db .simple legend + * { clear: both; }
.db .field-hint { font-size: 0.78rem; color: var(--muted); line-height: 1.4; }
.db .privacy { margin-top: 8px; }

/* The debt list: one compact row per debt */
.db .debts { display: grid; gap: 6px; }
.db #debt-rows { display: grid; gap: 6px; }
.db .d-row { display: grid; grid-template-columns: minmax(0, 1fr) 5.1rem 3.7rem 4.5rem 20px; grid-template-areas: "name owed rate min del"; gap: 5px; align-items: center; }
.db .d-row > :nth-child(1) { grid-area: name; } .db .d-row > :nth-child(2) { grid-area: owed; } .db .d-row > :nth-child(3) { grid-area: rate; } .db .d-row > :nth-child(4) { grid-area: min; } .db .d-row > :nth-child(5) { grid-area: del; }
.db .d-row > .d-err { grid-area: auto; grid-column: 1 / -1; }
.db .d-head span { font-size: 0.74rem; font-weight: 600; color: var(--muted); }
.db .d-row input[type="text"] { min-height: 38px; padding: 7px 8px; font-size: 0.92rem; }
.db .d-row .money input { padding-left: calc(9px + var(--sym-w, 0.7em) * 0.95); }
.db .d-row .money span { left: 8px; font-size: 0.88rem; }
.db .d-row input.is-long { font-size: 0.8rem; letter-spacing: -0.01em; }
.db .d-row .pct input { padding-right: 20px; }
.db .d-row .pct span { right: 7px; font-size: 0.88rem; }
.db .d-name { position: relative; }
.db .d-name input { padding-left: 16px !important; }
.db .d-name .dc { position: absolute; left: 6px; top: 50%; width: 4px; height: 20px; border-radius: 2px; transform: translateY(-50%); }
.db .d-del { width: 24px; height: 32px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: var(--radius); font-size: 1.1rem; line-height: 1; padding: 0; }
.db .d-del:hover { color: var(--rust); }
.db .d-del:disabled { visibility: hidden; }
.db .d-err { grid-column: 1 / -1; font-size: 0.78rem; color: var(--rust); margin-top: -2px; }
.db .d-err:empty { display: none; }
.db .btn-add { justify-self: start; padding: 6px 10px; font-size: 0.85rem; }
.db .btn-add[hidden] { display: none; }
.db .row-extra { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 12px; align-items: center; }
.db .row-extra input[type="text"] { min-height: 42px; }
.db .budget-line { font-size: 0.84rem; color: var(--muted); line-height: 1.35; font-variant-numeric: tabular-nums; }
.db .budget-line b { color: var(--ink); font-weight: 600; }

/* Main graph extras */
.chart-box .band { stroke: var(--paper); stroke-width: 0.8; stroke-linejoin: round; }
.chart-box .half-label { font-size: 10.5px; font-weight: 700; letter-spacing: 0.12em; fill: var(--muted); }
.chart-box .half-sub { font-size: 11.5px; fill: var(--muted); }
.chart-box .band-label { font-size: 11.5px; font-weight: 600; fill: #fff; pointer-events: none; }
.chart-box .free-dot { stroke: var(--paper); stroke-width: 2; }
.chart-box .free-dot.snow { fill: var(--slate); }
.chart-box .free-dot.aval { fill: var(--gold); }
.chart-box .free-v { font-size: 12.5px; font-weight: 700; }
.chart-box .free-v.snow { fill: var(--slate); }
.chart-box .free-v.aval { fill: var(--gold); }
.chart-box .free-halo { stroke: var(--paper); stroke-width: 4; stroke-linejoin: round; paint-order: stroke; }
.chart-box .win-dot { stroke: var(--paper); stroke-width: 1.5; }
.chart-box .cross-dot { stroke: var(--paper); stroke-width: 1.5; fill: var(--ink); }
.tip .t-head { font-size: 0.74rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.tip .t-snow { color: var(--slate); font-weight: 600; }
.tip .t-aval { color: var(--gold); font-weight: 600; }
.tip .t-ev { font-size: 0.8rem; color: var(--ink); }

/* Sections under the calculator */
.db .db-section { padding-top: 60px; display: grid; gap: 12px; }
.db .db-msg { font-size: 1.05rem; max-width: 70ch; }
.db .db-msg b { font-weight: 700; }
.db .db-msg .g { color: var(--gold); }
.db .db-msg .s { color: var(--slate); }
.db .order-box, .db .interest-box { border-top: 1px solid var(--ink); padding-top: 8px; }
.order-box .o-name, .interest-box .o-name { font-family: var(--font-body); font-size: 14px; font-weight: 600; fill: var(--ink); }
.order-box .o-sub { fill: var(--muted); }
.order-box .o-bar.snow { fill: var(--slate); }
.order-box .o-bar.aval { fill: var(--gold); }
.order-box .o-v { font-size: 12px; font-weight: 600; }
.order-box .o-v.snow { fill: var(--slate); }
.order-box .o-v.aval { fill: var(--gold); }
.order-box .o-total .o-name { font-weight: 600; }
.order-box .o-sep { stroke: var(--line); }
.interest-box .i-seg { stroke: var(--paper); stroke-width: 1; }
.interest-box .i-v { font-size: 13px; font-weight: 700; fill: var(--ink); }
.interest-box .i-diff { fill: none; stroke: var(--gold); stroke-width: 1.3; }
.interest-box .i-diff-v { font-size: 12px; font-weight: 600; fill: var(--gold); }
.db .legend-static { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 0.84rem; color: var(--muted); }
.db .legend-static span { display: inline-flex; align-items: center; gap: 7px; }
.db .sq { width: 14px; height: 8px; border-radius: 2px; display: inline-block; }
.db .sq-snow { background: var(--slate); }
.db .sq-aval { background: var(--gold); }

/* Year by year */
.db #years h2 { margin-bottom: 2px; }
.db .yt-scroll { overflow-x: auto; }
.db .yt { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.95rem; border-top: 1px solid var(--ink); }
.db .yt th, .db .yt td { padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.db .yt th:first-child { text-align: left; }
.db .yt th:last-child, .db .yt td:last-child { padding-right: 0; }
.db .yt thead th { font-size: 0.78rem; color: var(--muted); font-weight: 600; vertical-align: bottom; }
.db .yt thead .grp th { padding-bottom: 0; border-bottom: 0; }
.db .yt tbody th { font-weight: 600; }
.db .yt td.snow { color: var(--slate); }
.db .yt td.aval { color: var(--gold); }
.db .yt td.zero { color: var(--muted); }
.db .yt-note { margin-top: 2px; }

/* Reading: one content width, heading left and text right on wide screens */
.db .prose, .db .disclaimer { max-width: none; }
@media (min-width: 900px) {
  .db .section.prose { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); column-gap: 48px; row-gap: 0; align-items: start; }
  .db .section.prose > h2 { grid-column: 1; grid-row: 1 / span 30; }
  .db .section.prose > :not(h2) { grid-column: 2; margin-bottom: 16px; }
}
.db .sources { font-size: var(--step--1); color: var(--muted); }

@media (max-width: 1200px) and (min-width: 961px) { .db .workspace { grid-template-columns: minmax(0, 1fr) 390px; gap: 28px; } }
@media (max-width: 960px) {
  .db .workspace { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .db .stage { display: contents; }
  .db .stage .answer { order: 1; }
  .db .stage .landscape { order: 2; }
  .db .panel { order: 3; margin-top: 20px; }
  .db .stage .stats { order: 4; margin-top: 28px; }
}
@media (max-width: 960px) and (min-width: 700px) {
  .db .simple { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
  .db .simple .col:nth-child(2) { border-top: 0; border-left: 1px solid var(--line); padding-left: 18px; }
  .db .simple .col:nth-child(1) { padding-right: 18px; }
  .db .row-extra { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .db .hero-head { padding-block: 18px 0; }
  .db .hero-head h1 { font-size: 1.5rem; }
  .db .hero-head .eyebrow { display: none; }
  .db .answer .big { font-size: 2.9rem; }
  .db .answer-line { font-size: 0.85rem; flex-basis: 100%; padding-bottom: 0; }
  .db .landscape { padding-top: 6px; }
  .db .panel { padding: 14px 12px 16px; margin-inline: -4px; margin-top: 14px; }
  .db .legend-row { gap: 6px 14px; padding-top: 6px; }
  .db .legend { gap: 2px 12px; font-size: 0.8rem; }
  .db .legend-note { display: none; }
  .db .answer .label { display: block; }
  /* Phones: the name gets its own line, the three numbers sit under it. */
  .db .d-row { grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.8fr) minmax(0, 1fr) 26px; grid-template-areas: "name name name del" "owed rate min ."; gap: 4px 5px; }
  .db .d-head { grid-template-areas: "owed rate min del"; }
  .db .d-head > :nth-child(1) { display: none; }
  .db #debt-rows { gap: 12px; }
  .db .d-row input[type="text"] { font-size: 16px; }
  .db .d-row input.is-long { font-size: 16px; }
  .db .d-row .money span { font-size: 15px; left: 9px; }
  .db .d-row .money input { padding-left: calc(12px + var(--sym-w, 0.7em)); }
  .db .yt { font-size: 0.84rem; }
  .db .yt th, .db .yt td { padding-right: 8px; }
  .db .yt .wide, .db .yt-note .wide { display: none; }
}

/* While a number is invalid, keep the last result but fade it. */
.db .is-stale .landscape, .db .is-stale .stats { opacity: 0.35; transition: opacity 0.15s; }
