/* Enhanced Mobile Responsiveness for CSX System */

/* ======================================
   MOBILE TABLES - Make all tables responsive
   ====================================== */
@media screen and (max-width: 768px) {
    /* Wrap all tables in scrollable containers */
    .overflow-x-auto,
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        margin: 0 -0.5rem;
        padding: 0 0.5rem;
    }
    
    table {
        min-width: 600px;
        font-size: 0.875rem;
    }
    
    /* Make table cells more compact on mobile */
    th, td {
        padding: 0.5rem 0.375rem !important;
        font-size: 0.8rem !important;
    }
    
    /* Add visual scroll indicator */
    .overflow-x-auto::-webkit-scrollbar {
        height: 6px;
    }
    
    .overflow-x-auto::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 3px;
    }
    
    .overflow-x-auto::-webkit-scrollbar-thumb {
        background: #ffd700;
        border-radius: 3px;
    }
}

/* ======================================
   MOBILE FORMS - Better form layouts
   ====================================== */
@media screen and (max-width: 640px) {
    /* Stack all grid columns on mobile */
    .grid,
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4,
    .md\:grid-cols-2,
    .md\:grid-cols-3,
    .md\:grid-cols-4,
    .lg\:grid-cols-2,
    .lg\:grid-cols-3,
    .lg\:grid-cols-4 {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    /* Full width inputs on mobile */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="date"],
    input[type="datetime-local"],
    select,
    textarea,
    .input-field {
        width: 100% !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 0.75rem !important;
        margin-bottom: 0.25rem;
    }
    
    /* Stack form buttons vertically */
    .flex.space-x-3,
    .flex.gap-3,
    .flex.gap-4 {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }
    
    .flex.space-x-3 > *,
    .flex.gap-3 > *,
    .flex.gap-4 > * {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
    }
}

/* ======================================
   MOBILE CARDS - Better card layouts
   ====================================== */
@media screen and (max-width: 768px) {
    /* Responsive card padding */
    .bg-casino-secondary,
    .card,
    .rounded-lg {
        padding: 1rem !important;
        margin-bottom: 1rem;
    }
    
    /* Stack card headers vertically */
    .flex.justify-between.items-center {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }
    
    /* Stat cards responsive */
    .stat-card,
    .bg-casino-accent {
        padding: 0.875rem !important;
        margin-bottom: 0.75rem;
    }
}

/* ======================================
   MOBILE NAVIGATION - Better nav items
   ====================================== */
@media screen and (max-width: 768px) {
    /* Quick filter buttons */
    .btn-secondary,
    .btn-primary {
        padding: 0.625rem 0.875rem !important;
        font-size: 0.875rem !important;
        white-space: nowrap;
    }
    
    /* Horizontal scrolling for filter buttons */
    .flex.flex-wrap.gap-2 {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        gap: 0.5rem !important;
        padding-bottom: 0.5rem;
    }
    
    /* Prevent button text wrapping */
    .flex.flex-wrap.gap-2 button {
        flex-shrink: 0;
    }
}

/* ======================================
   MOBILE MODALS - Better modal experience
   ====================================== */
@media screen and (max-width: 640px) {
    /* Full screen modals on mobile */
    .modal,
    [role="dialog"] {
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }
    
    .modal-content {
        height: 100%;
        display: flex;
        flex-direction: column;
    }
    
    .modal-body {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ======================================
   MOBILE TEXT - Responsive typography
   ====================================== */
@media screen and (max-width: 640px) {
    /* Responsive heading sizes */
    h1, .text-3xl {
        font-size: 1.5rem !important;
        line-height: 2rem !important;
    }
    
    h2, .text-2xl {
        font-size: 1.25rem !important;
        line-height: 1.75rem !important;
    }
    
    h3, .text-xl {
        font-size: 1.125rem !important;
        line-height: 1.5rem !important;
    }
    
    h4, .text-lg {
        font-size: 1rem !important;
        line-height: 1.25rem !important;
    }
    
    /* Prevent text overflow */
    .truncate,
    .text-ellipsis {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ======================================
   MOBILE SPECIFIC COMPONENTS
   ====================================== */
@media screen and (max-width: 768px) {
    /* Search bars */
    .search-container,
    .relative:has(input[type="text"]) {
        width: 100% !important;
    }
    
    /* User search dropdown */
    #search_results {
        left: 0.5rem !important;
        right: 0.5rem !important;
        width: auto !important;
        max-height: 300px !important;
    }
    
    /* Selected user display */
    #selected_user {
        font-size: 0.875rem !important;
    }
    
    /* Deposit/Withdrawal forms */
    #manualDepositForm,
    #manualWithdrawForm {
        padding: 0 !important;
    }
    
    /* Transaction tables - show only essential columns */
    .transaction-table th:not(:nth-child(1)):not(:nth-child(2)):not(:nth-child(3)),
    .transaction-table td:not(:nth-child(1)):not(:nth-child(2)):not(:nth-child(3)) {
        display: none;
    }
    
    /* Admin tool cards */
    .admin-tool-card {
        padding: 1rem !important;
        margin-bottom: 0.75rem !important;
    }
    
    .admin-tool-card h3 {
        font-size: 1rem !important;
    }
    
    .admin-tool-card p {
        font-size: 0.875rem !important;
    }
}

/* ======================================
   MOBILE DASHBOARD IMPROVEMENTS
   ====================================== */
@media screen and (max-width: 640px) {
    /* Dashboard stats grid */
    .dashboard-stats {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 0.5rem !important;
    }
    
    .dashboard-stat-card {
        padding: 0.75rem !important;
    }
    
    .dashboard-stat-card .text-2xl,
    .dashboard-stat-card .text-3xl {
        font-size: 1.25rem !important;
    }
    
    /* Activity feed */
    .activity-item {
        padding: 0.75rem !important;
        font-size: 0.875rem !important;
    }
    
    .activity-time {
        font-size: 0.75rem !important;
    }
    
    /* Charts responsive */
    .chart-container {
        min-height: 200px !important;
        max-height: 300px !important;
    }
}

/* ======================================
   MOBILE REPORTS PAGE
   ====================================== */
@media screen and (max-width: 768px) {
    /* Date range picker */
    .date-range-container {
        flex-direction: column !important;
    }
    
    .date-range-container input {
        width: 100% !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Report filters */
    .filter-section {
        padding: 0.75rem !important;
    }
    
    /* Quick date filters horizontal scroll */
    .quick-filters {
        display: flex !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        gap: 0.5rem !important;
        padding: 0.5rem 0 !important;
    }
    
    .quick-filters button {
        flex-shrink: 0;
        padding: 0.5rem 0.75rem !important;
        font-size: 0.8rem !important;
    }
}

/* ======================================
   MOBILE USER MANAGEMENT
   ====================================== */
@media screen and (max-width: 640px) {
    /* User cards */
    .user-card {
        padding: 0.75rem !important;
    }
    
    .user-card .user-info {
        font-size: 0.875rem !important;
    }
    
    .user-card .user-actions {
        margin-top: 0.75rem !important;
    }
    
    .user-card .user-actions button {
        padding: 0.5rem !important;
        font-size: 0.75rem !important;
    }
    
    /* User table mobile view */
    .user-table-mobile {
        display: block !important;
    }
    
    .user-table-mobile thead {
        display: none;
    }
    
    .user-table-mobile tbody,
    .user-table-mobile tr,
    .user-table-mobile td {
        display: block !important;
        width: 100% !important;
    }
    
    .user-table-mobile tr {
        margin-bottom: 1rem;
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 0.5rem;
        padding: 0.75rem;
    }
    
    .user-table-mobile td {
        padding: 0.25rem 0 !important;
        display: flex;
        justify-content: space-between;
    }
    
    .user-table-mobile td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #ffd700;
        margin-right: 0.5rem;
    }
}

/* ======================================
   TOUCH OPTIMIZATIONS
   ====================================== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    button,
    a,
    .clickable,
    .menu-item,
    .submenu-item,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px !important;
        min-width: 44px !important;
    }
    
    /* Remove hover effects on touch devices */
    .hover\:bg-casino-accent:hover {
        background: transparent !important;
    }
    
    /* Active states for touch feedback */
    button:active,
    a:active,
    .clickable:active {
        opacity: 0.8;
        transform: scale(0.98);
    }
}

/* ======================================
   LANDSCAPE OPTIMIZATIONS
   ====================================== */
@media screen and (max-height: 500px) and (orientation: landscape) {
    /* Reduce header height in landscape */
    .mobile-header {
        height: 3rem !important;
        padding: 0.5rem !important;
    }
    
    /* Adjust content spacing */
    .main-content {
        padding-top: 3rem !important;
    }
    
    /* Compact forms in landscape */
    input,
    select,
    textarea {
        padding: 0.5rem !important;
    }
    
    /* Hide non-essential elements */
    .landscape-hide {
        display: none !important;
    }
}

/* ======================================
   PERFORMANCE OPTIMIZATIONS
   ====================================== */
@media screen and (max-width: 768px) {
    /* Use GPU acceleration for animations */
    .mobile-sidebar,
    .modal,
    .dropdown {
        will-change: transform;
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
    
    /* Optimize image rendering */
    img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
    
    /* Reduce animation complexity on mobile */
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
}

/* ======================================
   ACCESSIBILITY IMPROVEMENTS
   ====================================== */
@media screen and (max-width: 768px) {
    /* Better focus indicators */
    *:focus {
        outline: 3px solid #ffd700 !important;
        outline-offset: 2px !important;
    }
    
    /* Skip navigation link */
    .skip-nav {
        position: absolute;
        top: -40px;
        left: 0;
        background: #ffd700;
        color: #000;
        padding: 0.5rem 1rem;
        z-index: 100;
        text-decoration: none;
    }
    
    .skip-nav:focus {
        top: 0;
    }
}

/* ======================================
   UTILITY CLASSES FOR MOBILE
   ====================================== */
@media screen and (max-width: 768px) {
    /* Hide on mobile */
    .mobile-hidden,
    .hide-mobile {
        display: none !important;
    }
    
    /* Show only on mobile */
    .mobile-only {
        display: block !important;
    }
    
    /* Full width on mobile */
    .mobile-full-width {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Stack on mobile */
    .mobile-stack {
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Center on mobile */
    .mobile-center {
        text-align: center !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }
}

/* ======================================
   SPECIFIC PAGE FIXES
   ====================================== */
/* Bank info page */
@media screen and (max-width: 640px) {
    #bank_name,
    #account_name,
    #account_number {
        width: 100% !important;
    }
    
    .bank-info-display {
        grid-template-columns: 1fr !important;
    }
}

/* E-chips deposit/withdrawal pages */
@media screen and (max-width: 768px) {
    #user_balance_display {
        padding: 0.75rem !important;
    }
    
    #user_balance_display .grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
}

/* Admin reset pages */
@media screen and (max-width: 640px) {
    #new_password,
    #confirm_password,
    #new_security_code,
    #confirm_security_code {
        width: 100% !important;
    }
    
    .security-guidelines .grid {
        grid-template-columns: 1fr !important;
    }
}

/* Settings page */
@media screen and (max-width: 768px) {
    .settings-section {
        padding: 1rem !important;
        margin-bottom: 1rem !important;
    }
    
    .color-picker-container {
        flex-direction: column !important;
    }
}

/* Login/Registration pages */
@media screen and (max-width: 640px) {
    .auth-container {
        padding: 1rem !important;
        margin: 1rem !important;
    }
    
    .auth-form {
        padding: 1.5rem !important;
    }
    
    .auth-logo {
        max-width: 150px !important;
        margin: 0 auto 1rem !important;
    }
}