:root {
  --bg: #f1e8d6;
  --bg-2: #e9dcc3;
  --surface: #faf5ea;
  --surface-2: #f3eadb;
  --line: #e0d0b0;
  --ink: #3a2c17;
  --ink-2: #5c4a2f;
  --muted: #86704d;
  --gold: #b3843a;
  --gold-deep: #8a6424;
  --gold-soft: #ead6a8;
  --gold-glow: rgba(179, 132, 58, .18);
  --ok: #5f8445;
  --ok-soft: #dfe8cf;
  --warn: #bb7a25;
  --warn-soft: #f4e0bf;
  --bad: #a94a35;
  --bad-soft: #f2d5cb;
  --shadow: 0 1px 2px rgba(80, 55, 20, .06), 0 8px 24px rgba(80, 55, 20, .08);
  --shadow-lg: 0 24px 60px rgba(60, 40, 10, .22);
  --r: 18px;
  --r-sm: 12px;
  --serif: "Playfair Display", Georgia, serif;
  --sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17130d; --bg-2: #1f1a12; --surface: #241e15; --surface-2: #2d261b; --line: #3d3324;
    --ink: #f2e7d2; --ink-2: #dccdb0; --muted: #a8946f; --gold: #d6aa5c; --gold-deep: #e8c47f;
    --gold-soft: #4a3a1f; --gold-glow: rgba(214, 170, 92, .16);
    --ok: #9cc27d; --ok-soft: #2c3522; --warn: #e2a453; --warn-soft: #3e2f19; --bad: #e0876f; --bad-soft: #402520;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17130d; --bg-2: #1f1a12; --surface: #241e15; --surface-2: #2d261b; --line: #3d3324;
  --ink: #f2e7d2; --ink-2: #dccdb0; --muted: #a8946f; --gold: #d6aa5c; --gold-deep: #e8c47f;
  --gold-soft: #4a3a1f; --gold-glow: rgba(214, 170, 92, .16);
  --ok: #9cc27d; --ok-soft: #2c3522; --warn: #e2a453; --warn-soft: #3e2f19; --bad: #e0876f; --bad-soft: #402520;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans); color: var(--ink); background: var(--bg);
  background-image: radial-gradient(1200px 600px at 100% -10%, var(--gold-glow), transparent 60%),
                    radial-gradient(900px 500px at -10% 110%, var(--gold-glow), transparent 60%);
  background-attachment: fixed; font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold-deep); }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0; letter-spacing: .2px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.boot { min-height: 100vh; display: grid; place-items: center; }

/* ---------- crest / brand ---------- */
.crest {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; flex: none;
  font-family: var(--serif); font-weight: 700; color: #fff8e8; font-size: 17px; letter-spacing: .5px;
  background: linear-gradient(145deg, #d6ab5f, #9a6f2b); box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 6px 16px rgba(154,111,43,.35);
}
.crest.big { width: 76px; height: 76px; border-radius: 22px; font-size: 30px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand b { font-family: var(--serif); font-size: 19px; display: block; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 12px; letter-spacing: 1.6px; text-transform: uppercase; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 26px 18px; display: flex; flex-direction: column; gap: 28px;
  border-right: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 70%, transparent); backdrop-filter: blur(8px);
}
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; text-decoration: none;
  color: var(--ink-2); font-weight: 500; transition: background .15s, color .15s;
}
.nav a svg { width: 20px; height: 20px; flex: none; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--gold-soft); color: var(--gold-deep); font-weight: 600; }
.side .me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; background: var(--surface-2); }
.side .me .grow { min-width: 0; flex: 1; }
.side .me b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .me small { color: var(--muted); font-size: 12px; }

main { padding: 30px 36px 60px; max-width: 1180px; width: 100%; }
.topline { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.topline h1 { font-size: 30px; }
.topline .sub { color: var(--muted); margin-top: 4px; }
.eyebrow { font-size: 12px; letter-spacing: 1.8px; text-transform: uppercase; color: var(--gold); font-weight: 600; margin-bottom: 6px; }

.mobile-top, .bottom-nav { display: none; }

/* ---------- cards ---------- */
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g2 { grid-template-columns: 1.35fr 1fr; }
.g2e { grid-template-columns: 1fr 1fr; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { font-size: 18px; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card h3 .link { font-family: var(--sans); font-size: 13px; font-weight: 500; color: var(--gold-deep); text-decoration: none; cursor: pointer; background: none; border: 0; padding: 0; }
.section { margin-top: 16px; }

.stat { position: relative; overflow: hidden; }
.stat .k { color: var(--muted); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 8px; letter-spacing: -.3px; }
.stat .s { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.stat .ico { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); font-size: 15px; }
.stat.hero { background: linear-gradient(150deg, #c89a4c 0%, #9c722e 100%); color: #fff9ec; border-color: transparent; }
.stat.hero .k, .stat.hero .s { color: rgba(255, 246, 225, .85); }
.stat.hero .ico { background: rgba(255,255,255,.18); }
.stat.hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 140px; height: 140px; border-radius: 50%; border: 22px solid rgba(255,255,255,.08); }
.pos { color: var(--ok); } .neg { color: var(--bad); }
.stat.hero .pos, .stat.hero .neg { color: inherit; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface);
  padding: 10px 16px; border-radius: 12px; cursor: pointer; font-weight: 600; font-size: 14px; transition: transform .08s, background .15s, box-shadow .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.gold { background: linear-gradient(150deg, #c99c4f, #a0752f); color: #fff9ec; border-color: transparent; box-shadow: 0 6px 16px rgba(160,117,47,.3); }
.btn.gold:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn svg { width: 18px; height: 18px; }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }

label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.in, select.in, textarea.in {
  width: 100%; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); outline: none; transition: border .15s, box-shadow .15s;
}
textarea.in { resize: vertical; min-height: 70px; }
.in:focus { border-color: var(--gold); box-shadow: 0 0 0 4px var(--gold-glow); background: var(--surface); }
.in.big { font-size: 26px; font-weight: 700; padding: 14px 16px; }
.row { display: flex; gap: 12px; } .row > * { flex: 1; min-width: 0; }
.err { color: var(--bad); font-size: 13.5px; min-height: 20px; margin: 4px 0 8px; }

.seg { display: inline-flex; padding: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg.full { display: flex; } .seg.full button { flex: 1; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px 6px 6px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 13.5px; font-weight: 500; }
.chip.plain { padding-left: 12px; }
.chip.on { background: var(--gold-soft); border-color: var(--gold); color: var(--gold-deep); font-weight: 600; }
.pick { display: flex; gap: 8px; flex-wrap: wrap; }
.pick button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 8px 12px; cursor: pointer; font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px; }
.pick button.on { border-color: var(--gold); background: var(--gold-soft); color: var(--gold-deep); font-weight: 600; }

/* ---------- avatar ---------- */
.av { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 16px; flex: none; background: var(--c, var(--gold-soft)); box-shadow: 0 0 0 2px var(--surface); }
.av.lg { width: 48px; height: 48px; font-size: 24px; }
.av.xl { width: 64px; height: 64px; font-size: 32px; }
.av.sm { width: 24px; height: 24px; font-size: 13px; }

/* ---------- month switch ---------- */
.month { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px; box-shadow: var(--shadow); }
.month b { min-width: 130px; text-align: center; font-weight: 600; }
.month button { width: 34px; height: 34px; border: 0; background: transparent; border-radius: 10px; cursor: pointer; font-size: 18px; color: var(--gold-deep); }
.month button:hover { background: var(--surface-2); }

/* ---------- tasks ---------- */
.group-h { display: flex; align-items: center; gap: 10px; margin: 22px 0 10px; font-weight: 600; color: var(--ink-2); font-size: 14px; }
.group-h .count { background: var(--surface-2); border: 1px solid var(--line); padding: 1px 9px; border-radius: 999px; font-size: 12px; color: var(--muted); }
.group-h.late { color: var(--bad); }
.tasks { display: flex; flex-direction: column; gap: 10px; }
.task {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); transition: transform .15s, opacity .3s;
}
.task.late { border-left: 4px solid var(--bad); }
.task.done-anim { opacity: 0; transform: translateX(30px); }
.check {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--gold); background: transparent; cursor: pointer; flex: none; display: grid; place-items: center; transition: background .15s;
}
.check:hover { background: var(--gold-glow); }
.check svg { width: 16px; height: 16px; opacity: 0; color: #fff; }
.check.on { background: var(--gold); } .check.on svg { opacity: 1; }
.task .body { flex: 1; min-width: 0; cursor: pointer; }
.task .t { font-weight: 600; }
.task.is-done .t { text-decoration: line-through; color: var(--muted); }
.task .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 4px; font-size: 12.5px; color: var(--muted); align-items: center; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; color: var(--ink-2); }
.tag.gold { background: var(--gold-soft); border-color: transparent; color: var(--gold-deep); }
.tag.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.tag.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.pts { font-weight: 700; color: var(--gold-deep); font-size: 13px; white-space: nowrap; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- money ---------- */
.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-row .top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; margin-bottom: 6px; }
.bar-row .top .l { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-row .top .l span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .top .r { white-space: nowrap; font-weight: 600; }
.bar-row .top .r small { color: var(--muted); font-weight: 400; }
.track { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.track i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #d6ae65, #a97b33); }
.track i.over { background: linear-gradient(90deg, #d27c62, var(--bad)); }
.track i.warn { background: linear-gradient(90deg, #e2b064, var(--warn)); }

.tx-day { margin-top: 18px; }
.tx-day .h { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-weight: 600; padding: 0 4px 8px; }
.tx-list { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.tx { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; border-top: 1px solid var(--line); }
.tx:first-child { border-top: 0; }
.tx:hover { background: var(--surface-2); }
.tx .cat { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-size: 19px; flex: none; }
.tx .mid { flex: 1; min-width: 0; }
.tx .mid b { display: block; font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .mid small { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.tx .amt { font-weight: 700; white-space: nowrap; }
.tx .amt.amt-in { color: var(--ok); }

.chart { width: 100%; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--sans); }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.donut-wrap { display: flex; align-items: center; gap: 22px; }
.donut-wrap svg { flex: none; }
.donut-wrap .bars { flex: 1; min-width: 0; }

.member-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.mcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.mcard::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--c, var(--gold)); }
.mcard .hd { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.mcard .hd b { display: block; font-size: 15.5px; }
.mcard .hd small { color: var(--muted); font-size: 12.5px; }
.mcard .kv { display: flex; justify-content: space-between; font-size: 13.5px; padding: 5px 0; border-top: 1px dashed var(--line); }
.mcard .kv span { color: var(--muted); }
.mcard .kv b { font-weight: 600; }
.mcard.off { opacity: .55; }
.mcard .edit { position: absolute; top: 12px; right: 12px; }

.list-plain { display: flex; flex-direction: column; }
.list-plain > div { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-top: 1px solid var(--line); }
.list-plain > div:first-child { border-top: 0; }

.fab {
  position: fixed; right: 28px; bottom: 28px; width: 60px; height: 60px; border-radius: 20px; border: 0; cursor: pointer; z-index: 30;
  background: linear-gradient(150deg, #cfa256, #9c712d); color: #fff9ec; box-shadow: 0 14px 30px rgba(156,113,45,.45); display: grid; place-items: center;
}
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: scale(.95); }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(40, 28, 10, .45); backdrop-filter: blur(3px); z-index: 50; display: grid; place-items: center; padding: 16px; animation: fade .15s; }
.modal-bg[hidden] { display: none; }
.modal { background: var(--surface); border-radius: 22px; width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; padding: 24px; box-shadow: var(--shadow-lg); animation: pop .18s ease-out; border: 1px solid var(--line); }
.modal h2 { font-size: 22px; margin-bottom: 18px; display: flex; justify-content: space-between; align-items: center; }
.modal .actions { display: flex; gap: 10px; margin-top: 8px; }
.modal .actions .grow { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }

.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 11px 18px; border-radius: 12px; z-index: 60; font-weight: 500; font-size: 14px; box-shadow: var(--shadow-lg); animation: pop .2s; max-width: calc(100vw - 32px); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .box { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 26px; padding: 36px 30px; box-shadow: var(--shadow-lg); text-align: center; }
.auth h1 { font-size: 28px; margin: 18px 0 4px; }
.auth p { color: var(--muted); margin: 0 0 24px; }
.auth form { text-align: left; }
.auth .crest { margin: 0 auto; }
.ornament { display: flex; align-items: center; gap: 10px; color: var(--gold); font-size: 12px; letter-spacing: 3px; justify-content: center; margin-top: 22px; }
.ornament::before, .ornament::after { content: ""; height: 1px; width: 50px; background: linear-gradient(90deg, transparent, var(--gold)); }
.ornament::after { transform: scaleX(-1); }

.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.emoji-grid button { aspect-ratio: 1; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; cursor: pointer; font-size: 19px; padding: 0; }
.emoji-grid button.on { border-color: var(--gold); background: var(--gold-soft); box-shadow: 0 0 0 2px var(--gold-glow); }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.colors button.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--surface) inset; }

.progress-ring { position: relative; display: grid; place-items: center; }
.progress-ring .c { position: absolute; text-align: center; }
.progress-ring .c b { font-size: 20px; display: block; }
.progress-ring .c small { font-size: 11px; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g2, .g2e { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  main { padding: 12px 16px 110px; }
  .mobile-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 4px; padding-top: max(14px, env(safe-area-inset-top)); }
  .mobile-top .brand b { font-size: 17px; }
  .mobile-top .crest { width: 36px; height: 36px; font-size: 15px; border-radius: 11px; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--line);
    padding: 6px 6px max(8px, env(safe-area-inset-bottom));
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600; border-radius: 12px; }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a.on { color: var(--gold-deep); }
  .bottom-nav a.on svg { filter: drop-shadow(0 2px 6px var(--gold-glow)); }
  .fab { right: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 18px; }
  .topline h1 { font-size: 25px; }
  .stat .v { font-size: 21px; }
  .card { padding: 16px; }
  .g4 { gap: 10px; }
  .donut-wrap { flex-direction: column; align-items: stretch; }
  .donut-wrap svg { align-self: center; }
  .modal-bg { place-items: end center; padding: 0; }
  .modal { border-radius: 24px 24px 0 0; max-width: none; max-height: 92vh; padding: 22px 18px max(22px, env(safe-area-inset-bottom)); animation: up .22s ease-out; }
  .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
  @keyframes up { from { transform: translateY(40px); opacity: .5; } }
}
@media (max-width: 400px) {
  .stat .v { font-size: 18px; }
  .month b { min-width: 104px; font-size: 14px; }
}
