/**
 * ============================================================================
 * Thai Connect — Mobile Responsive Foundation (assets/css/responsive.css)
 * Version: 1.0 (Cache-busting: v=1)
 * 
 * STRICT RULES APPLIED:
 * 1. Wrapped in @media (max-width: 1023px) — Desktop (>=1024px) remains 100% untouched.
 * 2. Mobile Reset & Box Sizing
 * 3. iOS Safari Form Zoom Fix (font-size >= 16px)
 * 4. Touch Targets >= 44x44px (Apple HIG & WCAG)
 * 5. Horizontal Overflow Scroll Container (.table-responsive)
 * 6. Thai Typography Line-Height >= 1.5
 * 7. Disable Hover Effects on Touch Devices (hover: none)
 * 8. Motion Reduction for Accessibility (prefers-reduced-motion)
 * 9. Override 100vh with 100dvh (iOS Safari & Chrome Mobile Viewport Bar Fix)
 * ============================================================================
 */

@media (max-width: 1023px) {
    /* 1. Reset, Sizing & Horizontal Bleed Protection */
    *, 
    *::before, 
    *::after {
        box-sizing: border-box;
    }

    img, 
    video {
        max-width: 100%;
        height: auto;
    }

    html, 
    body {
        overflow-x: hidden;
    }

    /* 2. iOS Auto-Zoom Fix for Form Inputs (< 16px triggers Safari zoom) */
    input, 
    select, 
    textarea {
        font-size: 16px !important;
    }

    /* 3. Touch Targets >= 44x44px for Buttons and Interactive Elements */
    button, 
    .btn, 
    .btn-sm, 
    a.btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* 4. Responsive Scroll Container for Wide Tables / Content */
    .table-responsive {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* 5. Thai Typography Readability */
    body, 
    p, 
    span, 
    li, 
    button, 
    input, 
    textarea, 
    label {
        line-height: 1.5;
    }

    /* 6. Viewport Height Overrides (100vh -> 100dvh for Mobile Address Bars) */
    /* landing.css:150 */
    .tc-page-wrapper {
        min-height: 100dvh;
    }

    /* game_theme.css:99 */
    body.game-body {
        min-height: 100dvh;
    }

    /* game_theme.css:1385 */
    .menu-panel {
        height: 100dvh !important;
        max-height: 100dvh !important;
    }

    /* battle5v5.css:108 */
    body.battle5v5-body {
        min-height: 100dvh;
    }

    /* style.css:3285 (Login Page Auth Container) */
    .auth-container {
        min-height: 100dvh;
    }

    /* ===== MOBILE NAVBAR & HAMBURGER (index.php) ===== */
    /* ซ่อนป้าย "สยามเกม" ที่จอต่ำกว่า 1024px */
    .tc-brand-text-sub {
        display: none !important;
    }

    /* ซ่อนแถบเมนูแนวนอนบนเดสก์ท็อป */
    .tc-nav-menu {
        display: none !important;
    }

    /* ซ่อนปุ่มล็อกอิน/โปรไฟล์บนแถบบน ย้ายไปแสดงเต็มความกว้างใน Drawer */
    .tc-nav-actions > .tc-btn-nav-login,
    .tc-nav-actions > .tc-nav-user-badge {
        display: none !important;
    }

    /* แสดงปุ่มแฮมเบอร์เกอร์ฝั่งขวา */
    .tc-nav-hamburger {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        min-height: 44px !important;
        border-radius: 12px !important;
        background: rgba(255, 255, 255, 0.12) !important;
        border: 1px solid rgba(255, 255, 255, 0.22) !important;
        color: #ffffff !important;
        font-size: 1.35rem !important;
        cursor: pointer !important;
        padding: 0 !important;
        transition: background 0.2s ease, transform 0.2s ease !important;
    }

    .tc-nav-hamburger:active {
        transform: scale(0.94);
    }

    /* ล็อก scroll หน้าเว็บเมื่อเปิด Drawer */
    body.nav-drawer-open {
        overflow: hidden !important;
        touch-action: none !important;
    }

    /* Mobile Overlay ด้านหลัง Drawer */
    .tc-mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100dvh;
        background: rgba(12, 4, 24, 0.68);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
        z-index: 9998;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .tc-mobile-overlay.is-open {
        opacity: 1;
        visibility: visible;
    }

    /* Mobile Drawer: สไลด์เข้าจากทางขวา */
    .tc-mobile-drawer {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        left: auto !important;
        bottom: 0 !important;
        width: min(320px, 86vw) !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        background: rgba(26, 9, 39, 0.98) !important;
        backdrop-filter: blur(28px) !important;
        -webkit-backdrop-filter: blur(28px) !important;
        border: none !important;
        border-left: 1px solid rgba(245, 158, 11, 0.35) !important;
        border-radius: 0 !important;
        padding: 20px 18px 24px 18px !important;
        box-shadow: -12px 0 40px rgba(0, 0, 0, 0.75) !important;
        z-index: 9999 !important;
        display: flex !important;
        flex-direction: column !important;
        transform: translateX(105%) !important;
        transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1) !important;
        animation: none !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .tc-mobile-drawer.is-open {
        transform: translateX(0) !important;
    }

    /* ส่วนหัวภายใน Drawer */
    .tc-mobile-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-bottom: 16px;
        margin-bottom: 14px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    }

    .tc-mobile-drawer-brand {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .tc-mobile-drawer-title {
        font-size: 1.1rem;
        font-weight: 600;
        color: #ffffff;
    }

    .tc-mobile-drawer-close {
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        min-height: 44px !important;
        border-radius: 12px !important;
        background: rgba(255, 255, 255, 0.1) !important;
        border: 1px solid rgba(255, 255, 255, 0.15) !important;
        color: #f3e8ff !important;
        font-size: 1.25rem !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        padding: 0 !important;
        transition: background 0.2s ease !important;
    }

    .tc-mobile-drawer-close:hover {
        background: rgba(236, 72, 153, 0.25) !important;
    }

    /* รายการลิงก์ใน Drawer เรียงแนวตั้ง สูงอย่างน้อย 48px */
    .tc-mobile-menu-list {
        list-style: none !important;
        padding: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        flex: 1 0 auto;
    }

    .tc-mobile-menu-item a {
        display: flex !important;
        align-items: center !important;
        gap: 14px !important;
        min-height: 48px !important;
        padding: 12px 16px !important;
        border-radius: 14px !important;
        color: #f3e8ff !important;
        font-size: 1rem !important;
        font-weight: 500 !important;
        text-decoration: none !important;
        background: rgba(255, 255, 255, 0.04) !important;
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
        transition: all 0.2s ease !important;
    }

    .tc-mobile-menu-item a:hover,
    .tc-mobile-menu-item.active a {
        background: linear-gradient(90deg, rgba(236, 72, 153, 0.28) 0%, rgba(168, 85, 247, 0.18) 100%) !important;
        border-color: rgba(236, 72, 153, 0.45) !important;
        color: #ffffff !important;
    }

    /* ส่วนปุ่ม Auth / Profile ด้านล่างสุด เต็มความกว้าง */
    .tc-mobile-drawer-auth {
        margin-top: auto;
        padding-top: 18px;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
        display: flex;
        flex-direction: column;
        gap: 10px;
        width: 100%;
    }

    .tc-mobile-user-card {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 14px;
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.06);
        border: 1px solid rgba(255, 255, 255, 0.1);
    }

    .tc-mobile-user-info {
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .tc-mobile-user-name {
        font-weight: 600;
        color: #ffffff;
        font-size: 0.95rem;
    }

    .tc-mobile-btn {
        width: 100% !important;
        min-height: 48px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 10px !important;
        border-radius: 14px !important;
        font-weight: 600 !important;
        font-size: 1rem !important;
        text-decoration: none !important;
        border: none !important;
        cursor: pointer !important;
        transition: transform 0.2s ease, box-shadow 0.2s ease !important;
    }

    .tc-mobile-btn-primary {
        background: linear-gradient(135deg, #ec4899 0%, #a855f7 100%) !important;
        color: #ffffff !important;
        box-shadow: 0 4px 18px rgba(236, 72, 153, 0.45) !important;
    }

    .tc-mobile-btn-admin {
        background: rgba(245, 158, 11, 0.2) !important;
        border: 1px solid rgba(245, 158, 11, 0.45) !important;
        color: #fef3c7 !important;
    }

    .tc-mobile-btn-logout {
        background: rgba(239, 68, 68, 0.18) !important;
        border: 1px solid rgba(239, 68, 68, 0.35) !important;
        color: #fca5a5 !important;
    }
}

/* 7. ปิดการแสดงผลปุ่มแฮมเบอร์เกอร์และ Drawer บนหน้าจอเดสก์ท็อป (1024px ขึ้นไป) */
@media (min-width: 1024px) {
    .tc-nav-hamburger,
    .tc-mobile-overlay,
    .tc-mobile-drawer {
        display: none !important;
    }
}

/* 7. Disable Hover-only Visual Gimmicks on Touch Screens */
@media (max-width: 1023px) and (hover: none) {
    .tilt-card {
        transform: none !important;
        transition: none !important;
    }
}

/* 8. Reduced Motion for Accessibility */
@media (max-width: 1023px) and (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;
    }
}
