/* Royal Capital Solutions, v2: monthly cost calculator (reusable)
   Any page drops in <form class="calc" data-calc> with the fields below
   and loads js/calc.js. Built on the shared .field, .input and .err from
   components.css. No default interest rate: the visitor types their own,
   so the page never shows a rate without an approved source.

   ┌──────────── inputs ────────────┐┌──────── result ────────┐
   │ price          down payment    ││ $0,000 a month          │
   │ interest rate  property tax    ││ ▇▇▇▇▇▇▇▇▇▇▅▅▃▂ bar      │
   │ home insurance flood insurance ││ breakdown rows          │
   │ HOA dues                       ││ assumptions · button    │
   └────────────────────────────────┘└─────────────────────────┘

   CONTENTS: 1 frame · 2 fields · 3 result · 4 breakdown · 5 notes
   ============================================================ */

/* 1. FRAME ===================================================== */
.calc { display: grid; gap: var(--s-2); color: var(--text); }
.calc-in, .calc-out { border-radius: var(--r-card); background: var(--surface); }
.calc-in { display: grid; gap: var(--s-5) var(--s-4); align-content: start; padding: var(--s-5); }
@media (min-width: 40rem) { .calc-in { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 64rem) { .calc { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); } .calc-in { padding: var(--s-6); } }

/* 2. FIELDS: a unit inside the box, a hint or the error below it == */
.calc .field { align-content: start; }
.calc-affix { position: relative; display: block; }
.calc-affix > span { position: absolute; top: 50%; transform: translateY(-50%); color: var(--text-2); font-size: 1rem; pointer-events: none; }
.calc-affix .calc-pre { inset-inline-start: var(--s-4); }
.calc-affix .calc-post { inset-inline-end: var(--s-4); }
.calc-affix:has(.calc-pre) .input { padding-inline-start: var(--s-8); }
.calc-affix:has(.calc-post) .input { padding-inline-end: var(--s-10); }
.calc .input { font-variant-numeric: tabular-nums; }
.calc-hint { font-size: var(--fs-xs); line-height: 1.45; color: var(--text-2); }
.calc-hint a { color: var(--text-brand); font-weight: 600; text-underline-offset: 0.25em; text-decoration-thickness: 1px; }
.calc .err[hidden] { display: none; }

/* 3. RESULT ===================================================== */
.calc-out { display: grid; align-content: start; gap: var(--s-4); padding: var(--s-5); background: var(--surface-mint); }
.calc-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); }
.calc-total { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s-2); font-variant-numeric: tabular-nums; }
.calc-total strong { font-size: var(--fs-figure); font-weight: 500; line-height: 1; letter-spacing: -0.04em; }
.calc-total span { font-size: var(--fs-sm); color: var(--text-2); }
.calc-empty { font-size: var(--fs-sm); line-height: 1.5; color: var(--text-2); }
.calc-out:not(.is-ready) .calc-total, .calc-out:not(.is-ready) .calc-bar, .calc-out:not(.is-ready) .calc-parts { display: none; }
.calc-out.is-ready .calc-empty { display: none; }
@media (min-width: 64rem) { .calc-out { padding: var(--s-6); } }

/* 4. BREAKDOWN: one bar, then the rows it's made of =============== */
.calc-bar { display: flex; gap: 2px; height: 0.75rem; overflow: hidden; border-radius: var(--r-chip); }
.calc-bar span { min-width: 0; transition: flex-grow var(--t-ui) var(--ease); }
.calc-parts { display: grid; margin: 0; border-top: 1px solid var(--line-strong); }
.calc-parts > div { display: flex; align-items: center; gap: var(--s-3); padding-block: var(--s-2); border-bottom: 1px solid var(--line-strong); font-size: var(--fs-sm); }
.calc-parts dt { display: flex; align-items: center; gap: var(--s-2); color: var(--text-2); }
.calc-parts dd { margin-inline-start: auto; font-weight: 500; font-variant-numeric: tabular-nums; }
.calc-sw { flex: none; width: 0.625rem; height: 0.625rem; border-radius: 2px; }
.calc .k-pi { background: var(--g-900); }
.calc .k-tax { background: var(--g-600); }
.calc .k-ins { background: var(--g-500); }
.calc .k-flood { background: var(--g-400); }
.calc .k-hoa { background: var(--g-300); }
@media (prefers-reduced-motion: reduce) { .calc-bar span { transition: none; } }

/* 5. NOTES: assumptions sit with the result; the disclaimer is dated */
.calc-assume { font-size: var(--fs-xs); line-height: 1.5; color: var(--text-2); }
.calc-out .btn { justify-self: start; color: var(--on-action); font-weight: 600; }
.calc-note { padding-top: var(--s-3); border-top: 1px solid var(--line-strong); font-size: var(--fs-xs); line-height: 1.5; color: var(--text-2); }
