:root {
  --bg: #f4f6f5; --card: #ffffff; --text: #14231b; --muted: #6b7c73; --line: #e3e9e5;
  --green: #3ecf8e; --green-d: #25a972; --green-t: #1a9a65; --ink-g: #06301e; --green-l: #e3f8ee; --red: #d93a3a; --red-l: #fdeaea;
  --amber: #b7791f; --amber-l: #fdf3df; --radius: 16px; --shadow: 0 1px 2px rgba(15,40,25,.06), 0 4px 16px rgba(15,40,25,.05);
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1512; --card: #17211c; --text: #e8f1ec; --muted: #8fa398; --line: #25322b;
    --green: #3ecf8e; --green-d: #25a972; --green-t: #3ecf8e; --ink-g: #06301e; --green-l: #12281d; --red: #ff6b6b; --red-l: #2d1717;
    --amber: #f0b45a; --amber-l: #2b2210; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.income { color: var(--green-t); } .expense { color: var(--red); }

/* ───── каркас ───── */
.shell { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: -.3px; }
.logo svg { width: 28px; height: 28px; }
.page { max-width: 760px; margin: 0 auto; padding: 16px; }
.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); }
.nav button { flex: 1; background: none; border: 0; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: 11px; cursor: pointer; }
.nav button .ic { font-size: 21px; line-height: 1; }
.nav button.active { color: var(--green-t); font-weight: 700; }
@media (min-width: 900px) {
  .shell { padding-bottom: 24px; padding-left: 220px; }
  .nav { top: 0; bottom: auto; right: auto; width: 220px; height: 100vh; flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--line); padding: 76px 12px 12px; gap: 4px; }
  .nav button { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 15px; padding: 12px 14px; border-radius: 12px; }
  .nav button.active { background: var(--green-l); }
  .topbar { padding-left: 236px; }
  .page { padding-top: 24px; }
}

/* ───── карточки и текст ───── */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h3 { font-size: 15px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.title { font-size: 22px; font-weight: 800; margin: 4px 0 14px; letter-spacing: -.3px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
.stat small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.stat b { font-size: 17px; letter-spacing: -.3px; white-space: nowrap; }
.balance-card { background: linear-gradient(135deg, var(--green), var(--green-d)); color: var(--ink-g); border-radius: 20px; padding: 18px; margin-bottom: 12px; box-shadow: var(--shadow); }
.balance-card small { opacity: .85; } .balance-card .big { font-size: 32px; font-weight: 800; letter-spacing: -1px; margin: 2px 0 8px; }
.balance-card .sub { display: flex; gap: 18px; font-size: 14px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--green-l); color: var(--green-t); }
.badge.warn { background: var(--amber-l); color: var(--amber); }

/* ───── формы ───── */
input, select, textarea { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--card); outline: none; transition: border-color .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--green); }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 5px; font-weight: 600; }
.btn { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; cursor: pointer; background: var(--green); color: var(--ink-g); transition: transform .05s, opacity .15s; }
.btn:active { transform: scale(.98); } .btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: var(--green-l); color: var(--green-t); }
.btn.danger { background: var(--red-l); color: var(--red); }
.btn.plain { background: transparent; color: var(--muted); border: 1.5px solid var(--line); }
.btn.block { width: 100%; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 99px; border: 1.5px solid var(--line); background: var(--card); cursor: pointer; font-size: 14px; white-space: nowrap; }
.chip.active { background: var(--green); border-color: var(--green); color: var(--ink-g); font-weight: 700; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: none; padding: 10px; border-radius: 9px; font-weight: 700; cursor: pointer; color: var(--muted); }
.seg button.on-expense { background: var(--red-l); color: var(--red); }
.seg button.on-income { background: var(--green-l); color: var(--green-t); }

/* быстрый ввод */
.quick { display: flex; gap: 8px; align-items: center; }
.quick input { flex: 1; }
.icon-btn { flex: none; width: 46px; height: 46px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); font-size: 20px; cursor: pointer; display: grid; place-items: center; }
.icon-btn.rec { background: var(--red); border-color: var(--red); color: #fff; animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.hint { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* список операций */
.tx { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.tx:last-child { border-bottom: 0; }
.tx .ico { flex: none; width: 40px; height: 40px; border-radius: 12px; background: var(--bg); display: grid; place-items: center; font-size: 20px; }
.tx .meta { flex: 1; min-width: 0; }
.tx .meta b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .meta small { color: var(--muted); }
.tx .sum { font-weight: 700; white-space: nowrap; }
.day-head { font-size: 13px; color: var(--muted); font-weight: 700; margin: 14px 4px 2px; text-transform: capitalize; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }

/* графики */
.legend { margin-top: 10px; }
.legend-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 15px; }
.dot { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.bar-bg { height: 6px; background: var(--bg); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar-fill { height: 100%; border-radius: 4px; }
.donut-wrap { display: flex; justify-content: center; }
.daybars { width: 100%; height: 150px; }

/* модальные окна */
.overlay { position: fixed; inset: 0; background: rgba(8,16,12,.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 520px; border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; animation: up .18s ease-out; }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 22px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet h2 { font-size: 20px; margin-bottom: 8px; }
.fab { position: fixed; right: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--green); color: var(--ink-g); font-size: 30px; box-shadow: 0 6px 20px rgba(62,207,142,.45); cursor: pointer; z-index: 25; }
@media (min-width: 900px) { .fab { bottom: 28px; right: 28px; } }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 84px); transform: translate(-50%, 20px); background: #14231b; color: #fff; padding: 11px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 80; max-width: 92vw; display: flex; gap: 14px; align-items: center; font-size: 15px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { background: none; border: 0; color: #7dffb4; font-weight: 700; cursor: pointer; }
#toast.err { background: var(--red); }

/* авторизация */
.auth { max-width: 420px; margin: 0 auto; padding: 8vh 20px 30px; }
.auth .hero { text-align: center; margin-bottom: 22px; }
.auth .hero svg { width: 64px; height: 64px; }
.auth .hero h1 { font-size: 30px; margin: 8px 0 4px; letter-spacing: -.8px; }
.features { list-style: none; padding: 0; margin: 14px 0 0; color: var(--muted); font-size: 14px; }
.features li { padding: 4px 0; }
.error { color: var(--red); font-size: 14px; margin-top: 10px; min-height: 18px; }
.pay-plan { border: 2px solid var(--green); border-radius: 16px; padding: 14px; background: var(--green-l); }
.pay-plan ul { margin: 8px 0 12px; padding-left: 20px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .7s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.ai-answer { white-space: pre-wrap; line-height: 1.55; }
.credit-out { margin-top: 12px; padding: 12px; background: var(--bg); border-radius: 12px; font-size: 15px; }
.item-check { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.item-check input[type=checkbox] { width: 20px; height: 20px; flex: none; }
