/* Фінансовий дашборд для бізнесу — стримана «дорога» палітра.
   Один спокійний акцент (глибокий зелений), теплі нейтралі, без світіння. */

:root {
    --bg: #f4f2ee;
    --surface: #ffffff;
    --surface-2: #faf9f5;
    --ink: #23201c;
    --ink-soft: #6c665c;
    --ink-faint: #9a9488;
    --line: #e4dfd5;
    --line-strong: #d3ccbe;
    --accent: #1f6f5c;
    --accent-ink: #12503f;
    --accent-soft: #e8f0ec;
    --income: #1f6f5c;
    --expense: #a5443f;
    --danger: #b23b3b;
    --ok: #2f7d5a;
    --warn: #b9791d;
    --over: #b23b3b;
    --shadow: 0 1px 2px rgba(30, 26, 20, .05), 0 6px 20px rgba(30, 26, 20, .05);
    --radius: 14px;
    --radius-sm: 10px;
    --seg-1: #1f6f5c; --seg-2: #3f7d8c; --seg-3: #8a6d3b; --seg-4: #a5443f;
    --seg-5: #63688c; --seg-6: #4f8f63; --seg-7: #b0824a; --seg-8: #7c5c78;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #17140f;
        --surface: #221f18;
        --surface-2: #1d1a14;
        --ink: #ece6db;
        --ink-soft: #a49c8c;
        --ink-faint: #736c5d;
        --line: #322e25;
        --line-strong: #423d31;
        --accent: #4cb395;
        --accent-ink: #7fcbb4;
        --accent-soft: #1c3a32;
        --income: #4cb395;
        --expense: #d67f78;
        --danger: #d67f78;
        --ok: #57b580;
        --warn: #d69a4a;
        --over: #d67f78;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 22px rgba(0, 0, 0, .35);
        --seg-1: #4cb395; --seg-2: #5fa0b0; --seg-3: #b79663; --seg-4: #d67f78;
        --seg-5: #8c92b8; --seg-6: #6fb585; --seg-7: #d0a066; --seg-8: #a884a2;
    }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
    padding-bottom: 64px;
}

.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--income); }
.neg { color: var(--expense); }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); font-size: 13px; }

/* ---------- шапка ---------- */
.appbar {
    position: sticky; top: 0; z-index: 20;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--line);
}
.appbar-inner {
    max-width: 760px; margin: 0 auto; padding: 12px 16px 0;
    display: flex; flex-direction: column; gap: 10px;
}
.brand-row { display: flex; align-items: center; justify-content: space-between; }
.brand { font-size: 17px; font-weight: 640; letter-spacing: .2px; }
.brand span { color: var(--accent); }
.icon-btn {
    border: 1px solid var(--line-strong); background: var(--surface);
    color: var(--ink-soft); width: 34px; height: 34px; border-radius: 9px;
    display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-faint); }

.tabs { display: flex; gap: 2px; }
.tabs button {
    flex: 1; border: 0; background: none; cursor: pointer;
    padding: 10px 6px 12px; font-size: 14px; font-weight: 550;
    color: var(--ink-soft); border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- лейаут ---------- */
main { max-width: 760px; margin: 0 auto; padding: 18px 16px 40px; }
section.tab { display: none; }
section.tab.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.section-head {
    display: flex; align-items: center; justify-content: space-between;
    margin: 26px 2px 10px;
}
.section-head:first-child { margin-top: 4px; }
.section-head h2 { font-size: 13px; font-weight: 640; text-transform: uppercase; letter-spacing: .7px; color: var(--ink-soft); }
.link-btn {
    border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 600;
    cursor: pointer; padding: 4px 6px; border-radius: 7px;
}
.link-btn:hover { background: var(--accent-soft); }

.card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.list { display: flex; flex-direction: column; }
.list > .row + .row { border-top: 1px solid var(--line); }

.row {
    display: flex; align-items: center; gap: 12px;
    padding: 13px 15px; position: relative;
    -webkit-user-select: none; user-select: none;
    transition: transform .12s ease, box-shadow .12s ease;
}
.row.holding { transform: scale(.985); box-shadow: inset 0 0 0 2px var(--danger); border-radius: var(--radius-sm); }
.row .ico {
    width: 34px; height: 34px; flex: none; border-radius: 9px;
    background: var(--surface-2); border: 1px solid var(--line);
    display: grid; place-items: center; color: var(--ink-soft);
}
.row .ico svg { width: 17px; height: 17px; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 1px; }
.row .amount { font-weight: 600; text-align: right; }

/* ---------- картка «Загалом» ---------- */
.total-card { padding: 18px 18px 16px; margin-bottom: 6px; }
.total-card .label { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--ink-soft); }
.total-card .value { font-size: 30px; font-weight: 680; margin-top: 4px; letter-spacing: -.5px; }
.total-card .meta { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--ink-soft); }
.total-card .chip {
    display: inline-flex; gap: 5px; align-items: center;
    background: var(--surface-2); border: 1px solid var(--line);
    padding: 3px 9px; border-radius: 999px;
}
.fx-line { margin-top: 8px; font-size: 12px; color: var(--ink-faint); display: flex; align-items: center; gap: 6px; }
.fx-line.warn { color: var(--warn); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

/* ---------- прогрес-бари ---------- */
.bar { height: 7px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 7px; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s ease; }
.bar.ok > i { background: var(--ok); }
.bar.warn > i { background: var(--warn); }
.bar.over > i { background: var(--over); }
.bar-row { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; }

.budget-grid { padding: 16px; display: grid; gap: 18px; }
.budget-item .bh { display: flex; justify-content: space-between; align-items: baseline; }
.budget-item .bh b { font-weight: 600; }

/* ---------- форма операції ---------- */
.tx-form { padding: 16px; display: grid; gap: 12px; }
.seg {
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
    background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 4px;
}
.seg button {
    border: 0; background: none; padding: 9px; border-radius: 7px; cursor: pointer;
    font-weight: 570; font-size: 14px; color: var(--ink-soft);
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg button.on[data-v="income"] { color: var(--income); }
.seg button.on[data-v="expense"] { color: var(--expense); }

.field { display: grid; gap: 5px; }
.field > label { font-size: 12px; color: var(--ink-soft); font-weight: 560; letter-spacing: .2px; }
input, select, textarea {
    font: inherit; color: var(--ink); background: var(--surface);
    border: 1px solid var(--line-strong); border-radius: 9px; padding: 10px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 40px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
    border: 0; border-radius: 10px; padding: 11px 16px; font: inherit; font-weight: 600;
    cursor: pointer; background: var(--accent); color: #fff;
}
.btn:hover { background: var(--accent-ink); }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); }
.btn.ghost:hover { border-color: var(--ink-faint); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- регулярні: очікують ---------- */
.pending {
    padding: 14px 15px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line));
}
.pending + .pending { margin-top: 8px; }
.pending .grow { flex: 1 1 160px; min-width: 0; }
.pending .acts { display: flex; gap: 8px; }
.pending .btn { padding: 8px 12px; font-size: 13px; }
.badge {
    font-size: 11px; font-weight: 700; background: var(--over); color: #fff;
    border-radius: 999px; padding: 1px 7px; margin-left: 6px;
}

/* ---------- аналітика ---------- */
.analytics-controls { display: grid; gap: 10px; margin-bottom: 16px; }
.scope-seg { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.scope-seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 7px; font-size: 13px; font-weight: 550; color: var(--ink-soft); cursor: pointer; }
.scope-seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.period-nav { display: flex; align-items: center; justify-content: center; gap: 12px; }
.period-nav button { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 16px; }
.period-nav button:hover { color: var(--ink); }
.period-nav .plabel { font-weight: 600; min-width: 150px; text-align: center; }
.today-link { display: block; margin: 8px auto 0; }

.donut-wrap { display: flex; flex-direction: column; align-items: center; padding: 20px 16px 8px; }
.donut { position: relative; width: 210px; height: 210px; }
.donut svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.donut .center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.donut .center .t { font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .6px; }
.donut .center .v { font-size: 21px; font-weight: 680; margin-top: 2px; }
.empty { text-align: center; color: var(--ink-faint); padding: 40px 20px; }

.cat-line { display: flex; align-items: center; gap: 12px; padding: 11px 15px; }
.cat-line + .cat-line { border-top: 1px solid var(--line); }
.cat-line .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.cat-line .pct { color: var(--ink-soft); font-size: 13px; width: 48px; text-align: right; }

/* ---------- модалка ---------- */
.backdrop {
    position: fixed; inset: 0; z-index: 60; background: rgba(20, 17, 13, .45);
    display: grid; place-items: end center; padding: 0;
}
@media (min-width: 560px) { .backdrop { place-items: center; padding: 24px; } }
.modal {
    background: var(--surface); width: 100%; max-width: 460px;
    border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
    max-height: 88vh; overflow-y: auto;
}
@media (min-width: 560px) { .modal { border-radius: 16px; } }
.modal h3 { font-size: 16px; padding: 18px 18px 0; }
.modal form, .modal .modal-body { padding: 16px 18px 20px; display: grid; gap: 13px; }
.modal .actions { display: flex; gap: 10px; margin-top: 4px; }
.modal .actions .btn { flex: 1; }
.checkbox { display: flex; align-items: center; gap: 9px; font-size: 14px; color: var(--ink); }
.checkbox input { width: auto; }
.del-text { color: var(--danger); background: none; border: 0; font: inherit; font-weight: 600; cursor: pointer; padding: 6px; }

.manage-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.manage-row .grow { flex: 1; min-width: 0; }
.manage-row .mini { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 7px; padding: 5px 9px; font-size: 12.5px; cursor: pointer; color: var(--ink-soft); }

/* ---------- тост ---------- */
#toast {
    position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px);
    background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 10px;
    font-size: 13.5px; font-weight: 550; opacity: 0; pointer-events: none; transition: .22s ease; z-index: 90;
    max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); color: #fff; }

.hint { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.hold-hint { text-align: center; font-size: 11.5px; color: var(--ink-faint); margin-top: 10px; }
