:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #1a56db;
  --accent-text: #ffffff;
  --pos: #137333;
  --neg: #c5221f;
  --neg-bg: #fdecea;
  --pos-bg: #e6f4ea;
  --warn-bg: #fff4e5;
  --overlay: rgba(0, 0, 0, .45);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --card: #1b1e24;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --line: #2c3038;
    --accent: #6ea0ff;
    --accent-text: #0b1220;
    --pos: #6fd08c;
    --neg: #ff8a80;
    --neg-bg: #3a1c1a;
    --pos-bg: #16301d;
    --warn-bg: #3a2c14;
    --overlay: rgba(0, 0, 0, .65);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top nav { display: flex; max-width: 720px; margin: 0 auto; }
.top a {
  flex: 1; text-align: center; padding: 14px 8px; min-height: 48px;
  color: var(--muted); text-decoration: none; font-weight: 600;
  border-bottom: 3px solid transparent;
}
.top a.active { color: var(--accent); border-bottom-color: var(--accent); }
main { max-width: 720px; margin: 0 auto; padding: 16px 16px 110px; }
h1, h2 { margin: 0; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.total-label { color: var(--muted); font-size: .9rem; }
.total { font-size: 2.2rem; font-weight: 700; line-height: 1.1; margin: 2px 0 10px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.chip small { display: block; color: var(--muted); }
.chip b { font-weight: 600; }

.band { border-radius: 12px; padding: 14px; font-weight: 600; margin-bottom: 10px; }
.band.bad { background: var(--neg-bg); color: var(--neg); }
.band.good { background: var(--pos-bg); color: var(--pos); }
.days { display: flex; gap: 8px; margin-bottom: 14px; }
.days button {
  flex: 1; min-height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; cursor: pointer;
}
.days button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }

.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
}
.row.overdue { background: var(--neg-bg); }
.row.negative { outline: 2px solid var(--neg); }
.row .date { color: var(--muted); font-size: .85rem; }
.row .name { font-weight: 600; word-break: break-word; }
.row .payee { color: var(--muted); font-size: .9rem; word-break: break-word; }
.row .amount { text-align: right; font-weight: 700; white-space: nowrap; }
.row .after { text-align: right; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.row .after.neg { color: var(--neg); font-weight: 600; }
.row .btn { grid-column: 1 / -1; }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }

.btn {
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.block { display: block; width: 100%; text-align: left; margin-bottom: 8px; }

.fab {
  position: fixed; right: 18px; bottom: 18px; width: 60px; height: 60px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-text);
  font-size: 2rem; line-height: 1; cursor: pointer; box-shadow: 0 4px 14px rgba(0, 0, 0, .3); z-index: 6;
}

.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.acc { cursor: pointer; text-align: left; width: 100%; font: inherit; color: inherit; }
.acc.archived { opacity: .55; }
.hint { background: var(--warn-bg); border-radius: 12px; padding: 14px; margin-bottom: 12px; }

dialog {
  border: 0; border-radius: 16px; padding: 0; background: var(--card); color: var(--text);
  width: min(480px, 100%); max-height: 92vh; overflow: auto;
}
dialog::backdrop { background: var(--overlay); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
.modal-head h2 { font-size: 1.15rem; }
.icon-btn { width: 44px; height: 44px; border: 0; background: none; color: var(--text); font-size: 1.8rem; cursor: pointer; }
.modal-body { padding: 16px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: .9rem; color: var(--muted); }
.field input, .field select {
  min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; width: 100%;
}
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; }
.err { color: var(--neg); margin: 0; min-height: 1.2em; }
.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; }
.seg { display: flex; gap: 8px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; }
.seg span {
  display: block; text-align: center; min-height: 44px; line-height: 44px; border-radius: 10px;
  border: 1px solid var(--line); cursor: pointer;
}
.seg input:checked + span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }

@media (max-width: 600px) {
  dialog.full { width: 100%; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
  dialog.compact { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 16px 16px 0 0; }
}
