:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1f2430; --muted: #6b7280; --line: #e6e8ec;
  --accent: #2563eb; --expense: #dc2626; --income: #16a34a; --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 17px; font-weight: 600; margin: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.badge-demo { background: #fef3c7; color: #92400e; }

.controls { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; padding: 16px 24px 8px; }
.controls label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 500; }
.controls input { font-size: 14px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); }
button { font-size: 14px; padding: 9px 16px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; font-weight: 500; }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: #1d4ed8; }
button.ghost { background: var(--panel); border-color: var(--line); color: var(--ink); }
button:disabled { opacity: .5; cursor: not-allowed; }
.status { font-size: 13px; color: var(--muted); }
.status.error { color: var(--expense); }

.filters { padding: 4px 24px 8px; display: flex; flex-direction: column; gap: 8px; }
.filter-row { display: flex; align-items: center; gap: 12px; }
.filter-label { font-size: 12px; color: var(--muted); width: 54px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font-size: 13px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; color: var(--ink); }
.chip.on { background: #eef2ff; border-color: #c7d2fe; color: #3730a3; font-weight: 500; }
.chip .cnt { color: var(--muted); font-weight: 400; margin-left: 4px; }

.tabs { display: flex; gap: 4px; padding: 8px 24px 0; border-bottom: 1px solid var(--line); }
.tab { background: none; border: none; padding: 10px 14px; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; border-radius: 0; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 500; }

.content { padding: 20px 24px 40px; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.card-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.card-value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card-value.expense { color: var(--expense); }
.card-value.income { color: var(--income); }
.card-value .warn { font-size: 15px; color: #b45309; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.panel-title { font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.struct-bar { display: flex; height: 14px; border-radius: 6px; overflow: hidden; margin-bottom: 14px; background: #eef0f3; }
.struct-bar > span { display: block; height: 100%; }
.struct-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px 18px; font-size: 12.5px; }
.leg { display: flex; align-items: center; gap: 6px; }
.leg .sw { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.leg .val { color: var(--muted); margin-left: auto; font-variant-numeric: tabular-nums; }

.top-op { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.top-op:first-child { border-top: none; }
.top-op .r { display: flex; align-items: center; gap: 10px; }
.top-op .amt { font-variant-numeric: tabular-nums; font-weight: 500; min-width: 90px; text-align: right; }

.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 11px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
.c-date { width: 88px; } .c-bank { width: 92px; } .c-amt { width: 110px; text-align: right; }
.c-dir { width: 78px; } .c-cat { width: 200px; } .c-cnt { width: 64px; text-align: right; }
td.c-amt, td.c-cnt { text-align: right; font-variant-numeric: tabular-nums; }
.purpose { color: var(--muted); font-size: 13px; }
.counterparty { font-weight: 500; }
.pill { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.pill.debit { background: #fee2e2; color: #991b1b; }
.pill.credit { background: #dcfce7; color: #166534; }
.bank-tag { font-size: 11px; color: var(--muted); }
.cat-select { width: 100%; font-size: 13px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.src { display: block; font-size: 10px; color: var(--muted); margin-top: 3px; }
.src.ai { color: var(--accent); }
.dot-cat { display: inline-flex; align-items: center; gap: 6px; }
.dot-cat .sw { width: 8px; height: 8px; border-radius: 2px; }

@media (max-width: 760px) { .cards { grid-template-columns: 1fr; } }

.cmp-total td { font-weight: 600; border-top: 1.5px solid var(--line); }
.cmp-total td.income { color: var(--income); }
#cmp-chart svg text { font-family: inherit; }

.c-bal { width: 150px; } .c-mon { width: 96px; } .c-del { width: 36px; text-align: center; }
.bal-select { width: 100%; font-size: 12.5px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--muted); }
.bal-select.on { border-color: #c7d2fe; background: #eef2ff; color: #3730a3; font-weight: 500; }
tr.settled { background: #f5f3ff; }
tr.settled td.c-amt { color: #6d28d9; }
.bal-badge { font-size: 10px; padding: 1px 7px; border-radius: 999px; background: #ede9fe; color: #6d28d9; font-weight: 600; }
.accrual-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.accrual-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 500; }
.accrual-form input, .accrual-form select { font-size: 14px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.accrual-form input#ac-name { min-width: 200px; } .accrual-form input#ac-amount { width: 120px; }
.rest-open { color: #b45309; font-weight: 600; }
.rest-closed { color: var(--income); font-weight: 500; }
.del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px 6px; }
.del:hover { color: var(--expense); }

.login-wrap { min-height: 90vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 340px; }
.login-field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 14px; }
.login-field input { font-size: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.userbar { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.userbar .who { font-weight: 500; color: var(--ink); }
.logout { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 4px 6px; }

/* Менеджеру не показываем форму создания начислений и кнопки удаления */
.role-manager .accrual-form, .role-manager .del { display: none; }

.c-method { width: 170px; }
.method-select { font-size: 12.5px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.role-manager .method-select { pointer-events: none; opacity: .5; }

/* Левая панель разделов */
.layout { display: flex; gap: 20px; align-items: flex-start; padding: 16px 24px 40px; }
.sidenav { width: 190px; flex: none; position: sticky; top: 16px; }
.load-btn { width: 100%; margin-bottom: 16px; }
.nav-label { font-size: 11px; color: var(--muted); margin: 0 0 6px 10px; }
.sidenav-nav { display: flex; flex-direction: column; gap: 2px; }
.sidenav-nav .tab { text-align: left; justify-content: flex-start; padding: 9px 12px; border: none; border-radius: 8px; font-size: 14px; color: var(--muted); background: none; width: 100%; }
.sidenav-nav .tab:hover { background: var(--panel); }
.sidenav-nav .tab.active { background: #eef2ff; color: #3730a3; font-weight: 500; }
.content { flex: 1; min-width: 0; padding: 0; }
.controls { padding: 0 0 12px; }
.filters { padding: 0 0 12px; }
.file-label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 500; }
.file-label input { font-size: 12px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; }
.role-manager .owner-only { display: none; }
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidenav { width: 100%; position: static; }
  .sidenav-nav { flex-direction: row; flex-wrap: wrap; }
  .sidenav-nav .tab { width: auto; }
}

.c-proj { width: 160px; }
.proj-select { width: 100%; font-size: 12.5px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--muted); }
.proj-select.on { border-color: #c7d2fe; background: #eef2ff; color: #3730a3; font-weight: 500; }
