/* ===============================================
   RESPONSIVE CSS — PREMIUM FINTECH UI
   =============================================== */

/* -----------------------------------------------
   1. GLOBAL OVERFLOW PROTECTION & BASE SAFETY
   ----------------------------------------------- */
* {
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
    -webkit-tap-highlight-color: transparent;
}

/* Prevent flex/grid children from causing horizontal scroll */
.flex-item, .grid-item, .card, .form-group, input, .btn, .table-responsive, pre {
    min-width: 0;
    max-width: 100%;
}

/* Prevent long URLs/text from breaking layout */
p, span, td, th, div, code {
    overflow-wrap: anywhere;
}

/* -----------------------------------------------
   2. PREMIUM DESKTOP UI (min-width: 1025px)
   ----------------------------------------------- */
@media (min-width: 1025px) {
    /* Prevent excessive stretching on ultrawide monitors */
    .main-content {
        max-width: 1400px;
        margin-left: auto;
        margin-right: auto;
    }

    /* Premium Card System */
    .card, 
    .stat-card { 
        border-radius: 12px !important; 
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02) !important;
        border: 1px solid var(--border-color) !important;
        transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
    }

    /* Subtle hover elevation for interactive cards */
    @media (hover: hover) {
        .stat-card:hover { 
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05) !important;
            border-color: var(--color-primary) !important;
        }
    }
}

/* -----------------------------------------------
   3. TABLET RESPONSIVE UI (max-width: 1024px)
   ----------------------------------------------- */
@media (max-width: 1024px) {
    /* Stack Grid Layouts */
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr !important;
    }
}

/* -----------------------------------------------
   4. MOBILE SAFARI / TOUCH OPTIMIZATION
   ----------------------------------------------- */
/* FIX: Prevent iOS Safari auto-zoom on input focus */
input, select, textarea {
    font-size: 16px !important;
}

/* -----------------------------------------------
   5. COMPACT MOBILE APP UI (max-width: 768px)
   ----------------------------------------------- */
@media (max-width: 768px) {
    /* Layout & Navbar Fixes */
    .main-content {
        margin-left: 0 !important;
        padding-top: 80px !important; 
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important; 
        overflow-x: hidden;
    }

    .navbar {
        position: fixed !important;
        top: 10px !important;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        z-index: 1100 !important;
        height: 55px !important;
    }

    /* Sidebar / Drawer */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-xl);
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        z-index: 1200;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .sidebar.active { 
        transform: translateX(0); 
    }

    /* Navbar Adjustments */
    .menu-toggle { 
        display: flex; 
        align-items: center;
    }
    .user-name { display: none; }
    .navbar-profile { gap: 0; }

    /* Content Spacing */
    .dashboard-content { 
        padding: 12px 14px !important; 
    }
    
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px !important;
        margin-bottom: 14px !important;
        padding: 14px !important;
    }
    .card-header h1, .card-header h2 { 
        font-size: 18px !important; 
    }

    /* ===============================================
       PREMIUM MOBILE CARDS
       =============================================== */
    .card {
        border-radius: 12px !important;
        padding: 14px !important;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03) !important;
        border: 1px solid var(--border-color) !important;
        margin-bottom: 14px !important;
    }

    /* Compact Typography */
    .text-muted, .form-group label { font-size: 12px !important; }
    p { font-size: 13px !important; }

    /* Optimize Forms & Inputs */
    .form-group { margin-bottom: 12px !important; }
    .form-group input, .form-group select, .form-group textarea {
        min-height: 44px !important;
        padding: 10px 14px !important;
        border-radius: 8px !important;
    }

    /* Compact Buttons */
    .btn {
        padding: 10px 14px !important;
        font-size: 14px !important;
        border-radius: 8px !important;
    }
    .btn-sm {
        padding: 6px 10px !important;
        font-size: 12px !important;
    }

    /* ===============================================
       STAT CARDS (2-Column App Layout)
       =============================================== */
    .summary-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
        margin-bottom: 16px !important;
    }
    .stat-card {
        padding: 12px !important;
        border-radius: 12px !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        gap: 4px !important;
    }
    .stat-card h3 {
        font-size: 11px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        margin-bottom: 6px !important;
    }
    
    /* Responsive Numbers (Prevent Overflow) */
    .stat-value {
        font-size: clamp(16px, 4.5vw, 20px) !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        letter-spacing: -0.5px !important;
    }

    /* ===============================================
       TABLES & FOOTER
       =============================================== */
    .footer { 
        text-align: center;
        justify-content: center;
    }
    
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 8px !important;
        border: 1px solid var(--border-color) !important;
    }
    .data-table {
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 0 !important;
        font-size: 11px !important;
        min-width: 600px; /* Forces horizontal scroll instead of page stretching */
    }
    .data-table th, .data-table td {
        padding: 8px 10px !important;
        white-space: normal !important; 
        word-break: break-word !important; 
        vertical-align: top !important;
        line-height: 1.3 !important;
    }
    .data-table thead th {
        font-size: 10px !important;
        font-weight: 700 !important;
        text-transform: uppercase !important;
        background-color: var(--bg-input) !important;
    }
    .data-table .btn-sm {
        padding: 4px 8px !important;
        font-size: 10px !important;
        white-space: nowrap !important;
    }
}

/* -----------------------------------------------
   6. SMALL PHONE ADJUSTMENTS (max-width: 480px)
   ----------------------------------------------- */
@media (max-width: 480px) {
    /* Make modals act like bottom sheets for better reach */
    .modal-overlay {
        align-items: flex-end !important;
        padding: 0 !important;
    }
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        max-height: 85vh !important;
        overflow-y: auto !important;
    }
    
    /* Filter Bar Horizontal Scroll */
    .filter-bar {
        overflow-x: auto;
        flex-wrap: nowrap !important;
        padding-bottom: 4px;
    }
    .filter-btn {
        flex-shrink: 0;
    }
}

/* -----------------------------------------------
   7. ULTRA-SMALL SCREEN ADJUSTMENTS (max-width: 360px)
   ----------------------------------------------- */
@media (max-width: 360px) {
    .dashboard-content { padding: 10px 12px !important; }
    .summary-cards { gap: 8px !important; }
    .stat-card { padding: 10px !important; }
    .stat-card h3 { font-size: 10px !important; }
    .stat-value { font-size: 15px !important; }
}

/* -----------------------------------------------
   8. ACCESSIBILITY & REDUCED MOTION
   ----------------------------------------------- */
/* Prevent accidental text selection on interactive cards */
.stat-card, .btn, .nav-link {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Accessibility: Focus Visible */
.btn:focus-visible,
.stat-card:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--color-primary) !important;
    outline-offset: 2px !important;
    box-shadow: none !important;
}

/* Touch Feedback (Scale down slightly when pressed) */
@media (hover: none) {
    .stat-card:active,
    .btn:active {
        transform: scale(0.98) !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}