/* Calm tint: a pale tinted page, cards one shade off, one teal accent, big numbers, round buttons.
   Logical properties (inline-start/end) everywhere so Arabic (right to left) needs no new rules. */

:root {
  --page: #EDF3F0;
  --card: #F9FCFA;
  --card-2: #E1EBE6;
  --ink: #15211D;
  --muted: #56665F;
  --line: #D2DED8;
  --accent: #1E6A5A;
  --accent-ink: #FFFFFF;
  --accent-soft: #CFE5DC;
  --warn: #A3422A;
  --scrim: rgba(12, 22, 19, .38);
  --shadow: 0 10px 30px rgba(20, 50, 40, .16);
  --r-card: 24px;
  --r-field: 16px;
  --tabs-h: 72px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0E1513;
    --card: #17201D;
    --card-2: #222D29;
    --ink: #E4EEEA;
    --muted: #97A8A1;
    --line: #2B3833;
    --accent: #84D1BA;
    --accent-ink: #082620;
    --accent-soft: #21413A;
    --warn: #F29C82;
    --scrim: rgba(0, 0, 0, .55);
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #0E1513; --card: #17201D; --card-2: #222D29; --ink: #E4EEEA; --muted: #97A8A1;
  --line: #2B3833; --accent: #84D1BA; --accent-ink: #082620; --accent-soft: #21413A;
  --warn: #F29C82; --scrim: rgba(0, 0, 0, .55); --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.pos { color: var(--accent); }
[hidden] { display: none !important; }
body.sheet-open { overflow: hidden; }

/* ---- top bar ---- */
.top {
  display: flex; align-items: center; gap: 8px;
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 6px;
}
.top h1 { flex: 1; margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
.top-tools { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-grid; place-items: center;
  border: 0; background: transparent; color: var(--ink);
}
.icon-btn:active { background: var(--card-2); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:disabled { opacity: .3; }

.month-switch { display: flex; align-items: center; gap: 2px; }
.month-switch b { min-width: 7.5em; text-align: center; font-weight: 600; font-size: 15px; }

/* ---- page ---- */
main {
  max-width: 560px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 96px);
  outline: none;
}
section { margin-top: 22px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 4px 10px; }
.sec-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.link {
  border: 0; background: transparent; color: var(--accent); font-weight: 600;
  padding: 10px 4px; min-height: 44px;
}

.card { background: var(--card); border-radius: var(--r-card); padding: 18px; }
.stack > * + * { margin-top: 10px; }

/* ---- the big number ---- */
.hero { padding: 22px 20px 18px; }
.hero-label { font-size: 15px; color: var(--muted); }
.hero-num { display: flex; align-items: baseline; gap: 8px; margin: 2px 0 6px; flex-wrap: wrap; }
.hero-num .n { font-size: clamp(40px, 13vw, 54px); font-weight: 650; letter-spacing: -.025em; line-height: 1.05; }
.hero-num .cur { font-size: 17px; color: var(--muted); font-weight: 600; }
.hero-line { margin: 0; font-size: 15px; color: var(--muted); }
/* three boxes share the row; a long figure makes its box wider and, if need be, wraps to a second line */
.trio {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 16px; padding: 0; border: 0; background: transparent; width: 100%; text-align: start;
}
.trio > div { flex: 1 1 0; min-width: max-content; background: var(--card-2); border-radius: 18px; padding: 10px 12px; }
.trio small { display: block; font-size: 13px; color: var(--muted); }
.trio b { display: block; font-size: clamp(15px, 4.3vw, 17px); font-weight: 650; white-space: nowrap; }
.hero .link { display: block; margin: 8px 0 -8px auto; }

/* ---- rows (entries, due items) ---- */
.list { background: var(--card); border-radius: var(--r-card); padding: 4px 0; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 16px; min-height: 60px; border: 0; background: transparent; text-align: start;
}
button.row:active { background: var(--card-2); }
.row + .row { border-top: 1px solid var(--line); }
.badge {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; background: var(--card-2); font-size: 19px; line-height: 1;
}
.badge.acc { background: var(--accent-soft); color: var(--accent); }
.badge svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.row-main { flex: 1; min-width: 0; }
.row-main b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main small { display: block; color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main small.wrap, .item-top .row-main small { white-space: normal; }
.plain-btn { border: 0; background: transparent; padding: 0; text-align: start; }
.row.due { gap: 10px; }
.row-amt { flex: none; font-weight: 650; font-variant-numeric: tabular-nums; text-align: end; }
.row-amt small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }

.day-head { display: flex; justify-content: space-between; margin: 20px 6px 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.day-head:first-child { margin-top: 8px; }

.empty { padding: 18px; color: var(--muted); text-align: center; background: var(--card); border-radius: var(--r-card); margin: 0; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 650; white-space: nowrap;
}
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: var(--card-2); color: var(--ink); }
.btn.danger { background: transparent; color: var(--warn); border: 1.5px solid currentColor; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 14.5px; }
.btn.wide { width: 100%; }
.btn:active { filter: brightness(.94); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

/* ---- items on Owe and Own ---- */
.item { background: var(--card); border-radius: var(--r-card); padding: 16px 16px 14px; }
.item + .item { margin-top: 10px; }
.item-top { display: flex; align-items: flex-start; gap: 12px; width: 100%; padding: 0; border: 0; background: transparent; text-align: start; }
.item-top .row-main b { font-size: 16.5px; }
.item-figs { margin-top: 10px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.item-figs .big { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 99px; background: var(--card-2); overflow: hidden; margin-top: 10px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.item .btn-row { margin-top: 12px; }
.chip { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--card-2); color: var(--muted); }
.chip.acc { background: var(--accent-soft); color: var(--accent); }

.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.totals > div { background: var(--card); border-radius: 20px; padding: 14px 16px; min-width: 0; }
.totals small { display: block; color: var(--muted); font-size: 13.5px; }
.totals b { display: block; font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

details.done-list { margin-top: 10px; }
details.done-list summary { list-style: none; padding: 12px 6px; color: var(--muted); font-weight: 600; cursor: pointer; }
details.done-list summary::-webkit-details-marker { display: none; }
details.done-list summary::before { content: "▸ "; }
details.done-list[open] summary::before { content: "▾ "; }

.nudge { background: var(--accent-soft); border-radius: var(--r-card); padding: 16px 18px; margin-top: 12px; }
.nudge b { display: block; }
.nudge p { margin: 4px 0 12px; font-size: 14.5px; }

/* ---- bottom bar and + ---- */
.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px max(8px, calc(50% - 280px)) calc(8px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: 0; background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 0 0 2px;
}
.tabs svg { width: 56px; height: 30px; padding: 4px 16px; border-radius: 99px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--ink); }
.tabs button[aria-current="page"] svg { background: var(--accent-soft); color: var(--accent); }

.fab {
  position: fixed; z-index: 11;
  inset-inline-end: max(16px, calc(50% - 264px));
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  width: 64px; height: 64px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.fab svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.fab:active { transform: scale(.96); }

/* ---- sheets ---- */
.scrim { position: fixed; inset: 0; z-index: 20; background: var(--scrim); animation: fade .18s ease-out; }
.sheet {
  position: fixed; z-index: 21; inset-inline: 0; bottom: 0;
  max-width: 560px; margin: 0 auto; max-height: calc(100dvh - 24px);
  display: flex; flex-direction: column;
  background: var(--page); border-radius: 28px 28px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet.full { top: 0; max-height: none; border-radius: 0; }
.sheet-head { display: flex; align-items: center; gap: 6px; padding: 10px 8px 4px 20px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 19px; font-weight: 650; min-width: 0; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px 20px; }
.grip { width: 36px; height: 4px; border-radius: 9px; background: var(--line); margin: 8px auto 0; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .scrim, .sheet { animation: none; } }

/* ---- forms ---- */
.field { display: block; margin-top: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 0 4px 6px; }
.field > small { display: block; font-size: 13px; color: var(--muted); margin: 6px 4px 0; }
.input {
  width: 100%; min-height: 52px; padding: 12px 16px; border-radius: var(--r-field);
  border: 1.5px solid transparent; background: var(--card); color: var(--ink); font-size: 17px;
}
.input:focus { outline: none; border-color: var(--accent); }
.input.bad { border-color: var(--warn); }
.err { color: var(--warn); font-size: 13.5px; margin: 6px 4px 0; min-height: 0; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 999px; background: var(--card-2); }
.seg button { border: 0; border-radius: 999px; min-height: 40px; background: transparent; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.form-actions { margin-top: 22px; }
.form-actions .btn + .btn { margin-top: 10px; }

/* ---- add sheet ---- */
.amount {
  display: flex; align-items: baseline; justify-content: center; gap: 8px;
  margin: 14px 0 4px; min-height: 64px;
}
.amount .n { font-size: clamp(42px, 13vw, 56px); font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.amount .n.empty { color: var(--muted); opacity: .5; }
.amount .cur { font-size: 17px; font-weight: 600; color: var(--muted); }
.amount.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.hint { text-align: center; font-size: 13.5px; color: var(--muted); margin: 0 0 10px; }
.hint.warn { color: var(--warn); }
.cats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px 4px; }
.cat {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: 0; background: transparent; padding: 4px 0; min-width: 0; border-radius: 16px;
}
.cat .badge { width: 46px; height: 46px; font-size: 21px; background: var(--card); }
.cat span { font-size: 12px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat[aria-pressed="true"] .badge { background: var(--accent); color: var(--accent-ink); }
.cat:active .badge { background: var(--accent-soft); }
.extras { display: flex; gap: 8px; margin: 12px 0 10px; }
.extras .input { min-height: 44px; padding: 8px 14px; font-size: 15px; border-radius: 999px; }
.extras .date { flex: 0 0 auto; width: auto; max-width: 46%; }
.extras .note { flex: 1; min-width: 0; }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.keys button {
  min-height: 52px; border: 0; border-radius: 18px; background: var(--card);
  font-size: 22px; font-weight: 550; font-variant-numeric: tabular-nums;
}
.keys button:active { background: var(--accent-soft); }
.keys svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }

/* ---- month summary ---- */
.stmt { background: var(--card); border-radius: var(--r-card); padding: 6px 18px; }
.stmt-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; font-variant-numeric: tabular-nums; }
.stmt-row + .stmt-row { border-top: 1px solid var(--line); }
.stmt-row.main b { font-size: 17px; }
.stmt-row.sub { padding: 8px 0 8px 18px; padding-inline-start: 18px; padding-inline-end: 0; color: var(--muted); font-size: 15px; border-top: 0; }
.stmt-row.total { font-size: 20px; font-weight: 700; border-top: 2px solid var(--ink); }

/* ---- settings ---- */
.set-group { margin-top: 22px; }
.set-group h3 { margin: 0 6px 8px; font-size: 15px; color: var(--muted); font-weight: 650; }
.cat-list { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px 0 10px;
  border-radius: 999px; border: 0; background: var(--card); font-weight: 600; font-size: 14.5px;
}
.cat-pill.add { background: transparent; border: 1.5px dashed var(--line); color: var(--accent); padding: 0 14px; }
.note-line { font-size: 14.5px; color: var(--muted); margin: 0 6px 12px; }

/* ---- toast ---- */
.toast {
  position: fixed; z-index: 40; inset-inline: 16px;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 92px);
  max-width: 528px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 8px 8px 18px; padding-inline-start: 18px; padding-inline-end: 8px; min-height: 52px; border-radius: 18px;
  background: var(--ink); color: var(--page); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toast span { flex: 1; min-width: 0; font-weight: 550; }
.toast button { border: 0; background: transparent; color: var(--accent-soft); font-weight: 700; min-height: 40px; padding: 0 12px; border-radius: 12px; }
.sheet-open .toast { bottom: calc(env(safe-area-inset-bottom) + 16px); }

.confirm-text { font-size: 16.5px; margin: 8px 4px 0; }
