/* Ledgerbook — styles */
:root {
  --bg: #f5f4ee;
  --surface: #ffffff;
  --surface-2: #f0efe8;
  --ink: #18201c;
  --muted: #5d6963;
  --line: #e2e0d6;
  --accent: #166534;
  --accent-ink: #ffffff;
  --accent-soft: #dcf3e3;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --warn: #a15c07;
  --warn-soft: #fdf0d8;
  --info: #1e4fa8;
  --info-soft: #e3ecfb;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .05);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 64px;
  --hero-bg: #166534;
  --hero-ink: #ffffff;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1310;
  --surface: #121c18;
  --surface-2: #18251f;
  --ink: #e6eee9;
  --muted: #94a59c;
  --line: #24342c;
  --accent: #4ade80;
  --accent-ink: #052e16;
  --accent-soft: #143524;
  --hero-bg: #17603a;
  --hero-ink: #eafff1;
  --danger: #f87171;
  --danger-soft: #3a1717;
  --warn: #fbbf24;
  --warn-soft: #3a2a0c;
  --info: #93b4f5;
  --info-soft: #172640;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1310;
    --surface: #121c18;
    --surface-2: #18251f;
    --ink: #e6eee9;
    --muted: #94a59c;
    --line: #24342c;
    --accent: #4ade80;
    --accent-ink: #052e16;
    --accent-soft: #143524;
  --hero-bg: #17603a;
  --hero-ink: #eafff1;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --warn: #fbbf24;
    --warn-soft: #3a2a0c;
    --info: #93b4f5;
    --info-soft: #172640;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num, .money { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2.section { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; margin: 22px 2px 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.pos { color: var(--accent); }
.neg { color: var(--danger); }
.warn-text { color: var(--warn); }

/* ---------- Layout ---------- */
.app { min-height: 100vh; }
main {
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 96px);
  max-width: 980px;
  margin: 0 auto;
  outline: none;
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 2px 14px; }
.topbar h1 { font-size: 26px; font-weight: 750; letter-spacing: -.02em; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }

.rail {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.brand { display: none; }
.nav-item {
  position: relative; flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--accent); }
.nav-item .badge {
  position: absolute; top: 7px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

@media (min-width: 900px) {
  .rail {
    top: 0; bottom: 0; right: auto; width: 220px; height: auto;
    flex-direction: column; justify-content: flex-start; gap: 2px;
    padding: 20px 12px; border-top: 0; border-right: 1px solid var(--line);
    background: var(--surface); backdrop-filter: none;
  }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 18px; padding: 4px 10px 18px; letter-spacing: -.01em; }
  .brand img { border-radius: 8px; }
  .nav-item { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px; border-radius: 10px; font-size: 14.5px; }
  .nav-item:hover { background: var(--surface-2); color: var(--ink); }
  .nav-item.active { background: var(--accent-soft); color: var(--accent); }
  .nav-item .badge { position: static; margin-left: auto; }
  .nav-settings { margin-top: auto; }
  main { margin-left: 220px; padding: 20px 32px 96px; max-width: 1100px; }
}

/* ---------- Cards & stats ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card + .card { margin-top: 12px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stats > .stat:not(.hero):last-child:nth-child(even) { grid-column: 1 / -1; }
@media (min-width: 700px) {
  .stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
  .stats > .stat:not(.hero):last-child:nth-child(even) { grid-column: auto; }
}
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 20px; font-weight: 720; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; overflow-wrap: anywhere; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.hero { grid-column: 1 / -1; background: var(--hero-bg); border-color: transparent; color: var(--hero-ink); }
.stat.hero .label, .stat.hero .sub { color: color-mix(in srgb, var(--hero-ink) 78%, transparent); }
.stat.hero .neg { color: #fecaca; }
.stat.hero .value { font-size: 30px; }
@media (min-width: 700px) { .stat.hero { grid-column: auto; } .stat.hero .value { font-size: 26px; } }

/* ---------- Lists ---------- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px;
  border: 0; border-top: 1px solid var(--line); background: none; width: 100%; text-align: left; text-decoration: none;
  color: inherit; font: inherit; cursor: pointer;
}
.item:first-child { border-top: 0; }
button.item:hover, a.item:hover { background: var(--surface-2); }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.item .end { text-align: right; flex: none; }
.item .amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.item progress { margin-top: 8px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: var(--accent-soft); color: var(--accent);
}
.avatar.k-bill { background: var(--info-soft); color: var(--info); }
.avatar.k-warn { background: var(--warn-soft); color: var(--warn); }
.avatar.k-danger { background: var(--danger-soft); color: var(--danger); }

.empty { text-align: center; padding: 36px 18px; color: var(--muted); }
.empty svg { width: 36px; height: 36px; stroke-width: 1.5; margin-bottom: 8px; }
.empty .btn { margin-top: 14px; }

/* ---------- Pills, chips, segmented ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 650; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--info-soft); color: var(--info); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 16px 0 10px; }
.toolbar .search { flex: 1 1 200px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); padding: 6px 11px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 650; font-size: 14px;
  padding: 9px 14px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); text-decoration: none; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-ghost { background: none; color: var(--danger); border-color: var(--line); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: none; color: var(--muted); padding: 8px; border-radius: 10px; cursor: pointer; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-end { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px); z-index: 25;
  width: 56px; height: 56px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.22);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.4; }
@media (min-width: 900px) { .fab { bottom: 28px; right: 32px; } }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-width: 0;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 0; border-color: var(--accent); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); padding: 0; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14.5px; margin: 6px 0 12px; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }
@media (max-width: 420px) { .grid3 { grid-template-columns: 1fr 1fr; } }
.search input { padding-left: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a958f' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M21 21l-4.3-4.3'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: 11px center; background-size: 17px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px 12px 2px; margin: 0 0 12px; }
legend { font-size: 13px; font-weight: 700; padding: 0 6px; color: var(--muted); }
.calc-box { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.calc-box b { font-variant-numeric: tabular-nums; }

/* ---------- Progress ---------- */
progress { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border: 0; border-radius: 3px; background: var(--surface-2); overflow: hidden; display: block; }
progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 3px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 3px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 3px; }
progress.over::-webkit-progress-value { background: var(--danger); }
progress.over::-moz-progress-bar { background: var(--danger); }
progress.near::-webkit-progress-value { background: var(--warn); }
progress.near::-moz-progress-bar { background: var(--warn); }

/* ---------- Dialogs ---------- */
dialog { border: 0; padding: 0; color: var(--ink); background: var(--surface); }
dialog::backdrop { background: rgba(5, 12, 9, .5); }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; border-radius: 18px 18px 0 0;
  margin: auto auto 0; box-shadow: 0 -8px 30px rgba(0,0,0,.2);
}
@media (min-width: 640px) { .sheet { border-radius: 18px; margin: auto; } }
.sheet form { display: flex; flex-direction: column; max-height: 92vh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 18px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 18px; font-weight: 720; }
.sheet-body { padding: 16px 18px 6px; overflow-y: auto; flex: 1; }
.sheet-foot { display: flex; gap: 8px; justify-content: space-between; align-items: center; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet-foot:empty { display: none; }
.sheet-foot .right { display: flex; gap: 8px; margin-left: auto; }
.confirm { border-radius: 16px; max-width: 360px; width: calc(100% - 40px); }
.confirm form { padding: 20px; }
.confirm p { margin-bottom: 18px; }

/* ---------- Detail view ---------- */
.detail-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.detail-head .avatar { width: 52px; height: 52px; font-size: 18px; }
.detail-head h2 { font-size: 22px; font-weight: 750; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.notes { white-space: pre-wrap; font-size: 14.5px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; margin-bottom: 6px; background: none; border: 0; cursor: pointer; padding: 4px 0; font-family: inherit; }

/* ---------- Banner & toast ---------- */
.banner { display: flex; gap: 12px; align-items: center; padding: 11px 14px; border-radius: 12px; margin-bottom: 12px; font-size: 14px; background: var(--info-soft); color: var(--info); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner .grow { flex: 1; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 86px); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px);
  display: flex; gap: 12px; align-items: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast button { background: none; border: 0; color: var(--accent-soft); font: inherit; font-weight: 750; cursor: pointer; padding: 0; }
@media (min-width: 900px) { .toast { bottom: 32px; left: calc(50% + 110px); } }

/* ---------- Budget ---------- */
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav strong { min-width: 116px; text-align: center; font-size: 15px; }
.cat-row { padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.cat-row:first-child { border-top: 0; }
.cat-row:hover { background: var(--surface-2); }
.cat-row .spread { margin-bottom: 6px; }
.cat-row .name { font-weight: 650; }
.cat-row .figs { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.plan-line { display: grid; grid-template-columns: 1fr 130px auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.plan-line input { padding: 8px 10px; }

.agenda-group + .agenda-group { margin-top: 4px; }
.two-col { display: grid; gap: 12px; }
@media (min-width: 900px) { .two-col { grid-template-columns: 1fr 1fr; align-items: start; } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* utilities */
.mt0 { margin-top: 0 !important; }
.mt4 { margin-top: 4px; }
.mt12 { margin-top: 12px; }
.mt18 { margin-top: 18px; }
.mb12 { margin-bottom: 12px; }
.end-row { justify-content: flex-end; gap: 2px; }

.two-col > div > * + * { margin-top: 12px; }
.two-col > .card + .list, .two-col > .list { margin-top: 0; }

.item .title.wrap { white-space: normal; }
