/* ══════════════ BOTTOM NAV (HIDDEN ON DESKTOP) ══════════════ */
.bottom-nav {
    display: none;
}

/* ══════════════ RESPONSIVE ══════════════ */
@media (max-width: 860px) {
    html {
        height: auto;
        overflow: visible;
        overscroll-behavior: none;
    }

    body {
        display: block;
        overflow: visible;
        height: auto;
        min-height: 100vh;
        overscroll-behavior: none;
    }

    .sidebar {
        transform: translateX(-100%);
        width: 260px !important;
        padding: 28px 18px !important;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-collapse-btn {
        display: none !important;
    }

    .sidebar .sidebar-header {
        flex-direction: row !important;
        margin-bottom: 24px !important;
    }

    .sidebar .brand-text {
        display: inline !important;
    }

    .sidebar #sidebar-user-id {
        display: block !important;
    }

    .sidebar .nav-btn {
        justify-content: flex-start !important;
        padding: 12px 16px !important;
        width: auto !important;
        gap: 12px !important;
    }

    .sidebar .nav-btn .nav-text {
        display: inline !important;
    }

    .mobile-header {
        display: none;
    }

    .main-content {
        margin-left: 0;
        padding: 16px 16px 110px;
        height: auto;
        overflow-y: visible;
        scroll-padding-top: 100px;
    }

    .sticky-header-wrapper {
        margin: 0 -16px 0 -16px;
        padding: 8px 16px 12px 16px;
        top: 0px;
        /* Stick right below the mobile header */
        border-top: none;
        -webkit-mask-image: linear-gradient(to bottom, black 0%, black calc(100% - 16px), transparent 100%);
        mask-image: linear-gradient(to bottom, black 0%, black calc(100% - 16px), transparent 100%);
    }

    /* Bottom Navigation Bar */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 74px;
        background: rgba(14, 18, 27, 0.85);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        z-index: 9000;
        justify-content: space-around;
        align-items: center;
        padding: 0 10px 10px 10px;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.3);
        border-radius: 20px 20px 0 0;
    }

    .bottom-nav .nav-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        color: var(--text-muted);
        flex: 1;
        height: 100%;
        cursor: pointer;
        transition: var(--transition);
        padding: 0;
        margin-top: 10px;
    }

    .bottom-nav .nav-icon {
        font-size: 1.4rem;
        margin-bottom: 4px;
        transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    .bottom-nav .nav-text {
        font-size: 0.7rem;
        font-weight: 500;
    }

    .bottom-nav .nav-btn.active {
        color: var(--accent);
        background: transparent;
        box-shadow: none;
    }

    .bottom-nav .nav-btn.active .nav-icon {
        transform: translateY(-2px) scale(1.15);
    }

    /* Floating Action Button (FAB) */
    .bottom-nav .fab-wrapper {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 1;
        position: relative;
        top: -24px;
    }

    .bottom-nav .fab-btn {
        width: 64px;
        height: 64px;
        min-width: 64px;
        max-width: 64px;
        aspect-ratio: 1 / 1;
        flex-shrink: 0;
        background: linear-gradient(135deg, var(--accent), var(--purple));
        border-radius: 50%;
        color: white;
        box-shadow: 0 8px 24px rgba(99, 138, 255, 0.4);
        display: flex;
        align-items: center;
        justify-content: center;
        flex: none;
        border: 4px solid var(--bg-body);
        transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s;
        margin-top: 0;
    }

    .bottom-nav .fab-btn .nav-icon {
        font-size: 2rem;
        margin-bottom: 0;
        color: #fff;
    }

    .bottom-nav .fab-btn:active {
        transform: scale(0.9);
        box-shadow: 0 4px 12px rgba(99, 138, 255, 0.3);
    }

    .bottom-nav .nav-btn.fab-btn.active {
        background: var(--bg-card-hover) !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }

    .chart-grid,
    .chart-grid-full {
        grid-template-columns: 1fr;
    }

    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .summary-cards.odd-cards {
        grid-template-columns: repeat(6, 1fr);
    }

    .summary-cards.odd-cards .summary-card {
        grid-column: span 3;
    }

    .summary-cards.odd-cards .summary-card.span-2 {
        grid-column: span 2;
        padding: 12px 10px;
    }

    .summary-cards.odd-cards .summary-card.span-2 .card-label {
        font-size: 0.65rem;
        margin-bottom: 4px;
    }

    .summary-cards.odd-cards .summary-card.span-2 .card-value {
        font-size: 1rem;
    }

    .form-grid {
        grid-template-columns: 1fr 110px;
    }

    #fg-currency label {
        visibility: hidden;
    }

    .filter-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;
    }

    .filter-content {
        display: none;
        flex-direction: column;
        align-items: stretch;
        margin-top: 16px;
        width: 100%;
    }

    .filter-search-action {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        gap: 16px;
    }

    .filter-group-action {
        width: 100%;
    }

    .btn-clear-filters {
        width: 100%;
    }

    .filter-bar.open .filter-content {
        display: flex;
    }

    .filter-bar.open .filter-icon {
        transform: rotate(180deg);
    }

    .filter-bar {
        padding: 16px;
        flex-direction: column;
        align-items: stretch;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .global-time-filter {
        flex-direction: column;
        align-items: center;
        gap: 10px;
        padding: 12px 14px;
        margin-bottom: 8px;
    }

    .time-tabs {
        width: 100%;
        justify-content: flex-start;
    }

    .time-tab {
        padding: 8px 4px;
        font-size: 0.75rem;
        flex: 1;
        text-align: center;
        white-space: nowrap;
    }

    .time-nav {
        justify-content: center;
        width: 100%;
    }
}

@media (max-width: 600px) {

    /* Make tables responsive cards */
    .data-table:not(.matrix-table),
    .data-table:not(.matrix-table) thead,
    .data-table:not(.matrix-table) tbody,
    .data-table:not(.matrix-table) tr,
    .data-table:not(.matrix-table) td {
        display: block;
        width: 100%;
    }

    .data-table:not(.matrix-table) thead {
        display: none;
        /* Hide desktop headers */
    }

    .data-table:not(.matrix-table) tr {
        margin-bottom: 16px;
        background: rgba(255, 255, 255, 0.02);
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-sm);
        padding: 14px 16px;
        position: relative;
    }

    .data-table:not(.matrix-table) tr:hover {
        background: rgba(255, 255, 255, 0.04);
    }

    .data-table:not(.matrix-table) td {
        border-bottom: 1px solid rgba(255, 255, 255, 0.03);
        padding: 8px 0 !important;
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        white-space: normal;
    }

    .data-table:not(.matrix-table) td:last-child {
        border-bottom: none;
    }

    /* Inject label from data-label attribute */
    .data-table:not(.matrix-table) td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        text-align: left;
    }

    .data-table:not(.matrix-table) td:not([data-label])::before {
        display: none !important;
    }

    .data-table:not(.matrix-table) td:not([data-label]) {
        display: block;
        text-align: center;
        border-bottom: none;
    }

    /* Settings Tables specific mobile layout */
    #category-table tr,
    #txnmode-table tr,
    #location-table tr {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 16px;
    }

    #category-table td:not([data-label]),
    #txnmode-table td:not([data-label]),
    #location-table td:not([data-label]) {
        display: block;
        text-align: left;
        padding: 0 !important;
        width: auto !important;
    }

    #category-table .row-actions,
    #txnmode-table .row-actions {
        flex-direction: row;
        justify-content: flex-end;
        gap: 8px;
    }

    /* Disable data-labels for utility structural headers / separator rows */
    .month-separator,
    .day-separator {
        background: transparent !important;
        border: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Month-header row on mobile: 3-column grid matching transaction card columns */
    .month-header {
        display: grid !important;
        grid-template-columns: 1fr auto 28px !important;
        gap: 2px 10px;
        align-items: center;
        width: 100% !important;
        background: transparent !important;
        border: none !important;
        margin: 0 !important;
        padding: 12px 4px 6px 4px !important;
    }

    #recent-table .month-header {
        grid-template-columns: 1fr auto !important;
    }

    .month-separator td {
        height: 1px;
        background: var(--accent) !important;
        opacity: 0.3;
        margin: 8px 0 !important;
        padding: 0 !important;
    }

    #recent-table tr.day-separator,
    #all-table tr.day-separator,
    #selected-day-tbody tr.day-separator,
    #scheduled-table tr.day-separator {
        display: grid !important;
        grid-template-columns: 1fr auto 28px !important;
        gap: 2px 10px !important;
        align-items: center !important;
        width: 100% !important;
        border: none !important;
        border-top: 1px solid rgba(255, 255, 255, 0.12) !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        background: transparent !important;
        border-radius: 0 !important;
        padding: 10px 4px 6px 4px !important;
        margin-top: 14px !important;
        margin-bottom: 0 !important;
    }

    #recent-table tr.day-separator:first-child,
    #all-table tr.day-separator:first-child,
    #selected-day-tbody tr.day-separator:first-child,
    #scheduled-table tr.day-separator:first-child,
    .month-header + tr.day-separator {
        margin-top: 4px !important;
    }

    #recent-table tr.day-separator {
        grid-template-columns: 1fr auto !important;
    }

    #recent-table td.day-separator-empty:first-of-type,
    #all-table td.day-separator-empty:first-of-type,
    #selected-day-tbody td.day-separator-empty:first-of-type,
    #scheduled-table td.day-separator-empty:first-of-type {
        grid-column: 1;
        display: block !important;
        padding: 0 !important;
        background: transparent !important;
        border: none !important;
    }

    .day-date-label {
        display: flex !important;
        align-items: center;
        gap: 5px;
        font-size: 0.88rem;
        font-weight: 600;
        color: var(--text-secondary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding: 0 !important;
    }

    #recent-table td.day-separator-total,
    #all-table td.day-separator-total,
    #selected-day-tbody td.day-separator-total,
    #scheduled-table td.day-separator-total {
        grid-column: 2;
        display: flex !important;
        justify-content: flex-end !important;
        align-items: center !important;
        text-align: right !important;
        padding: 0 !important;
        background: transparent !important;
        font-size: 0.88rem !important;
        font-weight: 600 !important;
        border: none !important;
        white-space: nowrap;
    }

    #all-table td.day-separator-empty:last-of-type,
    #selected-day-tbody td.day-separator-empty:last-of-type,
    #scheduled-table td.day-separator-empty:last-of-type {
        grid-column: 3;
        display: block !important;
        width: 28px !important;
        padding: 0 !important;
        background: transparent !important;
        border: none !important;
    }

    #recent-table td.day-separator-empty:last-of-type {
        display: none !important;
    }

    .month-header td:not(.col-batch-select):not(.hide-on-mobile):not(.month-header-total):not(.month-header-empty) {
        grid-column: 1;
        min-width: 0;
        display: block !important;
        font-size: 1.1rem;
        font-weight: 700;
        color: var(--accent);
        text-transform: none;
        letter-spacing: normal;
        padding: 0 !important;
        background: transparent !important;
        border: none !important;
    }

    /* Monthly net total on mobile: aligned in column 2 right beside dummy action slot in column 3 */
    .month-header td.month-header-total {
        grid-column: 2;
        text-align: right !important;
        display: flex !important;
        justify-content: flex-end !important;
        align-items: center !important;
        font-size: 0.95rem !important;
        font-weight: 600 !important;
        padding: 0 !important;
        background: transparent !important;
        border: none !important;
        white-space: nowrap;
    }

    .month-header td.month-header-empty {
        grid-column: 3;
        display: block !important;
        width: 28px !important;
        padding: 0 !important;
        background: transparent !important;
        border: none !important;
    }

    #recent-table .month-header td.month-header-empty {
        display: none !important;
    }

    .row-actions {
        flex-direction: column;
        justify-content: center;
        gap: 6px;
    }

    /* Compact Layout for Transaction Tables on Mobile */
    #all-table tr:not(.month-separator):not(.month-header):not(.day-separator),
    #selected-day-tbody tr:not(.month-separator):not(.month-header):not(.day-separator) {
        display: grid;
        grid-template-areas:
            "category amount actions"
            "note note actions";
        grid-template-columns: 1fr auto 28px;
        gap: 3px 10px;
        padding: 10px 4px;
        margin-bottom: 0;
        background: transparent;
        border: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        border-radius: 0;
        align-items: center;
    }

    #scheduled-table tr:not(.month-separator):not(.month-header):not(.day-separator) {
        display: grid;
        grid-template-areas:
            "category amount actions"
            "meta-left meta-right actions"
            "note note actions";
        grid-template-columns: 1fr auto 28px;
        gap: 2px 10px;
        padding: 10px 4px;
        margin-bottom: 0;
        background: transparent;
        border: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        border-radius: 0;
        align-items: center;
    }

    #recent-table tr:not(.month-separator):not(.month-header):not(.day-separator) {
        display: grid;
        grid-template-areas:
            "category amount"
            "note note";
        grid-template-columns: 1fr auto;
        gap: 3px 10px;
        padding: 10px 4px;
        margin-bottom: 0;
        background: transparent;
        border: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        border-radius: 0;
        align-items: center;
    }

    /* Keep amount and expression inline on line 1 on mobile to prevent displacing mode to line 3 */
    .amount-cell-wrap {
        flex-wrap: nowrap !important;
        white-space: nowrap !important;
    }

    /* Disable ellipsis trimming for transaction mode on mobile and force right alignment */
    .mode-cell {
        max-width: none !important;
        overflow: visible !important;
        text-overflow: clip !important;
        white-space: nowrap !important;
        margin-left: auto !important;
    }

    #recent-table tr:last-child,
    #all-table tr:last-child,
    #selected-day-tbody tr:last-child,
    #scheduled-table tr:last-child {
        border-bottom: none;
    }

    .empty-note {
        display: none !important;
    }

    #recent-table td:not(.col-batch-select):not(.hide-on-mobile),
    #all-table td:not(.col-batch-select):not(.hide-on-mobile),
    #selected-day-tbody td:not(.col-batch-select):not(.hide-on-mobile),
    #scheduled-table td:not(.col-batch-select):not(.hide-on-mobile) {
        border-bottom: none !important;
        padding: 0 !important;
        display: flex;
        text-align: left;
    }

    #recent-table td::before,
    #all-table td::before,
    #selected-day-tbody td::before,
    #scheduled-table td::before {
        display: none !important;
    }

    #recent-table td[data-label="Category"],
    #all-table td[data-label="Category"],
    #selected-day-tbody td[data-label="Category"],
    #scheduled-table td[data-label="Category"] {
        grid-area: category;
        font-weight: 600;
        font-size: 0.95rem;
        color: var(--text-primary);
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #recent-table td[data-label="Amount"],
    #all-table td[data-label="Amount"],
    #selected-day-tbody td[data-label="Amount"],
    #scheduled-table td[data-label="Amount"] {
        grid-area: amount;
        justify-content: flex-end;
        font-size: 1.05rem;
        font-weight: 700;
        text-align: right;
    }

    #recent-table td[data-label="Date"],
    #all-table td[data-label="Date"],
    #selected-day-tbody td[data-label="Date"],
    #recent-table td[data-label="Mode"],
    #all-table td[data-label="Mode"],
    #selected-day-tbody td[data-label="Mode"],
    #recent-table td[data-label="Txn Mode"],
    #all-table td[data-label="Txn Mode"],
    #selected-day-tbody td[data-label="Txn Mode"] {
        display: none !important;
    }

    #recent-table td[data-label="Note"],
    #all-table td[data-label="Note"],
    #selected-day-tbody td[data-label="Note"],
    #scheduled-table td[data-label="Note"] {
        grid-area: note;
        font-size: 0.85rem;
        color: var(--text-secondary);
        white-space: normal;
        display: block;
        align-self: start;
        padding-top: 2px;
    }

    .note-content {
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        gap: 4px 6px !important;
        justify-content: flex-start !important;
        width: 100% !important;
    }

    .note-content > span {
        white-space: normal !important;
        word-break: break-word !important;
    }

    .badges-wrapper {
        display: inline-flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 4px !important;
        align-items: center !important;
        margin-left: 0 !important;
        justify-content: flex-start !important;
    }

    td.empty-note {
        display: none !important;
    }

    .empty-dash {
        display: none !important;
    }

    #recent-table td[data-label="Actions"] {
        display: none !important;
    }

    #all-table td[data-label="Actions"],
    #selected-day-tbody td[data-label="Actions"],
    #scheduled-table td[data-label="Actions"] {
        grid-area: actions;
        justify-content: flex-end;
        align-self: start;
        padding-top: 2px;
        width: 28px;
        box-sizing: border-box;
    }

    /* Scheduled Transactions table mobile metadata mapping: Next Run (Date) on left (meta-left), Freq on right (meta-right) */
    #scheduled-table td[data-label="Next Run"] {
        grid-area: meta-left;
        justify-self: start;
        font-size: 0.8rem;
        color: var(--text-muted);
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #scheduled-table td[data-label="Freq"] {
        grid-area: meta-right;
        justify-self: end;
        font-size: 0.8rem;
        color: var(--accent);
        text-align: right !important;
        white-space: nowrap;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block !important;
    }

    #scheduled-table td[data-label="Type"],
    #scheduled-table td[data-label="Mode"],
    #scheduled-table td[data-label="Last Run"] {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .summary-card {
        padding: 16px 14px;
    }

    .card-value {
        font-size: 1.35rem;
    }

    .card-label {
        font-size: 0.75rem;
        margin-bottom: 4px;
    }
}

@media (max-width: 860px) {

    .txn-header-grid {
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
        gap: 12px;
        margin-bottom: 18px;
    }

    .txn-header-grid .view-title {
        text-align: left;
        width: auto;
        margin-bottom: 0;
        font-size: 1.4rem;
    }

    #view-charts .view-title {
        text-align: center;
        width: 100%;
    }

    #view-transactions .table-footer {
        padding: 16px;
        font-size: 0.85rem;
        background: rgba(255, 255, 255, 0.02);
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-sm);
        margin-top: 16px;
        text-align: center;
        line-height: 1.6;
        color: var(--text-secondary);
    }
    .hide-on-mobile,
    .col-batch-select,
    th.col-batch-select,
    td.col-batch-select,
    .batch-select-checkbox,
    .batch-action-bar,
    #batch-action-bar,
    #modal-batch-update-overlay { display: none !important; }

    .form-bottom-spacer {
        height: 120px;
    }
}

@media (min-width: 769px) { .mobile-only-inline, .hide-on-desktop { display: none !important; } }

@media (hover: none) and (pointer: coarse) {
    body {
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -webkit-touch-callout: none;
    }
    
    input, textarea, select {
        user-select: auto;
        -webkit-user-select: auto;
        -moz-user-select: auto;
    }
    
    .data-table tbody tr.touchable-row.row-holding {
        background-color: rgba(255, 255, 255, 0.1) !important;
        border-radius: var(--radius-sm);
        transition: none !important;
    }
}

/* ══════════════ MAP PICKER RESPONSIVE ══════════════ */
@media (max-width: 860px) {
    #map-picker-overlay {
        width: 100vw !important;
        height: 100vh !important;
        max-width: none !important;
        max-height: none !important;
        border-radius: 0 !important;
    }
    #map-picker-backdrop {
        align-items: stretch !important;
    }
}
