/* TopAdminStars Invoicer — light, airy admin UI. */
:root {
    --bg: #ffffff;
    --bg-soft: #f7f8fa;
    --bg-hover: #f1f3f6;
    --border: #e4e7ec;
    --border-strong: #d0d5dd;
    --text: #1d2433;
    --text-soft: #475467;
    --muted: #8a94a6;
    --primary: #2f63e0;
    --primary-hover: #2554c7;
    --primary-soft: #eaf0fd;
    --danger: #d92d20;
    --danger-soft: #fdecea;
    --success: #12a150;
    --success-soft: #e7f6ee;
    --warning: #c77700;
    --warning-soft: #fff4e0;
    --radius: 6px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-pop: 0 8px 24px rgba(16, 24, 40, .12);
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 13px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
svg.icon { width: 16px; height: 16px; flex: none; stroke-width: 1.75; }
/* Icons inside buttons always keep button size, whatever container the button is in */
.btn svg.icon { width: 16px; height: 16px; margin: 0; color: currentColor; }
.btn-sm svg.icon { width: 14px; height: 14px; }

/* ---------- App shell ---------- */
.shell { display: flex; min-height: 100vh; }

.rail {
    width: 52px; flex: none;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 12px 0;
    border-right: 1px solid var(--border);
    background: var(--bg);
    position: sticky; top: 0; height: 100vh;
}
.rail .logo {
    width: 30px; height: 30px; border-radius: 7px;
    background: linear-gradient(135deg, #ff8a3d, #f04e23);
    color: #fff; display: grid; place-items: center; margin-bottom: 10px;
    font-weight: 700;
}
.rail .logo svg { width: 17px; height: 17px; fill: #fff; stroke: #fff; }
.rail a, .rail button {
    width: 34px; height: 34px; border-radius: var(--radius);
    display: grid; place-items: center;
    color: var(--muted); background: none; border: 0; cursor: pointer;
}
.rail a:hover, .rail button:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.rail a.active { background: var(--bg-hover); color: var(--text); }
.rail .spacer { flex: 1; }
.rail .avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: #4caf7a; color: #fff; font-size: 11px; font-weight: 600;
    display: grid; place-items: center;
}

.sidebar {
    width: 228px; flex: none;
    border-right: 1px solid var(--border);
    padding: 16px 10px;
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .app-title { font-size: 16px; font-weight: 700; padding: 2px 8px 14px; }
.sidebar .new-btn { display: flex; margin-bottom: 14px; }
.sidebar .new-btn .btn-primary:first-child { flex: 1; border-top-right-radius: 0; border-bottom-right-radius: 0; justify-content: flex-start; }
.sidebar .new-btn .dropdown > .btn-primary { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 1px solid rgba(255,255,255,.25); padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a {
    display: flex; align-items: center; gap: 9px;
    padding: 6px 8px; border-radius: var(--radius);
    color: var(--text); font-size: 13px;
}
.nav a svg { color: var(--text-soft); }
.nav a:hover { background: var(--bg-hover); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav a.active svg { color: var(--primary); }
.nav a .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.nav-section {
    margin: 16px 0 6px; padding: 10px 8px 0;
    border-top: 1px solid var(--border);
    font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .04em; text-transform: uppercase;
}
.sidebar .bottom { margin-top: auto; padding: 12px 8px 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.sidebar .bottom .ai { display: flex; gap: 6px; align-items: flex-start; }
.sidebar .bottom .ai svg { width: 13px; height: 13px; color: #f5a623; margin-top: 1px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: 52px; display: flex; align-items: center; gap: 10px;
    padding: 0 20px; border-bottom: 1px solid var(--border);
    position: sticky; top: 0; background: rgba(255,255,255,.92); backdrop-filter: blur(6px); z-index: 5;
}
.topbar .title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.topbar .title svg { color: var(--text-soft); }
.topbar .title .crumb { color: var(--muted); font-weight: 500; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.toolbar {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 10px 20px; border-bottom: 1px solid var(--border);
}
.toolbar .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.content { padding: 20px; }
.content.narrow { max-width: 860px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 30px; padding: 0 12px;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    background: #fff; color: var(--text);
    font: 500 13px var(--font); cursor: pointer; white-space: nowrap;
    box-shadow: var(--shadow);
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn:focus-visible, .input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--primary-soft); outline-offset: 0; border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { border-color: transparent; background: none; box-shadow: none; color: var(--text-soft); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.95); background: var(--success); }
.btn-icon { width: 30px; padding: 0; }
.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; box-shadow: none; }
.btn-group .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.btn-group .btn.active { background: var(--primary-soft); color: var(--primary); }

/* Segmented control (like "Все / Активные") */
.segmented { max-width: 100%; overflow-x: auto; display: inline-flex; background: var(--bg-soft); border-radius: var(--radius); padding: 2px; gap: 2px; }
.segmented a {
    white-space: nowrap; padding: 4px 10px; border-radius: 5px; color: var(--text-soft); font-size: 12.5px; font-weight: 500;
}
.segmented a:hover { color: var(--text); text-decoration: none; background: #fff; }
.segmented a.active { background: var(--primary-soft); color: var(--primary); }
.segmented a .n { color: var(--muted); margin-left: 4px; }

/* Dropdown */
.dropdown { position: relative; }
.dropdown-menu {
    display: none; position: absolute; right: 0; top: calc(100% + 4px); z-index: 20;
    min-width: 190px; padding: 4px; background: #fff;
    border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-pop);
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button {
    display: flex; align-items: center; gap: 8px; width: 100%;
    padding: 7px 10px; border: 0; background: none; border-radius: 5px;
    color: var(--text); font: 13px var(--font); text-align: left; cursor: pointer;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--bg-hover); text-decoration: none; }
.dropdown-menu .danger { color: var(--danger); }
.dropdown-menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label, .label { font-size: 12px; font-weight: 500; color: var(--text-soft); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .error, .error-text { font-size: 12px; color: var(--danger); }
.req::after { content: " *"; color: var(--danger); }
.input, .select, .textarea {
    width: 100%; height: 32px; padding: 0 10px;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    background: #fff; color: var(--text); font: 13px var(--font);
}
.textarea { height: auto; min-height: 80px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.select { appearance: none; padding-right: 28px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%238a94a6' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 9px center; }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--danger); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 20px; }
.checkbox { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text); cursor: pointer; }
.checkbox input { width: 15px; height: 15px; accent-color: var(--primary); }
.search { position: relative; }
.search svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 14px; height: 14px; }
.search .input { padding-left: 30px; width: 240px; height: 30px; }

/* ---------- Cards, tables ---------- */
.card { background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 13.5px; }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; }
.card-body { padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left; font-size: 11.5px; font-weight: 500; color: var(--muted);
    padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--bg-soft);
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfc; }
.table tr.clickable { cursor: pointer; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .muted, .muted { color: var(--muted); }
.table .sub { display: block; color: var(--muted); font-size: 12px; }
.table .strong { font-weight: 600; color: var(--text); }
.table .nowrap, .table td:first-child a.strong { white-space: nowrap; }
.table-wrap { overflow-x: auto; }

/* ---------- Chips & badges ---------- */
.chip {
    display: inline-flex; align-items: center; gap: 5px;
    height: 22px; padding: 0 8px; border: 1px solid var(--border); border-radius: 5px;
    background: #fff; font-size: 12px; color: var(--text-soft); white-space: nowrap;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; }
.chip.danger { color: var(--danger); border-color: #f6c7c2; background: var(--danger-soft); }
.chip svg { width: 12px; height: 12px; }

.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 5px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-draft { background: #f2f4f7; color: #667085; }
.badge-issued { background: var(--primary-soft); color: var(--primary); }
.badge-overdue { background: var(--danger-soft); color: var(--danger); }
.badge-paid { background: var(--success-soft); color: var(--success); }
.badge-cancelled { background: #f2f4f7; color: #98a2b3; text-decoration: line-through; }

/* ---------- Dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 14px 16px; }
.stat .label { display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 20px; font-weight: 600; margin-top: 6px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .value.small { font-size: 15px; }
.stat .foot { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat.danger .value { color: var(--danger); }
.stat.success .value { color: var(--success); }
.two-cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }

/* ---------- Board (kanban) ---------- */
.board { display: flex; gap: 16px; align-items: flex-start; overflow-x: auto; padding-bottom: 8px; }
.column { width: 260px; flex: none; }
.column-head {
    display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px;
    border-radius: var(--radius); font-weight: 500; margin-bottom: 10px; color: var(--text-soft);
}
.column-head .n { color: var(--muted); }
.column-head.draft { background: #eceff3; }
.column-head.issued { background: #dde7fb; color: var(--primary); }
.column-head.overdue { background: #fbe3e1; color: var(--danger); }
.column-head.paid { background: #dff3e8; color: var(--success); }
.board-card {
    display: block; padding: 10px 12px; margin-bottom: 8px;
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
    box-shadow: var(--shadow);
}
.board-card:hover { border-color: var(--primary); text-decoration: none; }
.board-card .top { display: flex; align-items: center; gap: 6px; color: var(--text-soft); font-size: 12px; }
.board-card .top .amount { margin-left: auto; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.board-card .name { margin: 6px 0 8px; }
.board-card .chips { display: flex; gap: 6px; flex-wrap: wrap; }
.column .empty-col { color: var(--muted); font-size: 12px; padding: 8px 12px; border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---------- Invoice editor ---------- */
.items { width: 100%; border-collapse: collapse; }
.items th { font-size: 11.5px; font-weight: 500; color: var(--muted); text-align: left; padding: 0 6px 6px; }
.items td { padding: 4px 6px; vertical-align: top; }
.items .col-service { width: 210px; }
.items .col-qty { width: 80px; }
.items .col-price { width: 120px; }
.items .col-unit { width: 72px; }
.items .col-amount { width: 120px; text-align: right; }
.items .amount { height: 32px; display: flex; align-items: center; justify-content: flex-end; font-variant-numeric: tabular-nums; font-weight: 500; }
.items .col-del { width: 36px; }
.totals { display: flex; justify-content: flex-end; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.totals .total { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.totals .total span { color: var(--muted); font-size: 13px; font-weight: 500; margin-right: 12px; }

/* ---------- Detail view ---------- */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.props { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 10px 12px; font-size: 13px; }
.props dt { color: var(--muted); }
.props dd { margin: 0; overflow-wrap: anywhere; }
.note-box { white-space: pre-wrap; color: var(--text-soft); }

/* ---------- Misc ---------- */
.flash {
    position: fixed; right: 20px; bottom: 20px; z-index: 50;
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px; border-radius: 8px; background: #1d2433; color: #fff;
    box-shadow: var(--shadow-pop); font-size: 13px; animation: flash-in .2s ease-out;
}
.flash.error { background: var(--danger); }
.flash svg { width: 15px; height: 15px; }
@keyframes flash-in { from { transform: translateY(8px); opacity: 0; } }
.alert { padding: 10px 12px; border-radius: var(--radius); background: var(--danger-soft); color: var(--danger); margin-bottom: 16px; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty > svg { width: 28px; height: 28px; color: var(--border-strong); margin-bottom: 8px; }
.empty .btn { margin-top: 12px; }
.pagination { display: flex; gap: 6px; justify-content: flex-end; padding: 12px 0 0; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.color-picker { display: flex; gap: 6px; }
.color-picker label { position: relative; cursor: pointer; }
.color-picker input { position: absolute; opacity: 0; }
.color-picker span { display: block; width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border); }
.color-picker input:checked + span { box-shadow: 0 0 0 2px var(--text); }
.row-actions { text-align: right; white-space: nowrap; width: 1%; }
.row-actions form { display: inline-block; }
.inactive td { color: var(--muted); }
details.edit-row summary { list-style: none; cursor: pointer; }
details.edit-row summary::-webkit-details-marker { display: none; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; background: var(--bg-soft); padding: 16px; }
.login-card { width: 100%; max-width: 360px; padding: 28px; }
.login-card .logo { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, #ff8a3d, #f04e23); display: grid; place-items: center; margin-bottom: 16px; }
.login-card .logo svg { width: 22px; height: 22px; fill: #fff; stroke: #fff; }
.login-card h1 { font-size: 18px; margin-bottom: 4px; }
.login-card p { color: var(--muted); margin: 0 0 20px; }
.login-foot { margin-top: 16px; font-size: 11px; color: var(--muted); text-align: center; max-width: 360px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .two-cols, .detail { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
    .sidebar { display: none; }
    .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
    .span-2 { grid-column: auto; }
    .content { padding: 16px; }
    .topbar, .toolbar { padding-left: 16px; padding-right: 16px; }
    .search .input { width: 100%; }
    .items .col-service { width: auto; }
}

/* =================== v0.2: accounting center =================== */
.badge-partial { background: var(--warning-soft); color: var(--warning); }
.amount-in { color: var(--success); }
.amount-out { color: var(--danger); }
.amount-move { color: var(--primary); }
.btn-soft-green { background: var(--success-soft); border-color: #bfe6cf; color: var(--success); }
.btn-soft-red { background: var(--danger-soft); border-color: #f6c7c2; color: var(--danger); }
.btn-soft-blue { background: var(--primary-soft); border-color: #c9d8f8; color: var(--primary); }
.btn-soft-green:hover { background: #d6efe1; } .btn-soft-red:hover { background: #fadbd7; } .btn-soft-blue:hover { background: #dbe6fb; }

/* Payments page: wallets column + list */
.ledger { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: calc(100vh - 52px); }
.wallets-col { border-right: 1px solid var(--border); padding: 16px 12px; background: #fcfcfd; }
.wallets-col .head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 10px; font-weight: 600; }
.wallet-item {
    display: flex; align-items: center; gap: 10px; padding: 9px 10px; margin-bottom: 6px;
    border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}
.wallet-item:hover { border-color: var(--border-strong); text-decoration: none; }
.wallet-item.active { background: var(--primary-soft); border-color: #c9d8f8; }
.wallet-item.off { opacity: .55; }
.wallet-badge { width: 30px; height: 30px; border-radius: 6px; color: #fff; font-size: 10.5px; font-weight: 700; display: grid; place-items: center; flex: none; letter-spacing: .02em; }
.wallet-item .meta { min-width: 0; flex: 1; }
.wallet-item .name, .wallet-item .sub { display: block; }
.wallet-item .name { font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wallet-item .sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wallet-item .bal { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 12.5px; }
.wallet-item .bal.neg { color: var(--danger); }
.ledger-main { min-width: 0; }
.ledger-head { display: flex; align-items: flex-start; gap: 16px; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.ledger-head .label { font-weight: 600; color: var(--text); font-size: 13px; }
.big-total { display: flex; gap: 18px; align-items: baseline; flex-wrap: wrap; margin-top: 2px; }
.big-total .v { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.big-total .v small { font-size: 15px; font-weight: 600; }
.big-total .approx { color: var(--muted); font-size: 13px; }
.ledger-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.tx-list { width: 100%; border-collapse: collapse; }
.tx-list td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tx-list tr:hover td { background: #fafbfc; }
.tx-list .dir { width: 36px; text-align: center; }
.tx-list .dir svg { width: 15px; height: 15px; }
.tx-list .who { width: 210px; }
.tx-list .who b { display: block; font-size: 12.5px; text-transform: uppercase; letter-spacing: .01em; }
.tx-list .who span { color: var(--muted); font-size: 11.5px; }
.tx-list .what .cat { font-weight: 500; }
.tx-list .what .cp { color: var(--muted); text-transform: uppercase; font-size: 12px; margin-left: 6px; letter-spacing: .02em; }
.tx-list .what .note { color: var(--muted); font-size: 12px; display: block; margin-top: 2px; }
.tx-list .amt { text-align: right; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx-list .amt .credited { display: block; font-size: 11.5px; color: var(--muted); font-weight: 400; }
.tx-list .act { width: 80px; text-align: right; white-space: nowrap; }
.tx-list .act form { display: inline-block; }
.group-row td { background: var(--bg-soft) !important; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 6px 12px; }

/* Slide-over drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .25); z-index: 40; display: none; }
.drawer {
    position: fixed; top: 0; right: 0; bottom: 0; width: 440px; max-width: 100vw; z-index: 41;
    background: #fff; box-shadow: var(--shadow-pop); display: none; flex-direction: column;
}
.drawer.open, .drawer.open + .drawer-backdrop { display: flex; }
.drawer.open + .drawer-backdrop { display: block; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); font-size: 16px; font-weight: 600; }
.drawer-head .dot-ico { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; }
.drawer-head .close { margin-left: auto; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.drawer-foot { border-top: 1px solid var(--border); padding: 12px 20px; display: flex; gap: 8px; justify-content: flex-end; }
.amount-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 8px; }
.amount-row .cur { height: 32px; border: 1px solid var(--border); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; color: var(--text-soft); background: var(--bg-soft); font-weight: 500; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 28px minmax(0, 1fr); gap: 8px; align-items: end; }
.split .arrow { color: var(--muted); padding-bottom: 7px; text-align: center; }
.callout { background: var(--bg-soft); border-radius: var(--radius); padding: 10px 12px; font-size: 12.5px; color: var(--text-soft); }
.callout.warn { background: var(--warning-soft); color: #8a5a00; }

/* Finance dashboard */
.page-title-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.page-title-row h1 { font-size: 15px; }
.page-title-row h1 span { font-weight: 500; color: var(--text-soft); }
.quick { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.quick a, .quick button {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; height: 54px;
    background: #fff; border: 1px solid var(--border); border-radius: 8px; color: var(--text); font: 600 12.5px var(--font); cursor: pointer; text-align: left;
}
.quick a:hover, .quick button:hover { border-color: var(--border-strong); text-decoration: none; box-shadow: var(--shadow); }
.quick .ico { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; flex: none; }
.ico.green { background: var(--success-soft); color: var(--success); }
.ico.red { background: var(--danger-soft); color: var(--danger); }
.ico.blue { background: var(--primary-soft); color: var(--primary); }
.ico.violet { background: #efebfd; color: #6250d6; }
.ico.orange { background: #fff1e6; color: #eb6834; }
.section-title { font-size: 16px; font-weight: 600; margin: 22px 0 10px; display: flex; align-items: baseline; gap: 8px; }
.section-title small { font-size: 12px; color: var(--muted); font-weight: 400; }
.section-title a { margin-left: auto; font-size: 12.5px; font-weight: 500; }
.flow { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-bottom: 1px solid var(--border); }
.flow > div { padding: 14px 16px; }
.flow .k { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: 5px; }
.flow .k svg { width: 13px; height: 13px; }
.flow .v { font-size: 20px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.flow .mid { text-align: center; } .flow .end { text-align: right; } .flow .end .k { justify-content: flex-end; }
.debtors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.debtors > div { padding: 12px 16px; } .debtors > div + div { border-left: 1px solid var(--border); }
.debtors h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.debtors h3 .n { font-size: 11px; padding: 0 6px; border-radius: 4px; }
.debtor { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--border); color: var(--text); }
.debtor:last-child { border-bottom: 0; }
.debtor:hover { text-decoration: none; color: var(--primary); }
.debtor .amt { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.charts-row { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 14px; }
.chart-card { padding: 14px 16px; position: relative; }
.chart-card .cap { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.legend { display: flex; gap: 12px; margin-left: auto; color: var(--text-soft); }
.legend i, .tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart .grid { stroke: #eef1f5; stroke-width: 1; }
svg.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
svg .hit { fill: transparent; cursor: crosshair; }
svg.chart .crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; visibility: hidden; pointer-events: none; }
.donut-wrap { display: flex; align-items: center; gap: 22px; justify-content: center; flex-wrap: wrap; }
svg.donut { width: 170px; height: 170px; flex: none; }
svg.donut .seg { cursor: pointer; }
svg.donut .donut-top { fill: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .06em; font-family: var(--font); }
svg.donut .donut-value { fill: var(--text); font-size: 12.5px; font-weight: 700; font-family: var(--font); }
.donut-legend { display: flex; flex-direction: column; gap: 8px; min-width: 160px; font-size: 12px; }
.donut-legend .row { display: flex; align-items: center; gap: 8px; }
.donut-legend .row b { margin-left: auto; font-variant-numeric: tabular-nums; }
.donut-legend .sw { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.summary .card { padding: 12px 14px 0; border-left: 3px solid var(--c); overflow: hidden; }
.summary .k { font-size: 12px; color: var(--muted); }
.summary .v { font-size: 18px; font-weight: 700; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
svg.spark { width: 100%; height: 44px; display: block; }
.two-lists { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.activity { display: flex; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.activity:last-child { border-bottom: 0; }
.activity .av { width: 26px; height: 26px; border-radius: 50%; background: #98a2b3; color: #fff; font-size: 11px; font-weight: 600; display: grid; place-items: center; flex: none; }
.activity .txt { flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-soft); }
.activity .when { text-align: right; font-size: 11px; color: var(--muted); white-space: nowrap; }
.activity .when b { display: block; color: var(--text-soft); font-weight: 600; }
.activity .when b.danger { color: var(--danger); } .activity .when b.success { color: var(--success); }

/* Floating tooltip for charts */
.tip { position: fixed; z-index: 60; pointer-events: none; background: #1d2433; color: #fff; padding: 7px 10px; border-radius: 6px; font-size: 12px; line-height: 1.5; box-shadow: var(--shadow-pop); display: none; white-space: nowrap; }

@media (max-width: 1200px) {
    .quick { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .charts-row, .two-lists { grid-template-columns: minmax(0, 1fr); }
    .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .ledger { grid-template-columns: minmax(0, 1fr); }
    .wallets-col { border-right: 0; border-bottom: 1px solid var(--border); }
    .flow, .debtors { grid-template-columns: minmax(0, 1fr); }
    .debtors > div + div { border-left: 0; border-top: 1px solid var(--border); }
    .flow .mid, .flow .end { text-align: left; } .flow .end .k { justify-content: flex-start; }
    .tx-list .who { width: auto; }
    .quick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* =================== v0.3: client cabinet =================== */
body.cabinet { background: var(--bg-soft); }
.cab-wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.cab-top { background: #fff; border-bottom: 1px solid var(--border); }
.cab-top .cab-wrap { display: flex; align-items: center; gap: 24px; height: 56px; }
.cab-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); font-size: 14px; }
.cab-brand:hover { text-decoration: none; }
.logo-sm { width: 28px; height: 28px; border-radius: 7px; background: linear-gradient(135deg, #ff8a3d, #f04e23); display: grid; place-items: center; }
.logo-sm svg { width: 16px; height: 16px; fill: #fff; stroke: #fff; }
.cab-nav { display: flex; gap: 4px; }
.cab-nav a { padding: 6px 12px; border-radius: var(--radius); color: var(--text-soft); font-weight: 500; }
.cab-nav a:hover { background: var(--bg-hover); text-decoration: none; color: var(--text); }
.cab-nav a.active { background: var(--primary-soft); color: var(--primary); }
.cab-user { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.cab-main { padding-top: 24px; padding-bottom: 24px; min-height: calc(100vh - 120px); }
.cab-title { font-size: 20px; margin-bottom: 16px; }
.cab-foot { text-align: center; color: var(--muted); font-size: 11px; padding-bottom: 20px; }
.cab-auth { display: grid; place-items: center; min-height: 60vh; }
.code-input { font-size: 22px; letter-spacing: 8px; text-align: center; height: 48px; font-variant-numeric: tabular-nums; }
@media (max-width: 700px) {
    .cab-top .cab-wrap { flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 10px; gap: 10px; }
    .cab-user .muted { display: none; }
    .cabinet .stats { grid-template-columns: minmax(0, 1fr) !important; }
}

/* =================== v0.4: tickets =================== */
.thread { display: flex; flex-direction: column; gap: 12px; }
.msg { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; max-width: 88%; background: #fff; }
.msg.client { align-self: flex-start; background: #f7f8fa; }
.msg.staff { align-self: flex-end; background: var(--primary-soft); border-color: #d3e0fa; }
.msg.internal { background: #fff8eb; border-style: dashed; border-color: #f5d7a1; }
.msg-head { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 4px; flex-wrap: wrap; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.nav a .badge-count { margin-left: auto; background: var(--danger); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 6px; line-height: 18px; font-weight: 600; }

/* =================== v0.5: languages, impersonation =================== */
.lang-switch { display: inline-flex; gap: 2px; background: var(--bg-soft); border-radius: 6px; padding: 2px; }
.lang-switch a { font-size: 11px; font-weight: 600; color: var(--muted); padding: 2px 7px; border-radius: 4px; }
.lang-switch a:hover { color: var(--text); text-decoration: none; background: #fff; }
.lang-switch a.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.impersonate-bar { background: #f59e0b; color: #1d2433; text-align: center; padding: 8px 16px; font-weight: 600; font-size: 13px; }
.impersonate-bar button { background: none; border: 0; padding: 0; margin-left: 10px; font: inherit; text-decoration: underline; cursor: pointer; color: #1d2433; }

/* =================== v0.7: self sign-up, trial =================== */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 40px; align-items: center; padding: 40px 0 30px; }
.hero h1 { font-size: clamp(28px, 4.4vw, 42px); letter-spacing: -0.02em; line-height: 1.15; margin-bottom: 14px; }
.hero-text > p { font-size: 17px; max-width: 560px; margin: 0 0 20px; }
.hero-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; font-size: 15px; }
.hero-points li { display: flex; gap: 8px; align-items: center; }
.hero-points .icon { width: 18px; height: 18px; color: var(--primary); }
.signup { display: grid; gap: 14px; }
.signup h2 { font-size: 17px; margin: 0; }
.signup .small { font-size: 12px; margin: 0; text-align: center; }
.signup .hint.ok { color: #16a34a; }
.signup .hint.bad { color: var(--danger); }
.btn-block { width: 100%; justify-content: center; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.trial-bar { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 14px 24px 0; padding: 9px 16px;
    border: 1px dashed #b8c8f3; border-radius: 10px; background: #f6f9ff; color: var(--text-soft); font-size: 13px; }
.trial-bar .icon { width: 15px; height: 15px; color: var(--primary); flex: none; }
.trial-bar.ending { border-color: #f1c27d; background: #fffaf1; }
.trial-bar.ending .icon { color: var(--warning); }
@media (max-width: 860px) { .trial-bar { margin: 10px 12px 0; } }

/* Radio choices as buttons (e.g. ticket priority): works without JavaScript */
.choice-group { display: flex; flex-wrap: wrap; gap: 6px; }
.choice { position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.choice > span { display: inline-block; padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text-soft); font-size: 13px; transition: background .12s, border-color .12s; }
.choice:hover > span { background: var(--bg-hover); }
.choice input:checked + span { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.choice-urgent input:checked + span { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.choice span .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.choice span small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 2px; }
.choice input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (max-width: 860px) { .hero { grid-template-columns: 1fr; gap: 24px; padding-top: 20px; } }
