:root {
    --bg: #101114;
    --surface: #17181c;
    --surface-2: #1d1e23;
    --border: #292b31;
    --text: #f2f0ea;
    --text-dim: #8b8d96;
    --accent: #e8b84d;
    --accent-dim: #8a6f2e;
    --expense: #e2685a;
    --income: #6fbf8b;

    --font-display: "Space Grotesk", sans-serif;
    --font-body: "Inter", sans-serif;
    --font-mono: "IBM Plex Mono", monospace;
}

/* ---------- Теми оформлення (перемикаються в Налаштування → Загальні) ----------
   Тема задається атрибутом data-theme на <html> (див. static/js/theme.js).
   Усі кольори інтерфейсу беруться зі змінних, тож нова тема = новий блок нижче. */

:root {
    --on-accent: #1a1305;
    --hover: rgba(255, 255, 255, 0.04);
    --hover-weak: rgba(255, 255, 255, 0.02);
    --overlay: rgba(8, 8, 10, 0.65);
    --feed-expense: var(--text);
    --radius: 14px;
}

/* Mono — як застосунок Monobank: графіт, білий акцент, зелені надходження */
:root[data-theme="mono"] {
    --bg: #262626;
    --surface: #303030;
    --surface-2: #3a3a3a;
    --border: #404040;
    --text: #f4f4f4;
    --text-dim: #9a9a9f;
    --accent: #f4f4f4;
    --accent-dim: #6a6a6a;
    --expense: #ff6b5e;
    --income: #2fc22f;
    --on-accent: #111111;
    --font-display: "Inter", sans-serif;
}

/* Gold — попередній вигляд: темний з золотим акцентом */
:root[data-theme="gold"] { /* значення за замовчуванням з :root */ }

/* Midnight — глибокий синій */
:root[data-theme="midnight"] {
    --bg: #0b1020;
    --surface: #121a30;
    --surface-2: #1a2440;
    --border: #243055;
    --text: #e8edf8;
    --text-dim: #8794b5;
    --accent: #5b9cff;
    --accent-dim: #2f5aa8;
    --expense: #ff7a8a;
    --income: #4fd6a0;
    --on-accent: #06122b;
    --overlay: rgba(3, 6, 16, 0.7);
}

/* Emerald — темно-зелений з м'ятним акцентом */
:root[data-theme="emerald"] {
    --bg: #0a1210;
    --surface: #101c18;
    --surface-2: #17271f;
    --border: #22382e;
    --text: #e9f3ee;
    --text-dim: #85a193;
    --accent: #34d399;
    --accent-dim: #1d7a59;
    --expense: #f0806e;
    --income: #5be3a8;
    --on-accent: #04170f;
    --overlay: rgba(2, 8, 6, 0.7);
}

/* Light — світла, спокійна */
:root[data-theme="light"] {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #f0f1f4;
    --border: #e1e3e9;
    --text: #16181d;
    --text-dim: #6b7280;
    --accent: #2563eb;
    --accent-dim: #93b4f5;
    --expense: #d94a3d;
    --income: #16a34a;
    --on-accent: #ffffff;
    --hover: rgba(0, 0, 0, 0.04);
    --hover-weak: rgba(0, 0, 0, 0.02);
    --overlay: rgba(20, 24, 33, 0.45);
    color-scheme: light;
}
:root[data-theme="light"] .sync-log { background: #11161d; }

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-dim); }
.small { font-size: 0.85rem; }

h1, h2 { font-family: var(--font-display); margin: 0 0 8px; letter-spacing: -0.01em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.05rem; font-weight: 600; }

/* ---------- Auth screens ---------- */

.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 40%),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
}
.auth-card.wide { max-width: 460px; }

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 20px;
}
.brand-mark { color: var(--accent); font-size: 1.4rem; line-height: 0; }

.form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--text-dim); }

input {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.95rem;
}
input:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent); }

.btn {
    font-family: var(--font-body);
    font-weight: 600;
    border-radius: 8px;
    padding: 10px 16px;
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.9rem;
}
.btn-primary { background: var(--accent); color: var(--on-accent); border: none; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }

.alert {
    background: rgba(226, 104, 90, 0.12);
    border: 1px solid rgba(226, 104, 90, 0.4);
    color: #f2a99e;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-top: 14px;
}

.steps { color: var(--text-dim); font-size: 0.9rem; line-height: 1.8; padding-left: 20px; }

/* ---------- App shell ---------- */

.app-shell { min-height: 100vh; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }

.content { padding: 28px; max-width: 1080px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }

/* ---------- Tabs ---------- */

.tabs {
    display: flex;
    gap: 4px;
    padding: 0 28px;
    margin-top: 16px;
    max-width: 1080px;
    margin-left: auto;
    margin-right: auto;
}
.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 10px 4px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel.hidden { display: none; }
.tab-panel { animation: fadeInUp 0.2s ease; }

/* ---------- Select ---------- */

.select-small {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 0.8rem;
    font-family: var(--font-body);
    cursor: pointer;
}

.head-controls { display: flex; align-items: center; gap: 10px; }

/* ---------- Sync progress ---------- */

.sync-progress {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--surface);
    border: 1px solid var(--accent-dim);
    border-radius: 12px;
    padding: 14px 18px;
}
.sync-progress.hidden { display: none; }
.sync-progress-bar {
    flex: 1;
    height: 10px;
    background: var(--surface-2);
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.sync-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.3s ease;
}
#sync-progress-text { color: var(--text); font-size: 0.85rem; white-space: nowrap; }

.btn-danger {
    background: transparent;
    border: 1px solid var(--expense);
    color: var(--expense);
}
.btn-danger:hover { background: rgba(226, 104, 90, 0.12); }
.btn-danger.hidden { display: none; }

.sync-log {
    background: #0a0b0d;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    max-height: 220px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.6;
    color: #7fd992;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}
.sync-log.hidden { display: none; }

.jar-card { border-color: var(--accent-dim); }

.transfer-note { margin: 10px 0 0; line-height: 1.4; }

/* ---------- Custom date range ---------- */

.custom-range {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}
.custom-range.hidden { display: none; }
.custom-range input[type="date"] {
    padding: 6px 8px;
    font-size: 0.8rem;
}

.budget-month-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 10px;
}
.budget-month-nav.hidden { display: none; }
.budget-month-label { font-weight: 600; font-size: 0.9rem; min-width: 150px; text-align: center; }
.budget-month-nav .btn:disabled { opacity: 0.35; cursor: default; }

.btn-tiny { padding: 6px 10px; font-size: 0.78rem; }
.btn-tiny.hidden { display: none; }

/* ---------- Category list (clickable, like Monobank's own breakdown) ---------- */

.category-list { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

.category-row {
    display: grid;
    grid-template-columns: 130px 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    background: transparent;
    text-align: left;
    font-family: var(--font-body);
    color: var(--text);
}
.category-row:hover { background: var(--surface-2); }
.category-row.active { background: var(--surface-2); border-color: var(--accent-dim); }

.category-name { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.category-bar-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.category-bar-fill { height: 100%; border-radius: 4px; }

.category-amount { font-family: var(--font-mono); font-size: 0.85rem; white-space: nowrap; }

.category-amount-dual {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    white-space: nowrap;
    display: flex;
    flex-direction: column;
    gap: 1px;
    text-align: right;
}

/* ---------- Donut chart + income/expense switch ---------- */

.io-switch { display: flex; gap: 4px; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.io-switch button {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    cursor: pointer;
    font-family: var(--font-body);
}
.io-switch button.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.io-switch-compact { flex-shrink: 0; }
.io-switch-compact button { padding: 6px 9px; font-size: 0.76rem; }

/* Той самий вигляд, що й .io-switch, але без спільного JS-обробника —
   щоб перемикач у модалці "Додати вручну" не чіплявся до глобального
   перемикача витрати/доходу в стрічці операцій. */
.manual-io-switch { display: flex; gap: 4px; background: var(--surface-2); border-radius: 8px; padding: 3px; margin: 10px 0; }
.manual-io-switch button {
    flex: 1; border: none; background: transparent; color: var(--text-dim); padding: 8px 12px;
    border-radius: 6px; font-size: 0.86rem; cursor: pointer; font-family: var(--font-body);
}
.manual-io-switch button.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.ledger-sort-hint { margin: 0 0 10px; }

.category-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    flex-wrap: wrap;
}
.donut-wrap {
    position: relative;
    width: 180px;
    height: 180px;
    flex-shrink: 0;
}
.donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    pointer-events: none;
}
.donut-center strong { font-size: 1.05rem; margin-top: 2px; }
.category-list { flex: 1; min-width: 220px; }

/* ---------- Sync time estimate ---------- */

.sync-estimate {
    padding: 10px 28px;
    max-width: 1080px;
    margin: 0 auto;
    text-align: right;
    color: var(--text-dim);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.sync-estimate.hidden { display: none; }

.settings-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.settings-gap-top { margin-top: 16px; }

#settings-btn { position: relative; }
#settings-btn.has-notice::after {
    content: "";
    position: absolute;
    top: 4px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--expense, #e2685a);
    border: 1.5px solid var(--surface);
}

.sync-period-input {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px 10px;
}
.input-tiny {
    width: 46px;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    text-align: right;
    padding: 0;
}
.input-tiny:focus { outline: none; }
/* убираем стрелки у number input в webkit, чтобы не мешали компактному виду */
.input-tiny::-webkit-outer-spin-button,
.input-tiny::-webkit-inner-spin-button { opacity: 0.6; }

.accounts-row { display: flex; gap: 16px; flex-wrap: wrap; }

.account-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
    min-width: 180px;
    flex: 1;
    position: relative;
}
.account-type {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    margin-bottom: 6px;
}
.account-title { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 10px; }
.account-balance { font-family: var(--font-mono); font-size: 1.4rem; font-weight: 600; }
.ccy { color: var(--text-dim); font-size: 1rem; }

.panel-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 20px;
}
@media (max-width: 800px) { .panel-grid { grid-template-columns: 1fr; } }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
}

.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

.period-switch { display: flex; gap: 4px; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.period-switch button {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    font-family: var(--font-body);
}
.period-switch button.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.totals-row { display: flex; gap: 32px; margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--border); }
.totals-row strong { font-size: 1.15rem; }
#total-spent { color: var(--expense); }
#total-income { color: var(--income); }

/* ---------- Ledger (signature element: receipt-style transaction list) ---------- */

.ledger-panel { position: relative; }

.ledger { display: flex; flex-direction: column; }

.ledger-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px dashed var(--border);
    gap: 12px;
}
.ledger-row:last-child { border-bottom: none; }

.ledger-left { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.ledger-desc { font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ledger-meta { font-size: 0.75rem; color: var(--text-dim); }

.ledger-amount { font-family: var(--font-mono); font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.ledger-amount.expense { color: var(--expense); }
.ledger-amount.income { color: var(--income); }

.category-pill {
    flex-shrink: 0;
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 5px 12px;
    border: 1px solid currentColor;
    border-radius: 8px;
    white-space: nowrap;
    text-align: center;
}

/* ---------- Ledger row actions (delete / move to category) ---------- */

.ledger-row-main { display: flex; align-items: center; justify-content: space-between; flex: 1; gap: 16px; min-width: 0; }
.ledger-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.ledger-action-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    line-height: 1;
    cursor: pointer;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.ledger-action-btn:hover { background: var(--surface-2); color: var(--text); }
.ledger-action-btn.danger:hover { border-color: var(--expense); color: var(--expense); }

/* ---------- Selectable account cards (клік замінює dropdown валют) ---------- */

.account-card-selectable { cursor: pointer; transition: border-color 0.15s ease, background 0.15s ease; }
.account-card-selectable:hover { border-color: var(--accent-dim); }
.account-card-selectable.selected { border-color: var(--accent); background: var(--surface-2); }

/* ---------- Settings modal ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
    animation: overlayIn 0.15s ease;
}
.modal-overlay.hidden { display: none; }

.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: 86vh;
    overflow-y: auto;
    animation: modalIn 0.18s cubic-bezier(0.2, 0.8, 0.3, 1);
}

@keyframes overlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
    .modal-overlay, .modal-card, .toast, .fade-in-row { animation: none !important; transition: none !important; }
}

/* ---------- Skeleton-плейсхолдери під час першого завантаження ---------- */

.skeleton {
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 37%, var(--surface-2) 63%);
    background-size: 400% 100%;
    animation: skeletonShimmer 1.4s ease infinite;
    border-radius: 6px;
}
@keyframes skeletonShimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}
@media (prefers-reduced-motion: reduce) {
    .skeleton { animation: none; background: var(--surface-2); }
}
.skeleton-list { display: flex; flex-direction: column; gap: 12px; padding: 4px 0; }
.skeleton-row { height: 14px; }
.skeleton-donut {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    flex-shrink: 0;
}
.skeleton-table-row { height: 38px; margin-bottom: 6px; border-radius: 8px; }

/* ---------- Модалка підтвердження (заміна нативного confirm()) ---------- */

.confirm-dialog-card {
    max-width: 380px;
    text-align: left;
}
.confirm-dialog-message {
    font-size: 0.92rem;
    line-height: 1.5;
    color: var(--text);
    margin: 0 0 20px;
}
.confirm-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ---------- Тости (заміна нативного alert()) ---------- */

.toast-stack {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 80;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(360px, calc(100vw - 40px));
}
.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--expense);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 0.84rem;
    line-height: 1.4;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    animation: toastIn 0.2s cubic-bezier(0.2, 0.8, 0.3, 1);
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.toast.toast-success { border-left-color: var(--income); }
.toast.toast-out { animation: toastOut 0.18s ease forwards; }
.toast-icon { flex-shrink: 0; margin-top: 1px; }
.toast-text { flex: 1; }
.toast-close {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
}
.toast-close:hover { color: var(--text); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(16px); }
}

/* ---------- Дрібні мікроанімації для списків, що перемальовуються ---------- */

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
.ledger-row, .budget-item-row, .refund-pair-card, .goal-item, .new-merchant-row, #excel-table-body tr[data-id], .feed-row {
    animation: fadeInUp 0.18s ease;
    animation-fill-mode: backwards;
}
/* Перемикання фільтрів (Тиждень/Місяць/Рік, Витрати/Доходи/Всі) після першого
   показу за сесію оновлює список без повторної анімації заходу рядків. */
.no-entrance-anim tr[data-id], .no-entrance-anim .budget-item-row {
    animation: none !important;
}

.btn { transition: transform 0.08s ease, background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease; }
.btn:active { transform: scale(0.97); }
.ledger-action-btn { transition: transform 0.08s ease, border-color 0.12s ease, color 0.12s ease; }
.ledger-action-btn:active { transform: scale(0.92); }

.budget-details-body { animation: fadeInUp 0.15s ease; }

.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

.modal-section { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--border); }

.danger-zone { border: 1px solid rgba(226, 104, 90, 0.4); border-radius: 10px; padding: 14px; border-top: 1px solid rgba(226, 104, 90, 0.4); }
.danger-zone h3 { color: #e2685a; margin-top: 0; }
.modal-section:first-of-type { margin-top: 0; padding-top: 0; border-top: none; }
.modal-section h3 { font-family: var(--font-display); font-size: 0.95rem; margin: 0 0 6px; }

.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.88rem;
    cursor: pointer;
    line-height: 1.4;
}
.toggle-row input { width: 16px; height: 16px; flex-shrink: 0; accent-color: var(--accent); }

.rule-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.rule-form input[type="text"] {
    flex: 1;
    min-width: 140px;
    padding: 8px 10px;
    font-size: 0.85rem;
}
.rule-form .select-small { flex-shrink: 0; }

.rules-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.rule-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--surface-2);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.82rem;
}
.rule-row-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.rule-row-text b { color: var(--accent); }
.rule-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.rule-row-edit {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-2);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.82rem;
    animation: fadeInUp 0.15s ease;
}
.rule-row-edit select { flex: 1; }

.rules-details summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}
.rules-details summary::-webkit-details-marker { display: none; }
.rules-details summary::before {
    content: "▶";
    display: inline-block;
    font-size: 0.7em;
    color: var(--text-dim);
    transition: transform 0.15s ease;
}
.rules-details[open] summary::before { transform: rotate(90deg); }
.rules-details summary:hover::before { color: var(--accent); }
.rules-details summary h3 { margin: 0; display: inline; }
.rules-details[open] > *:not(summary) { animation: fadeInUp 0.2s ease; }

/* ---------- Спливаючий список категорій (клік на 🏷) ---------- */

.category-popover {
    position: absolute;
    z-index: 60;
    width: 260px;
    max-height: 340px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-popover-loading { font-size: 0.82rem; color: var(--text-dim); padding: 6px 2px; }

.category-popover-title {
    font-size: 0.76rem;
    color: var(--text-dim);
    line-height: 1.35;
    padding: 0 2px;
}

.category-popover-filter {
    padding: 7px 9px;
    font-size: 0.82rem;
    flex-shrink: 0;
}

.category-popover-list {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.category-popover-item {
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.83rem;
    padding: 7px 9px;
    border-radius: 7px;
    cursor: pointer;
}
.category-popover-item:hover { background: var(--surface-2); }
.category-popover-item.hidden { display: none; }

/* ---------- Вибір категорії статті бюджету (дохід/витрата + магазини) ---------- */

.budget-item-category-btn, .budget-new-item-category-btn {
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.budget-cat-popover { width: 320px; max-height: 420px; }
.budget-cat-list { gap: 2px; }
.budget-cat-row { display: flex; flex-direction: column; }
.budget-cat-row.hidden { display: none; }
.budget-cat-row-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.83rem;
    padding: 7px 9px;
    border-radius: 7px;
    cursor: pointer;
    flex: 1;
    min-width: 0;
}
.budget-cat-row-main:hover { background: var(--surface-2); }
.budget-cat-row-main.active { background: var(--surface-2); color: var(--accent); }
.budget-cat-row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.budget-cat-row-amounts { display: flex; gap: 8px; flex-shrink: 0; font-size: 0.8rem; }
.budget-cat-row { position: relative; }
.budget-cat-row-expand {
    position: absolute;
    right: 6px;
    top: 3px;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.7rem;
    padding: 4px 6px;
}
.budget-cat-row-expand:hover { color: var(--accent); }
.budget-cat-row-main { padding-right: 26px; }
.budget-cat-row-merchants {
    padding: 2px 9px 8px 9px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: fadeInUp 0.15s ease;
}
.budget-cat-row-merchants.hidden { display: none; }
.budget-cat-merchant-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.76rem;
    color: var(--text-dim);
    padding: 3px 6px;
}
.budget-cat-merchant-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.category-popover-create { border-top: 1px dashed var(--border); padding-top: 8px; margin-top: 2px; }

.category-popover-create-toggle {
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--accent);
    font-size: 0.83rem;
    padding: 7px 9px;
    border-radius: 7px;
    cursor: pointer;
}
.category-popover-create-toggle:hover { background: var(--surface-2); }

.category-popover-create-form { display: flex; flex-direction: column; gap: 8px; padding: 6px 9px 2px; }
.category-popover-create-form.hidden { display: none; }

.category-popover-new-name { padding: 7px 9px; font-size: 0.82rem; }

.category-popover-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.category-popover-swatches .swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
}
.category-popover-swatches .swatch.selected { border-color: var(--text); }

/* ---------- Вкладка "Таблиця" (excel-подібний вигляд у гарній обгортці) ---------- */

.table-toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 14px 0 16px;
}

.table-search-input {
    flex: 1;
    min-width: 200px;
    padding: 9px 12px;
    font-size: 0.85rem;
}

.excel-table-wrap {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: auto;
    /* Вікно таблиці високе, але не вище за екран: вміщає ~12 рядків і не «ховається» в маленькій рамці */
    max-height: max(560px, 78vh);
    scrollbar-gutter: stable;
    background: var(--surface-2);
}
/* Лише головна таблиця операцій має фіксовану «просторість»; решта таблиць — за вмістом */
.ledger-panel .excel-table-wrap { min-height: 460px; }

.excel-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.excel-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    color: var(--text-dim);
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 10px 14px;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
    user-select: none;
    z-index: 1;
}
.excel-table thead th:hover { color: var(--text); }
.excel-table thead th.sorted { color: var(--accent); }

.excel-table tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.excel-table tbody tr:nth-child(even) { background: var(--hover-weak); }
.excel-table tbody tr:hover { background: var(--hover); }
.excel-table tbody tr:last-child td { border-bottom: none; }

.excel-table .col-desc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.excel-table .col-amount { text-align: right; font-weight: 600; }
.excel-table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.excel-table .col-actions .ledger-action-btn { margin-left: 4px; }
.excel-table .col-date, .excel-table .col-account { color: var(--text-dim); }

.income-text { color: var(--income); }
.expense-text { color: var(--expense); }

.excel-table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
    font-size: 0.85rem;
}

.excel-table-totals { display: flex; gap: 18px; flex-wrap: wrap; }

/* ---------- Вкладка "Бюджет" (власні картки-конверти) ---------- */

.budget-name-input { width: 100%; padding: 9px 12px; font-size: 0.9rem; margin-bottom: 10px; }

/* ---------- Табличний бюджет ---------- */

/* ---------- Табличний бюджет: сітка карток ---------- */

.budget-cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
    margin-top: 16px;
}
.budget-card-wide { grid-column: 1 / -1; }

/* Картки розділів бюджету потребують більше простору під таблицю статей, ніж
   маленькі картки "Огляд"/діаграм — тому своя сітка з ширшим мінімумом на
   колонку: на широких екранах вміщується кілька карток в ряд, на вузьких —
   автоматично складається в одну колонку. */
.budget-sections.budget-cards-grid {
    grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
}

.budget-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.budget-card-header {
    padding: 12px 16px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.95rem;
    color: #0f1013;
    background: linear-gradient(120deg, var(--accent), #f0c98a);
}
.budget-card-body { padding: 14px 16px; overflow-x: auto; }
.budget-card-body.budget-chart-box { position: relative; min-height: 220px; }
#budget-pie-chart.hidden { display: none; }
#budget-pie-empty.hidden { display: none; }
#budget-pie-empty { text-align: center; padding: 60px 10px; }
.budget-card-body.budget-chart-box canvas { max-height: 260px; }

/* Кожен розділ ("Огляд", "Підписки" тощо) — своя картка з "шапкою" у кольорі
   тієї ж мітки, що й у списку/діаграмі, щоб легко впізнавати розділ візуально. */
.budget-card-c0 .budget-card-header { background: linear-gradient(120deg, var(--accent), #f0c98a); }
.budget-card-c1 .budget-card-header { background: linear-gradient(120deg, #b79ce0, #8f7fd6); color: #17131f; }
.budget-card-c2 .budget-card-header { background: linear-gradient(120deg, #7fb8d6, #6fbf8b); color: #10201a; }

.budget-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.budget-table th {
    text-align: left; padding: 8px 10px; color: var(--text-dim); font-weight: 600;
    font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em;
    border-bottom: 1px solid var(--border);
}
.budget-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.budget-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }
.budget-table td.num { text-align: right; }
.budget-negative { color: var(--expense, #e2685a); }

.budget-section-block { padding: 0; }
.budget-section-head {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 12px 16px;
    background: var(--surface-2);
    background: linear-gradient(120deg, color-mix(in srgb, var(--section-color) 55%, var(--surface-2)), var(--surface-2) 130%);
    border-bottom: 1px solid var(--border);
}
.budget-section-block .budget-card-body { padding-top: 12px; }
.budget-section-name-input {
    font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; background: transparent;
    border: 1px solid transparent; border-radius: 6px; padding: 4px 8px; color: var(--text); flex: 1; min-width: 140px;
}
.budget-section-name-input:hover, .budget-section-name-input:focus { border-color: var(--border); background: var(--surface); }
.budget-section-totals { white-space: nowrap; }

.budget-items-table { table-layout: fixed; }
.budget-items-table .budget-cell-input {
    width: 100%; background: transparent; border: 1px solid transparent; border-radius: 6px;
    padding: 5px 7px; color: var(--text); font-size: 0.85rem; font-family: var(--font-body);
    box-sizing: border-box;
}
.budget-items-table select.budget-cell-input, .budget-items-table button.budget-cell-input { font-family: var(--font-body); cursor: pointer; }
.budget-items-table th:nth-child(1), .budget-items-table td:nth-child(1) { width: 26%; }
.budget-items-table th:nth-child(2), .budget-items-table td:nth-child(2) { width: 32%; }
.budget-items-table th:nth-child(3), .budget-items-table td:nth-child(3) { width: 18%; min-width: 84px; }
.budget-items-table th:nth-child(4), .budget-items-table td:nth-child(4) { width: 18%; min-width: 84px; }
.budget-items-table th:nth-child(5), .budget-items-table td:nth-child(5) { width: 36px; }
.budget-items-table td { overflow: visible; }
.budget-fact-auto { padding: 5px 7px; display: inline-block; color: var(--accent); font-weight: 600; }

.budget-details-toggle {
    display: block; margin-top: 4px; background: none; border: none; padding: 0;
    color: var(--text-dim); font-size: 0.74rem; cursor: pointer; text-align: left;
}
.budget-details-toggle:hover { color: var(--accent); }

.budget-item-details.hidden { display: none; }
.budget-item-details td { border-bottom: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 10px !important; }
.budget-details-body .checklist { max-height: 200px; }
.budget-merchant-save { margin-top: 8px; }

.budget-kind-badge {
    font-size: 0.7rem; padding: 2px 8px; border-radius: 999px; font-weight: 600; flex-shrink: 0;
}
.budget-kind-income { background: rgba(107, 194, 138, 0.15); color: var(--income, #6bc28a); }
.budget-kind-expense { background: rgba(226, 104, 90, 0.15); color: var(--expense, #e2685a); }

.budget-add-section-row { display: flex; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); flex-wrap: wrap; }
.budget-add-section-row .budget-cell-input {
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; font-size: 0.85rem;
}
#new-section-name { flex: 2; min-width: 160px; }
#new-section-kind { flex: 1; min-width: 100px; }

.budget-add-item-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.budget-add-item-row .budget-cell-input {
    background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; font-size: 0.85rem;
}
.budget-new-item-name { flex: 2; min-width: 140px; }
.budget-new-item-category-btn { flex: 1.5; min-width: 130px; font-family: var(--font-body); cursor: pointer; }
.budget-new-item-planned { flex: 1; min-width: 90px; }

/* ---------- Фінансові цілі ---------- */

.goals-add-row { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; flex-wrap: wrap; }
.goals-add-row .budget-name-input { margin-bottom: 0; flex: 1; min-width: 180px; }
.goal-price-field { max-width: 220px; }
.goals-add-row .btn { flex-shrink: 0; }

.goals-list { display: flex; flex-direction: column; gap: 6px; }

.goal-item {
    display: flex; align-items: center; gap: 12px; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
}
.goal-item.goal-done { opacity: 0.55; }
.goal-checkbox { width: 20px; height: 20px; flex-shrink: 0; cursor: pointer; accent-color: var(--accent); }
.goal-name { flex: 1; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.goal-item.goal-done .goal-name { text-decoration: line-through; }
.goal-price { font-weight: 600; color: var(--accent); white-space: nowrap; }
.goal-delete { flex-shrink: 0; }

.budget-modal-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.budget-modal-actions .btn-primary { margin-left: auto; }

.modal-section.hidden { display: none; }

/* ---------- Чек-листи з пошуком (напр. "Ручний вибір" у повернення) ---------- */

.checklist-search {
    width: 100%;
    padding: 9px 12px;
    font-size: 0.85rem;
    margin: 10px 0 8px;
}

.ledger-search-input {
    width: 200px;
    margin: 0;
    flex-shrink: 1;
}

.checklist {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.checklist-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 9px;
    border-radius: 6px;
    font-size: 0.83rem;
    cursor: pointer;
}
.checklist-item:hover { background: var(--surface-2); }
.checklist-item.hidden { display: none; }
.checklist-item input[type="checkbox"] { width: 15px; height: 15px; flex-shrink: 0; accent-color: var(--accent); }
.checklist-item-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.checklist-stats { display: flex; gap: 8px; flex-shrink: 0; font-family: var(--font-mono); font-size: 0.76rem; }
.checklist-stat.expense-text { color: var(--expense); }
.checklist-stat.income-text { color: var(--income); }

/* ---------- Повернення ---------- */

.refund-picker { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 16px; }
.refund-picker-col { flex: 1; min-width: 260px; display: flex; flex-direction: column; }
.refund-picker-label { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 6px; }
.refund-picker-col .checklist-search { margin: 0 0 6px; }

.refund-select {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 0.82rem;
    padding: 4px;
}
.refund-select option { padding: 6px 8px; border-radius: 6px; }
.refund-select option:checked { background: var(--accent); color: var(--on-accent); }

.refund-confirm-btn { margin-top: 14px; }

.refund-archive-title { font-family: var(--font-display); font-size: 1rem; margin: 0; }
.refund-section-title { font-family: var(--font-display); font-size: 1rem; margin: 18px 0 12px; }
.refund-wide-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 10px;
    cursor: pointer;
    user-select: none;
}
.refund-wide-toggle input { cursor: pointer; }

.refund-pair-card.refund-candidate { border-style: dashed; }

.refund-archive-details {
    margin-top: 26px;
    border-top: 1px dashed var(--border);
    padding-top: 14px;
}
.refund-archive-details summary {
    cursor: pointer;
    user-select: none;
    list-style: none;
}
.refund-archive-details summary::-webkit-details-marker { display: none; }
.refund-archive-details summary::before {
    content: "▶";
    display: inline-block;
    font-size: 0.7em;
    margin-right: 8px;
    color: var(--text-dim);
    transition: transform 0.15s ease;
}
.refund-archive-details[open] summary::before { transform: rotate(90deg); }
.refund-archive-details summary:hover::before { color: var(--accent); }
.refund-archive-details[open] > div { margin-top: 12px; animation: fadeInUp 0.2s ease; }

.refund-manual-details {
    margin-top: 22px;
    border-top: 1px dashed var(--border);
    padding-top: 14px;
}
.refund-manual-details summary {
    cursor: pointer;
    color: var(--accent);
    font-size: 0.85rem;
    user-select: none;
}
.refund-manual-details summary:hover { opacity: 0.85; }
.refund-manual-details[open] > *:not(summary) { animation: fadeInUp 0.2s ease; }

.refund-pair-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.refund-pair-tx { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 2px; }
.refund-pair-desc { font-size: 0.88rem; }
.refund-pair-link { color: var(--accent); font-size: 1.1rem; flex-shrink: 0; }

/* ---------- Нові магазини на перевірку ----------- */

#new-merchants-btn.hidden { display: none; }
#new-merchants-count { font-weight: 600; }

.new-merchant-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 4px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.new-merchant-row:last-child { border-bottom: none; }
.new-merchant-name { flex: 1; min-width: 140px; font-size: 0.88rem; }
.new-merchant-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* ---------- Мобільні екрани ---------- */

@media (max-width: 640px) {
    .topbar { padding: 12px 14px; flex-wrap: wrap; gap: 10px; }
    .topbar-right { gap: 8px; flex-wrap: wrap; }
    .topbar-right .muted { display: none; } /* email/ім'я не влазить поруч з кнопками — не критично на телефоні */
    .brand { font-size: 0.95rem; }

    .tabs { padding: 0 14px; gap: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .tab-btn { padding: 10px 10px; font-size: 0.84rem; white-space: nowrap; }

    .content { padding: 14px; gap: 16px; }
    .panel { padding: 16px; }
    .panel-head { flex-wrap: wrap; gap: 10px; }

    .category-layout { gap: 16px; }
    .donut-wrap { width: 140px; height: 140px; }
    .category-row { grid-template-columns: 92px 1fr auto; gap: 8px; font-size: 0.8rem; }

    .totals-row { flex-wrap: wrap; gap: 12px; }

    .budget-add-item-row, .budget-add-section-row { flex-direction: column; align-items: stretch; }
    .budget-add-item-row .budget-cell-input, .budget-add-section-row .budget-cell-input { width: 100%; min-width: 0; }
    .budget-cards-grid { grid-template-columns: 1fr; }

    .modal-card { padding: 18px; max-width: calc(100vw - 24px); }
    .category-popover, .budget-cat-popover { width: min(300px, calc(100vw - 24px)); }

    .refund-pair-card { flex-wrap: wrap; }
    .new-merchant-row { padding: 10px 0; }

    .toast-stack { left: 12px; right: 12px; bottom: 12px; max-width: none; }

    .excel-table-wrap { max-height: 70vh; }
    .ledger-panel .excel-table-wrap { min-height: 320px; }
}

/* --- fix: переключатель Дохід/Витрата + график (apply_fixes.py) --- */
.budget-kind-toggle { border: 0; cursor: pointer; font-family: inherit; transition: filter .15s, transform .1s; }
.budget-kind-toggle:hover { filter: brightness(1.3); }
.budget-kind-toggle:active { transform: scale(0.95); }
.budget-kind-toggle:disabled { opacity: .5; cursor: wait; }
.donut-wrap canvas { position: relative; z-index: 2; }
.donut-center { z-index: 1; padding: 0 28px; }
.donut-center strong { font-size: 0.95rem; white-space: nowrap; }


/* ---------- Свод: перемикач і картка ---------- */
.scope-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-bottom: 14px; }
.scope-currency { display: flex; align-items: center; gap: 8px; }
.scope-select {
    background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
    border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 0.85rem;
}
.account-card-total { cursor: pointer; border: 1px dashed var(--accent-dim); transition: border-color 0.15s ease, background 0.15s ease; }
.account-card-total:hover { border-color: var(--accent); }
.account-card-total.selected { border-style: solid; border-color: var(--accent); background: var(--surface-2); }
.ledger-extra { font-weight: 400; white-space: nowrap; }
.manual-amount-row { display: flex; gap: 8px; }
.manual-amount-row input { flex: 1; }
.manual-amount-row select { width: 110px; }

/* ---------- Таблиця (Excel-режим) ---------- */
.sheet-wrap { max-height: 70vh; }
.sheet-table tbody td { padding: 6px 10px; }
.sheet-table .cell-edit { cursor: text; }
.sheet-table .cell-edit:hover { outline: 1px dashed var(--accent-dim); outline-offset: -2px; }
.sheet-table .col-comment { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.sheet-table .col-actions { white-space: nowrap; }
.sheet-input {
    width: 100%; min-width: 80px; box-sizing: border-box;
    background: var(--bg, #111); color: var(--text); border: 1px solid var(--accent-dim);
    border-radius: 6px; padding: 5px 8px; font: inherit; font-size: 0.85rem;
}
.sheet-amount-input { min-width: 110px; text-align: right; font-family: "IBM Plex Mono", monospace; }
.sheet-new td { background: color-mix(in srgb, var(--accent) 6%, transparent); border-bottom: 2px solid var(--accent-dim); }
.sheet-table tfoot td {
    position: sticky; bottom: 0; background: var(--surface);
    border-top: 1px solid var(--border); padding: 10px 14px; font-size: 0.85rem;
}
.sheet-totals { text-align: right; }
.sheet-returned-btn {
    background: none; border: 1px dashed var(--accent-dim); color: var(--accent);
    border-radius: 6px; padding: 2px 8px; cursor: pointer; font: inherit; font-size: 0.8rem;
}

/* ---------- Повернення за спільні витрати ---------- */
.reimb-summary { line-height: 1.6; }
.reimb-share { color: var(--accent); font-weight: 600; font-size: 1.05rem; }
.reimb-list { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; }
.reimb-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.reimb-candidates { max-height: 220px; overflow-y: auto; margin: 10px 0; display: flex; flex-direction: column; gap: 6px; }
.reimb-candidate { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; font-size: 0.85rem; }

/* ---------- Проєкти ---------- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-top: 12px; }
.project-card {
    background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--accent);
    border-radius: 10px; padding: 14px 16px; cursor: pointer; transition: border-color 0.15s ease, transform 0.15s ease;
}
.project-card:hover { transform: translateY(-1px); border-color: var(--accent-dim); }
.project-card.selected { background: var(--surface); box-shadow: 0 0 0 1px var(--accent-dim); }
.project-name { font-weight: 600; margin-bottom: 6px; }
.project-spent { font-size: 1.15rem; margin-bottom: 4px; }
.project-chip {
    display: inline-block; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
    border-radius: 999px; padding: 2px 10px; font-size: 0.78rem;
}
.kpi-row { display: flex; flex-wrap: wrap; gap: 14px; margin: 14px 0; }
.kpi { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.kpi b { font-size: 1.05rem; }
.bar-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 130px; align-items: center; gap: 10px; font-size: 0.85rem; }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 10px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 6px; }
.bar-value { text-align: right; }

/* ---------- Порівняння місяців ---------- */
.cmp-highlight { border-radius: 10px; padding: 12px 16px; margin-bottom: 12px; border: 1px solid var(--border); }
.cmp-highlight.up { background: rgba(224, 96, 96, 0.10); border-color: rgba(224, 96, 96, 0.45); }
.cmp-highlight.down { background: rgba(92, 200, 168, 0.10); border-color: rgba(92, 200, 168, 0.45); }
.cmp-row-hl td { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.cmp-bar-cell { width: 160px; }
.cmp-bar { display: block; height: 8px; border-radius: 4px; min-width: 2px; }
.cmp-bar.up { background: #e06060; }
.cmp-bar.down { background: #5cc8a8; }

/* ---------- Аномалії ---------- */
.anomaly {
    display: flex; align-items: center; gap: 14px; padding: 12px 14px; margin-bottom: 8px;
    background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid #e8b84d; border-radius: 10px;
}
.anomaly.high { border-left-color: #e06060; }
.anomaly-icon { font-size: 1.4rem; }
.anomaly-main { flex: 1; min-width: 0; }
.anomaly-title { font-weight: 600; margin-bottom: 2px; }
.anomaly-actions { display: flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 720px) {
    .bar-row { grid-template-columns: 110px 1fr 90px; }
    .anomaly { flex-wrap: wrap; }
}


/* ---------- Таблиця бюджету (внизу вкладки «Бюджет») ---------- */
.budget-grid th, .budget-grid td { border: 1px solid var(--border); }
.budget-grid thead th { cursor: default; }
.budget-grid .grid-num { width: 44px; text-align: center; color: var(--text-dim); background: var(--surface); }
.budget-grid tbody tr:hover { background: var(--hover-weak); }
.budget-grid-total td { font-weight: 700; background: var(--surface); }


/* ---------- Утиліти ---------- */
.hidden { display: none !important; }
.inline-form { display: inline; margin: 0; }
.password-dialog-input { margin: 12px 0; }

/* ---------- Налаштування: вкладки-категорії ---------- */
.settings-card { max-width: 820px; min-height: 440px; }
.settings-layout { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 22px; align-items: start; }
.settings-nav { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; }
.settings-nav-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 10px;
    color: var(--text-dim);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 9px 12px;
    text-align: left;
    transition: background 0.15s ease, color 0.15s ease;
}
.settings-nav-btn:hover { color: var(--text); background: var(--hover); }
.settings-nav-btn.active { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.settings-nav-btn.active::before { content: ""; display: inline-block; width: 3px; height: 12px; margin-right: 8px; border-radius: 2px; background: var(--accent); vertical-align: -1px; }
.settings-pane > h3 { font-family: var(--font-display); font-size: 1.05rem; margin: 0 0 12px; }
.settings-pane .modal-section:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.settings-form { display: flex; flex-direction: column; gap: 4px; max-width: 360px; }
.settings-form .btn { align-self: flex-start; }

@media (max-width: 640px) {
    .settings-layout { grid-template-columns: 1fr; gap: 14px; }
    .settings-nav { flex-direction: row; overflow-x: auto; position: static; }
    .settings-nav-btn { white-space: nowrap; }
    .settings-card { min-height: 0; }
}

/* ---------- Графіки: власна підказка (HTML замість canvas — текст завжди чіткий) ---------- */
.chart-tooltip {
    position: fixed;
    z-index: 80;
    pointer-events: none;
    min-width: 190px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(12, 13, 16, 0.96);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.85rem;
    line-height: 1.35;
    opacity: 0;
    transition: opacity 0.12s ease;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .ct-title { font-family: var(--font-display); font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.chart-tooltip .ct-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.chart-tooltip .ct-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.chart-tooltip .ct-label { color: var(--text-dim); flex: 1; }
.chart-tooltip .ct-value { font-family: var(--font-mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.chart-tooltip .ct-row.ct-total { margin-top: 4px; padding-top: 6px; border-top: 1px solid var(--border); }
.chart-tooltip .ct-row.ct-total .ct-label { color: var(--text); font-weight: 600; }


/* ---------- Стрічка операцій у стилі банку ---------- */

.feed { display: flex; flex-direction: column; min-height: 320px; }

.feed-day {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.95rem;
    font-weight: 500;
    padding: 22px 0 10px;
}
.feed-day:first-child { padding-top: 6px; }

.feed-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 6px;
    border-radius: 12px;
    transition: background 0.12s ease;
}
.feed-row:hover { background: var(--hover); }

.feed-avatar {
    --c: var(--accent);
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.1rem;
    text-transform: uppercase;
    color: var(--c);
    background: color-mix(in srgb, var(--c) 18%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 35%, transparent);
}

.feed-main { flex: 1 1 auto; min-width: 0; }
.feed-title {
    font-size: 1rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.feed-sub {
    margin-top: 2px;
    font-size: 0.78rem;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.feed-amount { flex: 0 0 auto; text-align: right; font-size: 1rem; font-weight: 600; white-space: nowrap; }
.feed-amount.is-expense { color: var(--feed-expense); }
.feed-amount.is-income { color: var(--income); }
.feed-amount .ledger-extra { font-size: 0.72rem; color: var(--text-dim); font-weight: 400; }

/* Кнопки дій: нульової ширини, виїжджають ліворуч від суми при наведенні
   (на дотикових екранах — завжди), тож сума завжди притиснута до правого краю */
.feed-main { order: 1; }
.feed-actions { order: 2; flex: 0 0 0; width: 0; position: relative; align-self: stretch; opacity: 0; transition: opacity 0.12s ease; }
.feed-amount { order: 3; }
.feed-actions .ledger-action-btn { position: absolute; top: 50%; margin-top: -14px; background: var(--surface); }
.feed-actions .ledger-move-btn { right: 40px; }
.feed-actions .ledger-delete-btn { right: 6px; }
.feed-row:hover .feed-actions, .feed-row:focus-within .feed-actions { opacity: 1; }
@media (hover: none) { .feed-actions { opacity: 1; } }

.feed-empty { text-align: center; padding: 40px 0; }

@media (max-width: 640px) {
    .feed-row { gap: 12px; padding: 10px 2px; }
    .feed-avatar { width: 42px; height: 42px; }
    .feed-actions { display: none; }          /* на телефоні — місце під суму */
    .feed-row.show-actions .feed-actions { display: block; }
}

/* ---------- Вибір теми ---------- */

.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 10px; }
.theme-card {
    background: var(--surface-2);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    text-align: left;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 600;
}
.theme-card:hover { border-color: var(--accent-dim); }
.theme-card.active { border-color: var(--accent); }
.theme-swatch {
    height: 54px;
    border-radius: 8px;
    margin-bottom: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid rgba(128, 128, 128, 0.25);
}
.theme-swatch i { display: block; height: 6px; border-radius: 3px; }
.theme-swatch i:nth-child(1) { width: 55%; }
.theme-swatch i:nth-child(2) { width: 30%; }
.theme-card small { display: block; font-weight: 400; color: var(--text-dim); font-size: 0.72rem; margin-top: 2px; }


/* =====================================================================
   Каркас «як банківський застосунок»
   Плоский фон, шапка з іконками, картки рахунків як банківські картки,
   нижня панель вкладок, круглі кнопки. Кольори беруться зі змінних теми.
   ===================================================================== */

:root { --col: 760px; }

.svg-ico { display: block; flex: none; }
.ico { display: inline-flex; }

/* ---- Шапка: ⚙ | ім'я | 💵 🔍 ---- */
.topbar {
    position: sticky; top: 0; z-index: 40;
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
    padding: 10px max(14px, calc((100vw - var(--col)) / 2));
    background: var(--bg);
    border-bottom: none;
}
.topbar-title { display: flex; flex-direction: column; align-items: center; line-height: 1.2; min-width: 0; }
.topbar-name { font-weight: 600; font-size: 0.95rem; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-sub { font-size: 0.7rem; color: var(--text-dim); letter-spacing: 0.08em; text-transform: uppercase; }
.topbar-right { justify-content: flex-end; gap: 4px; }

.icon-btn {
    width: 44px; height: 44px; border-radius: 50%;
    display: inline-grid; place-items: center;
    background: transparent; border: none; color: var(--text); cursor: pointer;
    transition: background 0.12s ease, transform 0.08s ease;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn-sm { width: 36px; height: 36px; background: var(--surface-2); }

/* ---- Контент: вузька колонка, як у телефонному застосунку ---- */
.content { max-width: var(--col); padding: 8px 14px 28px; gap: 20px; }
.app-shell { padding-bottom: 92px; }

/* ---- Нижня панель вкладок ---- */
.tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    max-width: none; margin: 0;
    padding: 6px max(8px, calc((100vw - var(--col)) / 2)) calc(8px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    justify-content: space-around; gap: 0; overflow: visible;
}
.tab-btn {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 2px; border-bottom: none;
    font-size: 0.66rem; font-weight: 500; border-radius: 12px;
}
.tab-btn .ico { padding: 4px 14px; border-radius: 999px; transition: background 0.15s ease; }
.tab-btn.active { color: var(--text); border-bottom: none; }
.tab-btn.active .ico { background: var(--surface-2); }
.tab-btn:hover { color: var(--text); }

/* ---- Картки рахунків = банківські картки в горизонтальній стрічці ---- */
.accounts-row {
    flex-wrap: nowrap; gap: 12px; overflow-x: auto; scroll-snap-type: x proximity;
    padding: 2px 2px 6px; scrollbar-width: none; margin: 0 -14px; padding-inline: 14px;
}
.accounts-row::-webkit-scrollbar { display: none; }
.account-card {
    flex: 0 0 206px; min-width: 206px; height: 124px;
    display: flex; flex-direction: column; justify-content: space-between;
    padding: 14px 16px; border: none; border-radius: 18px;
    color: #fff; scroll-snap-align: start;
    background: linear-gradient(150deg, #2a2a2a 0%, #0c0c0c 100%);
    box-shadow: 0 1px 0 rgba(255,255,255,0.06) inset;
}
.account-card .account-type { color: rgba(255,255,255,0.65); margin: 0; font-size: 0.66rem; }
.account-card .account-title { color: rgba(255,255,255,0.9); margin: 0; font-size: 0.82rem; font-weight: 600; }
.account-card .account-balance { font-size: 1.3rem; }
.account-card .ccy { color: rgba(255,255,255,0.6); }
.account-card-selectable:hover { border: none; transform: translateY(-1px); }
.account-card-selectable.selected, .account-card-total.selected { box-shadow: 0 0 0 2px var(--text); background: linear-gradient(150deg, #2a2a2a 0%, #0c0c0c 100%); }
.account-card-total { border: none; background: linear-gradient(150deg, #4a4a4a 0%, #222 100%); }
.jar-card { border: none; background: linear-gradient(150deg, #34412f 0%, #121a10 100%); }

/* ---- Панелі: без рамок, м'які закруглення ---- */
.panel { background: var(--surface); border: none; border-radius: 22px; padding: 18px; }
.panel-head h2 { font-family: var(--font-body); font-size: 1.05rem; font-weight: 700; }
.ledger-panel { background: transparent; padding: 0; }
.ledger-panel .panel-head { padding: 0 4px; }
.excel-table-footer { border-top: none; padding: 14px 4px 0; }
.totals-row { border-top: none; background: var(--surface-2); border-radius: 16px; padding: 12px 16px; margin-top: 14px; }

/* ---- Кнопки та перемикачі — «таблетки» ---- */
.btn { border-radius: 999px; padding: 10px 18px; border: none; background: var(--surface-2); color: var(--text); }
.btn:hover { filter: brightness(1.12); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-ghost { background: var(--surface-2); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: transparent; border: 1px solid var(--expense); }
.btn-tiny { padding: 7px 12px; }

.io-switch, .period-switch, .manual-io-switch { background: var(--surface-2); border-radius: 999px; padding: 3px; }
.io-switch button, .period-switch button, .manual-io-switch button { border-radius: 999px; }
.panel .io-switch, .panel .period-switch { background: var(--bg); }
.ledger-panel .io-switch { background: var(--surface); }

input, select, textarea { border-radius: 12px; border: 1px solid transparent; background: var(--surface-2); }
.ledger-search-input { border-radius: 999px; padding-left: 16px; }

.ledger-action-btn { border: none; background: var(--surface-2); border-radius: 50%; }
.feed-actions .ledger-action-btn { background: var(--surface-2); display: grid; place-items: center; padding: 0; }
.category-pill { border-radius: 999px; }

/* ---- Стрічка: більші круглі іконки ---- */
.feed-avatar { width: 48px; height: 48px; }
.feed-day { font-size: 0.9rem; }

/* ---- Вікно налаштувань: «шторка» ---- */
.modal-card { border: none; border-radius: 24px; background: var(--surface); }
.settings-nav-btn { border-radius: 999px; }

@media (max-width: 640px) {
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal-card { max-width: 100%; border-radius: 24px 24px 0 0; max-height: 92vh; }
    .topbar-right .muted { display: none; }
    .account-card { flex-basis: 190px; min-width: 190px; height: 116px; }
}


/* ---- Логотипи магазинів поверх іконки категорії ---- */
.feed-avatar { position: relative; overflow: hidden; }
.feed-logo {
    position: absolute; inset: 0; width: 100%; height: 100%;
    object-fit: contain; padding: 9px; background: #fff; border-radius: 50%;
}

/* ---- Широкі екрани: вкладки зверху (нижня панель може ховатись за краєм вікна),
        картки рахунків переносяться, а не обрізаються ---- */
@media (min-width: 900px) {
    :root { --col: 1000px; }
    .app-shell { padding-bottom: 28px; }
    .tabs {
        position: static; background: none; backdrop-filter: none; -webkit-backdrop-filter: none;
        border-top: none; justify-content: flex-start; gap: 6px;
        margin: 2px 0 6px; padding: 0 max(14px, calc((100vw - var(--col)) / 2));
    }
    .tab-btn { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 8px 16px; font-size: 0.88rem; border-radius: 999px; }
    .tab-btn .ico { padding: 0; background: none !important; }
    .tab-btn.active { background: var(--surface-2); }
}
@media (min-width: 641px) {
    .accounts-row { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
    .account-card { flex: 1 1 190px; min-width: 170px; }
}


/* ---- Бюджет: одна смуга підсумків + таблиця статей по розділах ---- */
.budget-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.budget-sum-tile { background: var(--surface-2); border-radius: 16px; padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.budget-sum-label { font-size: 0.78rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.budget-sum-value { font-size: 1.25rem; white-space: nowrap; }
.budget-sum-value.budget-negative { color: var(--expense); }

/* Розділи йдуть одним стовпцем, як секції однієї таблиці, а не сіткою карток */
#budget-sections.budget-cards-grid { grid-template-columns: 1fr; gap: 14px; }

@media (max-width: 640px) {
    .budget-summary { grid-template-columns: 1fr; }
    .budget-sum-tile { flex-direction: row; align-items: baseline; justify-content: space-between; }
}

/* ---- Бюджет: спокійніша шапка розділу, без градієнта; зручно на телефоні ---- */
.budget-section-head {
    background: var(--surface-2);
    border-left: 4px solid var(--section-color);
    border-bottom: 1px solid var(--border);
}
.budget-card { border: none; background: var(--surface-2); border-radius: 18px; }
.budget-section-block .budget-card-body { overflow-x: auto; }
.budget-items-table { min-width: 520px; }
#budget-plan-hint { display: none; }                  /* довгий пояснювальний рядок — зайвий шум */
.panel-head h2 { margin-right: 12px; }

@media (max-width: 640px) {
    .budget-sum-tile { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: center; }
    .budget-sum-label { grid-row: 1 / span 2; }
    .budget-sum-value { grid-column: 2; text-align: right; font-size: 1.15rem; }
    .budget-sum-tile .small { grid-column: 2; text-align: right; }
    .budget-section-totals { white-space: normal; }
}
