/**
 * Mobile Responsiveness
 * Responsive tables, touch targets, and mobile layouts
 */

/* ============================================
   RESPONSIVE TABLES
   ============================================ */

@media (max-width: 768px) {
    /* Stack table rows vertically */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Card-style table rows on mobile */
    .card table tbody tr {
        display: block;
        margin-bottom: 16px;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        padding: 12px;
        background: #f9fafb;
    }

    .card table thead {
        display: none;
    }

    .card table tbody td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border: none;
        text-align: right;
    }

    .card table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        text-align: left;
        color: var(--text-muted);
        font-size: 12px;
        text-transform: uppercase;
    }

    /* Stats grid - single column on mobile */
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    /* Pagination - smaller on mobile */
    .pagination {
        font-size: 12px;
    }

    .pagination .page-link {
        padding: 6px 10px;
    }
}

/* ============================================
   TOUCH TARGETS
   ============================================ */

@media (max-width: 768px) {
    /* Minimum 44px touch targets */
    .btn,
    button,
    a.btn,
    .page-link {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }

    /* Larger form inputs */
    input,
    select,
    textarea {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }

    /* Larger clickable areas */
    .card {
        padding: 16px;
    }

    /* Touch-friendly spacing */
    .btn + .btn {
        margin-left: 8px;
    }
}

/* ============================================
   MOBILE LAYOUTS (DEFAULT STATE - DESKTOP HIDDEN)
   ============================================ */
.mobile-sidebar-toggle-btn {
    display: none !important;
}
.mobile-theme-toggle-btn {
    display: none !important;
}
.desktop-theme-toggle {
    display: flex !important;
}
.header-top-row {
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
}

@media (max-width: 768px) {
    /* Stack dashboard headers vertically on mobile to prevent squishing */
    .header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 16px !important;
        margin-bottom: 24px !important;
    }

    .header h1 {
        font-size: 24px !important; /* Elegant typography scale on mobile */
    }

    .header-actions {
        width: 100% !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 8px !important;
        background: var(--bg-card, #ffffff);
        padding: 8px 12px !important;
        border-radius: 12px !important;
        border: 1px solid var(--border-color, #e5e7eb) !important;
        box-shadow: var(--shadow-soft) !important;
        margin-top: 8px !important;
    }

    [data-theme="dark"] .header-actions {
        background: #1e293b !important;
        border-color: #334155 !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
    }

    .mobile-actions-group {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: flex-end !important;
        gap: 12px !important;
    }

    /* Currency selector smaller and premium on mobile */
    .currency-selector-btn {
        padding: 6px 10px !important;
        font-size: 13px !important;
        height: 36px !important;
        min-height: 36px !important;
        min-width: auto !important;
        background: transparent !important;
        border-color: var(--border-color, #e5e7eb) !important;
    }
    [data-theme="dark"] .currency-selector-btn {
        border-color: #334155 !important;
        color: #f1f5f9 !important;
    }

    /* Notification bell button smaller on mobile */
    .notification-bell-btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        font-size: 16px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Tier badge smaller and premium on mobile */
    #header-tier-badge {
        padding: 4px 10px !important;
        font-size: 10px !important;
        height: 24px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        white-space: nowrap !important;
        border-radius: 12px !important;
    }

    /* Balance chip premium & smaller on mobile */
    .balance-chip {
        padding: 6px 12px !important;
        font-size: 13px !important;
        height: 36px !important;
        min-height: 36px !important;
        min-width: auto !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 8px !important;
        background: var(--gray-100, #f3f4f6) !important;
        color: var(--text-primary, #1f2937) !important;
        font-weight: 600 !important;
    }
    [data-theme="dark"] .balance-chip {
        background: #334155 !important;
        color: #f1f5f9 !important;
    }
    [data-theme="dark"] .balance-chip:hover {
        background: #475569 !important;
    }

    /* Mobile-specific header overrides */
    .mobile-sidebar-toggle-btn {
        display: flex !important;
        background: transparent;
        border: none;
        font-size: 24px;
        cursor: pointer;
        color: var(--text-primary, #1f2937);
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        transition: background 0.2s;
    }
    .mobile-sidebar-toggle-btn:hover {
        background: rgba(0,0,0,0.05);
    }
    [data-theme="dark"] .mobile-sidebar-toggle-btn {
        color: #f1f5f9 !important;
    }
    [data-theme="dark"] .mobile-sidebar-toggle-btn:hover {
        background: rgba(255,255,255,0.1);
    }

    .mobile-theme-toggle-btn {
        display: flex !important;
        background: transparent;
        border: 1px solid var(--border-color, rgba(0,0,0,0.1));
        color: var(--text-primary, #374151);
        width: 36px;
        height: 36px;
        border-radius: 50%;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        font-size: 18px;
        transition: all 0.2s;
    }
    .mobile-theme-toggle-btn:hover {
        background: rgba(0,0,0,0.05);
    }
    [data-theme="dark"] .mobile-theme-toggle-btn {
        color: #f1f5f9 !important;
        border-color: rgba(255,255,255,0.2) !important;
    }
    [data-theme="dark"] .mobile-theme-toggle-btn:hover {
        background: #334155 !important;
    }

    .desktop-theme-toggle {
        display: none !important;
    }

    .header-top-row {
        display: flex !important;
        width: 100% !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    /* Single column layouts */
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    /* Full width modals */
    .modal-content {
        margin: 0;
        border-radius: 0;
        min-height: 100vh;
    }

    /* Sticky headers on mobile */
    .card h2,
    .card h3 {
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
        padding: 12px 0;
    }

    /* Hide desktop-only elements */
    .desktop-only {
        display: none !important;
    }

    /* Show mobile-only elements */
    .mobile-only {
        display: block !important;
    }
}

/* ============================================
   PAGINATION MOBILE
   ============================================ */

@media (max-width: 768px) {
    .pagination {
        flex-wrap: wrap;
        gap: 4px;
    }

    .pagination .page-item {
        flex: 0 0 auto;
    }

    /* Hide page numbers on very small screens, keep prev/next */
    @media (max-width: 480px) {
        .pagination .page-item:not(:first-child):not(:last-child) {
            display: none;
        }
    }
}

/* ============================================
   IMMERSIVE MODAL MOBILE
   ============================================ */

@media (max-width: 768px) {
    .immersive-modal {
        width: 100% !important;
        max-height: 100vh !important;
        border-radius: 16px 16px 0 0 !important;
        position: fixed !important;
        bottom: 0;
        max-width: 100% !important;
    }

    .immersive-modal-backdrop {
        align-items: flex-end !important;
        padding: 0 !important;
    }

    .modal-content-list {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .list-item {
        min-height: 48px;
        padding: 14px 0;
    }

    .list-item-pin {
        padding: 8px 12px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ============================================
   WALLET MOBILE
   ============================================ */

@media (max-width: 768px) {
    .stat-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    .glass-card {
        padding: 16px !important;
    }

    .payment-tabs {
        width: 100% !important;
    }

    .payment-tab {
        flex: 1;
        text-align: center;
        min-height: 44px;
    }

    .grid-presets {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .preset-btn {
        min-height: 48px;
    }
}

@media (max-width: 480px) {
    .stat-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.mobile-only {
    display: none;
}

.desktop-only {
    display: block;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }

    .desktop-only {
        display: none;
    }

    /* Hero Typography Scaling & Prevent Word Splitting */
    .docs-hero h1,
    .contact-hero h1,
    .public-content h1,
    [class*="-hero"] h1 {
        font-size: 28px !important;
        line-height: 1.25 !important;
        word-break: keep-all !important;
        overflow-wrap: break-word !important;
        white-space: normal !important;
    }

    .docs-hero,
    .contact-hero,
    [class*="-hero"] {
        padding: 32px 16px !important;
        margin-bottom: 24px !important;
        border-radius: 16px !important;
    }

    .docs-hero p,
    .contact-hero p,
    [class*="-hero"] p {
        font-size: 15px !important;
    }
}

/* ==========================================================================
   PHASE 1 FOUNDATION: FINE-GRAINED BREAKPOINTS, GRID OVERRIDES & UTILITIES
   ========================================================================== */

/* ─── NEW BREAKPOINTS & GRID OVERRIDES ──────────────────────── */
@media (max-width: 768px) {
    /* Force grids to single column on mobile */
    [class*="grid"], [class*="Grid"], [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 425px) {
    h1 { font-size: var(--font-size-4xl) !important; }
    h2 { font-size: var(--font-size-3xl) !important; }
    h3 { font-size: var(--font-size-2xl) !important; }
}

@media (max-width: 360px) {
    h1 { font-size: var(--font-size-4xl) !important; }
    h2 { font-size: var(--font-size-3xl) !important; }
    h3 { font-size: var(--font-size-2xl) !important; }
}

@media (max-width: 320px) {
    h1 { font-size: var(--font-size-4xl) !important; }
    h2 { font-size: var(--font-size-3xl) !important; }
    h3 { font-size: var(--font-size-2xl) !important; }
    h4 { font-size: var(--font-size-xl) !important; }

    .container, .public-content, main, section, .section {
        max-width: 100vw !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    section, .section {
        margin-bottom: 24px !important;
    }
}

/* ─── RESPONSIVE UTILITY CLASSES ─────────────────────────── */
.text-hero { font-size: var(--font-size-4xl); }
.text-section-title { font-size: var(--font-size-3xl); }
.text-subsection { font-size: var(--font-size-2xl); }
.text-body { font-size: var(--font-size-base); }

.p-section { padding: var(--space-10); }
.p-card { padding: var(--space-8); }
.p-container { padding: var(--space-6) var(--space-6); }

@media (max-width: 768px) {
    .p-section { padding: var(--space-6) var(--space-4) !important; }
    .p-card { padding: var(--space-6) !important; }
}

@media (max-width: 425px) {
    .p-section { padding: var(--space-4) var(--space-3) !important; }
    .p-card { padding: var(--space-4) !important; }
}

.grid-auto-fit {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
}

@media (max-width: 768px) {
    .grid-auto-fit {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }
}

.flex-col-mobile {
    display: flex;
    flex-direction: row;
}

@media (max-width: 768px) {
    .flex-col-mobile {
        flex-direction: column !important;
    }
}

.hide-mobile { display: block; }
.show-mobile { display: none; }

@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
    .show-mobile { display: block !important; }
}

/* ─── REUSABLE RESPONSIVE TABLE PATTERN ─────────────────── */
@media (max-width: 768px) {
    /* Apply mobile collapsing layout to standard tables marked responsive */
    table.responsive-table,
    .card table {
        display: block !important;
        width: 100% !important;
        overflow-x: hidden !important;
    }

    table.responsive-table thead,
    .card table thead {
        display: none !important;
    }

    table.responsive-table tbody,
    .card table tbody {
        display: block !important;
        width: 100% !important;
    }

    table.responsive-table tbody tr,
    .card table tbody tr {
        display: block !important;
        margin-bottom: 16px !important;
        padding: 16px !important;
        border: 1px solid var(--border-color, #e5e7eb) !important;
        border-radius: 8px !important;
        background: var(--bg-card, white) !important;
    }

    [data-theme="dark"] table.responsive-table tbody tr,
    [data-theme="dark"] .card table tbody tr {
        background: var(--bg-card, #1e293b) !important;
        border-color: var(--border-color, #334155) !important;
    }

    table.responsive-table td,
    .card table td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 10px 0 !important;
        border: none !important;
        text-align: right !important;
        font-size: 14px !important;
    }

    table.responsive-table td::before,
    .card table td::before {
        content: attr(data-label) !important;
        font-weight: 600 !important;
        color: var(--text-muted, #6b7280) !important;
        text-transform: uppercase !important;
        font-size: 12px !important;
        text-align: left !important;
        margin-right: 12px !important;
    }

    table.responsive-table td:first-child::before,
    .card table td:first-child::before {
        /* Optional: hide metadata label for primary identifier column if needed */
    }
}
