/* Layout only: account isolation and Firestore flows stay in budget.html. */
.content, .view, .card, .chart-wrap, .grid-4 > *, .grid-3 > *, .grid-2 > * {
    min-width: 0;
}
.budget-filters { flex-wrap: wrap; min-width: 0; }
.section-header, .chart-header { gap: 1rem; }
.budget-chart { position: relative; height: 320px; width: 100%; min-width: 0; }
.budget-chart-donut { height: 380px; max-width: 500px; margin: 0 auto; }
#sparkline-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
#year-summary-cards { grid-template-columns: repeat(var(--year-card-count, 3), minmax(0, 1fr)); }
.year-btn-group { flex-wrap: wrap; }
.year-total { overflow-wrap: anywhere; }
.budget-table-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
.budget-table-scroll table { white-space: nowrap; }
.budget-table-scroll .cat-header, .budget-table-scroll .cat-cell {
    position: sticky; left: 0; background: var(--card); z-index: 1;
}
.table-scroll-hint { display: none; }
.date-input-row input { width: 100%; min-width: 0; }
.cat-btn { min-width: 0; }
.cat-btn-name, .cat-name, .tx-cat { overflow-wrap: anywhere; }
button:focus-visible, a:focus-visible, .budget-table-scroll:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 3px;
}
body:has(.modal-overlay.active), body:has(#custom-cat-modal[style*="display: flex"]) {
    overflow: hidden;
}
@media (max-width: 1100px) {
    .topnav {
        display: grid; grid-template-columns: minmax(0, 1fr) auto;
        height: auto; padding: 0.65rem 1rem; gap: 0.5rem 1rem;
    }
    .topnav-logo { grid-column: 1; grid-row: 1; }
    .topnav-user { grid-column: 2; grid-row: 1; }
    .topnav-tabs {
        grid-column: 1 / -1; grid-row: 2; min-width: 0;
        padding: 0.25rem 0; gap: 0.25rem; overscroll-behavior-x: contain;
    }
    .topnav-tabs .nav-tab { flex: 0 0 auto; min-height: 44px; }
}
@media (max-width: 768px) {
    .topnav { padding: 0.5rem 0.75rem; gap: 0.4rem; }
    .topnav-user { gap: 8px; }
    #light-mode-btn { width: 44px !important; height: 44px !important; margin-right: 0 !important; }
    .signout-btn { min-height: 44px; padding: 0.4rem 0.65rem; }
    .topnav-logo img { width: 32px; height: 32px; }
    .topnav-logo span { font-size: 1rem; }
    .nav-tab { min-height: 44px; font-size: 0.8rem; padding: 0.6rem 0.8rem; }
    .content { padding: 1rem 0.75rem calc(1.5rem + env(safe-area-inset-bottom)); }
    .page-title { font-size: 1.4rem; overflow-wrap: anywhere; }
    .page-sub { font-size: 0.85rem; margin-bottom: 0.5rem; }
    .section-header, .chart-header { flex-direction: column; align-items: stretch; gap: 0.8rem; }
    .month-selector { justify-content: space-between; gap: 0.5rem; }
    .month-label { min-width: 0; }
    .month-btn { width: 44px; height: 44px; }
    .budget-filters { width: 100%; }
    .budget-filters select { flex: 1 1 100px; min-width: 0; }
    select.styled, .note-input, .date-input-row input, .auth-input { font-size: 16px; min-height: 44px; }
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; }
    .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); gap: 0.75rem; }
    #year-summary-cards { grid-template-columns: minmax(0, 1fr); }
    .kpi-card { padding: 1rem 0.8rem; border-radius: 16px; }
    .kpi-icon { width: 36px; height: 36px; }
    .kpi-label { font-size: 0.7rem; letter-spacing: 0; }
    .kpi-value { font-size: clamp(1.05rem, 4.5vw, 1.5rem); overflow-wrap: anywhere; }
    .kpi-trend { font-size: 0.7rem; overflow-wrap: anywhere; }
    .card, .chart-wrap { padding: 1rem; border-radius: 16px; }
    .chart-title { overflow-wrap: anywhere; }
    .budget-chart { height: 280px; }
    .budget-chart-donut { height: 390px; }
    #sparkline-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
    .table-scroll-hint { display: block; font-size: 0.75rem; color: var(--text3); margin-bottom: 0.6rem; }
    .budget-table-scroll .cat-header, .budget-table-scroll .cat-cell,
    .cmp-table td:first-child, .cmp-table th:first-child { max-width: 140px; white-space: normal; overflow-wrap: anywhere; }
    .year-btn, .pill { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
    .tx-item { display: grid; grid-template-columns: 36px minmax(0, 1fr) 44px; gap: 6px 10px; padding: 0.75rem; }
    .tx-icon { grid-column: 1; grid-row: 1 / 3; width: 36px; height: 36px; }
    .tx-info { grid-column: 2; grid-row: 1; }
    .tx-date { grid-column: 2; grid-row: 2; }
    .tx-amount { grid-column: 2; grid-row: 3; text-align: left; min-width: 0; overflow-wrap: anywhere; }
    .tx-delete { grid-column: 3; grid-row: 1 / 4; width: 44px; height: 44px; opacity: 1; }
    .tx-month-total { flex-wrap: wrap; gap: 0.5rem; padding-inline: 0; }
    .cat-item { flex-wrap: wrap; padding: 0.75rem; gap: 8px; }
    .cat-info { min-width: 100px; }
    .record-card { flex-wrap: wrap; gap: 8px; overflow-wrap: anywhere; }
    .modal-overlay { align-items: flex-end; }
    .modal-content {
        width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh;
        padding: 1.25rem 1rem calc(1rem + env(safe-area-inset-bottom));
        border-radius: 20px 20px 0 0; overscroll-behavior-y: contain;
    }
    .modal-content > .page-title { padding-right: 44px; }
    .modal-close { top: 0.5rem; right: 0.5rem; width: 44px; height: 44px; }
    .amount-display { font-size: 2.5rem; padding: 0.8rem 0; min-height: 80px; overflow-wrap: anywhere; }
    #amount-text { min-width: 0; }
    .cat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .cat-btn { min-height: 70px; }
    .cat-btn-name { font-size: 0.75rem; }
    .del-cat { min-width: 28px; min-height: 28px; }
    .login-card { padding: 1.5rem 1rem; }
    #custom-cat-modal { padding: 1rem; }
    #custom-cat-modal > div { width: 100% !important; max-height: 90dvh; overflow-y: auto; padding: 1.25rem !important; background: var(--card) !important; }
    #custom-cat-modal button { min-height: 44px; }
    .toast { max-width: calc(100vw - 24px); width: max-content; overflow-wrap: anywhere; }
}
@media (max-width: 360px) {
    #sparkline-grid { grid-template-columns: minmax(0, 1fr); }
    .topnav-user { gap: 4px; }
    .user-avatar { width: 28px; height: 28px; }
    .cat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (pointer: coarse) {
    .tx-delete { opacity: 1; width: 44px; height: 44px; }
}
