/* ── fonts ──────────────────────────────────────────────────────────────── */
@font-face {
  font-family: 'Geist'; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url('/fonts/geist-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
                 U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
                 U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Geist'; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url('/fonts/geist-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Geist Mono'; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url('/fonts/geist-mono-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
                 U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
                 U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Geist Mono'; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url('/fonts/geist-mono-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

/* ── tokens ─────────────────────────────────────────────────────────────── */
:root {
  --bg:        #ffffff;
  --bg-2:      #fafafa;
  --fg:        #000000;
  --gray-100:  #f2f2f2;
  --gray-200:  #ebebeb;
  --gray-400:  #a1a1a1;
  --gray-600:  #666666;
  --green:     #0a7d3f;
  --red:       #d93036;
  --dim:       #e8e8e8;
  --sans: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --pad: 20px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #0a0a0a;
    --bg-2:     #000000;
    --fg:       #ededed;
    --gray-100: #1a1a1a;
    --gray-200: #262626;
    --gray-400: #6b6b6b;
    --gray-600: #a1a1a1;
    --green:    #3ecf7f;
    --red:      #ff6369;
    --dim:      #2b2b2b;
    color-scheme: dark;
  }
}

/* ── base ───────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
body { min-height: 100dvh; }

button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
input  { background: none; border: 0; outline: none; }
ul { margin: 0; padding: 0; list-style: none; }
[hidden] { display: none !important; }

.num { font-family: var(--mono); font-variant-numeric: tabular-nums;
       font-feature-settings: 'tnum' 1; letter-spacing: -0.02em; }

/* ── lock ───────────────────────────────────────────────────────────────── */
.lock {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: var(--pad);
}
.lock-form { display: grid; gap: 16px; width: 100%; max-width: 260px; text-align: center; }
.pin {
  width: 100%;
  font-family: var(--mono);
  font-size: 34px;
  letter-spacing: 0.34em;
  text-align: center;
  text-indent: 0.34em;   /* balance the trailing letter-space */
  padding: 18px 0;
  background: var(--gray-100);
  border-radius: 8px;
}
.lock-error { margin: 0; font-size: 14px; color: var(--red); }

/* ── app shell ──────────────────────────────────────────────────────────── */
.app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) var(--pad)
           calc(env(safe-area-inset-bottom) + 92px);   /* clears the tab bar */
}

/* ── kind toggle ────────────────────────────────────────────────────────── */
.kind {
  position: relative;
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--gray-100);
  border-radius: 8px;
  padding: 3px;
}
.kind-btn {
  position: relative; z-index: 1;
  padding: 9px 0;
  font-size: 14px; font-weight: 500;
  color: var(--gray-600);
  transition: color .18s ease;
}
.kind-btn.is-active { color: var(--fg); }
.kind-thumb {
  position: absolute; z-index: 0;
  inset: 3px auto 3px 3px;
  width: calc(50% - 3px);
  background: var(--bg);
  border-radius: 6px;
  transition: transform .22s cubic-bezier(.32, .72, 0, 1);
}
.kind[data-kind="income"] .kind-thumb { transform: translateX(100%); }

/* ── amount ─────────────────────────────────────────────────────────────── */
.amount { padding: 34px 0 8px; text-align: center; }
.amount-row {
  display: flex; align-items: baseline; justify-content: center; gap: 2px;
}
.amount-sign {
  font-family: var(--mono);
  font-size: clamp(52px, 17vw, 72px);
  font-weight: 500;
  letter-spacing: -0.045em;
  color: var(--gray-400);
  transition: color .18s ease, opacity .15s ease;
}
.amount-input {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(52px, 17vw, 72px);
  font-weight: 500;
  letter-spacing: -0.045em;
  word-spacing: -0.32em;
  text-align: left;
  width: 1ch;          /* JS sizes this to the content, in mono ch units */
  max-width: 100%;
  padding: 0;
}
.amount-input::placeholder { color: var(--dim); }
.amount-row:has(.amount-input:placeholder-shown) .amount-sign { opacity: 0; }
.app[data-kind="income"] .amount-sign { color: var(--green); }
.app[data-kind="income"] .amount-input { color: var(--green); }

.converted {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: 15px;
  color: var(--gray-400);
  min-height: 21px;
}

/* ── pills ──────────────────────────────────────────────────────────────── */
.pills { display: flex; gap: 6px; }
.pills-scroll {
  overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(var(--pad) * -1); padding: 4px var(--pad) 6px;
  scroll-snap-type: x proximity;
}
.pills-scroll::-webkit-scrollbar { display: none; }
.pills-wrap { flex-wrap: wrap; row-gap: 8px; padding: 16px 0 6px; }

.pill {
  flex: 0 0 auto;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--gray-100);
  color: var(--gray-600);
  font-size: 14px; font-weight: 500;
  white-space: nowrap;
  scroll-snap-align: center;
  transition: background .15s ease, color .15s ease;
}
.pill.is-active { background: var(--fg); color: var(--bg); }
.pill:active { opacity: .7; }

/* ── name ───────────────────────────────────────────────────────────────── */
.name-input {
  width: 100%;
  margin-top: 14px;
  padding: 14px 0;
  font-size: 17px;
  border-bottom: 1px solid var(--gray-200);
  border-radius: 0;
}
.name-input::placeholder { color: var(--gray-400); }

/* ── when ───────────────────────────────────────────────────────────────── */
.when { display: flex; gap: 6px; margin-top: 18px; }
.when-btn {
  flex: 1;
  padding: 10px 0;
  border-radius: 8px;
  background: var(--gray-100);
  color: var(--gray-600);
  font-size: 14px; font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.when-btn.is-active { background: var(--fg); color: var(--bg); }
.when-pick { position: relative; overflow: hidden; }
.when-pick input[type="date"] {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  -webkit-appearance: none; appearance: none;
}

/* ── buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: block; width: 100%;
  padding: 15px 0;
  border-radius: 8px;
  font-size: 15px; font-weight: 500;
  text-align: center;
  transition: opacity .15s ease, background .15s ease;
}
.btn-primary { background: var(--fg); color: var(--bg); }
.btn-primary:active { opacity: .8; }
.btn-primary:disabled { opacity: .3; }
.btn-ghost { background: none; color: var(--gray-600); font-size: 14px; padding: 14px 0; }
.btn-submit { margin-top: 24px; }
.btn-submit.is-done { background: var(--green); color: #fff; }

/* ── ledger ─────────────────────────────────────────────────────────────── */
.ledger { margin-top: 40px; }
.ledger-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-200);
}
.ledger-month {
  font-size: 13px; font-weight: 500;
  color: var(--gray-400);
}
.ledger-totals { display: flex; gap: 12px; font-family: var(--mono); font-size: 14px; }
.t-expense { font-weight: 500; }
.t-income  { font-weight: 500; color: var(--green); }
.t-income:empty { display: none; }

.entries { padding-top: 2px; }
.entry {
  display: flex; align-items: baseline; gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--gray-200);
}
.entry-main { flex: 1; min-width: 0; }
.entry-name {
  display: block;
  font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.entry-meta { font-size: 13px; color: var(--gray-400); }
.entry-amount { font-family: var(--mono); font-size: 15px; white-space: nowrap; }
.entry.is-income .entry-amount { color: var(--green); }
.entry-del {
  padding: 0 0 0 4px;
  font-size: 15px;
  /* Invisible but still laid out, so the row does not jump when it opens —
     pointer-events keeps a stray tap on the right edge from deleting. */
  opacity: 0; pointer-events: none;
  transition: opacity .15s ease;
}
.entry.is-open .entry-del { opacity: 1; pointer-events: auto; color: var(--red); }
.entry-day { padding: 22px 0 6px; font-size: 13px; color: var(--gray-400); }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}
.entry.is-new { animation: slide-in .28s cubic-bezier(.32, .72, 0, 1); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ── tabs ───────────────────────────────────────────────────────────────── */
.tabs {
  position: fixed; z-index: 10;
  left: 0; right: 0; bottom: 0;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--gray-200);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs-inner {
  display: grid; grid-template-columns: 1fr 1fr;
  max-width: 480px; margin: 0 auto;
  padding: 0 var(--pad);
}
.tab {
  padding: 13px 0 12px;
  font-size: 13px; font-weight: 500;
  color: var(--gray-400);
  transition: color .15s ease;
}
.tab.is-active { color: var(--fg); }

/* ── table view ─────────────────────────────────────────────────────────── */
.years { margin-top: 4px; }
.year + .year { margin-top: 34px; }
.year-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 24px 0 11px;
  border-bottom: 1px solid var(--gray-200);
}
.year-name  { font-family: var(--mono); font-size: 13px; color: var(--gray-400); }
.year-total { font-family: var(--mono); font-size: 15px; font-weight: 500; }

.month { border-bottom: 1px solid var(--gray-200); }
.month-head {
  display: flex; align-items: baseline; gap: 10px;
  width: 100%; padding: 15px 0; text-align: left;
}
.month-main  { flex: 1; display: flex; align-items: baseline; gap: 8px; }
.month-name  { font-size: 15px; }
.month-count { font-family: var(--mono); font-size: 12px; color: var(--gray-400); }
.month-total { font-family: var(--mono); font-size: 15px; }
.month-chev {
  width: 10px;
  font-size: 15px; color: var(--gray-400);
  transition: transform .2s cubic-bezier(.32, .72, 0, 1);
}
.month.is-open .month-chev { transform: rotate(90deg); }
.month.is-open .month-name { font-weight: 500; }

.month-body { padding: 0 0 18px; }
.cat { padding-top: 14px; }
.cat-head {
  display: flex; align-items: baseline; gap: 10px;
  width: 100%; text-align: left;
}
.cat-name  { flex: 1; font-size: 14px; color: var(--gray-600); }
.cat-share { font-family: var(--mono); font-size: 12px; color: var(--gray-400); }
.cat-total { font-family: var(--mono); font-size: 14px; }
.cat.is-open .cat-name { color: var(--fg); }

.cat-bar {
  height: 2px; margin-top: 8px; border-radius: 2px;
  background: var(--gray-200);
}
.cat-bar > i {
  display: block; height: 100%; border-radius: 2px;
  background: var(--fg);
  transition: width .3s cubic-bezier(.32, .72, 0, 1);
}

.cat-entries { padding: 4px 0 2px; }
.cat-entry {
  display: flex; align-items: baseline; gap: 10px;
  padding: 8px 0 0;
  font-size: 13px;
}
.cat-entry-name {
  flex: 1; min-width: 0;
  color: var(--gray-600);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cat-entry-date   { font-family: var(--mono); font-size: 12px; color: var(--gray-400); }
.cat-entry-amount { font-family: var(--mono); color: var(--gray-600); }

/* Income reads green wherever it is totalled. */
#view-table[data-kind="income"] .year-total,
#view-table[data-kind="income"] .month-total,
#view-table[data-kind="income"] .cat-total { color: var(--green); }
#view-table[data-kind="income"] .cat-bar > i { background: var(--green); }

.empty { padding: 72px 0; text-align: center; font-size: 14px; color: var(--gray-400); }
