/* Loan Manager — "Coastal Teal" design system, ported from the vehicle
   ownership cost calculator (frontend/src/theme/schemes.ts scheme #21 and
   concept/results-teal.html). Light only, like the source app. */

/* ---------- Tokens ---------- */
:root {
  --canvas: #eef5f6;
  --wave: #d5e7e8;
  --kpi: #145b66;
  --kpi-end: #1c7881;
  --accent: #37c6b2;
  --surface: #fff;
  --text: #253745;
  --muted: #647987;
  --faint: #93a5b0;
  --border: #bcd3d6;
  --border-soft: #e6f0f1;
  --soft: color-mix(in srgb, var(--wave) 45%, white);

  --good: #15803d; --good-soft: #f0fdf4;
  --bad: #b42318; --bad-soft: #fef3f2;
  --warn: #b54708; --warn-soft: #fef0e1;
  --info: #175cd3; --info-soft: #eaf1fd;

  --kpi-gradient: linear-gradient(135deg, var(--kpi) 0%, var(--kpi-end) 100%);
  --shadow: 0 1px 2px rgba(20, 91, 102, .06), 0 8px 24px -8px rgba(20, 91, 102, .14);
  --shadow-btn: 0 8px 20px -8px rgba(20, 91, 102, .7);
  --radius: 20px;
  color-scheme: light;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--canvas); }
body {
  margin: 0; min-height: 100vh; background: var(--canvas); color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-x: clip; position: relative;
}
a { color: var(--kpi-end); text-decoration: none; font-weight: 500; }
a:hover { color: var(--kpi); text-decoration: underline; }
h1 { margin: 0; font-size: clamp(28px, 4vw, 40px); font-weight: 800; letter-spacing: -.02em; color: var(--kpi); line-height: 1.15; }
h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; color: var(--text); }
h3 { margin: 22px 0 8px; font-size: 15px; font-weight: 700; }
code { font-size: .9em; background: var(--canvas); padding: 1px 6px; border-radius: 6px; }
.wrap { position: relative; z-index: 1; max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.good-t { color: var(--good); font-weight: 600; } .bad-t { color: var(--bad); font-weight: 600; }

:focus-visible { outline: 2px solid var(--kpi); outline-offset: 2px; }

/* ---------- Wave band behind the header ---------- */
.wave-band {
  position: absolute; inset: 0 0 auto 0; height: 300px; z-index: 0;
  background: var(--wave); overflow: hidden; pointer-events: none;
}
.wave-band svg { position: absolute; bottom: -1px; left: 0; width: 100%; height: 110px; }
.wave-band path { fill: var(--canvas); }

/* ---------- Top bar ---------- */
.top { position: relative; z-index: 2; }
.bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding-block: 20px 8px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; color: var(--kpi); letter-spacing: .01em; }
.brand:hover { text-decoration: none; color: var(--kpi); }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--kpi-gradient); color: #fff; font-size: 17px; box-shadow: var(--shadow-btn);
}
.top nav { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.top nav a {
  padding: 7px 14px; border-radius: 999px; color: var(--kpi); font-weight: 600; font-size: 14px;
  background: rgba(255, 255, 255, .55); border: 1px solid color-mix(in srgb, var(--kpi) 14%, transparent);
  transition: background .2s;
}
.top nav a:hover { background: var(--surface); text-decoration: none; color: var(--kpi); }
.top nav a.on { background: var(--surface); box-shadow: var(--shadow); border-color: transparent; }
.top nav a.btn { margin-left: 4px; padding: 8px 16px; background: var(--kpi-gradient); color: #fff; border-color: transparent; box-shadow: var(--shadow-btn); }
.top nav button.link { padding: 7px 10px; font-size: 14px; color: var(--muted); }
.top nav button.link:hover { color: var(--kpi); }

/* ---------- Hero (page title on the wave) ---------- */
.hero { padding-block: 28px 8px; }
.hero p { margin: 8px 0 0; color: var(--muted); max-width: 70ch; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  padding: 4px 12px; border-radius: 999px; background: rgba(255, 255, 255, .7);
  font-size: 13px; font-weight: 500; color: var(--text); border: 1px solid rgba(20, 91, 102, .08);
  font-variant-numeric: tabular-nums;
}
.chip b { color: var(--kpi); }

main.wrap { padding-bottom: 32px; }
footer { position: relative; z-index: 1; padding-block: 8px 32px; text-align: center; }

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 20px 0 24px; }
@media (max-width: 960px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .kpis { grid-template-columns: minmax(0, 1fr); gap: 12px; } }
.kpi {
  position: relative; overflow: hidden; padding: 20px 20px 18px; border-radius: var(--radius); color: #fff;
  background: var(--kpi-gradient); box-shadow: 0 10px 30px -10px rgba(20, 91, 102, .55);
  transition: transform .2s ease, box-shadow .2s ease;
}
.kpi::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 140px; height: 140px;
  border-radius: 50%; background: radial-gradient(circle, rgba(55, 198, 178, .45), transparent 70%);
  pointer-events: none;
}
.kpi:hover { transform: scale(1.02); box-shadow: 0 16px 36px -10px rgba(20, 91, 102, .6); }
.kpi-head { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; opacity: .92; }
.kpi-icon {
  flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: rgba(255, 255, 255, .14); color: var(--accent);
}
.kpi-icon svg { width: 18px; height: 18px; }
.kpi-value { margin-top: 14px; font-size: clamp(24px, 2.4vw, 30px); font-weight: 800; letter-spacing: -.01em; line-height: 1.15;
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi-sub { margin-top: 8px; font-size: 13px; opacity: .8; }
.kpi .good-t, .kpi .bad-t { color: #fff; font-weight: 700; }
.kpi .tag { display: inline-block; padding: 0 8px; border-radius: 999px; background: rgba(255, 255, 255, .16); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin: 0 0 24px; }
.card > h2 + p, .card-head p { margin: 4px 0 0; }
.card-head { margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: 24px 24px 0; }
.card.flush > .card-foot { padding: 14px 24px 18px; margin: 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.row-between > h2 { flex: 1 1 auto; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.scroll { overflow-x: auto; }
.card > .scroll { margin-inline: -24px; padding-inline: 12px; }
.card.flush > .scroll { margin: 0; padding: 0 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 999px; border: 1px solid transparent; cursor: pointer;
  font: inherit; font-size: 14px; font-weight: 600; line-height: 1.2; white-space: nowrap;
  background: var(--kpi-gradient); color: #fff; box-shadow: var(--shadow-btn);
  transition: transform .15s ease, box-shadow .2s ease, background .2s, filter .2s;
}
.btn:hover { color: #fff; text-decoration: none; box-shadow: 0 12px 26px -8px rgba(20, 91, 102, .75); filter: brightness(1.06); }
.btn:active { transform: scale(.97); }
.btn.outline { background: var(--surface); border-color: var(--kpi-end); color: var(--kpi); box-shadow: none; }
.btn.outline:hover { background: var(--soft); color: var(--kpi); filter: none; }
.btn.ok { background: var(--good); box-shadow: 0 8px 20px -8px rgba(21, 128, 61, .6); }
.btn.danger { background: var(--bad); box-shadow: 0 8px 20px -8px rgba(180, 35, 24, .6); }
.small-btn { padding: 6px 12px; font-size: 13px; }

button.link {
  background: none; border: 0; padding: 4px 6px; margin: -4px -6px; border-radius: 8px;
  font: inherit; font-weight: 600; color: var(--kpi-end); cursor: pointer;
}
button.link:hover { color: var(--kpi); background: var(--soft); }
button.link.danger { color: var(--bad); }
button.link.danger:hover { background: var(--bad-soft); color: var(--bad); }
.actions { display: flex; gap: 14px; align-items: center; }
.actions form { margin: 0; }
form.inline { display: inline; margin: 0; }

/* ---------- Segmented control ---------- */
.seg {
  display: inline-flex; padding: 4px; gap: 4px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--border-soft); box-shadow: var(--shadow); margin: 20px 0 0;
}
.seg a {
  padding: 7px 16px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); transition: all .2s ease;
}
.seg a:hover { color: var(--kpi); text-decoration: none; }
.seg a.on { background: var(--kpi-gradient); color: #fff; box-shadow: 0 4px 12px -4px rgba(20, 91, 102, .6); }

/* ---------- Pills ---------- */
.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--canvas); color: var(--muted); border: 1px solid var(--border-soft); white-space: nowrap;
}
.pill.good, .pill.paid, .pill.extra, .pill.overpaid { background: var(--good-soft); color: var(--good); border-color: #bbf7d0; }
.pill.bad, .pill.missed, .pill.declined { background: var(--bad-soft); color: var(--bad); border-color: #f7cfcb; }
.pill.partial, .pill.due, .pill.pending { background: var(--warn-soft); color: var(--warn); border-color: #f9d7b5; }
.pill.actual { background: var(--soft); color: var(--kpi); border-color: var(--wave); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
td[dir="auto"] { white-space: normal; }
.num { text-align: right; }
tfoot td { font-weight: 700; border-top: 1px solid var(--border); border-bottom: 0; color: var(--kpi); }
tr.current td { background: var(--canvas); }
tr.current td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tr.projected td { color: var(--muted); }
tr.sub-row td { border-bottom: 1px dashed var(--border-soft); color: var(--muted); padding-block: 5px; }
/* Recent payments: on phones the year drops to its own line so the note gets the room */
@media (max-width: 520px) {
  table.recent .yr { display: block; color: var(--muted); font-size: 13px; }
  table.recent td { vertical-align: top; }
}
tr.declined .struck { text-decoration: line-through; opacity: .7; }

/* ---------- Forms ---------- */
.form { max-width: 420px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.form label { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; font-weight: 600; font-size: 14px; }
.form label .muted { font-weight: 500; }
.form input, .copy-row input {
  width: 100%; min-width: 0; height: 44px; font: inherit; font-weight: 400; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
  transition: border-color .2s, box-shadow .2s;
}
.form input[type="file"] { height: auto; padding: 10px 14px; background: var(--canvas); border-style: dashed; }
.form input:hover, .copy-row input:hover { border-color: var(--faint); }
.form input:focus, .copy-row input:focus {
  outline: none; border-color: var(--kpi); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}
.form input::placeholder { color: var(--faint); }
input.code { height: 56px; font-size: 1.6rem; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.form.grid2 { max-width: none; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.form.grid2 .span2 { grid-column: 1 / -1; }
.inline-form { max-width: none; grid-template-columns: minmax(0, 320px) auto; align-items: end; justify-content: start; }
@media (max-width: 520px) { .inline-form { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Flash & banners ---------- */
.flash, .banner {
  margin: 16px 0; padding: 12px 16px; border-radius: 14px; border-left: 4px solid;
  background: var(--good-soft); color: var(--good); font-weight: 600;
}
.flash.error { background: var(--bad-soft); color: var(--bad); }
.banner.good { background: var(--good-soft); color: var(--good); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner a { color: inherit; text-decoration: underline; }
main > .flash:first-child { margin-top: 0; }

/* ---------- Progress & chart ---------- */
.progress { height: 12px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--kpi), var(--accent)); border-radius: 99px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px 16px; flex-wrap: wrap; margin-top: 28px; }
.chart-head h3 { margin: 0; }
.chart { position: relative; margin-top: 8px; border-radius: 12px; touch-action: pan-y; }
.chart:focus-visible { outline-offset: 4px; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--border-soft); stroke-width: 1; }
.chart .base { stroke: var(--border); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .tick.strong { fill: var(--text); font-weight: 600; }
.chart .halo { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.chart .val { fill: var(--kpi); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.chart path { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .s-area { fill: var(--kpi); fill-opacity: .08; stroke: none; }
.chart .s-actual { stroke: var(--kpi); stroke-width: 2.5; }
.chart .s-proj { stroke: var(--kpi-end); stroke-dasharray: 6 5; }
.chart .s-orig { stroke: var(--faint); stroke-dasharray: 1 5; stroke-width: 2.5; }
.chart .today { stroke: var(--border); stroke-dasharray: 3 3; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart circle { stroke: var(--surface); stroke-width: 2; }
.chart .dot-actual { fill: var(--kpi); }
.chart .dot-proj { fill: var(--kpi-end); }
.chart .dot-orig { fill: var(--faint); }
.chart-tip {
  position: absolute; z-index: 2; pointer-events: none; min-width: 170px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: 12px;
  box-shadow: 0 10px 30px -10px rgba(20, 91, 102, .35); font-size: 13px;
}
.tip-head { color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.tip-row b { font-variant-numeric: tabular-nums; color: var(--text); }
.tip-row span { color: var(--muted); }
.tip-row i { flex: none; width: 14px; height: 0; border-top: 2.5px solid; }
.chart-foot { margin: 10px 0 0; }
.legend { display: flex; gap: 16px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 20px; height: 0; border-top: 2.5px solid; vertical-align: middle; margin-right: 6px; }
.k-orig { border-color: var(--faint) !important; border-top-style: dotted !important; }
.k-actual { border-color: var(--kpi) !important; }
.k-proj { border-color: var(--kpi-end) !important; border-top-style: dashed !important; }

/* ---------- Modal ---------- */
.modal {
  border: 0; border-radius: var(--radius); padding: 24px; width: min(460px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow), 0 30px 80px -20px rgba(20, 91, 102, .45);
}
.modal::backdrop { background: rgba(37, 55, 69, .45); backdrop-filter: blur(3px); }
.modal .form { max-width: none; }
.modal .form p { margin: 0; }
.modal .row-between { margin-bottom: 0; }
.modal .row { margin-top: 4px; }
.close {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; border: 0;
  background: var(--soft); color: var(--kpi); font-size: 22px; line-height: 1; cursor: pointer; transition: background .2s;
}
.close:hover { background: var(--wave); }

/* ---------- Auth, setup, admin ---------- */
.auth-wrap { position: relative; z-index: 1; max-width: 460px; margin: 0 auto; padding: 6vh 16px 40px; }
.auth-wrap.wide { max-width: 760px; }
.auth-brand { display: flex; margin-bottom: 24px; }
.auth-wrap > h1 { margin-bottom: 8px; }
.auth-wrap > h1 + p { margin: 0 0 24px; }
.auth .card h1 { font-size: 26px; margin-bottom: 8px; }
.auth .card > h2 { margin-bottom: 4px; }
.auth .card > .form, .auth .card > form { margin-top: 18px; }
.invite-box { background: var(--canvas); border: 1px solid var(--wave); border-radius: 14px; padding: 14px 16px; margin: 16px 0; }
.invite-box p { margin: 0 0 10px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; }
.steps { list-style: none; padding: 0; margin: 0; counter-reset: step; }
.steps > li { counter-increment: step; }
.steps > li h2 { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.steps > li h2::before {
  content: counter(step); flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 10px;
  background: var(--kpi-gradient); color: #fff; font-size: 14px; font-weight: 700;
}
.qr { display: flex; justify-content: center; margin: 16px 0; }
.qr svg { background: #fff; padding: 10px; border-radius: 14px; border: 1px solid var(--wave); max-width: 100%; height: auto; }
code.key { font-size: 1rem; word-break: break-all; background: var(--canvas); padding: 6px 10px; border-radius: 8px; }
details summary { cursor: pointer; color: var(--kpi-end); font-weight: 600; }
.welcome { border-top: 4px solid var(--accent); }
.welcome .dismiss { margin-top: 16px; }
.bookmark-help { margin-top: 14px; display: grid; gap: 10px; }
.bookmark-help .others { display: grid; gap: 8px; margin-top: 8px; }
kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font: inherit; font-size: .85em; background: var(--surface); }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
  .kpi:hover, .btn:active { transform: none; }
}
