:root {
  --bg: #0b1220;
  --card: #151f33;
  --card2: #0f182a;
  --line: #25324d;
  --text: #eef3ff;
  --muted: #93a3c0;
  --accent: #3ddc97;
  --accent-ink: #052a1a;
  --danger: #f87171;
  --warn: #fbbf24;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); touch-action: manipulation; }
body { min-height: 100vh; padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; padding: 0; }
input, select {
  font: inherit; font-size: 16px; color: var(--text); background: var(--card2);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; width: 100%; min-height: 46px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- Шапка ---------- */
.top {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 10px;
  max-width: 700px; margin: auto; padding: calc(14px + env(safe-area-inset-top)) 16px 4px;
}
.eyebrow { letter-spacing: 2px; color: var(--accent); font-size: 11px; font-weight: 800; }
h1 { font-size: 27px; margin: 4px 0 6px; }
.cloud {
  display: flex; align-items: center; gap: 7px; background: var(--card); border: 1px solid var(--line);
  padding: 8px 12px; border-radius: 999px; font-size: 13px; color: var(--muted); margin-bottom: 8px; white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.cloud[data-state=ok] .dot { background: var(--accent); }
.cloud[data-state=busy] .dot { background: #60a5fa; animation: pulse 1s infinite alternate; }
.cloud[data-state=warn] .dot { background: var(--warn); }
.cloud[data-state=error] .dot { background: var(--danger); }

/* ---------- Загальне ---------- */
main { max-width: 700px; margin: auto; padding: 4px 16px 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 16px; margin: 12px 0; }
.card.list { padding: 2px 14px; }
.hero { background: linear-gradient(135deg, #12423a, #14213b); }
.h { font-size: 17px; margin: 0 0 6px; }
.cardhead { display: flex; justify-content: space-between; align-items: center; }
.cardhead .h { margin: 0; }
.label { color: var(--muted); font-size: 14px; }
.big { font-size: 40px; font-weight: 800; margin: 4px 0 2px; letter-spacing: -.5px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.up { color: var(--danger); display: block; margin-top: 2px; }
.down { color: var(--accent); display: block; margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.stat { background: rgba(0, 0, 0, .2); padding: 12px; border-radius: 14px; }
.stat b { display: block; font-size: 17px; margin-top: 4px; }
.summary { color: var(--muted); margin: 4px 4px 0; font-size: 14px; }
.summary b { color: var(--text); }
.subhead { color: var(--muted); font-size: 13px; font-weight: 700; margin: 16px 0 2px; text-transform: uppercase; letter-spacing: .5px; }
.empty { text-align: center; color: var(--muted); padding: 30px 14px; line-height: 1.5; }

.monthnav { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px; }
.monthnav b { font-size: 17px; }
.iconbtn { width: 42px; height: 42px; flex: none; border-radius: 12px; background: var(--card2); font-size: 22px; display: grid; place-items: center; }
.linkbtn { color: var(--accent); font-weight: 700; font-size: 14px; padding: 6px 0; }

.btn { display: block; width: 100%; padding: 15px; border-radius: 14px; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 16px; text-align: center; }
.btn:active { filter: brightness(.9); }
.btn.secondary { background: #22304b; color: var(--text); font-weight: 650; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid #5b2a33; }
.btn + .btn { margin-top: 10px; }

.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; width: 100%; text-align: left; }
.row + .row { border-top: 1px solid var(--line); }
.ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; flex: none; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; flex: none; }
.title { display: block; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { display: block; color: var(--muted); font-size: 13px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amt { font-weight: 750; white-space: nowrap; flex: none; }
.bar { display: block; height: 6px; background: var(--card2); border-radius: 99px; overflow: hidden; margin-top: 7px; }
.bar i { display: block; height: 100%; border-radius: 99px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 13px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.dayhead { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; font-weight: 700; margin: 18px 4px -4px; }

/* ---------- Навігація ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around;
  background: rgba(11, 18, 32, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); padding: 4px 10px; min-width: 84px; }
.tabbar button span { font-size: 21px; filter: grayscale(1); opacity: .65; }
.tabbar button.on { color: var(--text); }
.tabbar button.on span { filter: none; opacity: 1; }
.fab {
  position: fixed; right: 18px; bottom: calc(82px + env(safe-area-inset-bottom)); z-index: 11;
  width: 60px; height: 60px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  font-size: 34px; font-weight: 500; line-height: 1; box-shadow: 0 10px 28px rgba(61, 220, 151, .35);
}
@media (min-width: 740px) { .fab { right: calc(50% - 332px); } }

/* ---------- Нижня панель ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet[hidden] { display: none; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); animation: fade .2s; }
.panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 700px; margin: auto;
  background: #121b2d; border-radius: 24px 24px 0 0; border-top: 1px solid var(--line);
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 94vh; max-height: 94dvh; overflow-y: auto;
  overscroll-behavior: contain; animation: up .25s ease;
}
.grab { width: 40px; height: 5px; border-radius: 9px; background: #33415f; margin: 0 auto 8px; }
.panel h2 { margin: 2px 0 6px; font-size: 19px; display: flex; justify-content: space-between; align-items: center; }
.amountview { font-size: 42px; font-weight: 800; text-align: center; padding: 4px 0 12px; letter-spacing: -.5px; }
.amountview.zero { color: #4a5a7a; }
.catgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-bottom: 10px; }
.cat {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 2px; border-radius: 14px;
  background: var(--card2); border: 2px solid transparent; font-size: 11.5px; color: var(--muted); line-height: 1.15; text-align: center;
  overflow-wrap: anywhere;
}
.cat .e { font-size: 22px; }
.cat.on { border-color: var(--accent); color: var(--text); background: #12302a; }
.fields { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; margin-bottom: 10px; }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 12px; }
.numpad button { padding: 13px 0; font-size: 24px; font-weight: 600; border-radius: 14px; background: var(--card); }
.numpad button:active { background: #22304b; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.sw { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; }
.sw.on { border-color: #fff; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(156px + env(safe-area-inset-bottom)); z-index: 30;
  background: #e8fff4; color: #052a1a; padding: 10px 18px; border-radius: 999px; font-weight: 700; white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
.toast.warn { background: #fff3d6; color: #4a3200; }
.toast[hidden] { display: none; }

@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pulse { to { opacity: .35; } }
