/**
 * PTP Universal Mobile CSS v123
 * 
 * Critical mobile styles applied to ALL PTP templates
 * Ensures consistent mobile experience across the platform
 * 
 * @version 123.0.0
 * @updated v123: Enhanced safe area support, better touch targets
 */

/* ===========================================
   CSS RESET & BASE
   =========================================== */

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    scroll-behavior: auto; /* FIXED: smooth breaks when tab hidden */
    -webkit-overflow-scrolling: touch;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    max-width: 100vw;
}

/* ===========================================
   SAFE AREA SUPPORT (Notched Devices)
   =========================================== */

body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Bottom safe area for fixed footers */
.ptp-fixed-bottom,
.ptp-sticky-footer,
.fixed-bottom-bar {
    padding-bottom: env(safe-area-inset-bottom);
}

/* v123: Enhanced safe area for full-height layouts */
@supports(min-height: 100dvh) {
    .ptp-full-height,
    .ptp-auth-page,
    .ptp-checkout-page {
        min-height: 100dvh;
    }
}

/* ===========================================
   RESPONSIVE IMAGES
   =========================================== */

img {
    max-width: 100%;
    height: auto;
    display: block;
}

img[loading="lazy"] {
    background-color: #f3f4f6;
}

/* ===========================================
   TOUCH TARGETS (iOS Requirement: 44px min)
   =========================================== */

a,
button,
input[type="button"],
input[type="submit"],
input[type="reset"],
.btn,
.button,
[role="button"] {
    min-height: 44px;
    min-width: 44px;
    -webkit-tap-highlight-color: transparent;
}

/* v123: Better active states for touch */
button:active,
.btn:active,
.button:active,
input[type="submit"]:active {
    transform: scale(0.98);
}

/* Inline links don't need min size */
p a,
span a,
li a {
    min-height: auto;
    min-width: auto;
}

/* ===========================================
   FORM INPUTS (Prevent iOS Zoom)
   =========================================== */

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
textarea,
select {
    font-size: 16px !important;
    -webkit-appearance: none;
    appearance: none;
    border-radius: 8px;
}

@media (max-width: 768px) {
    input,
    textarea,
    select {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* v123: Focus states for mobile */
input:focus,
textarea:focus,
select:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(252, 185, 0, 0.2);
}

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

@media (max-width: 640px) {
    html {
        font-size: 15px;
    }
    
    h1, .h1 {
        font-size: 28px !important;
        line-height: 1.2;
    }
    
    h2, .h2 {
        font-size: 24px !important;
        line-height: 1.25;
    }
    
    h3, .h3 {
        font-size: 20px !important;
        line-height: 1.3;
    }
    
    h4, .h4 {
        font-size: 18px !important;
    }
    
    p, li {
        font-size: 15px;
        line-height: 1.6;
    }
}

/* ===========================================
   MOBILE LAYOUT HELPERS
   =========================================== */

@media (max-width: 768px) {
    /* Full width containers */
    .container,
    .wrapper,
    .content-wrapper {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
    
    /* Stack flex items */
    .flex-row-mobile,
    .d-flex:not(.flex-row) {
        flex-direction: column;
    }
    
    /* Hide on mobile */
    .hide-mobile,
    .desktop-only {
        display: none !important;
    }
    
    /* Show on mobile */
    .show-mobile,
    .mobile-only {
        display: block !important;
    }
    
    /* Full width buttons */
    .btn-mobile-full,
    .button-mobile-full {
        width: 100% !important;
        display: block !important;
    }
}

@media (min-width: 769px) {
    .hide-desktop,
    .mobile-only {
        display: none !important;
    }
}

/* ===========================================
   MOBILE CARDS & GRIDS
   =========================================== */

@media (max-width: 640px) {
    /* Single column grids */
    .grid,
    .card-grid,
    .trainer-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
    
    /* Card spacing */
    .card,
    .ptp-card {
        margin-bottom: 16px;
        border-radius: 12px;
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    /* Two column grids on tablet */
    .grid,
    .card-grid,
    .trainer-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 20px !important;
    }
}

/* ===========================================
   MOBILE NAVIGATION
   =========================================== */

@media (max-width: 768px) {
    /* Sticky header */
    .ptp-header,
    .ft-header,
    header.sticky {
        position: sticky;
        top: 0;
        z-index: 200;
    }
    
    /* Mobile menu */
    .mobile-menu {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.95);
        z-index: 400;
        padding: 80px 24px 24px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .mobile-menu.open {
        transform: translateX(0);
    }
    
    .mobile-menu a {
        display: block;
        padding: 16px 0;
        font-size: 18px;
        color: white;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }
}

/* ===========================================
   MOBILE MODALS & OVERLAYS
   =========================================== */

@media (max-width: 768px) {
    .modal,
    .ptp-modal {
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }
    
    .modal-content,
    .ptp-modal-content {
        padding: 20px 16px !important;
        padding-bottom: calc(20px + env(safe-area-inset-bottom)) !important;
    }
}

/* ===========================================
   MOBILE TABLES
   =========================================== */

@media (max-width: 768px) {
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Card-style tables on mobile */
    .table-responsive-cards thead {
        display: none;
    }
    
    .table-responsive-cards tr {
        display: block;
        margin-bottom: 16px;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        padding: 12px;
    }
    
    .table-responsive-cards td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border-bottom: 1px solid #f3f4f6;
    }
    
    .table-responsive-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #374151;
    }
    
    .table-responsive-cards td:last-child {
        border-bottom: none;
    }
}

/* ===========================================
   MOBILE SCROLL & OVERFLOW
   =========================================== */

/* v133.2: Universal scroll fix */
html {
    overflow-y: scroll !important;
    height: auto !important;
}

body {
    overflow-y: visible !important;
    height: auto !important;
    min-height: 100vh;
}

/* Horizontal scroll containers */
.scroll-x,
.horizontal-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.scroll-x::-webkit-scrollbar,
.horizontal-scroll::-webkit-scrollbar {
    display: none;
}

/* Only block scroll when modal/menu is ACTUALLY open */
body.ptp-modal-active,
body.ptp-menu-active {
    overflow: hidden !important;
}

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

@media (max-width: 640px) {
    .section,
    .ptp-section {
        padding: 32px 16px !important;
    }
    
    .py-mobile-sm { padding-top: 16px !important; padding-bottom: 16px !important; }
    .py-mobile-md { padding-top: 24px !important; padding-bottom: 24px !important; }
    .py-mobile-lg { padding-top: 32px !important; padding-bottom: 32px !important; }
    
    .px-mobile-sm { padding-left: 12px !important; padding-right: 12px !important; }
    .px-mobile-md { padding-left: 16px !important; padding-right: 16px !important; }
    .px-mobile-lg { padding-left: 24px !important; padding-right: 24px !important; }
    
    .mb-mobile-sm { margin-bottom: 12px !important; }
    .mb-mobile-md { margin-bottom: 16px !important; }
    .mb-mobile-lg { margin-bottom: 24px !important; }
}

/* ===========================================
   MOBILE BUTTONS
   =========================================== */

@media (max-width: 640px) {
    .btn,
    .button,
    .ptp-btn {
        padding: 14px 20px;
        font-size: 15px;
        border-radius: 8px;
    }
    
    .btn-lg,
    .button-lg {
        padding: 16px 24px;
        font-size: 16px;
    }
    
    /* Stack button groups */
    .btn-group,
    .button-group {
        flex-direction: column;
        gap: 12px;
    }
    
    .btn-group .btn,
    .button-group .button {
        width: 100%;
    }
}

/* ===========================================
   LOADING STATES
   =========================================== */

.skeleton,
.loading-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===========================================
   ACCESSIBILITY
   =========================================== */

/* Reduced motion */
@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;
    }
}

/* Focus states for touch */
:focus-visible {
    outline: 2px solid #FCB900;
    outline-offset: 2px;
}

/* Skip link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #0A0A0A;
    color: white;
    padding: 8px 16px;
    z-index: 500;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
}

/* ===========================================
   PTP BRAND COLORS
   =========================================== */

:root {
    --ptp-gold: #FCB900;
    --ptp-gold-hover: #E5A800;
    --ptp-gold-light: #FFF8E6;
    --ptp-black: #0A0A0A;
    --ptp-white: #FFFFFF;
    --ptp-gray-50: #F9FAFB;
    --ptp-gray-100: #F3F4F6;
    --ptp-gray-200: #E5E7EB;
    --ptp-gray-300: #D1D5DB;
    --ptp-gray-400: #9CA3AF;
    --ptp-gray-500: #6B7280;
    --ptp-gray-600: #4B5563;
    --ptp-gray-700: #374151;
    --ptp-gray-800: #1F2937;
    --ptp-green: #22C55E;
    --ptp-red: #EF4444;
    --ptp-radius: 8px;
    --ptp-radius-lg: 12px;
    --ptp-shadow: 0 1px 3px rgba(0,0,0,0.1);
    --ptp-shadow-md: 0 4px 6px rgba(0,0,0,0.1);
}

/* ===========================================
   ADMIN BAR ADJUSTMENTS
   =========================================== */

body.admin-bar {
    padding-top: 0;
}

body.admin-bar .ptp-header,
body.admin-bar .ft-header,
body.admin-bar header.sticky {
    top: 32px;
}

@media screen and (max-width: 782px) {
    body.admin-bar .ptp-header,
    body.admin-bar .ft-header,
    body.admin-bar header.sticky {
        top: 46px;
    }
}

/* ===========================================
   DUPLICATE HEADER FIX
   =========================================== */

body.ptp-custom-template .elementor-location-header,
body.ptp-custom-template header.elementor-element,
body.ptp-custom-template #masthead,
body.ptp-custom-template .site-header,
body.ptp-custom-template .theme-header,
body.ptp-custom-template header[data-elementor-type="header"] {
    display: none !important;
}

/* Only one skip link */
.skip-link:not(:first-of-type) {
    display: none !important;
}

/* ===========================================
   v133.2.1: EMERGENCY SCROLL FIX
   This overrides EVERYTHING to ensure scroll works
   =========================================== */
html:not(.ptp-modal-active):not(.ptp-menu-active),
html:not(.ptp-modal-active):not(.ptp-menu-active) body {
    overflow-y: scroll !important;
    overflow-x: hidden !important;
    height: auto !important;
    position: static !important;
}
