/* Mobile-First Bootstrap Enhancements for LottoMuse */

/* =================================================================
   MOBILE-FIRST RESPONSIVE ENHANCEMENTS
   ================================================================= */

/* Enhanced Mobile Navigation */
@media (max-width: 767.98px) {
    .navbar-brand {
        font-size: 1.1rem !important;
        letter-spacing: 0.5px !important;
    }
    
    .navbar-nav .nav-link {
        padding: 0.75rem 1rem !important;
        border-radius: 0.5rem !important;
        margin: 0.25rem 0 !important;
    }
    
    .navbar-collapse {
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid rgba(255, 255, 255, 0.2);
    }
}

/* Reduce body-bottom padding for chat pages as those pages have their own
   scrollable container and fixed footer handling. This avoids duplicate
   padding that can produce the white gap below content. */
body.chat-page {
    padding-bottom: 0 !important;
}

/* On mobile, lock body height and hide the site footer so the chat fills 100vh */
@media (max-width: 767.98px) {
    body.chat-page {
        height: 100vh !important;
        overflow: hidden !important;
        min-height: 0 !important;
    }
    body.chat-page .site-footer {
        display: none !important;
    }
}


/* Mobile-Optimized Form Controls */
@media (max-width: 767.98px) {
    .form-control,
    .form-select {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 0.75rem 1rem !important;
        border-radius: 0.5rem !important;
    }
    
    .btn {
        padding: 0.75rem 1.5rem !important;
        font-size: 1rem !important;
        min-height: 44px; /* Touch-friendly minimum */
    }
    
    .btn-sm {
        padding: 0.5rem 1rem !important;
        font-size: 0.875rem !important;
        min-height: 38px;
    }
}

/* Enhanced Card Responsiveness */
@media (max-width: 575.98px) {
    .card {
        border-radius: 1rem !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    }
    
    .card-body {
        padding: 1.25rem !important;
    }
    
    .card-header {
        padding: 1rem 1.25rem !important;
        border-radius: 1rem 1rem 0 0 !important;
    }
}

/* Mobile-Friendly Tables */
@media (max-width: 767.98px) {
    .table-responsive {
        border-radius: 0.75rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table td,
    .table th {
        padding: 0.75rem 0.5rem !important;
        font-size: 0.875rem !important;
        vertical-align: middle !important;
    }
    
    .table .btn {
        font-size: 0.75rem !important;
        padding: 0.375rem 0.75rem !important;
        min-height: auto !important;
    }
}

/* Enhanced Modal Responsiveness */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
    }
    
    .modal-content {
        border-radius: 1rem !important;
    }
    
    .modal-header,
    .modal-footer {
        padding: 1rem !important;
    }
    
    .modal-body {
        padding: 1.25rem !important;
    }
}

/* Mobile-Optimized Typography */
@media (max-width: 767.98px) {
    h1, .h1 {
        font-size: 2rem !important;
        line-height: 1.2 !important;
        margin-bottom: 1rem !important;
    }
    
    h2, .h2 {
        font-size: 1.75rem !important;
        line-height: 1.3 !important;
        margin-bottom: 0.875rem !important;
    }
    
    h3, .h3 {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
        margin-bottom: 0.75rem !important;
    }
    
    .lead {
        font-size: 1.125rem !important;
        line-height: 1.5 !important;
    }
}

/* Enhanced Button Spacing for Touch */
@media (max-width: 767.98px) {
    .btn + .btn {
        margin-left: 0 !important;
        margin-top: 0.5rem !important;
    }
    
    .btn-group-vertical .btn {
        margin-top: 0 !important;
    }
    
    .d-grid .btn + .btn {
        margin-top: 0.75rem !important;
    }
}

/* Mobile-Friendly Form Groups */
@media (max-width: 767.98px) {
    .row.g-3 {
        --bs-gutter-x: 1rem !important;
        --bs-gutter-y: 1rem !important;
    }
    
    .mb-3 {
        margin-bottom: 1.25rem !important;
    }
    
    .form-floating > label {
        padding: 1rem !important;
    }
}

/* Enhanced Alert Responsiveness */
@media (max-width: 767.98px) {
    .alert {
        border-radius: 0.75rem !important;
        padding: 1rem !important;
        font-size: 0.9rem !important;
    }
    
    .alert-dismissible .btn-close {
        padding: 1rem !important;
    }
}

/* Mobile-Optimized Navigation Pills/Tabs */
@media (max-width: 767.98px) {
    .nav-pills .nav-link,
    .nav-tabs .nav-link {
        padding: 0.75rem 1rem !important;
        font-size: 0.9rem !important;
        white-space: nowrap !important;
    }
    
    .nav-pills,
    .nav-tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
    }
    
    .nav-pills::-webkit-scrollbar,
    .nav-tabs::-webkit-scrollbar {
        display: none !important;
    }
}

/* Touch-Friendly Pagination */
@media (max-width: 767.98px) {
    .pagination .page-link {
        padding: 0.75rem 1rem !important;
        font-size: 0.9rem !important;
        min-width: 44px !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}

/* Mobile-Optimized Dropdowns */
@media (max-width: 767.98px) {
    .dropdown-menu {
        border-radius: 0.75rem !important;
        padding: 0.5rem !important;
        min-width: 200px !important;
    }
    
    .dropdown-item {
        padding: 0.75rem 1rem !important;
        border-radius: 0.5rem !important;
        font-size: 0.9rem !important;
    }
}

/* Enhanced Spacing for Mobile */
@media (max-width: 575.98px) {
    .container-fluid {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    .py-5 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }
    
    .py-4 {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }
}

/* Safe-area inset support — landscape mobile (notch/Dynamic Island on left/right side)
   viewport-fit=cover is set in _Layout.cshtml, so we must compensate with env() padding.
   max() ensures at least 0.75rem even on non-notched devices.
   Excludes .chat-page because that page manages its own overflow/layout independently. */
@supports (padding: max(0px)) {
    @media (orientation: landscape) and (max-width: 991.98px) {
        body:not(.chat-page) .container-fluid {
            padding-left: max(0.75rem, env(safe-area-inset-left)) !important;
            padding-right: max(0.75rem, env(safe-area-inset-right)) !important;
        }
    }
}

/* Mobile-Specific Utilities */
@media (max-width: 767.98px) {
    .mobile-stack > * + * {
        margin-top: 1rem !important;
    }
    
    .mobile-center {
        text-align: center !important;
    }
    
    .mobile-full-width {
        width: 100% !important;
    }
}

/* Enhanced Focus States for Mobile */
@media (max-width: 767.98px) {
    .form-control:focus,
    .form-select:focus,
    .btn:focus {
        box-shadow: 0 0 0 0.25rem rgba(91, 62, 144, 0.25) !important;
        border-color: #5B3E90 !important;
    }
}

/* Safe Area Support for Modern Mobile Devices */
@supports (env(safe-area-inset-bottom)) {
    @media (max-width: 767.98px) {
        .pb-3,
        .py-3 {
            padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
        }
        
        .mb-3 {
            margin-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
        }
    }
}

/* Improved Accessibility for Mobile */
@media (max-width: 767.98px) {
    .sr-only-mobile {
        position: absolute !important;
        width: 1px !important;
        height: 1px !important;
        padding: 0 !important;
        margin: -1px !important;
        overflow: hidden !important;
        clip: rect(0, 0, 0, 0) !important;
        white-space: nowrap !important;
        border: 0 !important;
    }

    .show-mobile {
        display: block !important;
    }

    .hide-mobile {
        display: none !important;
    }
}

/* My Numbers - Mobile quick-view foundation + gas-station mode */
@media (max-width: 991.98px) {
    .my-numbers-mode-switch {
        border: 1px solid #d7dee7;
        border-radius: 0.6rem;
        padding: 0.65rem;
        background: #f8f9fa;
    }

    .my-numbers-mode-switch legend {
        font-size: 0.8rem;
        color: #495057;
    }

    .my-numbers-mode-switch .btn {
        min-height: 44px;
        font-weight: 600;
    }

    .my-numbers-mode-switch .btn-check:focus-visible + .btn {
        outline: 3px solid #f7d046;
        outline-offset: 2px;
    }

    .my-numbers-quick-list {
        border-top: 1px solid #e9ecef;
        /* Bring content closer to screen edges by reducing horizontal padding from .p-2 (0.5rem) */
        padding-left: 0.25rem !important;
        padding-right: 0.25rem !important;
        /* Reduce horizontal gutters slightly to compensate for less edge space */
        --bs-gutter-x: 0.5rem;
    }

    .my-numbers-quick-item {
        padding: 1rem;
        border-bottom: 1px solid #e9ecef;
        background: #fff;
    }

    .my-numbers-quick-item:last-child {
        border-bottom: 0;
    }

    .my-numbers-quick-row {
        display: grid;
        grid-template-columns: 88px 1fr;
        gap: 0.5rem;
        align-items: start;
        margin-bottom: 0.5rem;
    }

    .my-numbers-quick-row:last-child {
        margin-bottom: 0;
    }

    .my-numbers-quick-label {
        margin: 0;
        font-size: 0.75rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: #6c757d;
    }

    .my-numbers-quick-value {
        min-width: 0;
        font-size: 0.9rem;
    }

    .my-numbers-quick-item .number-badges {
        flex-wrap: wrap;
        row-gap: 0.35rem;
    }

    .my-numbers-quick-list.gas-station-mode {
        border-top: 2px solid #212529;
        background: #000;
    }

    .my-numbers-quick-list.gas-station-mode .my-numbers-quick-item {
        background: #000;
        color: #fff;
        border-bottom: 2px solid #2d2d2d;
    }

    .my-numbers-quick-list.gas-station-mode .my-numbers-quick-label {
        color: #ffe066;
        letter-spacing: 0.05em;
    }

    .my-numbers-quick-list.gas-station-mode .my-numbers-quick-value {
        color: #fff;
        font-size: 1rem;
        font-weight: 600;
    }

    .my-numbers-quick-list.gas-station-mode .number-badges {
        column-gap: 0.45rem;
        row-gap: 0.45rem;
    }

    .my-numbers-quick-list.gas-station-mode .number-badges .badge {
        min-width: 2.15rem;
        width: 2.15rem;
        height: 2.15rem;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        font-size: 1.1rem;
        font-weight: 800;
        line-height: 1;
        text-align: center;
        border: 2px solid #fff;
    }

    .my-numbers-quick-list.gas-station-mode .number-badges .badge.bg-primary,
    .my-numbers-quick-list.gas-station-mode .number-badges .badge.ball-main-neutral {
        background: #e6e6e6 !important; /* Neutral high-contrast */
        color: #000 !important;
        border-color: #e6e6e6 !important;
    }

    .my-numbers-quick-list.gas-station-mode .number-badges .badge.bg-dark,
    .my-numbers-quick-list.gas-station-mode .number-badges .badge.ball-bonus-neutral {
        background: #333 !important;
        color: #fff !important;
        border-color: #999 !important;
    }

    .my-numbers-quick-list.gas-station-mode .number-badges .badge.ball-main-matched {
        background: #00e676 !important;
        color: #000 !important;
        border-width: 3px !important;
        border-color: #fff !important; /* Non-color indicator */
    }

    .my-numbers-quick-list.gas-station-mode .number-badges .badge.ball-bonus-matched {
        background: #ffeb3b !important;
        color: #000 !important;
        border-width: 3px !important;
        border-style: dashed !important;
        border-color: #fff !important;
    }

    /* Gas-station mode: bonus-ball must remain visually distinct (gold), never black */
    .my-numbers-quick-list.gas-station-mode .number-badges .badge.bonus-ball {
        background: radial-gradient(circle at 35% 30%, #fff7c2 0%, #ffd84d 50%, #d99e00 100%) !important;
        color: #000 !important;
        border: 3px solid #fff !important;
        box-shadow:
            0 0 0 3px #c98a00,
            inset 0 -1px 2px rgba(0, 0, 0, 0.3),
            inset 0 1px 2px rgba(255, 255, 255, 0.6) !important;
        font-weight: 900 !important;
    }

    .my-numbers-quick-list.gas-station-mode .number-badges .badge.bonus-ball.ball-bonus-matched {
        background: radial-gradient(circle at 35% 30%, #fffbcc 0%, #ffe14d 50%, #b87800 100%) !important;
        border-style: dashed !important;
        border-color: #fff !important;
    }

    .my-numbers-quick-list.gas-station-mode .badge.bg-success,
    .my-numbers-quick-list.gas-station-mode .badge.bg-secondary,
    .my-numbers-quick-list.gas-station-mode .badge.bg-warning {
        font-weight: 700;
    }

    .my-numbers-quick-list.gas-station-mode .topic-link {
        color: #9ad0ff !important;
        text-decoration: underline;
    }

    .my-numbers-quick-list.gas-station-mode .delete-saved-number-btn {
        color: #ffb3b3 !important;
        border-color: #ff7a7a;
    }

    .my-numbers-quick-list.gas-station-mode .delete-saved-number-btn:focus-visible {
        outline: 3px solid #ffe066;
        outline-offset: 2px;
    }
}

/* iPhone landscape: 2-column card layout (sm ≥576px, within quick-view lg range) */
@media (min-width: 576px) and (max-width: 991.98px) {
    .my-numbers-quick-list {
        border-top: 0;
        /* Reduce horizontal padding to bring items closer to the edge, matching portrait updates */
        padding: 0.5rem 0.25rem !important;
    }

    .my-numbers-quick-item {
        border: 1px solid #e9ecef;
        border-radius: 0.375rem;
        display: flex;
        flex-direction: column;
        height: auto;
    }

    .my-numbers-quick-item:last-child {
        border-bottom: 1px solid #e9ecef;
    }

    .my-numbers-quick-list.gas-station-mode {
        border-top: 0;
    }

    .my-numbers-quick-list.gas-station-mode .my-numbers-quick-item {
        border-color: #2d2d2d;
    }
}

/* ==========================================
   Fix: Use dynamic viewport height for mobile
   Avoids 100vh address-bar issue that creates
   white space under scrollable content on mobile
   ========================================== */
@media (max-width: 991px) {
    /* Fallback variable so older browsers still get a working unit */
    :root { --vh: 1vh; }

    /* Preferred modern unit (dynamic viewport height) */
    @supports (height: 100dvh) {
        .app-container,
        .chatgpt-sidebar {
            height: 100dvh !important;
            min-height: 100dvh !important;
            max-height: 100dvh !important;
        }
        
        body.chat-page .chatgpt-container {
            height: 100% !important;
            min-height: 0 !important;
            max-height: none !important;
        }
    }

    /* Fallback for browsers without support for 100dvh: use --vh set by JS */
    @supports not (height: 100dvh) {
        .app-container,
        .chatgpt-sidebar {
            height: calc(var(--vh, 1vh) * 100) !important;
            min-height: calc(var(--vh, 1vh) * 100) !important;
            max-height: calc(var(--vh, 1vh) * 100) !important;
        }
        
        body.chat-page .chatgpt-container {
            height: 100% !important;
            min-height: 0 !important;
            max-height: none !important;
        }
    }

    /* Chat pages use a fixed bottom nav, so reserve that height to keep the
       entire input card visible (textarea + hint + suggestion buttons). */
    body.chat-page .chat-container {
        height: calc(100% - var(--bottom-nav-height) - env(safe-area-inset-bottom, 0px)) !important;
        min-height: 0 !important;
        max-height: none !important;
    }
}

