:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --text: #22252a;
  --muted: #6b6f76;
  --border: #e2ddd3;
  --accent: #2f6b5a;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe9;
  --warn: #a5561b;
  --warn-soft: #fbeee2;
  --danger: #b3261e;
  --good: #2f6b5a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a; --surface: #1e2125; --surface-2: #262a2f; --text: #e9e7e2; --muted: #9da1a8;
    --border: #33373d; --accent: #6fbfa5; --accent-ink: #10231d; --accent-soft: #1f3530;
    --warn: #e7a46a; --warn-soft: #3a2a1c; --danger: #f2a199; --good: #6fbfa5;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }

button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px; padding: .5rem .9rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
}
button:hover, .btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-link { border: 0; background: none; color: var(--accent); padding: .25rem .4rem; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn-danger { color: var(--danger); }
button:disabled { opacity: .6; cursor: default; }

input, select, textarea {
  font: inherit; width: 100%; padding: .55rem .7rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: .85rem; font-weight: 600; margin: .8rem 0 .3rem; }
label.check { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
label.check input { width: auto; }
.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; margin-top: .6rem; }

/* ---- Auth pages ---- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.auth-card .btn { width: 100%; margin-top: .4rem; }
.divider { display: flex; align-items: center; gap: .7rem; color: var(--muted); font-size: .8rem; margin: 1.1rem 0 .2rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.brand { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; }
.logo { width: 40px; height: 40px; object-fit: contain; }

/* ---- App shell ---- */
header.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.top-inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 1rem; }
.top-inner .brand { margin: 0; flex: 1; }
nav.tabs { max-width: 1100px; margin: 0 auto; padding: 0 16px; display: flex; gap: .2rem; overflow-x: auto; }
nav.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: .6rem .7rem; color: var(--muted); white-space: nowrap; }
nav.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0 0 1rem; flex-wrap: wrap; }
.section-head p { margin: .2rem 0 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: .8rem; color: var(--muted); }
.stat .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .value.neg { color: var(--danger); }
.stat .sub { font-size: .8rem; color: var(--muted); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 12px; }
.grid2 .card + .card { margin-top: 0; }

.list { display: grid; gap: 10px; }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; gap: 1rem; align-items: flex-start; }
.item.inactive { opacity: .6; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .meta { color: var(--muted); font-size: .85rem; margin-top: .15rem; display: flex; flex-wrap: wrap; gap: .25rem .9rem; }
.item .notes { margin-top: .4rem; font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.item .right { text-align: right; flex-shrink: 0; }
.item .amount { font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.item .actions { display: flex; gap: .2rem; justify-content: flex-end; margin-top: .3rem; }

.pill { display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.good { background: var(--accent-soft); color: var(--good); }

table.simple { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.simple td { padding: .4rem 0; border-bottom: 1px solid var(--border); }
table.simple tr:last-child td { border-bottom: 0; }
table.simple td.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.simple tr.total td { font-weight: 700; border-top: 2px solid var(--border); }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }
.post-body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: .4rem; }
.comment { border-left: 3px solid var(--border); padding: .2rem 0 .2rem .8rem; margin-top: .6rem; font-size: .92rem; }
.comment .who { font-size: .8rem; color: var(--muted); }
.reply-row { display: flex; gap: .5rem; margin-top: .7rem; }
.reply-row input { flex: 1; }
.activity li { margin-bottom: .35rem; font-size: .9rem; }
.activity { padding-left: 1.1rem; margin: 0; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; margin-top: .4rem; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }
.filters { display: flex; gap: .4rem; flex-wrap: wrap; }
.filters button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

/* ---- Modal ---- */
dialog { border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 22px; }
dialog .row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
dialog .foot { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.2rem; }
.copybox { display: flex; gap: .5rem; margin-top: .6rem; }
.copybox input { font-size: .85rem; }

@media (max-width: 560px) {
  .item { flex-direction: column; gap: .4rem; }
  .item .right { text-align: left; width: 100%; }
  .item .actions { justify-content: flex-start; }
  dialog .row { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}

