:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #1c2330;
  --muted: #6b7484;
  --line: #e3e6eb;
  --line-strong: #cfd4dc;
  --accent: #23548c;
  --accent-ink: #ffffff;
  --accent-soft: #e8eef6;
  --ok: #2f7d5b;
  --ok-soft: #e6f2ec;
  --bad: #b23a32;
  --bad-soft: #fbeceb;
  --warn: #9a6a12;
  --warn-soft: #fbf3e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 45, .05);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 24px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.pre { white-space: pre-wrap; }
.loading, .empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty { background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line);
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px 20px; padding: 10px 24px;
}
.viewing-as .top { box-shadow: inset 0 -3px 0 #d9a441; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 600; white-space: nowrap; }
.mark { background: var(--ink); color: #fff; font-weight: 700; font-size: 12px; letter-spacing: .04em; padding: 5px 7px; border-radius: 6px; }
.demo { font-size: 11px; font-weight: 500; color: var(--warn); background: var(--warn-soft); padding: 2px 7px; border-radius: 99px; }
.nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: var(--muted); padding: 8px 12px; border-radius: 8px; white-space: nowrap; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.nav a:hover { color: var(--ink); background: var(--bg); }
.nav a.active { color: var(--ink); background: var(--accent-soft); }
.badge { background: var(--accent); color: #fff; font-size: 12px; line-height: 1; padding: 3px 7px; border-radius: 99px; }
.user { display: flex; align-items: center; gap: 10px; }
.who { display: flex; flex-direction: column; line-height: 1.2; font-size: 13px; text-align: right; }
.who span { color: var(--muted); font-size: 12px; }
.switch { max-width: 220px; }

main { max-width: 1120px; margin: 0 auto; padding: 24px 24px 120px; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin-right: auto; }
.narrow { max-width: 640px; margin: 0 auto; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #aeb5c0; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #1c4675; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-ghost { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.link { border: 0; background: none; color: var(--accent); padding: 4px 0; min-height: 0; }
.btn.small { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn[disabled], .btn.disabled { opacity: .55; pointer-events: none; }
.input {
  width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff;
}
.input.small { min-height: 32px; padding: 4px 8px; font-size: 13px; width: auto; }
textarea.input { resize: vertical; }
.input.file { padding: 7px; }
.field { display: block; margin-bottom: 14px; }
.field .label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field .hint { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.amount-input { display: grid; grid-template-columns: 1fr 86px; gap: 6px; }
.toggles { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.toggle { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.toggle input { width: 18px; height: 18px; }
.form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.error { color: var(--bad); font-size: 14px; margin-bottom: 10px; }

/* ---------- lists ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters .input { width: auto; }
.filters .search { flex: 1 1 260px; }
.list-meta { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.section { margin-bottom: 26px; }
.section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.section-meta { color: var(--muted); font-size: 13px; margin-right: auto; }
.count { color: var(--muted); font-weight: 500; margin-left: 4px; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row { display: grid; grid-template-columns: 1fr auto; gap: 14px; padding: 12px 16px; border-top: 1px solid var(--line); align-items: start; }
.row:first-child { border-top: 0; }
.row:hover { background: #fafbfc; }
.row.checked { background: var(--accent-soft); }
.row:has(.check) { grid-template-columns: auto 1fr auto; }
.check { display: flex; align-items: center; padding-top: 2px; cursor: pointer; }
.check input { width: 18px; height: 18px; cursor: pointer; }
.row-main { color: var(--ink); min-width: 0; }
.row-title { font-weight: 600; }
.row-sub { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.row-sub.muted { color: var(--muted); }
.row-flags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.row-flags:empty { display: none; }
.row-side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.amount { font-weight: 700; white-space: nowrap; }
.due { font-size: 13px; color: var(--muted); white-space: nowrap; }
.due.late { color: var(--bad); font-weight: 600; }
.turn { font-size: 12px; color: var(--muted); }

.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; white-space: nowrap; background: #eef0f3; color: #4a5260; }
.chip.amber { background: #fbf1dc; color: #8a5d0b; }
.chip.orange { background: #fdeadd; color: #9b4a14; }
.chip.violet { background: #efeafa; color: #5b3e9a; }
.chip.blue { background: #e6eef8; color: #23548c; }
.chip.teal { background: #e3f2ef; color: #1f6b5c; }
.chip.gray { background: #eceef1; color: #4d5562; }
.chip.red { background: var(--bad-soft); color: var(--bad); }
.flag { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 5px; background: #eef0f3; color: #4d5562; }
.flag.urgent { background: var(--bad); color: #fff; }
.flag.late { background: var(--bad-soft); color: var(--bad); }

.bulkbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; z-index: 20; display: flex; align-items: center; gap: 10px;
  background: var(--ink); color: #fff; padding: 8px 8px 8px 16px; border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
  max-width: calc(100% - 24px); flex-wrap: wrap;
}
.bulkbar .btn.ghost { color: #c9cfd8; }
.bulkbar .input { background: #fff; color: var(--ink); }
.bulk-info { font-size: 14px; margin-right: 4px; }

/* ---------- card ---------- */
.back { border: 0; background: none; color: var(--muted); padding: 0; margin-bottom: 10px; cursor: pointer; }
.card-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.card-head h1 { margin: 4px 0 2px; }
.payee { font-size: 16px; }
.card-amount { text-align: right; }
.big { font-size: 26px; font-weight: 700; white-space: nowrap; }
.status-line { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--muted); flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.action-form { background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 16px; margin-bottom: 18px; box-shadow: var(--shadow); }
.action-title { font-weight: 700; margin-bottom: 12px; }
.details {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; margin-bottom: 20px;
}
.details > div { background: var(--surface); padding: 10px 14px; }
.details .wide { grid-column: 1 / -1; }
.details span { display: block; font-size: 12px; color: var(--muted); }
.details b { font-weight: 500; }
.block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.files { list-style: none; margin: 0; padding: 0; }
.files li { padding: 8px 0; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.files li:first-child { border-top: 0; }
.upload { display: flex; gap: 8px; align-items: center; }
.comment { display: flex; gap: 8px; margin-bottom: 12px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--line); position: relative; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 14px; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.timeline li:first-child::before { background: var(--accent); }

/* ---------- plan ---------- */
.accounts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-bottom: 18px; }
.account { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; }
.acc-balance { font-size: 20px; font-weight: 700; }
.inline { display: flex; gap: 6px; align-items: center; }
.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
.totals > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.totals span { display: block; font-size: 12px; color: var(--muted); }
.totals b { font-size: 20px; }
.totals .bad { background: var(--bad-soft); border-color: #f0cfcc; }
.totals .bad b, .totals .bad span { color: var(--bad); }
.totals .good { background: var(--ok-soft); border-color: #cfe5d9; }
.totals .good b { color: var(--ok); }
.plan { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.plan-row {
  display: grid; grid-template-columns: 30px 170px minmax(0, 1fr) 120px 110px 120px 150px; gap: 10px; align-items: center;
  padding: 10px 14px; border-top: 1px solid var(--line);
}
.plan-headrow { border-top: 0; font-size: 12px; color: var(--muted); background: #fafbfc; padding-top: 8px; padding-bottom: 8px; }
.plan-row.checked { background: var(--accent-soft); }
.plan-row.cover-no, .plan-row.cover-part { background: #fffafa; }
.plan-title { display: flex; flex-direction: column; color: var(--ink); min-width: 0; }
.plan-title b { font-weight: 600; }
.num { text-align: right; white-space: nowrap; }
.prio { width: 100%; }
.cover { text-align: right; }
.short { color: var(--bad); font-size: 13px; font-weight: 600; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.dot.ok { background: var(--ok); }
.money-line { padding: 7px 14px; background: var(--bad-soft); color: var(--bad); font-size: 13px; font-weight: 600; border-top: 2px solid var(--bad); }
.limit { margin-top: 10px; max-width: 520px; }

/* ---------- concerts ---------- */
.concerts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.concert { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: var(--ink); display: flex; flex-direction: column; gap: 10px; }
.concert:hover { border-color: var(--line-strong); }
.concert-title { display: flex; flex-direction: column; }
.concert-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.concert-nums span { display: block; font-size: 12px; color: var(--muted); }

/* ---------- login, fab, toast ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); }
.login .brand { margin-bottom: 16px; font-size: 17px; }
.fab { display: none; }
.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 30;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; transition: .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--bad); }

/* ---------- phone ---------- */
@media (max-width: 860px) {
  .top { grid-template-columns: 1fr auto; padding: 8px 12px; }
  .nav { grid-column: 1 / -1; grid-row: 2; margin: 0 -12px; padding: 0 8px; }
  .brand-text { display: none; }
  .who { display: none; }
  .switch { max-width: 170px; }
  main { padding: 16px 12px 120px; }
  h1 { font-size: 21px; }
  .page-head .btn.primary { display: none; }
  .fab {
    display: flex; position: fixed; right: 16px; bottom: 18px; width: 56px; height: 56px; border-radius: 50%; z-index: 15;
    background: var(--accent); color: #fff; font-size: 30px; align-items: center; justify-content: center; box-shadow: 0 6px 18px rgba(35, 84, 140, .35);
  }
  .bulkbar { bottom: 86px; }
  .row { padding: 12px; gap: 10px; }
  .details { grid-template-columns: 1fr 1fr; }
  .card-head { flex-direction: column; gap: 6px; }
  .card-amount { text-align: left; }
  .totals { grid-template-columns: 1fr 1fr; }
  .plan-headrow { display: none; }
  .plan-row { grid-template-columns: 26px 1fr auto; grid-template-areas: "c t s" "c p d" "c x y"; row-gap: 4px; }
  .plan-row > :nth-child(1) { grid-area: c; align-self: start; }
  .plan-row > :nth-child(2) { grid-area: p; }
  .plan-row > :nth-child(3) { grid-area: t; }
  .plan-row > :nth-child(4) { grid-area: d; text-align: right; }
  .plan-row > :nth-child(5) { grid-area: s; }
  .plan-row > :nth-child(6) { grid-area: x; text-align: left; font-size: 12px; }
  .plan-row > :nth-child(7) { grid-area: y; }
  .prio { max-width: 210px; }
  .grid2 { grid-template-columns: 1fr; }
  .form { padding: 14px; }
  .form-actions.sticky { position: sticky; bottom: 0; background: var(--surface); padding: 10px 0; margin: 0 -2px; }
  .form-actions .btn { flex: 1; }
  .filters .input { flex: 1 1 140px; }
}

.account .btn.link { align-self: flex-start; }
.plan-row { grid-template-columns: 30px 196px minmax(0, 1fr) 120px 110px 120px 150px; gap: 14px; }
.cash { display: flex; gap: 8px 22px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 18px; color: var(--muted); font-size: 14px; }
.cash b { color: var(--ink); margin-left: 4px; }
.cash .bad, .cash .bad b { color: var(--bad); }
.cash .good b { color: var(--ok); }
@media (max-width: 860px) {
  .accounts { grid-template-columns: 1fr 1fr; gap: 8px; }
  .account { padding: 10px; }
  .acc-balance { font-size: 17px; }
  .plan-row { grid-template-columns: 26px 1fr auto; gap: 4px 10px; }
  .who { display: flex; } .who span { display: none; }
}
