@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  color-scheme: dark;
  --bg: #0a0a0a;
  --bg-panel: #111111;
  --bg-raised: #161616;
  --border: #262220;
  --accent: #c1392b;
  --accent-hover: #e14b3a;
  --text: #ece7dc;
  --text-muted: #8f8a82;
  --text-dim: #635f59;
  --ok: #7fe6a0;
  --ok-bg: #16241a;
  --bad: #ff9188;
  --bad-bg: #2a1210;
  --warn: #e0b64f;
  --warn-bg: #2e2410;
  --info: #5fc3ff;
  --info-bg: #142530;
  --s-in: #4a86d4;
  --s-out: #d0473a;
  --s-dep: #bb7f28;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
}
a { color: var(--accent-hover); text-decoration: none; }
code, .mono { font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; font-size: 12px; color: var(--text-muted); }

/* ---------- header */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px 10px;
  background: rgba(10,10,10,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-family: 'Cormorant Garamond', serif; font-weight: 700; font-size: 17px; line-height: 1; letter-spacing: 1px; }
.brand .no-seo { color: var(--accent); display: block; }
.brand .kicker { display: block; color: var(--accent); font-family: 'Inter', sans-serif; font-size: 8px; letter-spacing: 2px; margin-top: 3px; font-weight: 600; }
.top h1 { flex: 1; margin: 0; font-family: 'Cormorant Garamond', serif; font-size: 24px; font-weight: 700; letter-spacing: .3px; text-align: right; }
.icon-btn { background: transparent; border: 1px solid var(--border); color: var(--text-muted); width: 34px; height: 34px; border-radius: 8px; padding: 0; margin: 0; font-size: 16px; display: grid; place-items: center; cursor: pointer; }

main { padding: 14px 16px 0; max-width: 960px; margin: 0 auto; min-width: 0; overflow-x: clip; }
.top h1, .brand { white-space: nowrap; }

/* ---------- tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--bg-panel); border-top: 1px solid var(--border);
}
.tabbar button {
  background: none; border: 0; margin: 0; padding: 8px 0 6px; border-radius: 0;
  color: var(--text-dim); font-size: 10.5px; font-weight: 600; letter-spacing: .3px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; position: relative;
}
.tabbar button .ic { font-size: 19px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--text); }
.tabbar button.active .ic { filter: none; opacity: 1; }
.tabbar button.active::before { content: ''; position: absolute; top: -1px; left: 28%; right: 28%; height: 2px; background: var(--accent); border-radius: 2px; }
.tabbar .dot { position: absolute; top: 5px; left: calc(50% + 8px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 100px; background: var(--accent); color: #fff; font-size: 10px; line-height: 16px; }

/* ---------- cards */
.card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.card h2 { margin: 0 0 10px; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1.2px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card h2 .r { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text-muted); font-size: 12px; }
.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.small { font-size: 12px; }
.empty { color: var(--text-dim); text-align: center; padding: 28px 8px; }

/* ---------- KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; min-width: 0; }
.tile .lbl { color: var(--text-muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; }
.tile .val { font-family: 'Cormorant Garamond', serif; font-size: 26px; font-weight: 700; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .sub { color: var(--text-dim); font-size: 11.5px; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

/* ---------- chips / segmented */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; background: var(--bg-raised); border: 1px solid var(--border); color: var(--text-muted); border-radius: 100px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; margin: 0; cursor: pointer; white-space: nowrap; }
.chip.active { background: rgba(193,57,43,.16); border-color: var(--accent); color: var(--text); }
.chip .n { color: var(--text-dim); margin-left: 4px; font-weight: 500; }
.chip.active .n { color: var(--bad); }

.filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-bottom: 12px; }
.filters select, .filters input { width: 100%; min-width: 0; }

/* ---------- forms */
input, select, textarea, button { font: inherit; background: var(--bg-raised); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 10px 11px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%); background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
textarea { resize: vertical; min-height: 70px; }
label { display: block; margin: 12px 0 5px; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .6px; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.row3 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 8px; }
.full { width: 100%; }
.btn { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.btn:active { background: var(--accent-hover); }
.btn.secondary { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn.danger { background: transparent; border-color: #5a2520; color: var(--bad); }
.btns { display: flex; gap: 8px; margin-top: 16px; }
.btns .btn { flex: 1; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg-raised); border: 1px solid var(--border); border-radius: 8px; padding: 3px; gap: 3px; }
.seg button { margin: 0; border: 0; background: transparent; color: var(--text-muted); padding: 7px 4px; border-radius: 6px; font-weight: 600; font-size: 13px; cursor: pointer; }
.seg button.active { background: var(--accent); color: #fff; }
.seg.in button.active[data-v="income"] { background: #1d3a2a; color: var(--ok); }

/* ---------- task list */
.task { display: flex; gap: 12px; align-items: flex-start; padding: 12px 2px; border-bottom: 1px solid var(--border); }
.task:last-child { border-bottom: 0; }
.check { flex: 0 0 22px; width: 22px; height: 22px; margin: 1px 0 0; padding: 0; border-radius: 50%; border: 2px solid var(--text-dim); background: transparent; cursor: pointer; display: grid; place-items: center; color: transparent; font-size: 12px; }
.check.p1 { border-color: var(--accent-hover); }
.check.p2 { border-color: var(--warn); }
.task.done .check { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.task .body { flex: 1; min-width: 0; cursor: pointer; }
.task .title { font-weight: 500; word-wrap: break-word; }
.task.done .title { color: var(--text-dim); text-decoration: line-through; }
.task .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; font-size: 11.5px; color: var(--text-muted); }
.task .notes { color: var(--text-dim); font-size: 12px; margin-top: 3px; white-space: pre-line; max-height: 3.2em; overflow: hidden; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 100px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; background: var(--bg-raised); color: var(--text-muted); border: 1px solid var(--border); }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.group-h { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1.4px; font-weight: 600; margin: 16px 2px 2px; }

/* ---------- transactions */
.tx { display: flex; gap: 12px; align-items: center; padding: 11px 2px; border-bottom: 1px solid var(--border); cursor: pointer; }
.tx:last-child { border-bottom: 0; }
.tx .ico { flex: 0 0 36px; height: 36px; border-radius: 10px; background: var(--bg-raised); border: 1px solid var(--border); display: grid; place-items: center; font-size: 17px; }
.tx .body { flex: 1; min-width: 0; }
.tx .t1 { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .t2 { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { font-weight: 600; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.tx .amt .o { display: block; font-size: 11px; color: var(--text-dim); font-weight: 500; }
.day-h { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; font-weight: 600; margin: 14px 2px 0; }

/* ---------- budget bar */
.bar { height: 8px; background: var(--bg-raised); border-radius: 100px; overflow: hidden; margin: 8px 0 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 100px; }
.bar.ok > i { background: #3f9f68; }

/* ---------- tables */
.tbl-wrap { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; cursor: pointer; user-select: none; }
th.sorted { color: var(--text); }
td.n, th.n { text-align: right; }
tr:last-child td { border-bottom: none; }
tbody tr:active { background: rgba(255,255,255,.03); }
td.key { max-width: 170px; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
tfoot td { color: var(--text-muted); font-weight: 600; border-top: 1px solid var(--border); border-bottom: 0; }

.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--text-muted); }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.kv.total { border-top: 1px solid var(--border); margin-top: 4px; }
.kv.total .k { color: var(--text); font-weight: 600; }

.chart-box { position: relative; height: 220px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); margin: 0 0 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------- FAB */
.fab { position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 25; width: 54px; height: 54px; border-radius: 50%; margin: 0; padding: 0; background: var(--accent); border: 0; color: #fff; font-size: 28px; line-height: 1; box-shadow: 0 10px 28px rgba(193,57,43,.35), 0 2px 8px rgba(0,0,0,.6); cursor: pointer; }

/* ---------- bottom sheet */
.sheet-bg { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); opacity: 0; transition: opacity .2s; }
.sheet-bg.open { opacity: 1; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 92vh; overflow-y: auto; background: var(--bg-panel); border-top: 1px solid var(--border); border-radius: 16px 16px 0 0; padding: 8px 16px calc(20px + var(--safe-b)); transform: translateY(100%); transition: transform .25s cubic-bezier(.2,.8,.2,1); max-width: 720px; margin: 0 auto; }
.sheet.open { transform: none; }
.sheet .grip { width: 38px; height: 4px; background: var(--border); border-radius: 4px; margin: 2px auto 10px; }
.sheet h3 { font-family: 'Cormorant Garamond', serif; font-size: 22px; margin: 0 0 4px; }

/* ---------- toast */
.toast { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 80; background: var(--bg-panel); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 14px; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.6); max-width: calc(100% - 32px); }
.toast.ok { border-left-color: var(--ok); }

.gate { padding: 80px 24px; text-align: center; }
.gate .brand { font-size: 34px; margin-bottom: 18px; }
.spin { color: var(--text-dim); text-align: center; padding: 40px 0; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.renew-group { padding: 10px 0; border-bottom: 1px solid var(--border); }
.renew-group:last-child { border-bottom: 0; }
.renew-group .doms { font-size: 12px; color: var(--text-dim); margin-top: 4px; word-break: break-all; }
.seg-wrap { margin-bottom: 12px; }
