/* === Reset & Base === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg: #0f172a; --bg-card: #1e293b; --bg-card-hover: #253349;
    --border: #334155; --border-light: #475569;
    --text: #e2e8f0; --text-muted: #94a3b8; --text-dim: #64748b;
    --primary: #c97d4f;
    --primary-hover: #b06d3f;
    --primary-light: #e8b896;
    --primary-rgb: 201 125 79;
    --success: #22c55e; --danger: #ef4444; --warning: #f59e0b;
    --income: #22c55e; --expense: #ef4444;
    --radius: 10px; --radius-sm: 6px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
}
html { font-size: 15px; -webkit-text-size-adjust: 100%; }

/* Responsive date text: full month on desktop, short numeric on mobile */
.date-fmt-short { display: none; }
@media (max-width: 768px) {
    .date-fmt-long { display: none !important; }
    .date-fmt-short { display: inline !important; }
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; line-height: 1.6; overflow-x: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Navbar === */
.navbar { background: var(--bg-card); border-bottom: 1px solid var(--border); padding: 0 1rem; position: sticky; top: 0; z-index: 100; }
@media (min-width: 901px) {
    .navbar { padding: 0 1.5rem; }
}
.nav-container { max-width: 1400px; margin: 0 auto; display: flex; align-items: center; min-height: 56px; gap: 1rem; position: relative; }
.nav-brand { color: var(--text); font-weight: 700; font-size: 1.2rem; display: flex; align-items: center; gap: 0.4rem; text-decoration: none; flex-shrink: 0; }
.nav-brand-logo { height: 1.85rem; width: auto; display: block; object-fit: contain; }
@media (max-width: 400px) {
    .nav-brand-logo { height: 1.45rem; }
}

.auth-brand { margin: 0 0 1rem; text-align: center; }
.auth-brand-logo { max-width: min(240px, 100%); height: auto; display: inline-block; vertical-align: top; }

.nav-toggle {
    display: none;
    margin-left: auto;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.nav-toggle:hover { background: rgba(255,255,255,0.06); border-color: var(--border-light); }
.nav-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.nav-toggle-bar {
    display: block;
    width: 20px;
    height: 2px;
    margin: 3px auto;
    background: currentColor;
    border-radius: 1px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}
.navbar.is-menu-open .nav-toggle-bar:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.navbar.is-menu-open .nav-toggle-bar:nth-child(2) { opacity: 0; }
.navbar.is-menu-open .nav-toggle-bar:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

.nav-menu {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-width: 0;
}
.nav-links { display: flex; gap: 0.25rem; flex: 1; flex-wrap: wrap; align-items: center; min-width: 0; }
.nav-link { color: var(--text-muted); padding: 0.5rem 0.85rem; border-radius: var(--radius-sm); font-size: 0.9rem; font-weight: 500; text-decoration: none; transition: all 0.15s; }
.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.05); text-decoration: none; }
.nav-link.active { color: var(--primary); background: rgb(var(--primary-rgb) / 0.1); }
.nav-user { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.user-name { color: var(--text-muted); font-size: 0.85rem; max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-logout { flex-shrink: 0; }

@media (max-width: 900px) {
    .nav-toggle { display: inline-flex; flex-direction: column; }
    .nav-menu {
        display: none;
        position: absolute;
        left: 0;
        right: 0;
        top: 100%;
        flex-direction: column;
        align-items: stretch;
        padding: 0.75rem 1rem 1rem;
        background: var(--bg-card);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 12px 24px rgba(0,0,0,0.35);
        gap: 0;
        max-height: calc(100vh - 56px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .navbar.is-menu-open .nav-menu { display: flex; }
    .nav-links {
        flex-direction: column;
        align-items: stretch;
        flex-wrap: nowrap;
        gap: 0.15rem;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid var(--border);
    }
    .nav-link { width: 100%; padding: 0.65rem 0.75rem; }
    .nav-user {
        flex-direction: column;
        align-items: stretch;
        gap: 0.65rem;
        padding-top: 0.85rem;
    }
    .user-name { max-width: none; white-space: normal; word-break: break-word; }
    .nav-logout { width: 100%; justify-content: center; }
}

/* === Main === */
.main-content { max-width: 1400px; margin: 0 auto; padding: 1.5rem; width: 100%; min-width: 0; box-sizing: border-box; }
@media (max-width: 600px) {
    .main-content { padding: 1rem 0.75rem; }
}

/* === Cards === */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 0.75rem; }
.card-title { font-size: 1rem; font-weight: 600; color: var(--text); }
.card-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.15rem; }

/* === Grid === */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* === Stat Cards === */
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; transition: border-color 0.2s; }
.stat-card:hover { border-color: var(--border-light); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.35rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.stat-value.positive { color: var(--income); }
.stat-value.negative { color: var(--expense); }
.stat-sub { font-size: 0.8rem; color: var(--text-dim); margin-top: 0.3rem; }

/* Account page: reconcile (left) + balance summary (right) */
.account-balance-grid {
    align-items: stretch;
}
.stat-card-balance-action {
    display: flex;
    flex-direction: column;
    border-left: 3px solid var(--primary);
    padding-left: calc(1.25rem - 3px);
}
.account-balance-stored-value {
    margin-top: 0.15rem;
}
.account-balance-reconcile-block {
    margin-top: 1.15rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.account-set-balance-form {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.account-set-balance-form .form-label {
    margin-bottom: 0;
    font-size: 0.8rem;
}
.account-set-balance-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}
.account-set-balance-row .form-input {
    flex: 1;
    min-width: 0;
}
.account-set-balance-submit {
    flex-shrink: 0;
    white-space: nowrap;
}

/* Account page: balance vs opening + transaction net */
.stat-balance-register {
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
}
.stat-balance-register.stat-balance-register--embedded {
    margin-top: 0.5rem;
    padding-top: 0;
    border-top: none;
}
.stat-balance-register-title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.45rem;
}
.stat-balance-register-rows {
    margin: 0;
}
.stat-balance-register-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    padding: 0.2rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.stat-balance-register-row:last-of-type {
    border-bottom: none;
}
.stat-balance-register-row dt {
    margin: 0;
    color: var(--text-muted);
    font-weight: 500;
}
.stat-balance-register-row dd {
    margin: 0;
    font-variant-numeric: tabular-nums;
    text-align: right;
}
.stat-balance-register-row-emph dt,
.stat-balance-register-row-emph dd {
    color: var(--text);
}
.stat-balance-register-row-total {
    margin-top: 0.25rem;
    padding-top: 0.45rem;
    border-top: 1px solid var(--border);
    border-bottom: none;
}
.stat-balance-register-row-total dt {
    color: var(--text);
    font-weight: 600;
}
.stat-balance-register-row-total dd {
    font-weight: 700;
    font-size: 1rem;
}
.stat-balance-register-match {
    margin: 0.65rem 0 0;
    line-height: 1.45;
}
.stat-balance-register-mismatch {
    color: var(--warning);
}

/* === Buttons === */
.btn { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.55rem 1.1rem; border: 1px solid transparent; border-radius: var(--radius-sm); font-size: 0.875rem; font-weight: 500; cursor: pointer; text-decoration: none; transition: all 0.15s; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-outline:hover { color: var(--text); border-color: var(--border-light); }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* === Forms === */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--text-muted); margin-bottom: 0.3rem; }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 0.55rem 0.75rem; background: var(--bg); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.9rem;
    transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--primary); }
.form-textarea { min-height: 80px; resize: vertical; }
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: min(100%, 12rem); }
@media (max-width: 600px) {
    .form-row { flex-direction: column; }
    .form-row .form-group { min-width: 0; }
}
.form-inline { display: flex; gap: 0.5rem; align-items: end; }
.form-input-sm { padding: 0.35rem 0.5rem; font-size: 0.8rem; }

/* Account transaction row: inline edit (pencil → save) */
.tx-inline-field { position: relative; }
.tx-inline-view,
.tx-inline-edit {
    display: flex;
    align-items: flex-start;
    gap: 0.35rem;
    flex-wrap: wrap;
}
.tx-inline-view { align-items: center; }
.tx-inline-edit { display: none; align-items: center; }
.tx-inline-field.is-editing .tx-inline-view { display: none !important; }
.tx-inline-field.is-editing .tx-inline-edit { display: flex !important; }
.tx-inline-text { flex: 1; min-width: 0; word-break: break-word; line-height: 1.45; }
.tx-inline-text.tx-inline-placeholder { color: var(--text-dim); font-style: italic; }
.tx-field-icon-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}
.tx-field-icon-btn:hover {
    color: var(--primary);
    background: rgb(var(--primary-rgb) / 0.12);
}
.tx-field-icon-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}
.tx-field-icon-svg { display: block; }

.account-tx-amount-cell {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.25rem;
    flex-wrap: nowrap;
}
.account-tx-flip-type-form {
    display: inline-flex;
    margin: 0;
    flex-shrink: 0;
}
button.tx-field-icon-btn.tx-save-btn {
    color: var(--success);
}
button.tx-field-icon-btn.tx-save-btn:hover {
    color: #4ade80;
    background: rgba(34, 197, 94, 0.12);
}
.tx-inline-edit .form-input-sm { flex: 1; min-width: 8rem; max-width: 100%; }
.tx-transfer-block {
    margin-top: 0.35rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
}

/* Account transaction row: category typeahead */
.category-combo { position: relative; flex: 1; min-width: 8rem; max-width: 20rem; }
.category-combo-input { width: 100%; }
.category-combo-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 2px);
    z-index: 45;
    margin: 0;
    padding: 0.25rem 0;
    list-style: none;
    max-height: 220px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: 0.8rem;
}
.category-combo-dropdown li {
    padding: 0.35rem 0.65rem;
    cursor: pointer;
    color: var(--text);
}
.category-combo-dropdown li:hover,
.category-combo-dropdown li.category-combo-active {
    background: rgb(var(--primary-rgb) / 0.15);
    color: var(--primary);
}

/* === Tables === */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    min-width: 0;
}
/* Edge-to-edge scroll area inside padded cards (avoids narrow inner scroll strip on phones) */
.card > .table-wrap {
    margin-left: -1.25rem;
    margin-right: -1.25rem;
    padding-left: 1.25rem;
    padding-right: 1.25rem;
    width: calc(100% + 2.5rem);
    max-width: none;
    box-sizing: border-box;
}
@media (max-width: 600px) {
    .card { padding-left: 1rem; padding-right: 1rem; }
    .card > .table-wrap {
        margin-left: -1rem;
        margin-right: -1rem;
        padding-left: 1rem;
        padding-right: 1rem;
        width: calc(100% + 2rem);
    }
}
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 0; }
/* Pair on matching th/td to hide secondary columns on phones / narrow tablets */
@media (max-width: 768px) {
    th.col-mobile-hide,
    td.col-mobile-hide {
        display: none !important;
    }
}
thead th { text-align: left; padding: 0.65rem 0.75rem; color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); }
.tx-data-table thead th.th-col-controls { vertical-align: middle; padding: 0.5rem 0.45rem; }
.th-col-inner { display: flex; align-items: center; justify-content: space-between; gap: 0.35rem; flex-wrap: nowrap; }
.th-col-inner-end { justify-content: flex-end; flex-direction: row-reverse; }
.th-col-label { flex: 1; min-width: 0; line-height: 1.25; }
.th-col-actions { display: inline-flex; align-items: center; gap: 0.15rem; flex-shrink: 0; }
.th-sort-link {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.65rem; height: 1.65rem; border-radius: var(--radius-sm);
    color: var(--text-dim); text-decoration: none; flex-shrink: 0;
}
.th-sort-link:hover { color: var(--text); background: rgba(255,255,255,0.06); text-decoration: none; }
.th-sort-svg { display: block; }
.th-sort-chev { transition: opacity 0.12s ease; }
.th-sort-link.is-sort-none .th-sort-chev { opacity: 0.4; }
.th-sort-link.is-sort-asc .th-sort-chev-down { opacity: 0.22; }
.th-sort-link.is-sort-asc .th-sort-chev-up { opacity: 1; stroke: var(--primary); }
.th-sort-link.is-sort-desc .th-sort-chev-up { opacity: 0.22; }
.th-sort-link.is-sort-desc .th-sort-chev-down { opacity: 1; stroke: var(--primary); }
.th-icon-link {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.65rem; height: 1.65rem; border-radius: var(--radius-sm);
    color: var(--text-dim); text-decoration: none; flex-shrink: 0;
}
.th-icon-link:hover { color: var(--text); background: rgba(255,255,255,0.06); text-decoration: none; }
.th-icon-svg { display: block; }
.th-filter-slot { position: relative; display: inline-flex; align-items: center; vertical-align: middle; }
.th-filter-slot-left .th-filter-panel { right: auto; left: 0; }
button.th-filter-toggle { border: none; background: transparent; padding: 0; cursor: pointer; font: inherit; color: inherit; }
.th-filter-toggle.has-active-filter { color: var(--primary); background: rgb(var(--primary-rgb) / 0.12); border-radius: var(--radius-sm); }
.th-filter-panel {
    position: absolute; z-index: 60; right: 0; top: calc(100% + 0.25rem);
    min-width: 220px; max-width: min(320px, 92vw);
    padding: 0.75rem; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.th-filter-panel[hidden] { display: none !important; }
.th-col-filter-form .form-label { display: block; margin-bottom: 0.2rem; }

.pagination-bar {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem 1rem;
    padding: 0.65rem 0 1rem; margin-bottom: 0.25rem; border-bottom: 1px solid var(--border);
}
.card > .pagination-bar:last-child { border-bottom: none; border-top: 1px solid var(--border); margin-bottom: 0; margin-top: 0.5rem; padding-top: 1rem; padding-bottom: 0; }
.pagination-summary { flex: 1; min-width: 8rem; }
.pagination-per-page { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.pagination-per-page-link {
    font-size: 0.8rem; padding: 0.2rem 0.45rem; border-radius: var(--radius-sm);
    color: var(--text-muted); text-decoration: none; border: 1px solid transparent;
}
.pagination-per-page-link:hover { color: var(--text); border-color: var(--border); text-decoration: none; }
.pagination-per-page-link.is-active { color: var(--primary); border-color: rgb(var(--primary-rgb) / 0.35); background: rgb(var(--primary-rgb) / 0.08); }
.pagination-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
@media (max-width: 480px) {
    .pagination-bar { flex-direction: column; align-items: stretch; }
    .pagination-nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.35rem;
        justify-content: flex-start;
    }
}
.pagination-page {
    display: inline-flex; align-items: center; justify-content: center; min-width: 2rem; height: 1.85rem;
    padding: 0 0.35rem; font-size: 0.8rem; border-radius: var(--radius-sm);
    color: var(--text-muted); text-decoration: none; border: 1px solid var(--border);
}
.pagination-page:hover { color: var(--text); background: rgba(255,255,255,0.04); text-decoration: none; }
.pagination-page-current {
    font-weight: 600; color: var(--primary); border-color: rgb(var(--primary-rgb) / 0.4); background: rgb(var(--primary-rgb) / 0.1);
}
.pagination-btn { min-height: 1.85rem; }
tbody td { padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--border); overflow-wrap: break-word; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* === Badges === */
.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-business { background: rgb(var(--primary-rgb) / 0.15); color: var(--primary-light); }
.badge-personal { background: rgba(168,85,247,0.15); color: #c084fc; }
.badge-income { background: rgba(34,197,94,0.15); color: #4ade80; }
.badge-expense { background: rgba(239,68,68,0.15); color: #f87171; }

/* === Entity Cards === */
.entity-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; text-decoration: none; display: block; transition: all 0.2s; }
.entity-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); text-decoration: none; }
.entity-card-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.entity-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.entity-card-name { font-weight: 600; font-size: 1.05rem; color: var(--text); }
.entity-card-type { font-size: 0.8rem; color: var(--text-muted); }
.entity-card-balance { font-size: 1.4rem; font-weight: 700; margin-top: 0.5rem; }

/* === Alerts === */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-success { background: rgba(34,197,94,0.1); color: #4ade80; border: 1px solid rgba(34,197,94,0.2); }
.alert-danger { background: rgba(239,68,68,0.1); color: #f87171; border: 1px solid rgba(239,68,68,0.2); }
.alert-info { background: rgb(var(--primary-rgb) / 0.1); color: var(--primary-light); border: 1px solid rgb(var(--primary-rgb) / 0.2); }
.alert-warning { background: rgba(245,158,11,0.1); color: #fbbf24; border: 1px solid rgba(245,158,11,0.2); }

/* === Auth Pages === */
.auth-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.auth-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px; padding: 2.5rem; width: 100%; max-width: 420px; box-sizing: border-box; }
@media (max-width: 480px) {
    .auth-wrapper { padding: 1rem; align-items: flex-start; padding-top: 2rem; }
    .auth-card { padding: 1.5rem 1.25rem; }
}
.auth-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.25rem; }
.auth-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; }

/* === Page Header === */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.25rem; flex-wrap: wrap; gap: 1rem; }
.page-header > div:first-child { min-width: 0; flex: 1 1 auto; }
.page-header .btn-group { justify-content: flex-end; flex: 1 1 100%; }
@media (min-width: 601px) {
    .page-header { align-items: center; }
    .page-header .btn-group { flex: 0 1 auto; }
}
.page-title { font-size: 1.5rem; font-weight: 700; word-wrap: break-word; }
@media (max-width: 600px) {
    .page-title { font-size: 1.25rem; }
}
.page-subtitle { color: var(--text-muted); font-size: 0.9rem; word-wrap: break-word; }

/* === Amount formatting === */
.amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.amount-positive { color: var(--income); }
.amount-negative { color: var(--expense); }

/* === Category color dot === */
.cat-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.4rem; vertical-align: middle; }

/* === Tabs === */
.tabs {
    display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem;
    overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap;
    scrollbar-width: thin;
}
.tabs::-webkit-scrollbar { height: 4px; }
.tab { padding: 0.6rem 1rem; color: var(--text-muted); font-size: 0.9rem; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.15s; text-decoration: none; flex-shrink: 0; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* === Modal === */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: none; align-items: center; justify-content: center; z-index: 200; }
.modal-overlay.open { display: flex; }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px; padding: 1.5rem; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.modal-book-category { max-width: 800px; }
.modal-link-transfer {
    max-width: min(960px, 96vw);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-link-transfer .modal-link-transfer-header,
.modal-link-transfer > p.text-muted,
#link-transfer-modal-loading,
#link-transfer-modal-error {
    flex-shrink: 0;
}
#link-transfer-modal-content.link-transfer-modal-content-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
/* Modal-only: summary + controls fixed; only the candidate table scrolls; submit bar always visible */
.link-transfer-body--modal {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
    flex: 1;
}
.link-transfer-body--modal .link-transfer-summary-card,
.link-transfer-body--modal .link-transfer-select-card > .card-header,
.link-transfer-body--modal .link-transfer-controls {
    flex-shrink: 0;
}
.link-transfer-body--modal .link-transfer-select-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 0;
}
.link-transfer-body--modal .link-transfer-pair-form {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.link-transfer-body--modal .link-transfer-table-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}
.link-transfer-body--modal .link-transfer-form-footer {
    flex-shrink: 0;
    padding: 1rem;
    margin: 0;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}
.btn-link-transfer-open { text-decoration: underline; color: var(--primary); }
.btn-link-transfer-open:hover { color: var(--text); text-decoration: underline; }
.modal-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }

/* === Empty State === */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state-icon { font-size: 3rem; margin-bottom: 0.75rem; opacity: 0.5; }
.empty-state-title { font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: 0.25rem; }

/* === Transaction row highlights === */
tr.tx-credit td { }
tr.tx-debit td { }

/* Scroll restoration: keep anchored rows clear of sticky navbar */
[id^="tx-row-"],
[id^="dup-tx-"],
[id^="data-row-"],
[id^="staging-row-"],
[id^="category-row-"],
[id^="budget-item-row-"] {
    scroll-margin-top: 4.5rem;
}

/* === Utility === */
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 1rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 1rem; }
.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

/* Import review: similar transactions (inline panel, no navigation) */
.import-review-table tbody td { vertical-align: middle; }
.import-col-date { width: 1%; white-space: nowrap; }
.import-date-cell { white-space: nowrap; vertical-align: middle; }
.import-date-text { white-space: nowrap; }
.import-date-wrap {
    display: inline-flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.35rem;
    position: relative;
}
.import-col-remove { width: 1%; padding-left: 0.35rem; padding-right: 0.35rem; }
.import-row-delete-btn {
    padding: 0.35rem;
    min-width: 2rem;
    justify-content: center;
}
.import-row-delete-btn svg { display: block; flex-shrink: 0; }
.import-similar-details { position: relative; }
.import-similar-summary {
    list-style: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    color: var(--warning);
    opacity: 0.9;
    padding: 0.1rem;
    border-radius: var(--radius-sm);
}
.import-similar-summary:hover { opacity: 1; color: var(--primary); }
.import-similar-summary::-webkit-details-marker { display: none; }
.import-similar-summary::marker { content: ''; }
.import-similar-details[open] .import-similar-summary {
    color: var(--primary);
    background: rgb(var(--primary-rgb) / 0.12);
}
.import-similar-summary.import-similar-summary-exact {
    color: var(--success);
    opacity: 1;
}
.import-similar-summary.import-similar-summary-exact:hover {
    color: var(--success);
    filter: brightness(1.15);
}
.import-similar-details[open] .import-similar-summary.import-similar-summary-exact {
    color: var(--success);
    background: rgba(34, 197, 94, 0.14);
}
.import-similar-item-exact {
    border-left: 3px solid var(--success);
    padding-left: 0.5rem;
    margin-left: -0.15rem;
}
.import-similar-item-exact .import-similar-item-meta {
    color: var(--success);
}
.import-similar-panel {
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    z-index: 30;
    min-width: 300px;
    max-width: min(440px, 92vw);
    padding: 0.65rem 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: 0.8rem;
    line-height: 1.45;
}
.import-similar-panel-title {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.5rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}
.import-similar-item {
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
}
.import-similar-item:last-child { border-bottom: none; padding-bottom: 0; }
.import-similar-item-meta { color: var(--text-muted); font-size: 0.78rem; }
.import-similar-item-desc { margin-top: 0.2rem; color: var(--text); word-break: break-word; }
.import-row-delete-form { display: inline; margin: 0; }
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Bills: searchable category combobox */
.category-combobox {
    position: relative;
}
.category-combobox-search {
    width: 100%;
}
.category-combobox-list {
    position: fixed;
    z-index: 10050;
    max-height: min(240px, 40vh);
    overflow-y: auto;
    margin: 0;
    padding: 0.25rem 0;
    list-style: none;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}
.category-combobox-list li {
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    font-size: 0.92rem;
    line-height: 1.35;
}
.category-combobox-list li:hover,
.category-combobox-list li.is-active {
    background: var(--bg-card-hover);
}
.category-combobox-list li.is-selected {
    font-weight: 600;
    color: var(--primary-light);
}

/* Table bulk selection (invoices, transactions, …) */
.table-col-bulk {
    width: 2.25rem;
    text-align: center;
    vertical-align: middle;
}
.table-col-bulk input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}
.bulk-actions-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
    padding: 0.65rem 1rem;
    margin-bottom: 0.75rem;
    background: rgba(201, 125, 79, 0.1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.bulk-actions-bar[hidden] {
    display: none !important;
}
.bulk-actions-bar__count {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
}
.bulk-actions-bar__form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
}

/* Tax section — guidance & worksheet navigation */
.tax-quick-jump {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
    padding: 0.65rem 0.85rem;
    margin: 0 0 1rem;
    font-size: 0.875rem;
    line-height: 1.45;
    background: rgba(201, 125, 79, 0.08);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.tax-quick-jump__label {
    font-weight: 600;
    color: var(--text-muted);
    margin-right: 0.25rem;
}
.tax-quick-jump a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.tax-quick-jump a:hover {
    color: var(--accent);
}
.tax-guidance-block {
    margin: 0 0 1rem;
}
.tax-guidance-block + .tax-guidance-block {
    margin-top: 0.5rem;
}
.tax-details-hint {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-elevated, var(--bg));
    margin-bottom: 0.5rem;
}
.tax-details-hint:last-child {
    margin-bottom: 0;
}
.tax-details-hint summary {
    cursor: pointer;
    padding: 0.6rem 0.85rem;
    font-weight: 600;
    font-size: 0.9rem;
    list-style-position: outside;
}
.tax-details-hint summary:hover {
    background: rgba(201, 125, 79, 0.06);
}
.tax-details-hint[open] summary {
    border-bottom: 1px solid var(--border);
}
.tax-details-hint__body {
    padding: 0.65rem 0.85rem 0.85rem;
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--text-muted);
}
.tax-details-hint__body p {
    margin: 0 0 0.6rem;
}
.tax-details-hint__body p:last-child {
    margin-bottom: 0;
}
.tax-details-hint__body ul {
    margin: 0.35rem 0 0;
    padding-left: 1.25rem;
}
.tax-details-hint__body li {
    margin-bottom: 0.35rem;
}
.tax-workflow-card .text-muted a {
    text-decoration: underline;
}

/* Federal worksheet — deduction explainer */
.tax-deduction-guide {
    margin: 0 0 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(201, 125, 79, 0.07);
}

/* Advisor */
.advisor-group-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 1.25rem 0 0.75rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}
.advisor-q-grid {
    display: grid;
    gap: 1rem;
}
@media (min-width: 900px) {
    .advisor-q-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
.advisor-q-label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.35rem;
    font-size: 0.92rem;
}
.advisor-rec-list {
    margin: 0;
    padding-left: 1.15rem;
}
.advisor-rec-list li {
    margin-bottom: 0.85rem;
}
.advisor-dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.35rem 1rem;
    font-size: 0.9rem;
    margin: 0;
}
.advisor-dl dt {
    color: var(--text-muted);
    margin: 0;
}
.advisor-dl dd {
    margin: 0;
}
.advisor-chat-log {
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: rgba(0, 0, 0, 0.15);
    font-size: 0.9rem;
}
.advisor-chat-msg {
    margin-bottom: 0.65rem;
    white-space: pre-wrap;
    word-break: break-word;
}
.advisor-chat-msg--user {
    color: var(--primary-light);
}
.advisor-chat-msg--assistant {
    color: var(--text);
}

/* Invoices: print view */
@media print {
    .no-print,
    .navbar,
    .alert,
    .tabs {
        display: none !important;
    }
    .main-content {
        padding: 0 !important;
        max-width: none !important;
    }
    .invoice-doc {
        box-shadow: none !important;
        border: none !important;
    }
}
