:root {
  --blue: #305CFF; --blue-deep: #0B18FF; --blue-dark: #0429B7;
  --blue-soft: #EEF2FF; --blue-tint: #A9B9FF;
  --ink: #171717; --muted: #5E6778; --faint: #9AA3B2;
  --panel: #F5F7FB; --line: #E6EAF2; --white: #FFFFFF;
  --red: #E5383B; --red-soft: #FDECEC; --green: #16A34A; --green-soft: #E8F6EE; --amber: #B7791F; --amber-soft: #FDF4E3;
  --grad: linear-gradient(135deg, #305CFF 0%, #0B18FF 55%, #0429B7 100%);
  --font: 'Montserrat', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  --r-sm: 6px; --r-md: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 var(--font); color: var(--ink); background: var(--white); -webkit-font-smoothing: antialiased; }
h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 700; margin: 0 0 12px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 28px; padding: 0 28px; height: 56px; background: var(--grad); color: #fff; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 15px; }
.brand svg { width: 22px; height: 20px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a { color: rgba(255,255,255,.78); text-decoration: none; padding: 7px 14px; border-radius: 999px; font-weight: 500; }
.tabs a:hover { color: #fff; background: rgba(255,255,255,.12); }
.tabs a.active { color: var(--blue-dark); background: #fff; font-weight: 600; }
.who { display: flex; gap: 14px; align-items: center; font-size: 13px; }
.link-btn { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; padding: 0; }

main { max-width: 1440px; margin: 0 auto; padding: 28px 28px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- forms ---------- */
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 7px 10px; background: #fff; min-height: 34px; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-soft); }
label.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
label.field > input, label.field > select { color: var(--ink); font-size: 14px; }
label.field.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
a { color: var(--blue); }
a.btn { text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; }
a:hover { color: var(--blue-deep); }
a.login { text-decoration: none; }
a.login:hover { text-decoration: underline; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; font-size: 13px; }
button { font: inherit; cursor: pointer; }
.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: var(--r-sm); padding: 7px 14px; font-weight: 500; min-height: 34px; }
.btn:hover { border-color: var(--blue-tint); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-deep); border-color: var(--blue-deep); }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 3px 10px; min-height: 28px; font-size: 13px; }

/* ---------- runway strip (кешфлоу) ---------- */
.runway { background: var(--panel); border-radius: var(--r-md); padding: 22px 24px 16px; margin-bottom: 28px; }
.runway-head { display: flex; justify-content: space-between; align-items: baseline; gap: 20px; flex-wrap: wrap; margin-bottom: 14px; }
.runway-figure { display: flex; gap: 36px; flex-wrap: wrap; }
.runway-figure div { display: grid; }
.runway-figure b { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.runway-figure span { font-size: 12px; color: var(--muted); }
.runway-figure b.neg { color: var(--red); }
.runway svg { display: block; width: 100%; height: 220px; overflow: visible; }
.runway .bar { fill: var(--blue); }
.runway .bar.low { fill: var(--blue-tint); }
.runway .bar.neg { fill: var(--red); }
.runway .bar.min { fill: var(--blue-dark); }
.runway .zero { stroke: var(--ink); stroke-width: 1; }
.runway .grid { stroke: var(--line); }
.runway text { font: 11px var(--font); fill: var(--muted); }
.runway text.val { fill: var(--ink); font-weight: 600; }
.runway text.val.neg { fill: var(--red); }
.runway .hit { fill: transparent; cursor: pointer; }
.runway .hit:hover { fill: rgba(48,92,255,.06); }

.warn-list { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 6px; }
.warn-list li { background: var(--amber-soft); color: #6B4A12; padding: 8px 12px; border-radius: var(--r-sm); font-size: 13px; }
.gap-note { background: var(--red-soft); color: #8A1C1E; padding: 10px 14px; border-radius: var(--r-sm); margin-bottom: 16px; font-weight: 500; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #FAFBFE; }
.cf-table td, .cf-table th { white-space: nowrap; }
.cf-table td:first-child, .cf-table th:first-child { position: sticky; left: 0; background: #fff; z-index: 1; min-width: 200px; }
.cf-table th:first-child { background: var(--panel); }
.cf-table tr.total td { font-weight: 700; border-top: 1px solid var(--ink); }
.cf-table tr.opening td { color: var(--muted); }
.cf-table td.click { cursor: pointer; }
.cf-table td.click:hover { color: var(--blue); text-decoration: underline; }
.cf-table td.neg { color: var(--red); }
.cf-cur { margin-bottom: 28px; }
.cf-cur h2 { display: flex; gap: 10px; align-items: baseline; }

/* ---------- вкладки виплат ---------- */
.loose-bal { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 13px; padding: 8px 2px 12px; }
.loose-item { display: inline-flex; gap: 6px; align-items: center; }
.subtabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.subtabs a { padding: 10px 14px; color: var(--muted); text-decoration: none; font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.subtabs a:hover { color: var(--ink); }
.subtabs a.on { color: var(--blue-dark); border-bottom-color: var(--blue); font-weight: 600; }
.subtabs .cnt { margin-left: 6px; background: var(--panel); color: var(--muted); border-radius: 999px; padding: 1px 7px; font-size: 12px; font-variant-numeric: tabular-nums; }
.subtabs a.on .cnt { background: var(--blue-soft); color: var(--blue-dark); }
.subtabs .cnt.warn { background: var(--red-soft); color: var(--red); }
input[type=checkbox] { min-height: 0; padding: 0; vertical-align: middle; }
tr.child-row td { background: #FBFCFE; font-size: 13px; padding-top: 6px; padding-bottom: 6px; }
tr.child-row.dim td { opacity: .55; }
tr.root-row td { border-bottom-color: transparent; }
tr.day-row td { background: var(--panel); font-size: 13px; padding-top: 10px; padding-bottom: 10px; }

/* ---------- filters ---------- */
.filters { display: grid; grid-template-columns: auto 1fr; gap: 14px 24px; padding: 16px 18px; background: var(--panel); border-radius: var(--r-md); margin-bottom: 14px; }
.filters .group-title { font-size: 12px; font-weight: 600; color: var(--muted); padding-top: 9px; }
.filters .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 7px 12px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--blue); color: #fff; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 11px; font-size: 13px; color: var(--muted); }
.chip.on { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); font-weight: 600; }

.sums { display: flex; gap: 20px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 6px 2px 12px; }
.sums b { color: var(--ink); font-variant-numeric: tabular-nums; }

.bulkbar { position: sticky; top: 64px; z-index: 10; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: var(--r-md); margin-bottom: 12px; }
.bulkbar select { min-height: 32px; padding: 4px 8px; color: var(--ink); background: #fff; }
.bulkbar select option { color: var(--ink); }
.bulkbar .btn { min-height: 32px; }
.bulkbar .count { font-weight: 600; margin-right: 6px; }

/* статуси */
.st { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-invoiced { background: var(--panel); color: var(--ink); }
.st-queued { background: var(--blue-soft); color: var(--blue-dark); }
.st-paid { background: var(--amber-soft); color: var(--amber); }
.st-posted { background: var(--green-soft); color: var(--green); }
.st-post_failed { background: var(--red-soft); color: var(--red); }
.st-split { background: #F3EEFF; color: #5B3CC4; }
.st-cancelled { background: #fff; color: var(--faint); text-decoration: line-through; }
.flag { color: var(--red); font-size: 12px; font-weight: 600; }
.login { font-weight: 600; }
.inv-link { font-weight: 600; text-decoration: none; border-bottom: 1px dashed var(--blue-tint); }
.inv-link:hover { border-bottom-style: solid; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--muted); font-size: 13px; }

.test-banner { background: var(--amber-soft); color: #6B4A12; text-align: center; font-size: 13px; font-weight: 600; padding: 7px 14px; border-bottom: 1px solid #F1DDB4; }
.card.test-mode { border-color: #F1DDB4; background: #FFFCF5; }

/* ---------- налаштування ---------- */
.card { border: 1px solid var(--line); border-radius: var(--r-md); padding: 20px 22px 8px; margin-bottom: 20px; max-width: 980px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.set-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; padding: 10px 0 14px; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-actions { display: flex; gap: 8px; padding-bottom: 2px; }
.test-out { margin-top: 8px; }
.ok-text { color: var(--green); font-weight: 600; font-size: 13px; }
code { font-size: 12px; background: var(--panel); padding: 1px 5px; border-radius: 4px; }

/* ---------- drawer ---------- */
.drawer { position: fixed; inset: 0; background: rgba(23,23,23,.28); display: none; z-index: 40; }
.drawer.open { display: block; }
.drawer-inner { position: absolute; right: 0; top: 0; bottom: 0; width: min(560px, 100%); background: #fff; padding: 28px; overflow-y: auto; box-shadow: -12px 0 40px rgba(4,41,183,.12); }
.drawer-close { position: absolute; right: 16px; top: 12px; border: 0; background: none; font-size: 26px; color: var(--muted); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; margin-bottom: 20px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.pre { white-space: pre-wrap; font-size: 12px; background: var(--panel); padding: 10px; border-radius: var(--r-sm); }
.section { margin-bottom: 22px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 22px; }

/* ---------- dialog ---------- */
dialog { border: 0; border-radius: var(--r-md); padding: 0; width: min(440px, 92vw); box-shadow: 0 20px 60px rgba(4,41,183,.18); }
dialog::backdrop { background: rgba(23,23,23,.35); }
#dlg-form { padding: 24px; display: grid; gap: 14px; }
#dlg-form .dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: var(--grad); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.login-art svg { width: 54px; height: 50px; }
.login-art p { font-size: 28px; font-weight: 700; line-height: 1.25; max-width: 420px; margin: 0; letter-spacing: -0.01em; }
.login-form { display: grid; align-content: center; justify-items: start; padding: 56px; gap: 14px; }
.login-form form { display: grid; gap: 14px; width: min(340px, 100%); }
.login-form input { width: 100%; }
@media (max-width: 800px) { .login-wrap { grid-template-columns: 1fr; } .login-art { display: none; } }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: var(--r-sm); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; z-index: 60; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); }

.empty { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 900px) {
  .topbar { gap: 12px; padding: 0 14px; overflow-x: auto; }
  main { padding: 18px 14px 60px; }
  .filters { grid-template-columns: 1fr; }
  .filters .group-title { padding-top: 0; }
  .who span { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
