/* ================================================
   MOBILE & RESPONSIVE DESIGN - ENHANCED
   athletes.online - Professional Mobile App Experience
   ================================================ */

/* ====================================
   BASE MOBILE STYLES (< 768px)
   ==================================== */
@media (max-width: 768px) {

    /* Prevent horizontal scroll on body */
    html,
    body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
        position: relative;
        touch-action: pan-x pan-y !important;
        /* Allow natural touch */
        overscroll-behavior: none !important;
    }

    /* Modal Background Lock - PREVENTS SCROLLING BEHIND MODALS */
    body.modal-open {
        overflow: hidden !important;
        height: 100vh !important;
        position: fixed !important;
        width: 100% !important;
    }

    /* Remove padding that causes horizontal shift */
    body.no-scroll {
        padding-right: 0 !important;
    }

    body {
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Dashboard Container - Lowered for visibility */
    .dashboard {
        width: 100% !important;
        max-width: 100% !important;
        padding: 110px 0 20px 0 !important;
        /* Increased to 110px to clear header */
        margin: 0 !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
        position: relative;
    }

    /* Fixed Top Navigation Bar for Mobile */
    .top-nav-controls {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 60px !important;
        background: #2563eb !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-around !important;
        align-items: center !important;
        padding: 0 16px !important;
        z-index: 2500 !important;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2) !important;
    }

    .top-nav-controls .admin-btn,
    .top-nav-controls .notification-btn,
    .top-nav-controls .logout-btn,
    .top-nav-controls .lang-btn {
        color: white !important;
        transform: none !important;
    }

    /* Dashboard Header - ENHANCED SPACING */
    .dashboard-header {
        display: none !important;
        /* Hide redundant header if icons moved */
        padding: 12px 16px !important;
        margin: 0 0 24px 0 !important;
        /* Increased margin to prevent overlap */
        background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
        box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
        position: relative !important;
        z-index: 1000 !important;
    }

    .dashboard-header h2 {
        font-size: 1.25rem !important;
        margin: 0 !important;
    }

    /* Notification Panel Fix - Adjusted for Fixed Top Bar */
    /* Notification Panel Fix - Adjusted for Fixed Top Bar */
    .notif-dropdown {
        z-index: 9999 !important;
        position: fixed !important;
        top: 60px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: calc(100% - 24px) !important;
        max-width: 350px !important;
        /* Limit width */
        border-radius: 0 0 12px 12px !important;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2) !important;
    }

    /* Header Icons - Prevent overlap with calendar */
    .dashboard-header .user-actions {
        position: relative !important;
        z-index: 51 !important;
    }

    /* ====================================
       DATE SELECTOR - Mobile Optimized
       ==================================== */
    .date-selector {
        padding: 8px 16px !important;
        margin: 0 !important;
        flex-wrap: nowrap !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    .date-selector button {
        padding: 8px 12px !important;
        min-width: 44px !important;
        min-height: 44px !important;
        font-size: 0.9rem !important;
        flex-shrink: 0 !important;
    }

    .current-date {
        font-size: 0.95rem !important;
        padding: 6px 12px !important;
        text-align: center !important;
        margin: 0 8px !important;
        flex: 1 !important;
        white-space: nowrap !important;
    }

    /* ====================================
       CALENDAR WIDGET - HORIZONTAL SWIPE
       ==================================== */
    .calendar-widget {
        padding: 0 !important;
        margin: 12px 0 !important;
        overflow: visible !important;
        position: relative;
    }

    /* Calendar Container - Horizontal Scroll */
    #cardsContainer,
    /* Added JS-generated container ID */
    .calendar-container,
    .calendar-grid {
        display: flex !important;
        flex-direction: row !important;
        justify-content: flex-start !important;
        /* Critical for scrolling back left */
        flex-wrap: nowrap !important;
        /* Force swipe */
        overflow-x: auto !important;
        overflow-y: hidden !important;
        scroll-snap-type: x mandatory !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 12px !important;
        padding: 8px 16px !important;
        scrollbar-width: none !important;
        touch-action: pan-x !important;
        width: 100% !important;
        max-width: 100% !important;
        overscroll-behavior-x: contain !important;
    }

    #cardsContainer::-webkit-scrollbar,
    .calendar-grid::-webkit-scrollbar {
        display: none !important;
        /* Chrome, Safari */
    }

    /* Calendar Day Card - Swipeable */
    .date-card,
    /* Added JS-generated class */
    .calendar-day {
        flex: 0 0 140px !important;
        /* Increased width */
        min-width: 140px !important;
        height: 140px !important;
        scroll-snap-align: start !important;
        /* Changed from center to start */
        padding: 12px !important;
        font-size: 0.85rem !important;
        border-radius: 16px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
        transition: transform 0.2s ease !important;

        /* Overrides for carousel positioning */
        position: relative !important;
        left: auto !important;
        top: auto !important;
        transform: none !important;
        opacity: 1 !important;
        /* Force distinct visibility */
        display: flex !important;
        /* Ensure it stays in flow */
        visibility: visible !important;
        margin: 0 !important;
    }

    .date-card:active,
    .calendar-day:active {
        transform: scale(0.95) !important;
    }

    /* Swipe Indicator for Calendar */
    .calendar-widget::after {
        content: '← Kaydırın →';
        display: block;
        text-align: center;
        font-size: 0.7rem;
        color: #94a3b8;
        padding: 4px 0;
        margin-top: -4px;
    }

    /* ====================================
       REPORTS CARDS - HORIZONTAL CAROUSEL
       ==================================== */
    .reports-section,
    .cards-container {
        display: flex !important;
        flex-direction: row !important;
        justify-content: flex-start !important;
        /* Critical for scrolling back left */
        flex-wrap: nowrap !important;
        /* Ensure no wrapping */
        overflow-x: auto !important;
        overflow-y: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
        /* Constrain to parent/screen */
        scroll-snap-type: x mandatory !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 12px !important;
        padding: 22px 16px 12px 16px !important;
        /* Added 10px top spacing */
        scrollbar-width: none !important;
        grid-template-columns: none !important;
        touch-action: pan-x !important;
        overscroll-behavior-x: contain !important;
    }

    .cards-container::-webkit-scrollbar {
        display: none !important;
    }

    .card,
    .report-card {
        flex: 0 0 160px !important;
        min-width: 160px !important;
        height: 160px !important;
        scroll-snap-align: start !important;
        /* Changed from center to start */
        padding: 16px 12px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 16px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    }

    .card svg,
    .card img {
        width: 56px !important;
        height: 56px !important;
        margin-bottom: 8px !important;
    }

    .card-title {
        font-size: 0.9rem !important;
        margin: 0 !important;
        text-align: center !important;
    }

    /* Reports Section - Add Swipe Hint */
    .reports-section::after,
    .cards-container::after {
        content: '';
        flex: 0 0 8px;
        height: 1px;
    }

    /* ====================================
       ATHLETES & STAFF - HORIZONTAL SCROLL
       ==================================== */
    .athletes-list,
    .staff-list,
    .players-list {
        padding: 0 !important;
        margin: 16px 0 !important;
        overflow: visible !important;
    }

    .section-title {
        font-size: 1.1rem !important;
        margin: 0 0 12px 16px !important;
        font-weight: 600 !important;
    }

    /* Player Cards Container - Horizontal Carousel */
    .athletes-list>div:not(.section-title),
    .staff-list>div:not(.section-title),
    .players-grid,
    #mainPlayerGrid,
    #mainStaffGrid {
        display: flex !important;
        flex-direction: row !important;
        justify-content: flex-start !important;
        /* Critical for scrolling back left */
        flex-wrap: nowrap !important;
        /* Force swipe */
        overflow-x: auto !important;
        overflow-y: hidden !important;
        scroll-snap-type: x mandatory !important;
        /* Changed from proximity */
        -webkit-overflow-scrolling: touch !important;
        gap: 12px !important;
        padding: 8px 16px !important;
        scrollbar-width: none !important;
        touch-action: pan-x !important;
        width: 100% !important;
        max-width: 100% !important;
        overscroll-behavior-x: contain !important;
    }

    .athletes-list>div::-webkit-scrollbar,
    .staff-list>div::-webkit-scrollbar,
    .players-grid::-webkit-scrollbar,
    #mainPlayerGrid::-webkit-scrollbar,
    #mainStaffGrid::-webkit-scrollbar {
        display: none !important;
    }

    /* Player Card - Swipeable */
    .player-card,
    .staff-card {
        flex: 0 0 160px !important;
        /* Increased from 140px */
        min-width: 160px !important;
        width: 160px !important;
        scroll-snap-align: start !important;
        padding: 12px !important;
        margin: 0 !important;
        border-radius: 12px !important;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08) !important;
    }

    .player-card img {
        width: 125px !important;
        /* Increased to 125px */
        height: 125px !important;
        border-radius: 12px !important;
        margin: 0 auto 10px !important;
        display: block !important;
        object-fit: cover !important;
    }

    .player-info h4 {
        font-size: 0.95rem !important;
        margin: 4px 0 !important;
        text-align: center !important;
        white-space: normal !important;
        /* Allow wrapping */
        overflow: visible !important;
        text-overflow: clip !important;
    }

    .player-info p {
        font-size: 0.75rem !important;
        text-align: center !important;
        margin: 2px 0 !important;
        white-space: normal !important;
    }

    /* ====================================
       MODALS - Full Screen + Fixed UI
       ==================================== */
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .modal-header {
        padding: 14px 16px !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 200 !important;
        background: white !important;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
    }

    .modal-header h2 {
        font-size: 1.05rem !important;
        margin: 0 !important;
    }

    /* Close Button - Mobile Optimized */
    .modal-header .close-btn,
    .modal-header button[onclick*="close"] {
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 8px !important;
    }

    /* ====================================
       MODAL TABS - Horizontal Scroll + FULL TEXT
       ==================================== */
    /* Horizontal Scroll Sections - NATIVE SWIPE FEEDBACK */
    .calendar-grid,
    .calendar-container,
    #mainPlayerGrid,
    #mainStaffGrid,
    .cards-container,
    .reports-section {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scroll-snap-type: x mandatory !important;
        gap: 16px !important;
        padding: 8px 24px !important;
        /* More side padding to see neighbors */
        scroll-padding: 0 24px !important;
        display: flex !important;
        flex-wrap: nowrap !important;
    }

    .calendar-day,
    .player-card,
    .staff-card,
    .card {
        scroll-snap-align: center !important;
        /* Snap to center for better focus */
        flex: 0 0 240px !important;
        /* Fixed width to ensure overflow occurs */
        min-width: 240px !important;
    }

    /* Small Adjustments for smaller screens */
    @media (max-width: 480px) {

        .calendar-day,
        .player-card,
        .staff-card,
        .card {
            flex: 0 0 85% !important;
            /* Show 85% of card + 15% of next one */
            min-width: 85% !important;
        }
    }

    .tabs {
        display: flex !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch !important;
        scroll-snap-type: x proximity !important;
        gap: 8px !important;
        padding: 8px 16px !important;
        margin: 0 -16px !important;
        scrollbar-width: none !important;
        border-bottom: 1px solid #e2e8f0 !important;
    }

    .tabs::-webkit-scrollbar {
        display: none !important;
    }

    /* Tab Button - FULL category names visible */
    .tab-btn {
        flex-shrink: 0 !important;
        flex-grow: 0 !important;
        min-width: auto !important;
        padding: 10px 18px !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
        scroll-snap-align: start !important;
        border-radius: 20px !important;
        font-weight: 500 !important;
    }

    .tab-btn.active {
        background: #2563eb !important;
        color: white !important;
    }

    .tab-btn:not(.active) {
        background: #f1f5f9 !important;
        color: #475569 !important;
    }

    /* ====================================
       REPORT ENTRY - Icons Smaller
       ==================================== */
    .report-entry {
        padding: 12px !important;
        margin: 8px 16px !important;
        border-radius: 12px !important;
    }

    /* Edit & Delete Icons - SMALLER SIZE */
    /* Edit & Delete Icons - SMALLER SIZE */
    .report-entry .edit-btn,
    .report-entry .delete-btn,
    .report-entry svg,
    .report-entry .action-icons svg,
    .card .delete-btn svg,
    button svg {
        width: 18px !important;
        height: 18px !important;
        min-width: 18px !important;
        min-height: 18px !important;
    }

    .report-entry .action-icons {
        gap: 12px !important;
    }

    .report-entry .action-icons button {
        padding: 8px !important;
        min-width: 36px !important;
        min-height: 36px !important;
    }

    /* ====================================
       FORM ELEMENTS - Touch Friendly
       ==================================== */
    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        font-size: 16px !important;
        /* Prevents iOS zoom */
        padding: 12px !important;
        min-height: 44px !important;
        border-radius: 8px !important;
    }

    textarea {
        min-height: 120px !important;
    }

    button,
    .btn {
        min-height: 44px !important;
        padding: 12px 20px !important;
        font-size: 0.95rem !important;
        border-radius: 8px !important;
    }

    /* ====================================
       USER MENU - Proper Positioning
       ==================================== */
    .user-menu {
        right: 8px !important;
        top: 56px !important;
        min-width: 200px !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    }

    /* Language Dropdown - CENTERED on Mobile */
    .lang-dropdown {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
        top: 60px !important;
        min-width: 250px !important;
        z-index: 9999 !important;
        text-align: center !important;
    }

    .lang-option {
        text-align: center !important;
        /* Center text inside options */
        padding: 12px !important;
    }

    /* Player & Staff Card Text - Force Wrapping & Prevent Truncation */
    .player-card-name,
    .player-card-position,
    .player-info h4,
    .player-info p,
    .player-card-name span {
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: unset !important;
        line-height: 1.2 !important;
        display: block !important;
        max-width: 100% !important;
        word-break: break-word !important;
    }

    .player-card-info,
    .player-info {
        padding: 8px 4px !important;
        text-align: center !important;
        width: 100% !important;
    }

    /* Refine Swipe Interaction */
    .calendar-grid,
    .calendar-container,
    .reports-section,
    .cards-container,
    #mainPlayerGrid,
    #mainStaffGrid,
    .players-grid {
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        /* Allow both but prioritize horizontal */
        scroll-padding: 0 16px !important;
        overscroll-behavior-x: contain !important;
        /* Prevent page swipe nav */
    }

    /* Player & Staff Card Text - Force Wrapping & Prevent Truncation */
    .player-card-name,
    .player-card-position,
    .player-info h4,
    .player-info p,
    .player-card-name span {
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: unset !important;
        line-height: 1.2 !important;
        display: block !important;
        max-width: 100% !important;
        word-break: break-word !important;
    }

    .player-card-info,
    .player-info {
        padding: 8px 4px !important;
        text-align: center !important;
        width: 100% !important;
    }

    /* Refine Swipe Interaction */
    .calendar-grid,
    .calendar-container,
    .reports-section,
    .cards-container,
    #mainPlayerGrid,
    #mainStaffGrid,
    .players-grid {
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        /* Allow both but prioritize horizontal */
        scroll-padding: 0 16px !important;
    }

    /* ====================================
       UTILITY CLASSES
       ==================================== */
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: block !important;
    }
}

/* Conflict removed: Legacy 480px overrides */

/* ====================================
   LANDSCAPE ORIENTATION
   ==================================== */
@media (max-width: 768px) and (orientation: landscape) {
    .modal-content {
        height: auto !important;
        max-height: 100vh !important;
        overflow-y: auto !important;
    }

    .calendar-day {
        flex: 0 0 140px !important;
    }

    .card {
        flex: 0 0 180px !important;
    }
}

/* ====================================
   PWA STANDALONE MODE
   ==================================== */
@media (display-mode: standalone) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .dashboard-header {
        padding-top: calc(12px + env(safe-area-inset-top)) !important;
    }

    /* Hide browser-specific UI */
    .browser-only {
        display: none !important;
    }
}

/* ====================================
   TOUCH DEVICE OPTIMIZATION
   ==================================== */
@media (hover: none) and (pointer: coarse) {

    /* Larger touch targets */
    a,
    button,
    .clickable {
        min-height: 44px;
        min-width: 44px;
        padding: 12px;
    }

    /* Remove hover effects */
    .card:hover,
    .player-card:hover,
    .calendar-day:hover,
    button:hover {
        transform: none !important;
    }

    /* Active/Tap feedback */
    .card:active,
    .player-card:active,
    .calendar-day:active,
    button:active {
        transform: scale(0.97) !important;
        opacity: 0.85 !important;
        transition: all 0.1s ease !important;
    }

    /* Smooth momentum scrolling */
    .calendar-container,
    .calendar-grid,
    .cards-container,
    .athletes-list>div,
    .staff-list>div,
    .players-grid,
    .tabs {
        scroll-behavior: smooth !important;
    }
}