/* ============================================
   FINÉO - Mobile-First Optimization
   Primary mobile experience with native app feel
   ============================================ */

/* --- Safe Areas (notched phones) --- */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --bottom-nav-height: 60px;
}

/* --- Disable text selection (native app feel) --- */
* {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Allow selection only in form inputs */
input,
textarea,
[contenteditable="true"],
code,
pre {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

/* Disable image drag */
img {
    -webkit-user-drag: none;
    user-drag: none;
    pointer-events: none;
}

/* --- Prevent horizontal overflow globally --- */
@media (max-width: 768px) {
    html {
        overflow-x: hidden !important;
        width: 100% !important;
    }

    body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
        position: relative;
    }

    .app-layout {
        display: flex;
        flex-direction: column;
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        min-height: 100vh;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        min-height: 100vh;
        overflow-x: hidden !important;
        flex: 1;
    }

    .page-content {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .topbar {
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box !important;
    }

    /* Prevent ANY element from creating horizontal overflow */
    .card,
    .card-body,
    .card-header,
    .card-footer,
    .filters-bar,
    .page-header,
    form,
    .form-row,
    .form-group,
    .grid-2,
    .grid-3,
    .grid-auto,
    .kpi-grid,
    .charts-grid,
    .goals-grid,
    .empty-state,
    .shared-banner {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ALL inline max-width must not exceed screen */
    [style*="max-width"] {
        max-width: 100% !important;
    }

    /* ALL inline width with px must be constrained */
    [style*="width:"][style*="px"] {
        max-width: 100% !important;
    }

    /* ALL inline min-width must be overridden */
    [style*="min-width"] {
        min-width: 0 !important;
    }

    /* Tables must scroll inside their container */
    .table-container {
        max-width: 100% !important;
        overflow-x: auto;
    }

    /* Prevent long text/code from overflowing */
    code, pre, .truncate {
        max-width: 100%;
        overflow-x: auto;
        word-break: break-all;
    }
}

/* ============================================
   BOTTOM NAVIGATION BAR (Mobile only)
   ============================================ */
.bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--bottom-nav-height);
        padding-bottom: var(--safe-bottom);
        background: var(--white);
        border-top: 1px solid var(--gray-200);
        z-index: 200;
        align-items: stretch;
        justify-content: space-around;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
        -webkit-backdrop-filter: blur(12px);
        backdrop-filter: blur(12px);
        background: rgba(255, 255, 255, 0.95);
    }

    [data-theme="dark"] .bottom-nav {
        background: rgba(30, 41, 59, 0.95);
        border-color: var(--gray-700);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    }

    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        flex: 1;
        text-decoration: none;
        color: var(--gray-400);
        font-size: 0.65rem;
        font-weight: 500;
        padding: 6px 0;
        position: relative;
        transition: color 0.2s;
        -webkit-tap-highlight-color: transparent;
        user-select: none;
    }

    .bottom-nav-item svg,
    .bottom-nav-item i {
        width: 22px;
        height: 22px;
        transition: transform 0.2s;
    }

    .bottom-nav-item.active {
        color: var(--green);
    }

    .bottom-nav-item.active svg,
    .bottom-nav-item.active i {
        transform: scale(1.1);
    }

    .bottom-nav-item:active {
        color: var(--green);
    }

    .bottom-nav-item:active svg,
    .bottom-nav-item:active i {
        transform: scale(0.9);
    }

    /* Active indicator dot */
    .bottom-nav-item.active::after {
        content: '';
        position: absolute;
        top: 3px;
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: var(--green);
    }

    [data-theme="dark"] .bottom-nav-item {
        color: var(--gray-500);
    }
    [data-theme="dark"] .bottom-nav-item.active {
        color: var(--green);
    }

    /* --- FAB (Floating Action Button) --- */
    .bottom-nav-fab {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--green), var(--green-dark));
        color: white;
        border: none;
        margin-top: -18px;
        box-shadow: 0 4px 15px rgba(16, 185, 129, 0.35);
        cursor: pointer;
        transition: transform 0.2s, box-shadow 0.2s;
        -webkit-tap-highlight-color: transparent;
        position: relative;
        z-index: 1;
    }

    .bottom-nav-fab svg,
    .bottom-nav-fab i {
        width: 24px;
        height: 24px;
    }

    .bottom-nav-fab:active {
        transform: scale(0.92);
        box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
    }

    /* --- Add space for bottom nav on page content --- */
    .main-content {
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 8px);
    }

    /* Hide desktop footer on mobile (bottom nav replaces it) */
    .app-footer {
        display: none;
    }

    /* Hide sidebar footer logout on mobile (it's in bottom nav menu) */
    .sidebar-footer {
        display: block;
    }
}

/* ============================================
   TOPBAR MOBILE OPTIMIZATION
   ============================================ */
@media (max-width: 768px) {
    .topbar {
        height: 52px;
        padding: 0 var(--space-3);
        padding-top: var(--safe-top);
        gap: var(--space-1);
        overflow: hidden;
    }

    .topbar-left {
        overflow: hidden;
        min-width: 0;
    }

    .topbar-title {
        font-size: 0.9rem;
        font-weight: 600;
        max-width: 140px;
    }

    .topbar-right {
        gap: var(--space-1);
        flex-shrink: 0;
    }

    /* Hide search on mobile - already in responsive.css but reinforce */
    .topbar-search {
        display: none !important;
    }

    /* Hide space/share selectors on mobile */
    .space-selector,
    .share-selector {
        display: none !important;
    }

    /* Compact topbar buttons */
    .notif-bell,
    .theme-toggle {
        width: 36px;
        height: 36px;
        border-radius: var(--radius-md);
    }

    .notif-bell svg,
    .notif-bell i,
    .theme-toggle svg,
    .theme-toggle i {
        width: 16px;
        height: 16px;
    }

    .user-avatar {
        width: 30px;
        height: 30px;
        font-size: 0.65rem;
    }

    /* Compact UI mode toggle */
    .switch-toggle {
        width: 38px;
        height: 22px;
    }
    .switch-slider::before {
        width: 16px;
        height: 16px;
    }
    .switch-toggle input:checked + .switch-slider::before {
        transform: translateX(16px);
    }

    /* Menu toggle button */
    .menu-toggle {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    /* Dropdowns: prevent overflow */
    .share-dropdown {
        max-width: calc(100vw - 24px);
    }

    #searchAutocomplete {
        max-width: calc(100vw - 24px);
        min-width: 0 !important;
    }
}

@media (max-width: 480px) {
    .topbar {
        height: 48px;
        padding: 0 var(--space-2);
        padding-top: var(--safe-top);
    }

    .topbar-title {
        font-size: 0.85rem;
        max-width: 120px;
    }

    /* Hide less important topbar items on very small screens */
    .theme-toggle {
        display: none;
    }

    .switch-toggle {
        display: none;
    }
}

/* ============================================
   MOBILE CARDS FOR TRANSACTIONS (replace table)
   ============================================ */
.mobile-transaction-list {
    display: none;
}

@media (max-width: 768px) {
    .mobile-transaction-list {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .table-container:has(+ .mobile-transaction-list),
    .mobile-transaction-list ~ .table-container,
    .desktop-table-wrapper {
        display: none;
    }

    .mobile-tx-card {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px;
        background: var(--white);
        border-radius: var(--radius-lg);
        border: 1px solid var(--gray-100);
        text-decoration: none;
        color: inherit;
        transition: background 0.15s;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-tx-card:active {
        background: var(--gray-50);
    }

    [data-theme="dark"] .mobile-tx-card {
        background: var(--gray-800);
        border-color: var(--gray-700);
    }
    [data-theme="dark"] .mobile-tx-card:active {
        background: var(--gray-700);
    }

    .mobile-tx-icon {
        width: 40px;
        height: 40px;
        border-radius: var(--radius-md);
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        font-size: 1.2rem;
    }

    .mobile-tx-icon.income {
        background: var(--green-light);
        color: var(--green-dark);
    }
    .mobile-tx-icon.expense {
        background: var(--red-light);
        color: var(--red-dark);
    }
    .mobile-tx-icon.transfer {
        background: var(--blue-light);
        color: var(--blue);
    }

    [data-theme="dark"] .mobile-tx-icon.income {
        background: rgba(16, 185, 129, 0.15);
    }
    [data-theme="dark"] .mobile-tx-icon.expense {
        background: rgba(239, 68, 68, 0.15);
    }
    [data-theme="dark"] .mobile-tx-icon.transfer {
        background: rgba(59, 130, 246, 0.15);
    }

    .mobile-tx-info {
        flex: 1;
        min-width: 0;
    }

    .mobile-tx-desc {
        font-size: 0.875rem;
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-bottom: 2px;
    }

    .mobile-tx-meta {
        font-size: 0.7rem;
        color: var(--gray-400);
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .mobile-tx-amount {
        text-align: right;
        flex-shrink: 0;
    }

    .mobile-tx-amount .amount {
        font-size: 0.95rem;
        font-weight: 600;
        display: block;
    }

    .mobile-tx-amount .amount.income {
        color: var(--green);
    }
    .mobile-tx-amount .amount.expense {
        color: var(--red);
    }
    .mobile-tx-amount .amount.transfer {
        color: var(--blue);
    }

    .mobile-tx-date {
        font-size: 0.65rem;
        color: var(--gray-400);
    }

    /* Date separator in transaction list */
    .mobile-tx-date-sep {
        font-size: 0.7rem;
        font-weight: 600;
        color: var(--gray-500);
        padding: 8px 4px 4px;
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }
}

/* ============================================
   MOBILE FILTERS (collapsible)
   ============================================ */
@media (max-width: 768px) {
    .filters-bar {
        position: relative;
    }

    .mobile-filter-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        width: 100%;
        padding: 10px;
        background: var(--gray-50);
        border: 1px solid var(--gray-200);
        border-radius: var(--radius-md);
        color: var(--gray-600);
        font-size: 0.8rem;
        font-weight: 500;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    [data-theme="dark"] .mobile-filter-toggle {
        background: var(--gray-800);
        border-color: var(--gray-700);
        color: var(--gray-400);
    }

    .mobile-filter-toggle svg,
    .mobile-filter-toggle i {
        width: 16px;
        height: 16px;
    }

    .filters-bar.collapsed .form-control,
    .filters-bar.collapsed .form-group,
    .filters-bar.collapsed .btn:not(.mobile-filter-toggle) {
        display: none;
    }

    .mobile-filter-badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: var(--green);
        color: white;
        font-size: 0.6rem;
        font-weight: 700;
    }
}

@media (min-width: 769px) {
    .mobile-filter-toggle {
        display: none;
    }
}

/* ============================================
   PULL TO REFRESH
   ============================================ */
.pull-to-refresh {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 300;
    justify-content: center;
    padding-top: calc(var(--safe-top, 0px) + 8px);
    pointer-events: none;
}

.pull-to-refresh.active {
    display: flex;
}

.pull-refresh-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--white);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: ptr-spin 0.8s linear infinite;
}

[data-theme="dark"] .pull-refresh-spinner {
    background: var(--gray-700);
}

@keyframes ptr-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.pull-refresh-spinner svg,
.pull-refresh-spinner i {
    width: 18px;
    height: 18px;
    color: var(--green);
}

/* ============================================
   SWIPE INDICATOR
   ============================================ */
.swipe-indicator {
    display: none;
}

@media (max-width: 768px) {
    .swipe-indicator {
        display: block;
        position: fixed;
        top: 50%;
        left: 0;
        transform: translateY(-50%);
        width: 4px;
        height: 60px;
        background: var(--gray-300);
        border-radius: 0 4px 4px 0;
        opacity: 0;
        transition: opacity 0.3s, width 0.3s;
        z-index: 98;
        pointer-events: none;
    }

    .swipe-indicator.visible {
        opacity: 0.5;
        width: 6px;
    }
}

/* ============================================
   IMPROVED TOUCH FEEDBACK
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Better active states */
    .btn:active {
        transform: scale(0.97);
        opacity: 0.85;
    }

    .card:active {
        transform: scale(0.99);
    }

    .nav-item:active {
        background: var(--navy-lighter);
        transform: scale(0.98);
    }

    /* Remove 300ms tap delay */
    * {
        touch-action: manipulation;
    }

    /* Better scrolling */
    .page-content {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }

    /* Prevent text selection on interactive elements */
    .btn,
    .nav-item,
    .bottom-nav-item,
    .mobile-tx-card,
    .kpi-card {
        user-select: none;
        -webkit-user-select: none;
    }

    /* Larger form controls */
    .form-control,
    .form-select,
    select {
        min-height: 48px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    textarea.form-control {
        min-height: 100px;
    }

    /* Better checkbox/radio targets */
    input[type="checkbox"],
    input[type="radio"] {
        width: 22px;
        height: 22px;
    }
}

/* ============================================
   MOBILE KPI IMPROVEMENTS
   ============================================ */
@media (max-width: 768px) {
    .kpi-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .kpi-card {
        padding: 12px;
        gap: 8px;
        border-radius: var(--radius-lg);
    }

    .kpi-icon {
        width: 36px;
        height: 36px;
    }

    .kpi-icon svg,
    .kpi-icon i {
        width: 18px;
        height: 18px;
    }

    .kpi-value {
        font-size: 1.1rem;
        line-height: 1.2;
    }

    .kpi-label {
        font-size: 0.65rem;
        line-height: 1.3;
    }
}

@media (max-width: 380px) {
    .kpi-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .kpi-card {
        flex-direction: row;
        align-items: center;
        padding: 10px 12px;
    }

    .kpi-value {
        font-size: 1rem;
    }
}

/* ============================================
   MOBILE CHARTS
   ============================================ */
@media (max-width: 768px) {
    .charts-grid {
        gap: 12px;
    }

    .chart-container {
        height: 200px;
    }

    .card-header h3 {
        font-size: var(--font-sm);
    }
}

/* ============================================
   MOBILE MODALS (Bottom Sheet)
   ============================================ */
@media (max-width: 768px) {
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal {
        border-radius: 20px 20px 0 0;
        max-height: calc(92vh - var(--safe-bottom));
        margin: 0;
        width: 100%;
        max-width: 100%;
        animation: slideUp 0.3s ease;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
            opacity: 0.5;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    /* Bottom sheet handle */
    .modal-header::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        border-radius: 2px;
        background: var(--gray-300);
        margin: 0 auto 12px;
    }

    [data-theme="dark"] .modal-header::before {
        background: var(--gray-600);
    }

    .modal-footer {
        padding-bottom: calc(var(--space-4) + var(--safe-bottom));
    }

    .modal-footer .btn {
        min-height: 48px;
        font-size: 0.95rem;
    }
}

/* ============================================
   MOBILE PAGE HEADER
   ============================================ */
@media (max-width: 768px) {
    .page-content {
        padding: 12px;
    }

    .page-header {
        margin-bottom: 16px;
        gap: 8px;
    }

    .page-header h1 {
        font-size: 1.25rem;
    }

    .page-header .btn {
        padding: 10px 16px;
        font-size: 0.85rem;
        border-radius: var(--radius-md);
    }
}

/* ============================================
   MOBILE CARDS
   ============================================ */
@media (max-width: 768px) {
    .card {
        border-radius: var(--radius-lg);
        margin-bottom: 12px;
    }

    .card-header {
        padding: 12px;
    }

    .card-body {
        padding: 12px;
    }

    .card-footer {
        padding: 10px 12px;
    }
}

/* ============================================
   MOBILE TABLES (when cards not applicable)
   ============================================ */
@media (max-width: 768px) {
    .table-container {
        margin: 0 -12px;
        padding: 0 12px;
        border-radius: 0;
    }

    table {
        font-size: 0.75rem;
    }

    table thead th {
        padding: 8px;
        font-size: 0.65rem;
        white-space: nowrap;
    }

    table tbody td {
        padding: 10px 8px;
    }

    /* Action buttons in table */
    td .btn-group {
        gap: 4px;
    }

    td .btn-sm {
        padding: 6px 8px;
        font-size: 0.7rem;
    }
}

/* ============================================
   MOBILE PAGINATION
   ============================================ */
@media (max-width: 768px) {
    .pagination {
        justify-content: center;
        padding: 12px 0;
        padding-bottom: calc(12px + var(--safe-bottom));
    }

    .pagination a,
    .pagination span {
        min-width: 36px;
        height: 36px;
        border-radius: var(--radius-md);
        font-size: 0.8rem;
    }
}

/* ============================================
   MOBILE NOTIFICATION DROPDOWN
   ============================================ */
@media (max-width: 768px) {
    .notif-dropdown {
        position: fixed;
        top: 52px;
        right: 8px;
        left: 8px;
        width: auto;
        max-height: calc(70vh - var(--safe-bottom));
        border-radius: var(--radius-lg);
    }

    .notif-dropdown-body {
        max-height: calc(60vh - var(--safe-bottom));
    }
}

/* ============================================
   MOBILE FORMS - COMPREHENSIVE
   ============================================ */
@media (max-width: 768px) {
    .form-group {
        margin-bottom: 12px;
    }

    .form-label {
        font-size: 0.8rem;
        margin-bottom: 4px;
    }

    .form-control {
        padding: 10px 12px;
        border-radius: var(--radius-md);
    }

    /* Remove max-width constraints on cards inside forms */
    .card[style*="max-width"] {
        max-width: 100% !important;
    }

    /* Grid layouts: remove max-width on containers */
    .grid-2[style*="max-width"],
    .grid-3[style*="max-width"],
    div[style*="max-width: 900px"],
    div[style*="max-width:900px"] {
        max-width: 100% !important;
    }

    /* Form rows: single column on mobile */
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 0;
    }

    /* Flex layouts inside forms: stack vertically */
    .flex.gap-4,
    .flex.gap-3,
    div[style*="display:flex"][style*="gap:"] {
        flex-direction: column;
    }

    /* Form action buttons: full width, stacked */
    .flex.gap-4.mt-6,
    .card-body > form > .flex:last-child {
        flex-direction: column;
        gap: 8px;
    }

    .flex.gap-4 .btn,
    .flex.gap-4.mt-6 .btn {
        width: 100%;
        justify-content: center;
        min-height: 48px;
    }

    /* Full-width buttons on forms */
    .form-actions .btn,
    .card-footer .btn {
        flex: 1;
        min-height: 44px;
        justify-content: center;
    }

    /* Stacked form actions */
    .form-actions {
        flex-direction: column-reverse;
        gap: 8px;
    }

    /* Split rows: stack on mobile */
    .split-row,
    .split-row.flex,
    div[class*="split-row"] {
        flex-direction: column !important;
        gap: 8px !important;
        padding: 12px;
        background: var(--gray-50);
        border-radius: var(--radius-md);
        margin-bottom: 8px;
    }

    [data-theme="dark"] .split-row,
    [data-theme="dark"] div[class*="split-row"] {
        background: var(--gray-800);
    }

    .split-row > div[style*="flex:"],
    .split-row > div {
        flex: none !important;
        width: 100% !important;
    }

    .split-row .btn-danger {
        align-self: flex-end;
    }

    /* Profile page: grid-2 stack to single column */
    .grid-2 {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    /* Grid auto: reduce minimum size */
    .grid-auto {
        grid-template-columns: 1fr !important;
    }

    /* API token form: stack */
    form[style*="display:flex"][style*="gap:8px"] {
        flex-direction: column;
    }

    form[style*="display:flex"] input[style*="max-width:200px"] {
        max-width: 100% !important;
    }

    /* RGPD section: stack */
    .card-body > div[style*="display:flex"][style*="flex-wrap:wrap"] {
        flex-direction: column;
        gap: 16px;
    }

    .card-body > div[style*="display:flex"] > div[style*="min-width:200px"] {
        min-width: 0 !important;
    }

    .card-body > div[style*="display:flex"] > div[style*="border-left"] {
        border-left: none !important;
        border-top: 2px solid var(--red);
        padding-left: 0 !important;
        padding-top: 12px;
    }

    /* Delete account: stack password + button */
    div[style*="display:flex"][style*="gap:8px"][style*="align-items:center"] {
        flex-direction: column;
        align-items: stretch !important;
    }

    input[style*="max-width:200px"] {
        max-width: 100% !important;
    }

    /* Account info section: stack */
    .card-body[style*="display:flex"][style*="justify-content:space-between"] {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start !important;
    }

    /* Color picker: larger on mobile */
    .color-picker {
        width: 48px;
        height: 48px;
    }

    .color-picker-group {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* Icon selector: wrap on mobile */
    .icon-option span {
        width: 40px;
        height: 40px;
    }

    /* Tags: better wrapping */
    div[style*="display:flex"][style*="flex-wrap:wrap"][style*="gap:6px"] {
        gap: 6px;
    }

    div[style*="display:flex"][style*="flex-wrap:wrap"] label {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    /* Textarea */
    textarea.form-control {
        min-height: 80px;
    }

    /* Small text / help text */
    small {
        font-size: 0.7rem;
        line-height: 1.4;
    }

    /* Budget modal forms */
    .modal .form-row {
        grid-template-columns: 1fr !important;
    }

    /* Ticket forms */
    .ticket-status-form {
        flex-direction: column;
        align-items: stretch !important;
    }

    .ticket-meta {
        flex-direction: column;
        gap: 8px;
    }
}

/* ============================================
   MOBILE EMPTY STATES
   ============================================ */
@media (max-width: 768px) {
    .empty-state {
        padding: 40px 20px;
    }

    .empty-state svg,
    .empty-state i {
        width: 48px;
        height: 48px;
    }

    .empty-state h3 {
        font-size: 1rem;
    }

    .empty-state p {
        font-size: 0.8rem;
    }
}

/* ============================================
   MOBILE AUTH LAYOUT
   ============================================ */
@media (max-width: 480px) {
    .auth-layout {
        padding: 16px;
        padding-top: calc(16px + var(--safe-top));
    }

    .auth-card {
        padding: 24px 20px;
        border-radius: var(--radius-xl);
    }

    .auth-logo h1 {
        font-size: 1.5rem;
    }
}

/* ============================================
   MOBILE SIDEBAR IMPROVEMENTS
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        width: 280px;
        padding-top: var(--safe-top);
        padding-bottom: calc(var(--safe-bottom) + var(--bottom-nav-height));
    }

    .sidebar-overlay {
        -webkit-backdrop-filter: blur(4px);
        backdrop-filter: blur(4px);
        background: rgba(0, 0, 0, 0.4);
    }

    .sidebar-header {
        padding: 16px 20px;
    }

    .sidebar-logo {
        font-size: 1.4rem;
    }

    .nav-item {
        padding: 12px 20px;
        font-size: 0.875rem;
        border-radius: 0;
        margin: 0;
    }

    .nav-item i,
    .nav-item svg {
        width: 20px;
        height: 20px;
    }

    .sidebar-section {
        padding: 8px 20px;
        font-size: 0.6rem;
    }
}

/* ============================================
   TOAST POSITION (above bottom nav)
   ============================================ */
@media (max-width: 768px) {
    .toast-container {
        bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 8px);
        left: 12px;
        right: 12px;
        max-width: none;
    }
}

/* ============================================
   MOBILE CONFIRM MODAL
   ============================================ */
@media (max-width: 768px) {
    .confirm-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .confirm-modal {
        border-radius: 20px 20px 0 0;
        max-width: 100%;
        width: 100%;
        margin: 0;
        padding-bottom: calc(24px + var(--safe-bottom));
        animation: slideUp 0.25s ease;
    }

    .confirm-modal .confirm-actions .btn {
        min-height: 48px;
        flex: 1;
    }
}

/* ============================================
   MOBILE LANDSCAPE
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    .bottom-nav {
        height: 48px;
    }

    .bottom-nav-item {
        font-size: 0;
    }

    .bottom-nav-item svg,
    .bottom-nav-item i {
        width: 20px;
        height: 20px;
    }

    .bottom-nav-fab {
        width: 42px;
        height: 42px;
        margin-top: -12px;
    }

    .main-content {
        padding-bottom: calc(48px + var(--safe-bottom) + 4px);
    }
}

/* ============================================
   PRINT: Hide mobile elements
   ============================================ */
@media print {
    .bottom-nav,
    .pull-to-refresh,
    .swipe-indicator,
    .mobile-filter-toggle,
    .bottom-nav-fab {
        display: none !important;
    }

    .main-content {
        padding-bottom: 0 !important;
    }
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .bottom-nav-item svg,
    .bottom-nav-item i,
    .bottom-nav-fab,
    .btn,
    .card,
    .nav-item,
    .mobile-tx-card,
    .modal {
        transition: none !important;
        animation: none !important;
    }
}
