:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e3e6ee;
  --text: #161a23;
  --muted: #646b7c;
  --primary: #4f46e5;
  --primary-ink: #ffffff;
  --primary-soft: #eceafd;
  --danger: #d92d3a;
  --success: #138a52;
  --success-soft: #e3f5ec;
  --warn-soft: #fff4dc;
  --warn: #9a6400;
  /* person palette slots (users.color) */
  --c-s0: #4f46e5;
  --c-s1: #0d9488;
  --c-s2: #e8590c;
  --c-s3: #db2777;
  --c-s4: #0284c7;
  --c-s5: #65a30d;
  --c-s6: #9333ea;
  --c-s7: #b45309;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --surface: #161b24;
    --surface-2: #1d2430;
    --border: #2a3240;
    --text: #e8ebf2;
    --muted: #9aa3b5;
    --primary: #8b85ff;
    --primary-ink: #0e1117;
    --primary-soft: #262a4a;
    --danger: #ff6b76;
    --success: #4ad295;
    --success-soft: #16352a;
    --warn-soft: #3a2f14;
    --warn: #f5c25b;
    --c-s0: #8b85ff;
    --c-s1: #2dd4bf;
    --c-s2: #ff8c42;
    --c-s3: #f472b6;
    --c-s4: #38bdf8;
    --c-s5: #a3e635;
    --c-s6: #c084fc;
    --c-s7: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }

.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: .55rem .95rem; font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible, .tabs a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-icon { padding: .35rem .55rem; font-size: .85rem; }
.btn[disabled] { opacity: .6; cursor: default; }

label { display: grid; gap: .3rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; width: 100%; min-width: 0;
}
input[type="checkbox"] { width: 1.15rem; height: 1.15rem; accent-color: var(--success); cursor: pointer; padding: 0; }
.error { color: var(--danger); font-size: .9rem; margin: 0; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 24px; box-shadow: var(--shadow); display: grid; gap: 14px;
}
.login-card p { margin: 0; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 800; font-size: 1.05rem; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand-lg { font-size: 1.4rem; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--primary), var(--c-s1)); color: #fff; font-weight: 800; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.tabs a { padding: .4rem .85rem; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .92rem; }
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.who { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: .4rem; padding: .25rem .65rem; border-radius: 999px; background: var(--surface-2); font-size: .85rem; font-weight: 600; white-space: nowrap; }

.container { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; display: grid; gap: 18px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-hero { grid-template-columns: 1.3fr 1fr; }
.grid-people { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.hero-total { font-size: 2.2rem; font-weight: 800; letter-spacing: -.02em; margin: 4px 0 14px; }
.owe-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.owe-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; }
.owe-list .amt { font-weight: 700; }
.hero-foot { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.bg-s0 { background: var(--c-s0); }
.bg-s1 { background: var(--c-s1); }
.bg-s2 { background: var(--c-s2); }
.bg-s3 { background: var(--c-s3); }
.bg-s4 { background: var(--c-s4); }
.bg-s5 { background: var(--c-s5); }
.bg-s6 { background: var(--c-s6); }
.bg-s7 { background: var(--c-s7); }
.bg-none { background: var(--muted); }
.fill-s0 { fill: var(--c-s0); }
.fill-s1 { fill: var(--c-s1); }
.fill-s2 { fill: var(--c-s2); }
.fill-s3 { fill: var(--c-s3); }
.fill-s4 { fill: var(--c-s4); }
.fill-s5 { fill: var(--c-s5); }
.fill-s6 { fill: var(--c-s6); }
.fill-s7 { fill: var(--c-s7); }
.fill-none { fill: var(--muted); }
.person { display: inline-flex; align-items: center; gap: .45rem; font-weight: 600; }

.stat-label { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-big { font-size: 1.45rem; font-weight: 800; letter-spacing: -.01em; }
.stat-sub { color: var(--muted); font-size: .88rem; }
.person-card { border-top: 4px solid var(--border); }
.person-card.c-s0 { border-top-color: var(--c-s0); }
.person-card.c-s1 { border-top-color: var(--c-s1); }
.person-card.c-s2 { border-top-color: var(--c-s2); }
.person-card.c-s3 { border-top-color: var(--c-s3); }
.person-card.c-s4 { border-top-color: var(--c-s4); }
.person-card.c-s5 { border-top-color: var(--c-s5); }
.person-card.c-s6 { border-top-color: var(--c-s6); }
.person-card.c-s7 { border-top-color: var(--c-s7); }
.person-card.c-all { border-top-color: var(--text); }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge-paid { background: var(--success-soft); color: var(--success); }
.badge-open { background: var(--warn-soft); color: var(--warn); }
.badge-done { background: var(--surface-2); color: var(--muted); }

/* chart */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.chart-wrap { width: 100%; overflow-x: auto; }
.chart { display: block; width: 100%; min-width: 560px; height: auto; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .bar-paid { opacity: .45; }
.chart .now-marker { fill: var(--primary); }
.chart rect.hit { fill: transparent; }
.chart rect.hit:hover { fill: var(--surface-2); }

/* tables */
.table-wrap { width: 100%; overflow-x: auto; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: var(--surface-2); white-space: nowrap; }
th:first-child { border-top-left-radius: 10px; }
th:last-child { border-top-right-radius: 10px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sorted-asc::after { content: " ▲"; }
th.sorted-desc::after { content: " ▼"; }
tr.row-current td { background: var(--primary-soft); }
tr.row-paid td { color: var(--muted); }
tfoot td { font-weight: 800; border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; background: var(--success); border-radius: 999px; }
.progress-label { font-size: .78rem; color: var(--muted); margin-top: 3px; white-space: nowrap; }

.filters { display: grid; grid-template-columns: 1fr 1fr 2fr auto; gap: 10px; align-items: end; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.summary-line { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: .9rem; }
.summary-line strong { color: var(--text); }

/* audit */
.audit-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.audit-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.audit-list li:last-child { border-bottom: 0; }
.audit-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); font-weight: 800; font-size: .9rem; }
.audit-icon.a-create { background: var(--success-soft); color: var(--success); }
.audit-icon.a-delete { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.audit-icon.a-update, .audit-icon.a-paid { background: var(--primary-soft); color: var(--primary); }
.audit-main { min-width: 0; }
.audit-main p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.audit-time { color: var(--muted); font-size: .82rem; white-space: nowrap; text-align: right; }
.diff del { color: var(--danger); text-decoration: line-through; }
.diff ins { color: var(--success); text-decoration: none; font-weight: 600; }

/* dialog */
.dialog { border: 1px solid var(--border); border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.dialog::backdrop { background: rgba(10, 12, 20, .5); backdrop-filter: blur(2px); }
.dialog form { padding: 22px; display: grid; gap: 14px; }
.dialog-sm { width: min(400px, calc(100vw - 32px)); }
.dialog p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.preview { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: .9rem; }
.preview:empty { display: none; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .65rem 1rem; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow); z-index: 100; max-width: calc(100vw - 32px); }
.toast.toast-error { background: var(--danger); color: #fff; }

/* roles & users */
.role-tag { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--primary); background: var(--primary-soft); border-radius: 999px; padding: .05rem .45rem; }
.badge-admin { background: var(--primary-soft); color: var(--primary); }
tr.row-inactive td { color: var(--muted); }
tr.row-inactive .dot { opacity: .45; }
.uname { font-size: .85rem; }
.note { margin: 0; font-size: .88rem; }
.hint { font-size: .82rem; font-weight: 400; }
td.actions .btn + .btn { margin-left: 2px; }
label.check { display: flex; align-items: center; gap: .55rem; align-self: end; padding-bottom: .55rem; color: var(--text); }
label.check input { flex: none; }
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.pw-row { display: flex; gap: 8px; }
.pw-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.05rem; letter-spacing: .03em; }
.pw-copied { color: var(--success); font-size: .88rem; font-weight: 600; }
.pw-warn { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: .9rem; font-weight: 600; }

/* responsive */
@media (max-width: 900px) {
  .grid-hero { grid-template-columns: 1fr; }
  .grid-people { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .f-search { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; gap: 10px; }
  .tabs { order: 3; width: 100%; }
  .tabs a { flex: 1; text-align: center; }
  .hero-total { font-size: 1.8rem; }
  .card { padding: 14px; }
  .grid2 { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .f-add { grid-column: 1 / -1; }

  /* entries table -> cards */
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; background: var(--surface); }
  table.cards td { border: 0; padding: 5px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  table.cards td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 600; text-align: left; }
  table.cards td.cell-title { font-weight: 700; font-size: 1rem; text-align: left; }
  table.cards td.cell-title::before { content: none; }
  table.cards td.actions { justify-content: flex-end; }
  table.cards td.actions::before { content: none; }
  table.cards td.actions { flex-wrap: wrap; }
  table.cards td.actions:empty { display: none; }
  .tabs a { padding: .4rem .4rem; font-size: .85rem; }
  table.cards .progress { flex: 1; max-width: 160px; }
  .audit-list li { grid-template-columns: auto 1fr; }
  .audit-time { grid-column: 2; text-align: left; }
}
