/* Токены. Радиусы: панели 14px, поля 10px, кнопки и чипы — капсула. */
:root {
  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --bg: oklch(0.975 0.003 80);
  --surface: oklch(0.995 0.002 80);
  --surface-2: oklch(0.955 0.004 80);
  --line: oklch(0.90 0.005 80);
  --ink: oklch(0.22 0.01 70);
  --ink-2: oklch(0.42 0.01 70);
  --ink-3: oklch(0.52 0.01 70);

  --accent: oklch(0.66 0.16 52);
  --accent-ink: oklch(0.50 0.15 50);
  --accent-soft: oklch(0.93 0.04 60);
  --good: oklch(0.55 0.12 150);
  --good-soft: oklch(0.94 0.04 150);
  --warn: oklch(0.56 0.17 27);
  --warn-soft: oklch(0.94 0.035 27);

  --r-panel: 14px;
  --r-field: 10px;
  --shadow: 0 1px 2px oklch(0.3 0.02 70 / 0.06), 0 6px 24px oklch(0.3 0.02 70 / 0.06);

  --z-nav: 10;
  --z-sheet: 30;
  --z-toast: 40;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: oklch(0.17 0.005 70);
    --surface: oklch(0.21 0.006 70);
    --surface-2: oklch(0.25 0.006 70);
    --line: oklch(0.30 0.006 70);
    --ink: oklch(0.95 0.004 80);
    --ink-2: oklch(0.78 0.006 80);
    --ink-3: oklch(0.66 0.006 80);
    --accent: oklch(0.74 0.15 55);
    --accent-ink: oklch(0.80 0.13 58);
    --accent-soft: oklch(0.30 0.05 55);
    --good: oklch(0.74 0.12 150);
    --good-soft: oklch(0.28 0.04 150);
    --warn: oklch(0.72 0.15 27);
    --warn-soft: oklch(0.30 0.05 27);
    --shadow: 0 1px 2px oklch(0 0 0 / 0.3);
  }
}
:root[data-theme="dark"] {
  --bg: oklch(0.17 0.005 70);
  --surface: oklch(0.21 0.006 70);
  --surface-2: oklch(0.25 0.006 70);
  --line: oklch(0.30 0.006 70);
  --ink: oklch(0.95 0.004 80);
  --ink-2: oklch(0.78 0.006 80);
  --ink-3: oklch(0.66 0.006 80);
  --accent: oklch(0.74 0.15 55);
  --accent-ink: oklch(0.80 0.13 58);
  --accent-soft: oklch(0.30 0.05 55);
  --good: oklch(0.74 0.12 150);
  --good-soft: oklch(0.28 0.04 150);
  --warn: oklch(0.72 0.15 27);
  --warn-soft: oklch(0.30 0.05 27);
  --shadow: 0 1px 2px oklch(0 0 0 / 0.3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.15; text-wrap: balance; font-weight: 600; }
h1 { font-size: 22px; letter-spacing: -0.01em; }
h2 { font-size: 17px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- каркас ---------- */
.shell { min-height: 100dvh; }
.nav {
  position: fixed; inset: auto 0 0 0; z-index: var(--z-nav);
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in oklch, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.nav a {
  flex: 1; display: grid; place-items: center; align-content: center; gap: 2px;
  color: var(--ink-3); text-decoration: none; font-size: 11px; font-weight: 500;
  min-height: 44px;
}
.nav a svg { width: 22px; height: 22px; }
.nav a[aria-current="page"] { color: var(--ink); }
.nav a[aria-current="page"] svg { color: var(--accent); }
.nav .brand { display: none; }

.main {
  max-width: 1080px; margin: 0 auto;
  padding: 20px 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }

@media (min-width: 900px) {
  .nav {
    inset: 0 auto 0 0; width: 220px; height: 100dvh; padding: 24px 12px;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line); background: var(--surface);
  }
  .nav .brand { display: flex; align-items: center; gap: 10px; padding: 0 12px 20px; font-weight: 600; font-size: 16px; }
  .nav .brand i { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: oklch(0.99 0 0); font-style: normal; font-weight: 700; }
  .nav a { flex: none; display: flex; gap: 12px; justify-content: flex-start; padding: 10px 12px; border-radius: var(--r-field); font-size: 14px; }
  .nav a[aria-current="page"] { background: var(--surface-2); }
  .nav a:hover { color: var(--ink); }
  .main { margin-left: 220px; padding: 32px 40px 48px; max-width: none; }
  .main > * { max-width: 1040px; }
}

/* ---------- блоки ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel);
  padding: 18px;
}
.grid { display: grid; gap: 14px; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stack > * + * { margin-top: 14px; }
.label { color: var(--ink-3); font-size: 13px; font-weight: 500; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.spread { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 0 10px; }
.section-title h2 { font-size: 15px; color: var(--ink-2); font-weight: 600; }

/* главное число */
.hero { padding: 22px 20px 20px; }
.hero .big { font-size: clamp(40px, 11vw, 60px); font-weight: 600; letter-spacing: -0.03em; line-height: 1.05; margin: 6px 0 4px; }
.hero .big.neg { color: var(--warn); }
.hero .per-day { font-size: 17px; color: var(--ink-2); }
.hero .per-day b { color: var(--ink); font-weight: 600; }
.days { margin-top: 18px; }
.track { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.track > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .5s var(--ease-out); }

/* план месяца: одна полоса */
.split { display: flex; height: 10px; border-radius: 99px; overflow: hidden; gap: 2px; margin: 12px 0 10px; }
.split i { display: block; height: 100%; }
.legend { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 13px; }
.legend span { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.legend span::before { content: ""; width: 8px; height: 8px; border-radius: 3px; background: var(--c); flex: none; }
.legend b { font-weight: 500; text-align: right; }

/* метрики */
.metric .value { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; }
.metric .sub { font-size: 13px; color: var(--ink-3); margin-top: 2px; }

/* списки */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 2px; background: none; border: 0; text-align: left; min-height: 52px;
  border-radius: var(--r-field);
}
button.item:hover { background: var(--surface-2); }
button.item:active { transform: scale(0.99); }
.item .ico {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: grid; place-items: center; background: var(--surface-2); font-size: 17px;
}
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .amt { font-weight: 600; text-align: right; white-space: nowrap; }
.item .amt small { display: block; font-weight: 400; font-size: 12px; color: var(--ink-3); }
.amt.in { color: var(--good); }
.amt.neutral { color: var(--ink-3); font-weight: 500; }
.dot-pending { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); display: inline-block; margin-right: 6px; vertical-align: 1px; }

.day-head { display: flex; justify-content: space-between; padding: 16px 2px 4px; font-size: 13px; color: var(--ink-3); font-weight: 500; }

/* бары категорий */
.bars { display: grid; gap: 12px; }
.bar-row { display: grid; gap: 6px; background: none; border: 0; padding: 0; text-align: left; width: 100%; }
.bar-row .spread { font-size: 14px; }
.bar-row .spread b { font-weight: 600; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--ink-2); opacity: .85; }
.bar-row.top .bar > i { background: var(--accent); opacity: 1; }
.subrows { display: grid; gap: 6px; padding: 4px 0 6px 14px; border-left: 2px solid var(--line); margin-left: 4px; font-size: 13px; color: var(--ink-2); }

/* чипы и кнопки */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 99px; padding: 7px 14px; font-size: 14px; font-weight: 500; min-height: 36px;
  transition: background-color .15s var(--ease-out), color .15s var(--ease-out);
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip:active { transform: scale(0.97); }
.btn {
  border: 0; border-radius: 99px; padding: 10px 18px; font-weight: 600; min-height: 44px;
  background: var(--ink); color: var(--bg);
}
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: var(--warn-soft); color: var(--warn); }
.btn:active { transform: scale(0.97); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center;
}
.icon-btn svg { width: 18px; height: 18px; }

.month-switch { display: flex; align-items: center; gap: 8px; }
.month-switch b { min-width: 128px; text-align: center; font-weight: 600; }

.search {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-field);
  padding: 10px 14px; min-height: 44px;
}
.search::placeholder { color: var(--ink-3); }

.notice {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--accent-soft); color: var(--ink); border: 0; border-radius: var(--r-panel); padding: 14px 16px;
}
.notice b { font-weight: 600; }
.notice.warn { background: var(--warn-soft); }

.badge { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.badge.accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* график по месяцам */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--ink-3); font-size: 11px; font-family: var(--font); }
.chart .grid-line { stroke: var(--line); }
.chart .inc { stroke: var(--good); stroke-width: 2; fill: none; }
.chart .inc-dot { fill: var(--good); }
.chart rect { transition: opacity .15s; }
.chart g.col:hover rect { opacity: .8; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); margin-top: 10px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend span::before { content: ""; width: 8px; height: 8px; border-radius: 3px; background: var(--c); }

/* нижний лист (детали операции) */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 88dvh;
  background: var(--surface); color: var(--ink); border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
}
dialog.sheet[open] { animation: sheet-in .28s var(--ease-out); }
dialog.sheet::backdrop { background: oklch(0.1 0 0 / 0.45); animation: fade-in .2s var(--ease-out); }
.sheet-body { padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 88dvh; }
.grabber { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 0 auto 14px; }
@media (min-width: 900px) {
  dialog.sheet { margin: auto; border-radius: 18px; }
  dialog.sheet[open] { animation: pop-in .2s var(--ease-out); }
}
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.cat-grid button {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-field);
  padding: 10px 12px; text-align: left; min-height: 44px; font-size: 14px;
}
.cat-grid button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; text-align: right; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: var(--z-toast);
  transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow); animation: toast-in .22s var(--ease-out);
  max-width: calc(100vw - 32px);
}
@media (min-width: 900px) { .toast { bottom: 24px; left: calc(50% + 110px); } }

.empty { padding: 32px 8px; text-align: center; color: var(--ink-3); }
.skeleton { height: 120px; border-radius: var(--r-panel); background: var(--surface-2); animation: pulse 1.2s ease-in-out infinite; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; text-align: center; }
.login .panel { max-width: 380px; }
.login p { color: var(--ink-2); }

@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop-in { from { transform: scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes toast-in { from { transform: translate(-50%, 8px); opacity: 0; } }
@keyframes pulse { 50% { opacity: .55; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  button:active, .chip:active, .btn:active { transform: none !important; }
}
