@font-face {
  font-family: Vazirmatn;
  src: url(../fonts/Vazirmatn.woff2) format('woff2');
  font-weight: 100 900;
  font-display: block;
}

:root {
  --bg: #EDF0F3; --surface: #FFFFFF; --ink: #1A2331; --muted: #5E6B7C; --line: #D5DCE4;
  --paid: #2E6B5C; --left: #CBD4DE; --hot: #B7791F; --hotbg: #FBF1DF; --err: #B3261E;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121821; --surface: #1B2330; --ink: #E6EBF1; --muted: #95A2B3; --line: #2C3747;
    --paid: #5BB39C; --left: #333F50; --hot: #E3A948; --hotbg: #2E2717; --err: #F2B8B5;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box }
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100% }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: Vazirmatn, system-ui, sans-serif; line-height: 1.6; font-size: 16px;
  padding: var(--safe-area-inset-top, env(safe-area-inset-top, 0px)) var(--safe-area-inset-right, env(safe-area-inset-right, 0px)) var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
}
button, input, select { font: inherit; color: inherit }
main { max-width: 560px; margin: 0 auto; padding: 8px 16px 40px }

.top { display: flex; justify-content: space-between; align-items: center; min-height: 48px }
.brand { font-weight: 800; font-size: 18px }
button.icon {
  inline-size: 44px; block-size: 44px; display: grid; place-items: center;
  border: 0; background: none; border-radius: 50%; cursor: pointer; padding: 0; margin-inline-end: -10px;
}
button.icon svg { inline-size: 22px; block-size: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round }
button.icon:active { background: var(--line) }

/* summary */
h1 { font-size: 15px; font-weight: 500; color: var(--muted); margin: 4px 0 2px }
.total { font-size: 40px; font-weight: 800; letter-spacing: -.5px; line-height: 1.15; margin: 0; white-space: nowrap }
.total.more { font-size: 26px; margin-block-start: 10px }
.sub { color: var(--muted); font-size: 14px; margin: 4px 0 0 }
.facts { display: flex; gap: 8px 22px; flex-wrap: wrap; margin: 16px 0 22px; font-size: 14px }
.facts b { display: block; font-size: 18px; font-weight: 700; color: var(--ink); white-space: nowrap }
.facts span { color: var(--muted) }

.empty { text-align: center; padding: 40px 8px 24px }
.empty h1 { font-size: 20px; color: var(--ink); font-weight: 700 }
.empty p { color: var(--muted); margin: 8px auto 0; max-width: 34ch }

/* commitment card */
.card { background: var(--surface); border-radius: 14px; padding: 16px; border: 1px solid var(--line) }
.loan { margin-bottom: 12px; cursor: pointer; display: block; inline-size: 100%; text-align: start }
.loan.hot { border-color: var(--hot) }
.loan.done { opacity: .62 }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px }
.name { font-weight: 700; font-size: 17px; overflow-wrap: anywhere }
.rate { font-size: 14px; color: var(--muted); white-space: nowrap }
.loan.hot .rate { color: var(--hot); font-weight: 700 }
.ticks { display: grid; gap: 3px; margin: 12px 0 10px }
.ticks i { display: block; height: 14px; border-radius: 2px; background: var(--left) }
.ticks i.p { background: var(--paid) }
.ticks i.n { outline: 2px solid var(--paid); outline-offset: -2px }
.bar { height: 14px; border-radius: 4px; background: var(--left); margin: 12px 0 10px; overflow: hidden }
.bar i { display: block; height: 100%; background: var(--paid) }
/* Equal thirds when they fit; cells wrap onto new rows when the system font size makes them wider. */
.nums { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--muted) }
.nums > div { flex: 1 1 0; min-width: max-content }
.nums + .nums { margin-top: 8px }
.nums b { display: block; font-size: 15px; color: var(--ink); font-weight: 700; white-space: nowrap }
.last { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13.5px; color: var(--muted) }
.last b { color: var(--ink); font-weight: 700 }

/* home: one compact row per commitment */
.loan-row { display: block; inline-size: 100%; text-align: start; margin-bottom: 10px; padding: 14px 16px; cursor: pointer; font: inherit; color: inherit }
.loan-row.hot { border-color: var(--hot) }
.loan-row.done { opacity: .62 }
.lr-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px }
.lr-amt { font-weight: 700; font-size: 16px; white-space: nowrap }
.mini { display: block; height: 6px; border-radius: 3px; background: var(--left); margin: 10px 0 8px; overflow: hidden }
.mini i { display: block; height: 100%; background: var(--paid) }
.lr-meta { display: block; font-size: 13.5px; color: var(--muted) }
#lumpBtn { margin-top: 10px }
/* details sheet */
#detailsBody .rate { margin: 0 0 4px }
#detailsBody .rate.hot { color: var(--hot); font-weight: 700 }

/* buttons */
button.primary, button.secondary, button.danger {
  font-weight: 700; padding: 12px 16px; border-radius: 12px; cursor: pointer; min-height: 48px;
}
button.primary { border: 0; background: var(--paid); color: #fff }
@media (prefers-color-scheme: dark) { button.primary { color: #0D1A16 } }
button.secondary { border: 1px solid var(--line); background: var(--surface) }
button.danger { border: 1px solid var(--err); background: none; color: var(--err) }
button.wide { inline-size: 100%; margin-top: 4px }
button:disabled { opacity: .5 }
:focus-visible { outline: 2px solid var(--paid); outline-offset: 2px }

/* lump sum */
h2 { font-size: 18px; margin: 32px 0 4px }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 12px }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px }
input[type=text], select {
  inline-size: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); block-size: 46px; font-size: 16px;
}
input.big { font-size: 22px; font-weight: 700; block-size: auto; min-height: 56px }
input.num { direction: ltr; text-align: end }
[dir=rtl] input.num { text-align: right }
.lumpRow { display: flex; gap: 8px }
.lumpRow select { inline-size: auto; flex: none }
.opt { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; margin-top: 6px; font-size: 15px }
.opt:first-child { margin-top: 14px }
.opt.best { background: var(--hotbg) }
.opt .save { font-weight: 800; font-size: 17px; white-space: nowrap }
.opt small { display: block; color: var(--muted); font-size: 13px }
.foot { color: var(--muted); font-size: 12.5px; margin-top: 22px }

/* update prompt: a pill in the bottom inline-end corner, above the safe area */
button.update {
  position: fixed; z-index: 10; inset-inline-end: 16px;
  inset-block-end: calc(16px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 10px 18px;
  border: 0; border-radius: 999px; background: var(--ink); color: var(--bg);
  font-weight: 700; font-size: 15px; cursor: pointer; box-shadow: 0 8px 24px rgb(0 0 0 / .25);
}
button.update::before { content: '↻'; font-size: 18px; line-height: 1 }
button.update[hidden] { display: none }
@media (prefers-reduced-motion: no-preference) {
  button.update:not([hidden]) { animation: rise .25s ease-out }
  @keyframes rise { from { transform: translateY(12px); opacity: 0 } }
}

/* Full-screen pages (nav.js): slide in from the inline-end edge, like native screens. */
.page {
  position: fixed; inset: 0; background: var(--bg); overflow-y: auto; overscroll-behavior: contain;
  visibility: hidden; transform: translateX(100%);
}
[dir=rtl] .page { transform: translateX(-100%) }
.page.open { visibility: visible; transform: none; box-shadow: 0 0 32px rgb(0 0 0 / .2) }
@media (prefers-reduced-motion: no-preference) {
  .page { transition: transform .28s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .28s }
  .page.open { transition: transform .28s cubic-bezier(.2, .8, .2, 1), visibility 0s }
}
.appbar {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 4px;
  /* Line the title up with the centred content column on wide screens. */
  padding-block-start: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  padding-inline: max(4px, calc((100% - 560px) / 2 + 4px)) max(16px, calc((100% - 560px) / 2 + 16px));
  min-height: calc(56px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
  background: var(--bg); border-bottom: 1px solid var(--line);
}
button.icon.back { margin: 0 }
[dir=rtl] .back svg { transform: scaleX(-1) }
.appbar-title { margin: 0; font-size: 18px; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.appbar-title:focus { outline: none }
.page-body { display: block; max-width: 560px; margin: 0 auto; padding: 8px 16px calc(24px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))) }
.page input[type=text], .page select { background: var(--surface) }
/* The editor's Save bar stays pinned to the bottom of the page, clear of the system navigation bar. */
.actions.save-bar {
  position: sticky; bottom: 0;
  margin: 22px -16px calc(-24px - var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  padding: 12px 16px calc(12px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  background: var(--bg); border-top: 1px solid var(--line);
}
.field { margin-top: 14px }
.field small.hint, .field small.err { display: block; font-size: 12.5px; margin: 4px 0 0 }
.field small.err { color: var(--err) }
.field.invalid input, .field.invalid select { border-color: var(--err) }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px }
/* Two-column rows: labels share one height so the inputs line up even when a label wraps. */
.split > .field { display: flex; flex-direction: column }
.split > .field > label { flex: 1 0 auto; display: flex; align-items: flex-end }
.row-hint { display: block; font-size: 12.5px; margin: 4px 0 0 }
.split3 { display: grid; grid-template-columns: 1fr 1.6fr 1.2fr; gap: 8px }
.seg { display: flex; flex-wrap: wrap; gap: 6px }
.seg label { margin: 0; flex: 1 1 auto }
.seg input { position: absolute; opacity: 0; pointer-events: none }
.seg span {
  display: block; text-align: center; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line);
  color: var(--ink); font-size: 14.5px; cursor: pointer; min-height: 44px; line-height: 24px;
}
.seg input:checked + span { background: var(--paid); border-color: var(--paid); color: #fff; font-weight: 700 }
@media (prefers-color-scheme: dark) { .seg input:checked + span { color: #0D1A16 } }
.seg input:focus-visible + span { outline: 2px solid var(--paid); outline-offset: 2px }
.actions { display: flex; gap: 10px; margin-top: 22px }
.actions .primary { flex: 1 }
.group { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 4px }
.about { color: var(--muted); font-size: 13px; margin-top: 18px }
