/* Budget — mobile-first stylesheet */

:root {
  --canvas:     #E9EDE9;
  --surface:    #FFFFFF;
  --surface-2:  #F3F6F2;
  --ink:        #16211F;
  --muted:      #5F6F6B;
  --line:       #D5DED8;
  --brand:      #14504A;
  --brand-ink:  #FFFFFF;
  --brand-soft: #DCEAE4;
  --accent:     #C8552A;
  --accent-soft:#FBE7DD;
  --good:       #2E7D5B;
  --radius:     16px;
  --radius-sm:  10px;
  --shadow:     0 1px 2px rgba(20,40,36,.06), 0 8px 24px rgba(20,40,36,.06);
  --nav-h:      66px;
  --font-ui:    'Archivo', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-num:   'Instrument Serif', Georgia, 'Times New Roman', serif;
}

html[data-theme="dark"] {
  --canvas:     #0F1513;
  --surface:    #171F1D;
  --surface-2:  #1E2725;
  --ink:        #E6EDE9;
  --muted:      #8FA29C;
  --line:       #26322F;
  --brand:      #16302C;
  --brand-ink:  #A9E7CE;
  --brand-soft: #1C2A27;
  --accent:     #F0855A;
  --accent-soft:#2E211B;
  --good:       #7FD1AE;
  --shadow:     0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 12px);
  overscroll-behavior-y: contain;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

.num { font-variant-numeric: tabular-nums; }

.wrap { max-width: 620px; margin: 0 auto; padding: 0 16px; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--canvas);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner {
  max-width: 620px; margin: 0 auto;
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px;
}
.period {
  flex: 1; text-align: center;
  font-size: 15px; font-weight: 600; letter-spacing: .01em;
}
.period small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; }
.icon-btn {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font-size: 17px; cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }

/* ---------- hero ---------- */

.hero {
  background: var(--brand);
  color: var(--brand-ink);
  border-radius: var(--radius);
  padding: 20px 20px 18px;
  margin-top: 14px;
  box-shadow: var(--shadow);
}
.hero .label {
  font-size: 11.5px; letter-spacing: .09em; text-transform: uppercase;
  opacity: .72; font-weight: 600;
}
.hero .figure {
  font-family: var(--font-num);
  font-size: clamp(46px, 15vw, 62px);
  line-height: 1.02;
  letter-spacing: -0.02em;
  margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
}
.hero .figure.over { color: #FFB59B; }
.hero .sub { font-size: 13.5px; opacity: .8; }

/* pace meter — the signature element */
.pace { margin-top: 18px; }
.pace-track {
  position: relative; height: 12px; border-radius: 999px;
  background: rgba(255,255,255,.16); overflow: visible;
}
.pace-fill {
  position: absolute; inset: 0 auto 0 0; height: 100%;
  border-radius: 999px; background: var(--brand-ink); opacity: .85;
  transition: width .5s cubic-bezier(.2,.8,.2,1);
}
.pace-fill.over { background: #FF9F7A; opacity: 1; }
.pace-today {
  position: absolute; top: -5px; bottom: -5px; width: 2px;
  background: var(--brand-ink);
  border-radius: 2px;
}
.pace-today::after {
  content: attr(data-label);
  position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  white-space: nowrap; opacity: .8;
}
.pace-legend {
  display: flex; justify-content: space-between; gap: 10px;
  margin-top: 12px; font-size: 12.5px; opacity: .85;
}

/* ---------- generic cards ---------- */

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 24px 0 10px;
}
.section-head h2 { font-size: 13px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.section-head a { font-size: 13px; color: var(--brand); font-weight: 600; }
html[data-theme="dark"] .section-head a { color: var(--good); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 12px; }
.card-pad { padding: 16px; }

.stat-row { display: flex; gap: 10px; margin-top: 12px; }
.stat {
  flex: 1; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px;
}
.stat .k { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 19px; font-weight: 600; margin-top: 3px; }
.stat .v.pos { color: var(--good); }
.stat .v.neg { color: var(--accent); }

/* ---------- category rows ---------- */

.cat-row {
  display: block; padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.cat-row:last-child { border-bottom: 0; }
.cat-top { display: flex; align-items: center; gap: 10px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.cat-name { flex: 1; font-weight: 500; font-size: 15px; }
.cat-amt { font-size: 14.5px; font-weight: 600; }
.cat-amt small { color: var(--muted); font-weight: 500; }
.bar {
  height: 6px; border-radius: 999px; background: var(--surface-2);
  margin-top: 9px; overflow: hidden;
}
.bar span { display: block; height: 100%; border-radius: 999px; transition: width .4s ease; }
.cat-meta { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--muted); }
.cat-meta .over { color: var(--accent); font-weight: 600; }

/* ---------- transaction list ---------- */

.day-head {
  display: flex; justify-content: space-between;
  padding: 14px 16px 6px;
  font-size: 12px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
  background: var(--surface);
}
.txn {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.txn:last-child { border-bottom: 0; }
.txn .body { flex: 1; min-width: 0; }
.txn .t1 { font-size: 15px; font-weight: 500; }
.txn .t2 { font-size: 12.5px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn .amt { font-weight: 600; font-size: 15px; white-space: nowrap; }
.txn .amt.income { color: var(--good); }

.empty { padding: 28px 20px; text-align: center; color: var(--muted); font-size: 14px; background: var(--surface); }
.empty strong { display: block; color: var(--ink); font-size: 15.5px; margin-bottom: 4px; }

/* ---------- forms ---------- */

label.f { display: block; margin-bottom: 12px; }
label.f > span {
  display: block; font-size: 12px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; margin-bottom: 5px;
}
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 12px 13px;
  font: inherit; font-size: 16px;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  appearance: none;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
html[data-theme="dark"] input:focus-visible,
html[data-theme="dark"] select:focus-visible,
html[data-theme="dark"] button:focus-visible { outline-color: var(--good); }

select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' fill='none' stroke='%235F6F6B' stroke-width='1.7'/></svg>");
  background-repeat: no-repeat; background-position: right 13px center;
  padding-right: 34px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; width: 100%;
  font: inherit; font-weight: 600; font-size: 15px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--brand); color: var(--brand-ink);
  cursor: pointer;
}
html[data-theme="dark"] .btn { background: var(--good); color: #0F1513; }
.btn:active { transform: scale(.985); }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.danger { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.btn.sm { width: auto; padding: 9px 14px; font-size: 13.5px; }
.btn-row { display: flex; gap: 10px; }

.amount-input { position: relative; }
.amount-input .cur {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-weight: 600; font-size: 15px; pointer-events: none;
}
.amount-input input {
  padding-left: 46px; font-size: 26px; font-weight: 600; padding-top: 14px; padding-bottom: 14px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 13px; border-radius: 999px; font-size: 13.5px; font-weight: 500;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer;
}
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
html[data-theme="dark"] .chip.on { background: var(--good); color: #0F1513; border-color: var(--good); }

.flash {
  margin-top: 14px; padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--brand-soft); color: var(--ink); font-size: 14px;
  border: 1px solid var(--line);
}

.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

/* ---------- sheet / modal ---------- */

.sheet-bg {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10,20,18,.45);
  display: none;
}
.sheet-bg.open { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  max-width: 620px; margin: 0 auto;
  background: var(--canvas);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 92vh; overflow-y: auto;
  transform: translateY(102%);
  transition: transform .28s cubic-bezier(.2,.8,.2,1);
  display: none;
}
.sheet.open { display: block; transform: translateY(0); }
.sheet-grab { width: 40px; height: 4px; border-radius: 999px; background: var(--line); margin: 6px auto 14px; }
.sheet h3 { font-size: 17px; margin-bottom: 14px; }

/* ---------- bottom nav + fab ---------- */

.fab {
  position: fixed; right: 18px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 14px);
  z-index: 40;
  width: 58px; height: 58px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--accent); color: #fff;
  font-size: 30px; line-height: 1; font-weight: 300;
  box-shadow: 0 6px 20px rgba(200,85,42,.4);
}
.fab:active { transform: scale(.93); }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-inner { max-width: 620px; margin: 0 auto; display: flex; }
.nav a {
  flex: 1; height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10.5px; letter-spacing: .03em; color: var(--muted); font-weight: 600;
}
.nav a svg { width: 21px; height: 21px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a.on { color: var(--brand); }
html[data-theme="dark"] .nav a.on { color: var(--good); }

/* ---------- login ---------- */

.login-wrap {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 380px; }
.login-card .mark {
  font-family: var(--font-num); font-size: 40px; line-height: 1;
  color: var(--brand); margin-bottom: 6px;
}
html[data-theme="dark"] .login-card .mark { color: var(--good); }

/* ---------- reports ---------- */

.trend { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding: 4px 2px 0; }
.trend .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.trend .pair { display: flex; align-items: flex-end; gap: 3px; width: 100%; height: 100%; justify-content: center; }
.trend .b { width: 46%; border-radius: 4px 4px 0 0; min-height: 2px; }
.trend .b.inc { background: var(--good); }
.trend .b.exp { background: var(--accent); opacity: .85; }
.trend .lab { font-size: 10.5px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.legend { display: flex; gap: 16px; margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }

table.plain { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.plain td, table.plain th { padding: 11px 16px; border-bottom: 1px solid var(--line); text-align: left; }
table.plain th { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
table.plain td.r, table.plain th.r { text-align: right; }
table.plain tr:last-child td { border-bottom: 0; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
