/* My Expenses: one stylesheet for the whole app. Mobile first. */

:root {
  color-scheme: light;
  --bg: #eef1ef;
  --surface: #ffffff;
  --surface-2: #f7f8f6;
  --ink: #15201d;
  --ink-2: #4f6159;
  --ink-3: #6b7d76;
  --line: #dfe5e2;
  --brand: #0f6b5c;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3ee;
  --brand-soft-ink: #0a4a40;
  --hero: #15201d;
  --hero-ink: #f4f7f5;
  --hero-ink-2: #a9bdb7;
  --hero-track: #2c3c38;
  --hero-fill: #3fbf9f;
  --warn-bg: #fdeee2;
  --warn-ink: #7a3a12;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --ok-bg: #e3f3ee;
  --ok-ink: #0a4a40;
  --bar: #0f6b5c;
  --bar-dim: #b9ddd3;
  --track: #e4e9e6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s-other: #9aa6a1;
  --radius: 18px;
  --tabbar-h: 68px;
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c1210;
    --surface: #161f1c;
    --surface-2: #1c2723;
    --ink: #eef3f1;
    --ink-2: #b2c2bc;
    --ink-3: #8fa29b;
    --line: #2a3833;
    --brand: #35b394;
    --brand-ink: #06120e;
    --brand-soft: #173a32;
    --brand-soft-ink: #a6e6d3;
    --hero: #06100d;
    --hero-ink: #f4f7f5;
    --hero-ink-2: #a9bdb7;
    --hero-track: #22312c;
    --hero-fill: #3fbf9f;
    --warn-bg: #3a2414;
    --warn-ink: #f6c9a6;
    --danger: #f08a83;
    --danger-bg: #3a1714;
    --ok-bg: #173a32;
    --ok-ink: #a6e6d3;
    --bar: #35b394;
    --bar-dim: #24584b;
    --track: #24302c;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s-other: #6f7d78;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; min-height: 100vh; min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
svg { flex-shrink: 0; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- app shell ---------- */
.app { max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; position: relative; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 14px) 18px 10px; display: flex; align-items: center; gap: 12px;
}
.topbar h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.view { padding: 4px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
}
.tabbar-inner { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: end; }
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; min-height: 50px;
  font-size: 11px; font-weight: 600; color: var(--ink-3); text-decoration: none; background: none; border: 0; cursor: pointer;
}
.tab[aria-current="page"] { color: var(--brand); font-weight: 800; }
.tab .badge { position: absolute; margin-left: 22px; margin-top: -4px; }
.tab-wrap { position: relative; display: flex; justify-content: center; }
.fab {
  width: 62px; height: 62px; border-radius: 31px; border: 0; background: var(--brand); color: var(--brand-ink);
  display: flex; align-items: center; justify-content: center; margin-top: -30px; cursor: pointer;
  box-shadow: 0 6px 18px rgba(15, 107, 92, 0.35); border: 4px solid var(--surface);
}
.fab:active { transform: scale(0.96); }

.icon-btn {
  width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink);
}

/* ---------- cards and blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.card h2, .section-title { font-size: 16px; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-title a, .card h2 a { font-size: 13px; font-weight: 700; text-decoration: none; }
.muted { color: var(--ink-2); font-size: 13px; }
.tiny { color: var(--ink-3); font-size: 12px; }

.hero { background: var(--hero); color: var(--hero-ink); border-radius: 22px; padding: 20px; margin-bottom: 14px; }
.hero .label { font-size: 13px; color: var(--hero-ink-2); font-weight: 600; }
.hero .big { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; margin: 2px 0 12px; font-variant-numeric: tabular-nums; }
.hero .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.hero .chip { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 99px; background: var(--hero-track); color: var(--hero-ink); }
.hero .chip.up { color: #f6b48a; }
.hero .chip.down { color: #9fe0cf; }
.meter { height: 8px; border-radius: 4px; background: var(--hero-track); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--hero-fill); border-radius: 4px; }
.meter.over > i { background: #f08a6b; }
.hero .foot { font-size: 12px; color: var(--hero-ink-2); margin-top: 8px; }

.banner { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; margin-bottom: 14px; font-size: 14px; font-weight: 600; text-decoration: none; }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.err { background: var(--danger-bg); color: var(--danger); }
.banner.ok { background: var(--ok-bg); color: var(--ok-ink); }
.banner .grow { flex: 1; min-width: 0; }
.banner b { font-weight: 800; }

.actions-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.action {
  display: flex; align-items: center; gap: 10px; padding: 14px; border-radius: 16px; background: var(--surface);
  border: 1px solid var(--line); font-weight: 700; font-size: 14px; cursor: pointer; text-align: left; min-height: 56px; color: var(--ink);
  text-decoration: none;
}
.action .ic { width: 36px; height: 36px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-soft-ink); display: flex; align-items: center; justify-content: center; }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line);
  text-decoration: none; color: inherit; cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left;
}
.row:last-child { border-bottom: 0; }
.row .ic { width: 40px; height: 40px; border-radius: 13px; background: var(--surface-2); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; color: var(--ink-2); }
.row .main { flex: 1; min-width: 0; }
.row .t, .row .s { display: block; }
.row .t { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.row .amt small { display: block; font-size: 11px; color: var(--ink-3); font-weight: 600; }
.day-head { display: flex; justify-content: space-between; font-size: 12px; font-weight: 800; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; padding: 16px 2px 4px; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.pill.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #d4572a; color: #fff; font-size: 11px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }
.empty { text-align: center; padding: 30px 10px; color: var(--ink-2); font-size: 14px; }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* ---------- category bars ---------- */
.cat-bars { display: flex; flex-direction: column; gap: 12px; }
.cat-bar .top { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; margin-bottom: 5px; }
.cat-bar .top b { font-variant-numeric: tabular-nums; }
.cat-bar .track { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.cat-bar .track i { display: block; height: 100%; border-radius: 4px; background: var(--bar); }
.cat-bar.over .track i { background: #d4572a; }
.cat-bar .note { font-size: 12px; color: var(--ink-2); margin-top: 3px; }
.cat-bar.over .note { color: var(--warn-ink); font-weight: 700; }

/* ---------- charts ---------- */
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { width: 132px; height: 132px; flex-shrink: 0; }
.donut text { fill: var(--ink); font-family: var(--font); }
.legend { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; list-style: none; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .v { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }
@media (max-width: 360px) { .donut-wrap { flex-direction: column; align-items: stretch; } .donut { margin: 0 auto; } }

.bars { display: flex; align-items: flex-end; gap: 8px; height: 130px; padding-top: 22px; position: relative; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; cursor: pointer; background: none; border: 0; padding: 0; min-width: 0; }
.bars .b i { display: block; width: 100%; max-width: 34px; background: var(--bar-dim); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .b.cur i, .bars .b.sel i { background: var(--bar); }
.bars-x { display: flex; gap: 8px; margin-top: 6px; }
.bars-x span { flex: 1; text-align: center; font-size: 11px; color: var(--ink-3); font-weight: 600; min-width: 0; }
.bars-tip { position: absolute; top: 0; left: 0; right: 0; text-align: center; font-size: 12.5px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.baseline { height: 1px; background: var(--line); }

.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.stat .k { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.stat .v { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; overflow-wrap: anywhere; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-size: 11px; font-weight: 800; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; padding: 6px 6px 8px 0; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 6px 9px 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .pct { color: var(--ink-3); font-size: 12px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; min-width: 0; }
.field label, .lbl { font-size: 12.5px; font-weight: 700; color: var(--ink-2); }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  padding: 10px 12px; font-size: 16px; color: var(--ink); appearance: none; -webkit-appearance: none;
}
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.amount-input { font-size: 40px; font-weight: 800; text-align: center; border: 0; background: transparent; width: 100%; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; padding: 4px 0; min-height: 60px; }
.amount-input:focus { outline: none; }
.amount-wrap { text-align: center; padding: 8px 0 16px; }
.amount-wrap .cur { font-size: 13px; color: var(--ink-2); font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn {
  min-height: 40px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface);
  font-size: 13.5px; font-weight: 600; cursor: pointer; color: var(--ink);
}
.chip-btn[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 800; }
.cat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cat-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 10px 4px; min-height: 76px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-size: 11.5px; font-weight: 700; text-align: center;
  cursor: pointer; line-height: 1.2; color: var(--ink);
}
.cat-tile[aria-pressed="true"] { border: 2px solid var(--brand); background: var(--brand-soft); color: var(--brand-soft-ink); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 12px; }
.toggle-row .t { font-weight: 700; font-size: 14px; }
.toggle-row .s { font-size: 12px; color: var(--ink-2); }
.switch { position: relative; width: 50px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 15px; background: var(--track); transition: background 0.2s; border: 1px solid var(--line); }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 11px; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.switch input:checked + span { background: var(--brand); border-color: var(--brand); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 20px; border-radius: 15px;
  border: 0; background: var(--ink); color: var(--bg); font-weight: 800; font-size: 15.5px; cursor: pointer; text-decoration: none; width: 100%;
}
.btn.brand { background: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--surface); color: var(--danger); border: 1px solid var(--line); }
.btn.small { min-height: 40px; font-size: 13.5px; padding: 0 14px; border-radius: 12px; width: auto; }
.btn[disabled] { opacity: 0.55; cursor: default; }
.btn-row { display: flex; gap: 10px; margin-top: 6px; }
.btn-row .btn { flex: 1; }
.sticky-save { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); z-index: 5; padding-top: 6px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; margin-bottom: 12px; }
.seg button { min-height: 38px; border: 0; border-radius: 10px; background: transparent; font-weight: 700; font-size: 13.5px; cursor: pointer; color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.month-nav .m { font-weight: 800; font-size: 16px; text-align: center; flex: 1; }
.search { position: relative; margin-bottom: 12px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search .input { padding-left: 40px; }
.filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 4px; }
.total-line { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 2px 0; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.total-line b { color: var(--ink); font-size: 16px; font-variant-numeric: tabular-nums; }

/* ---------- receipt on the review screen ---------- */
.receipt-box { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 14px; }
.receipt-thumb { width: 92px; height: 118px; border-radius: 12px; border: 1px solid var(--line); object-fit: cover; background: var(--surface-2); flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: var(--ink-2); font-size: 12px; font-weight: 700; text-decoration: none; overflow: hidden; }
.receipt-thumb img { width: 100%; height: 100%; object-fit: cover; }
.receipt-meta { flex: 1; min-width: 0; }
.receipt-meta h2 { font-size: 18px; font-weight: 800; margin-bottom: 6px; overflow-wrap: anywhere; }
.items { list-style: none; font-size: 13px; }
.items li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.items li:last-child { border-bottom: 0; }
details.more-box { margin-bottom: 12px; }
details.more-box summary { cursor: pointer; font-weight: 700; font-size: 14px; padding: 10px 0; color: var(--brand); list-style: none; }
details.more-box summary::-webkit-details-marker { display: none; }

/* ---------- overlay and toast ---------- */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(8, 14, 12, 0.72); display: flex; align-items: center; justify-content: center; padding: 24px; }
.overlay .box { background: var(--surface); border-radius: 22px; padding: 24px; width: 100%; max-width: 340px; text-align: center; }
.overlay .box h3 { font-size: 18px; font-weight: 800; margin: 12px 0 4px; }
.progress { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; margin-top: 16px; }
.progress i { display: block; height: 100%; background: var(--brand); width: 0; transition: width 0.25s; }
.progress.indeterminate i { width: 35%; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--track); border-top-color: var(--brand); animation: spin 0.8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px); z-index: 70; background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 700; font-size: 14px; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,0.25); }
.toast.err { background: var(--danger); color: #fff; }

/* ---------- login ---------- */
.auth { max-width: 400px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 48px) 20px 40px; }
.brand-mark { width: 64px; height: 64px; border-radius: 18px; background: var(--hero); display: flex; align-items: center; justify-content: center; margin-bottom: 18px; color: var(--hero-fill); }
.auth h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 4px; }
.auth p.lead { color: var(--ink-2); margin-bottom: 22px; }

/* ---------- settings ---------- */
.set-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row { flex-wrap: wrap; }
.set-row .nm { flex: 1 1 100%; min-width: 0; font-weight: 700; font-size: 14px; overflow-wrap: break-word; }
.set-row .budget { flex: 1; }
@media (min-width: 420px) { .set-row .nm { flex-basis: 0; } .set-row .budget { flex: 0 0 120px; } }
.set-row.off .nm { color: var(--ink-3); text-decoration: line-through; }
.set-row .budget { width: 112px; min-height: 40px; font-size: 14px; padding: 6px 10px; text-align: right; }
.link-btn { background: none; border: 0; color: var(--brand); font-weight: 700; font-size: 13px; cursor: pointer; padding: 8px 4px; min-height: 40px; }
.inline-add { display: flex; gap: 8px; margin-top: 10px; }
.inline-add .input { flex: 1; min-width: 0; }
.howto { padding-left: 18px; font-size: 14px; color: var(--ink-2); }
.howto li { margin-bottom: 6px; }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--ink-2); }
