:root {
  --bg: #f4f5f7; --panel: #ffffff; --text: #1b2330; --muted: #677084; --line: #e2e5eb;
  --accent: #0f766e; --accent-soft: #e0f2ef; --red: #c0352b; --red-soft: #fde8e6;
  --amber: #a16207; --amber-soft: #fdf3d7; --green: #15803d; --green-soft: #e1f5e8;
  --blue: #1d4ed8; --blue-soft: #e3ebfd;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --panel: #1b2029; --text: #e7eaf0; --muted: #98a1b3; --line: #2c3340;
    --accent: #2dd4bf; --accent-soft: #123b38; --red: #f87171; --red-soft: #45201f;
    --amber: #fbbf24; --amber-soft: #40330f; --green: #4ade80; --green-soft: #153a24;
    --blue: #93b4ff; --blue-soft: #1c2a4d;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.app { display: flex; min-height: 100vh; }
.side { width: 220px; flex: none; background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 17px; padding: 0 10px 14px; color: var(--accent); }
#nav button { display: flex; justify-content: space-between; width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 9px 10px; border-radius: 8px; font: inherit; cursor: pointer; }
#nav button:hover { background: var(--bg); }
#nav button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#nav .count { color: var(--muted); font-size: 12px; font-weight: 400; }
#nav hr { border: 0; border-top: 1px solid var(--line); margin: 8px 4px; }
.content { flex: 1; min-width: 0; padding: 20px 28px 60px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: none; color: var(--muted); padding: 6px 12px; border-radius: 6px; font: inherit; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .seg button.on { color: #06211e; } }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.tile .lbl { color: var(--muted); font-size: 12.5px; }
.tile .val { font-size: 19px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; word-break: break-word; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile.red .val { color: var(--red); } .tile.green .val { color: var(--green); } .tile.amber .val { color: var(--amber); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.act { text-align: right; white-space: nowrap; }
tr:last-child > td { border-bottom: 0; }
tr.group > td { background: var(--bg); font-weight: 600; font-size: 13px; }
tr.group .gsum { font-weight: 400; color: var(--muted); margin-left: 10px; }
tr.total > td { font-weight: 700; border-top: 2px solid var(--line); }
tr.detail > td { background: var(--bg); padding: 12px 14px; }
.small { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); padding: 22px 6px; text-align: center; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.paid { background: var(--green-soft); color: var(--green); }
.badge.overdue { background: var(--red-soft); color: var(--red); }
.badge.partial { background: var(--amber-soft); color: var(--amber); }
.badge.open { background: var(--blue-soft); color: var(--blue); }
.badge.off { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

button.btn, .btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 6px 11px; border-radius: 8px; font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #06211e; } }
.btn.danger { color: var(--red); }
.btn.sm { padding: 3px 8px; font-size: 12.5px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; align-items: end; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
select, input, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 0; width: min(620px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.form { padding: 20px; }
.form .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.form label.full { grid-column: 1 / -1; }
.form .hint { font-size: 11.5px; }
.form .err { color: var(--red); min-height: 18px; margin-top: 8px; font-size: 13px; }
.form .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.form .actions .left { margin-right: auto; }
.bar { height: 6px; background: var(--line); border-radius: 9px; overflow: hidden; min-width: 70px; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.print-only { display: none; }
.app.at-home .side { display: none; }
.sync { margin-left: auto; }
.sync.error { color: var(--red); }
.login { max-width: 360px; margin: 8vh auto 0; display: flex; flex-direction: column; gap: 12px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.login .err { color: var(--red); min-height: 18px; font-size: 13px; }
.app.at-home .content { flex: none; width: min(1100px, 100%); margin: 0 auto; }
.top .seg, #scope { display: flex; gap: 8px; align-items: center; background: none; border: 0; padding: 0; }
.home { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.home-col { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.profile { position: relative; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-top: 10px; cursor: pointer; background: var(--bg); }
.profile:hover, .profile:focus-visible { border-color: var(--accent); outline: none; }
.profile .pname { font-weight: 700; font-size: 16px; padding-right: 76px; }
.profile .pstats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; margin-top: 8px; color: var(--muted); font-size: 12.5px; }
.profile .pstats b { display: block; color: var(--text); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.profile .pstats .red b { color: var(--red); }
.profile > .btn { position: absolute; top: 12px; right: 12px; }
@media (max-width: 800px) { .home { grid-template-columns: 1fr; } }

@media (max-width: 800px) {
  .app { flex-direction: column; }
  .side { width: auto; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 8px; }
  .brand { padding: 0 8px 6px; }
  #nav { display: flex; overflow-x: auto; gap: 4px; }
  #nav button { width: auto; white-space: nowrap; gap: 6px; }
  #nav hr { display: none; }
  .content { padding: 14px 16px 50px; }
  .form .grid { grid-template-columns: 1fr; }
}
@page { size: A4 landscape; margin: 10mm; }
@media print {
  th { white-space: normal; }
  tr { break-inside: avoid; }
  thead { display: table-header-group; }
  :root { --bg: #fff; --panel: #fff; --text: #000; --muted: #444; --line: #bbb; }
  .no-print, td.act, th.act { display: none !important; }
  .print-only { display: block; margin-bottom: 10px; }
  .content { padding: 0; }
  .card { border: 0; padding: 0; }
  .scroll { overflow: visible; }
  body { font-size: 10.5px; }
  th, td { padding: 4px 6px; }
}
