/* Mobile Responsive CSS - Enhanced */

/* ================================
   GLOBAL MOBILE FIXES
   ================================ */

/* Prevent horizontal scroll */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Touch-friendly tap targets */
@media (max-width: 768px) {
    button,
    a,
    input[type="button"],
    input[type="submit"],
    .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }

    /* Prevent iOS zoom on input focus */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Responsive images */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Responsive videos */
    video,
    iframe {
        max-width: 100%;
        height: auto;
    }
}

/* ================================
   TABLE RESPONSIVENESS
   ================================ */

@media (max-width: 768px) {
    /* Scrollable tables */
    .table-responsive {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 600px;
        font-size: 14px;
    }

    table th,
    table td {
        padding: 8px 12px;
        white-space: nowrap;
    }

    /* Alternative: Stack table on mobile */
    .table-stack {
        display: block;
        width: 100%;
    }

    .table-stack thead {
        display: none;
    }

    .table-stack tbody,
    .table-stack tr,
    .table-stack td {
        display: block;
        width: 100%;
    }

    .table-stack tr {
        margin-bottom: 15px;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        padding: 12px;
    }

    .table-stack td {
        text-align: right;
        padding: 8px 0;
        position: relative;
        border-bottom: 1px solid #f3f4f6;
    }

    .table-stack td:before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        color: #6b7280;
    }

    .table-stack td:last-child {
        border-bottom: none;
    }
}

/* ================================
   FORM RESPONSIVENESS
   ================================ */

@media (max-width: 768px) {
    form {
        width: 100%;
    }

    /* Stack form groups */
    .form-row,
    .grid {
        display: block !important;
    }

    .form-group,
    .grid > div {
        width: 100% !important;
        margin-bottom: 16px;
    }

    /* Full width inputs */
    input:not([type="checkbox"]):not([type="radio"]),
    select,
    textarea {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Better spacing for checkboxes/radios */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
        margin-right: 10px;
    }

    label {
        display: block;
        margin-bottom: 8px;
        font-weight: 500;
    }
}

/* ================================
   CARD & GRID RESPONSIVENESS
   ================================ */

@media (max-width: 768px) {
    /* Single column grids */
    .grid,
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4,
    [class*="grid-cols-"] {
        grid-template-columns: 1fr !important;
    }

    /* Cards full width */
    .card,
    .bg-white {
        margin-left: 0 !important;
        margin-right: 0 !important;
        border-radius: 12px;
    }

    /* Better padding for cards */
    .card,
    .bg-white {
        padding: 16px !important;
    }

    /* Stats cards */
    .stats-card {
        padding: 16px;
        margin-bottom: 12px;
    }
}

/* ================================
   NAVIGATION & MENU
   ================================ */

@media (max-width: 768px) {
    /* Hide desktop nav */
    nav .hidden.md\\:flex {
        display: none !important;
    }

    /* Mobile menu transitions */
    #mobileMenu {
        transition: transform 0.3s ease-out, opacity 0.3s ease-out;
    }

    /* Adjust nav height for mobile */
    nav {
        padding: 8px 16px;
    }

    /* Better logo sizing */
    nav .text-3xl {
        font-size: 1.75rem;
    }

    nav .text-xl {
        font-size: 1.125rem;
    }
}

/* ================================
   TYPOGRAPHY MOBILE SCALING
   ================================ */

@media (max-width: 768px) {
    h1, .text-4xl, .text-5xl {
        font-size: 1.875rem !important;
        line-height: 1.2;
    }

    h2, .text-3xl {
        font-size: 1.5rem !important;
    }

    h3, .text-2xl {
        font-size: 1.25rem !important;
    }

    h4, .text-xl {
        font-size: 1.125rem !important;
    }

    p, .text-base {
        font-size: 0.938rem;
        line-height: 1.6;
    }

    .text-sm {
        font-size: 0.813rem;
    }

    .text-xs {
        font-size: 0.75rem;
    }
}

/* ================================
   SPACING MOBILE ADJUSTMENTS
   ================================ */

@media (max-width: 768px) {
    /* Reduce padding */
    .px-8 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .py-12 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }

    .py-8 {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }

    /* Adjust margins */
    .mb-8 {
        margin-bottom: 1.5rem !important;
    }

    .mt-8 {
        margin-top: 1.5rem !important;
    }

    /* Container spacing */
    .container,
    .max-w-7xl,
    .max-w-6xl,
    .max-w-5xl {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

/* ================================
   MODAL & POPUP RESPONSIVENESS
   ================================ */

@media (max-width: 768px) {
    /* Full screen modals */
    .modal,
    [role="dialog"] {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh;
        margin: 0;
        border-radius: 0;
    }

    /* Modal content padding */
    .modal-content {
        padding: 20px;
    }
}

/* ================================
   ADMIN PANEL MOBILE
   ================================ */

@media (max-width: 768px) {
    /* Stack admin sidebar */
    .admin-sidebar {
        width: 100% !important;
        position: relative;
    }

    .admin-content {
        width: 100% !important;
        margin-left: 0 !important;
    }

    /* Mobile-friendly admin tables */
    .admin-table {
        font-size: 13px;
    }

    .admin-table th,
    .admin-table td {
        padding: 6px 8px;
    }
}

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

@media (max-width: 768px) {
    /* Hide on mobile */
    .hide-mobile {
        display: none !important;
    }

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

    /* Full width on mobile */
    .mobile-full {
        width: 100% !important;
    }

    /* Center text on mobile */
    .mobile-center {
        text-align: center !important;
    }

    /* Stack flex on mobile */
    .mobile-stack {
        flex-direction: column !important;
    }
}

/* ================================
   PREMIUM FEATURES MOBILE
   ================================ */

@media (max-width: 768px) {
    /* Premium cards */
    .premium-card {
        padding: 16px;
        margin-bottom: 16px;
    }

    /* Premium theme previews */
    .theme-preview {
        width: 100%;
        height: auto;
    }

    /* Avatar frames */
    .frame-selector {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ================================
   DASHBOARD MOBILE
   ================================ */

@media (max-width: 768px) {
    /* Stats grid */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    /* Charts responsive */
    .chart-container {
        width: 100%;
        overflow-x: auto;
    }

    canvas {
        max-width: 100%;
    }
}

/* ================================
   CHALLENGE CARDS MOBILE
   ================================ */

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

    .challenge-card {
        margin-bottom: 16px;
    }

    /* Challenge progress bars */
    .progress-bar {
        height: 10px;
    }
}

/* ================================
   PROFILE PAGE MOBILE
   ================================ */

@media (max-width: 768px) {
    /* Profile header stack */
    .profile-header {
        flex-direction: column !important;
        text-align: center;
    }

    .profile-avatar {
        margin: 0 auto 16px;
    }

    /* Profile tabs scroll */
    .profile-tabs {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
}

/* ================================
   LEADERBOARD MOBILE
   ================================ */

@media (max-width: 768px) {
    .leaderboard-item {
        padding: 12px;
        font-size: 14px;
    }

    .leaderboard-rank {
        font-size: 1.25rem;
    }

    .leaderboard-avatar {
        width: 40px;
        height: 40px;
    }
}

/* ================================
   SPECIAL MOBILE FIXES
   ================================ */

/* Fix for iOS safe area */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
}

/* Landscape orientation fixes */
@media (max-width: 768px) and (orientation: landscape) {
    /* Reduce heights in landscape */
    .min-h-screen {
        min-height: auto;
    }

    /* Adjust modal heights */
    .modal {
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* Extra small devices (< 475px) */
@media (max-width: 475px) {
    h1 {
        font-size: 1.5rem !important;
    }

    .px-4 {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    button,
    .btn {
        font-size: 14px;
        padding: 10px 14px;
    }
}

/* Print styles */
@media print {
    nav,
    footer,
    .no-print {
        display: none !important;
    }

    body {
        font-size: 12pt;
    }

    table {
        page-break-inside: avoid;
    }
}