/**
 * Mobile-First CSS Stylesheet
 *
 * Provides mobile-optimized styles for touch-friendly interfaces.
 * Includes utility classes, touch targets, and responsive enhancements.
 */

/* ============================================
   Mobile Base Styles
   ============================================ */

/* Prevent iOS zoom on input focus */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="password"],
input[type="date"],
select,
textarea {
    font-size: 16px !important;
}

/* Touch-friendly tap targets */
.touch-target,
button,
.btn,
a.btn,
.nav-link,
.card-link {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
}

/* Remove hover effects on touch devices */
@media (hover: none) {
    .btn:hover,
    .card:hover,
    a:hover {
        transform: none;
    }
}

/* Clear active/pressed states for touch */
.btn:active,
button:active,
a:active {
    opacity: 0.7;
    transform: scale(0.98);
}

/* ============================================
   Safe Area Insets (iOS Notch Support)
   ============================================ */

@supports (padding: env(safe-area-inset-top)) {
    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);
    }
}

/* ============================================
   Utility Classes
   ============================================ */

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

@media (min-width: 768px) {
    .mobile-only {
        display: none !important;
    }
}

/* Hide on mobile */
.desktop-only {
    display: none !important;
}

@media (min-width: 768px) {
    .desktop-only {
        display: block !important;
    }
}

/* Mobile scroll optimization */
.mobile-scroll {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

/* Prevent double-tap zoom */
.no-zoom {
    touch-action: manipulation;
}

/* ============================================
   Mobile Typography
   ============================================ */

@media (max-width: 767px) {
    body {
        font-size: 16px;
        line-height: 1.5;
    }

    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    h4 {
        font-size: 1.1rem;
    }

    h5, h6 {
        font-size: 1rem;
    }

    /* Improve readability */
    p, li {
        font-size: 1rem;
        line-height: 1.6;
    }
}

/* ============================================
   Mobile Spacing
   ============================================ */

@media (max-width: 767px) {
    .container,
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .card {
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    /* Reduce spacing between elements */
    .mb-4 {
        margin-bottom: 1.5rem !important;
    }

    .mb-5 {
        margin-bottom: 2rem !important;
    }

    /* Optimize padding */
    .py-5 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }
}

/* ============================================
   Mobile Navigation
   ============================================ */

@media (max-width: 991px) {
    /* Hamburger menu button */
    .navbar-toggler {
        border: none;
        padding: 0.5rem;
        min-width: 44px;
        min-height: 44px;
    }

    .navbar-toggler:focus {
        box-shadow: none;
    }

    /* Mobile nav overlay */
    .navbar-collapse {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        max-width: 300px;
        height: 100vh;
        background-color: white;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        transition: left 0.3s ease;
        z-index: 1050;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .navbar-collapse.show {
        left: 0;
    }

    /* Backdrop overlay */
    .navbar-collapse.show::before {
        content: "";
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }

    /* Mobile nav items */
    .navbar-nav {
        padding: 1rem;
    }

    .nav-link {
        padding: 0.75rem 1rem;
        min-height: 44px;
        display: flex;
        align-items: center;
        border-radius: 0.25rem;
        margin-bottom: 0.5rem;
    }

    .nav-link:active {
        background-color: rgba(0, 123, 255, 0.1);
    }
}

/* ============================================
   Mobile Buttons
   ============================================ */

@media (max-width: 767px) {
    /* Full-width buttons on mobile */
    .btn-block-mobile {
        display: block;
        width: 100%;
    }

    /* Button groups stack vertically */
    .btn-group {
        flex-direction: column;
    }

    .btn-group > .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Larger touch targets */
    .btn {
        min-height: 48px;
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
    }

    .btn-sm {
        min-height: 44px;
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
}

/* ============================================
   Mobile Cards
   ============================================ */

@media (max-width: 767px) {
    .card {
        border-radius: 8px;
        overflow: hidden;
    }

    .card-header {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card-footer {
        padding: 0.75rem 1rem;
    }

    /* Swipeable cards */
    .card-swipeable {
        position: relative;
        transition: transform 0.2s ease;
    }

    .card-swipeable:active {
        transform: scale(0.98);
    }
}

/* ============================================
   Mobile Modals
   ============================================ */

@media (max-width: 767px) {
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100vh;
    }

    .modal-content {
        min-height: 100vh;
        border-radius: 0;
    }

    .modal-header {
        padding: 1rem;
        min-height: 60px;
    }

    .modal-body {
        padding: 1rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer {
        padding: 1rem;
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 0.25rem 0;
    }
}

/* ============================================
   Mobile Tables (Basic Enhancement)
   ============================================ */

@media (max-width: 767px) {
    .table-responsive {
        border: none;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table {
        font-size: 0.875rem;
    }

    .table th,
    .table td {
        padding: 0.5rem;
        white-space: nowrap;
    }
}

/* ============================================
   Mobile Pull-to-Refresh Indicator
   ============================================ */

.pull-to-refresh-indicator {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: top 0.3s ease;
    z-index: 1000;
}

/* ============================================
   Mobile Performance Optimizations
   ============================================ */

/* Reduce animations on mobile */
@media (max-width: 767px) {
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
}

/* Optimize scroll performance */
.mobile-scroll-optimized {
    will-change: transform;
    transform: translateZ(0);
}

/* ============================================
   Mobile Color Contrast (Outdoor Viewing)
   ============================================ */

@media (max-width: 767px) {
    /* Increase contrast for better outdoor readability */
    .text-muted {
        color: #5a5a5a !important;
    }

    .text-secondary {
        color: #495057 !important;
    }

    /* Make links more visible */
    a {
        text-decoration: underline;
    }

    .btn-link {
        text-decoration: underline;
    }
}

/* ============================================
   Mobile Accessibility
   ============================================ */

/* Larger focus outlines for touch */
@media (max-width: 767px) {
    *:focus,
    *:focus-visible {
        outline: 3px solid rgba(0, 123, 255, 0.5);
        outline-offset: 2px;
    }

    /* Skip links for screen readers */
    .skip-link {
        position: absolute;
        top: -40px;
        left: 0;
        background: #000;
        color: #fff;
        padding: 8px;
        text-decoration: none;
        z-index: 9999;
    }

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

/* ============================================
   Mobile Landscape Optimizations
   ============================================ */

@media (max-width: 767px) and (orientation: landscape) {
    /* Reduce vertical spacing in landscape */
    body {
        padding-top: 48px;
    }

    .card {
        margin-bottom: 0.75rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }
}

/* ============================================
   WebSocket Connection Indicator
   ============================================ */

.ws-status-indicator {
    position: fixed;
    top: 60px;
    right: 10px;
    z-index: 1040;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    font-size: 0.875rem;
    transition: all 0.3s ease;
}

.ws-status-indicator .status-icon {
    font-size: 0.75rem;
    line-height: 1;
}

.ws-status-indicator .status-text {
    font-weight: 500;
}

/* Connection state colors */
.ws-status-indicator.ws-connecting .status-icon {
    color: #FFA500;
    animation: pulse 1.5s ease-in-out infinite;
}

.ws-status-indicator.ws-connected .status-icon {
    color: #28A745;
}

.ws-status-indicator.ws-disconnected .status-icon {
    color: #DC3545;
}

.ws-status-indicator.ws-reconnecting .status-icon {
    color: #FFA500;
    animation: pulse 1s ease-in-out infinite;
}

.ws-status-indicator.ws-failed .status-icon {
    color: #DC3545;
}

/* ============================================
   Live Updates Animations
   ============================================ */

/* Flash animation for updated elements */
@keyframes flash-up {
    0% { background-color: transparent; }
    50% { background-color: rgba(40, 167, 69, 0.3); }
    100% { background-color: transparent; }
}

@keyframes flash-down {
    0% { background-color: transparent; }
    50% { background-color: rgba(220, 53, 69, 0.3); }
    100% { background-color: transparent; }
}

@keyframes flash-same {
    0% { background-color: transparent; }
    50% { background-color: rgba(0, 123, 255, 0.2); }
    100% { background-color: transparent; }
}

.flash-up {
    animation: flash-up 1s ease-in-out;
}

.flash-down {
    animation: flash-down 1s ease-in-out;
}

.flash-same {
    animation: flash-same 1s ease-in-out;
}

.flash-update {
    animation: flash-same 1s ease-in-out;
}

/* ============================================
   Change Indicators
   ============================================ */

.change-indicator {
    display: inline-block;
    margin-left: 0.5rem;
    font-size: 1rem;
    font-weight: bold;
    animation: fade-in 0.3s ease-in;
}

.change-indicator.change-up {
    color: #28A745;
}

.change-indicator.change-down {
    color: #DC3545;
}

@keyframes fade-in {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* ============================================
   LIVE Badge Indicator
   ============================================ */

.live-indicator {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: bold;
    color: white;
    background-color: #DC3545;
    border-radius: 4px;
    margin-left: 0.5rem;
}

.live-indicator.pulsing {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* ============================================
   Hole Winner Indicators
   ============================================ */

.hole-winner-indicator {
    display: inline-block;
    margin-left: 0.5rem;
    font-size: 1rem;
}

.hole-winner-indicator.winner-team1 {
    color: #28A745;
}

.hole-winner-indicator.winner-team2 {
    color: #007BFF;
}

.hole-winner-indicator.winner-halved {
    color: #6C757D;
}

/* ============================================
   Mobile-Specific WebSocket Styles
   ============================================ */

@media (max-width: 767px) {
    .ws-status-indicator {
        top: 10px;
        right: 10px;
        font-size: 0.75rem;
        padding: 0.375rem 0.75rem;
    }

    .live-indicator {
        font-size: 0.625rem;
        padding: 0.2rem 0.4rem;
    }

    .change-indicator {
        font-size: 0.875rem;
    }
}

/* ============================================
   Collapsible Info Block
   ============================================ */

/* Base info block styles */
.info-block {
    background-color: rgb(200, 240, 250);
    border-radius: 8px;
    padding: 0;
    margin-bottom: 1rem;
    overflow: hidden;
}

.info-block-header {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
}

.info-block-title {
    flex: 1;
    font-weight: bold;
    font-size: 1rem;
}

.info-block-header i.fa-info-circle {
    color: #0c5460;
    font-size: 1.1rem;
}

.info-block-content {
    padding: 0 1rem 0.75rem 1rem;
}

/* Toggle button - hidden by default (desktop), shown on mobile */
.info-block-toggle {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: #0c5460;
    min-height: 44px;
    min-width: 44px;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
    /* Hidden by default - will be shown on mobile below */
    display: none !important;
}

.info-block-toggle i {
    font-size: 1rem;
    transition: transform 0.3s ease;
}

/* Desktop: Always expanded, content visible, hide toggle button */
@media (min-width: 768px) {
    /* Explicitly hide toggle button on desktop - higher specificity to override button rule */
    button.info-block-toggle,
    .info-block-toggle {
        display: none !important;
        visibility: hidden !important;
    }

    .info-block-content {
        max-height: none !important;
        overflow: visible !important;
        padding: 0 1rem 0.75rem 1rem !important;
        display: block !important;
    }

    .info-block {
        display: block !important;
    }
}

/* Mobile: Collapsible by default */
@media (max-width: 767px) {
    /* Show toggle button on mobile */
    .info-block-toggle {
        display: flex !important;
    }

    .info-block-toggle:hover {
        background-color: rgba(0, 0, 0, 0.05);
        border-radius: 4px;
    }

    .info-block-content {
        max-height: 0;
        overflow: hidden;
        padding: 0 1rem;
        transition: max-height 0.3s ease, padding 0.3s ease;
    }

    .info-block.expanded .info-block-content {
        max-height: 500px;
        padding: 0 1rem 0.75rem 1rem;
    }

    .info-block.expanded .info-block-toggle i {
        transform: rotate(180deg);
    }

    /* Ensure legend displays properly inside info block on mobile */
    .info-block .legend {
        display: flex;
        gap: 0.75rem;
        flex-wrap: wrap;
        margin-bottom: 0;
    }

    .info-block .legend-item {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        font-size: 0.9rem;
    }

    .info-block .legend-color {
        width: 16px;
        height: 16px;
        border-radius: 3px;
        flex-shrink: 0;
    }
}

/* ============================================
   Horizontal Scrollable Tabs (Mobile)
   ============================================ */

/* Container for horizontally scrollable tabs on mobile */
.nav-tabs-mobile-scroll {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.nav-tabs-mobile-scroll::-webkit-scrollbar {
    display: none;
}

/* Mobile tab navigation styling */
@media (max-width: 767px) {
    .nav-tabs-mobile-scroll {
        flex-wrap: nowrap;
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        /* Add slight padding to show scroll is available */
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }

    .nav-tabs-mobile-scroll .nav-link {
        min-width: 44px;
        min-height: 44px;
        padding: 12px 16px;
        white-space: nowrap;
        flex-shrink: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 0;
        margin-right: 0;
        border-bottom: 3px solid transparent;
        transition: all 0.2s ease;
    }

    /* Enhanced active tab styling for mobile */
    .nav-tabs-mobile-scroll .nav-link.active {
        border-bottom: 3px solid #0d6efd;
        background-color: rgba(13, 110, 253, 0.1);
        font-weight: 600;
    }

    /* Improve contrast for outdoor viewing */
    .nav-tabs-mobile-scroll .nav-link {
        color: #212529;
        background-color: #f8f9fa;
    }

    .nav-tabs-mobile-scroll .nav-link:hover {
        background-color: #e9ecef;
    }

    /* Icon spacing in mobile tabs */
    .nav-tabs-mobile-scroll .nav-link i {
        margin-right: 0.25rem;
        font-size: 0.875rem;
    }
}

/* Desktop: No special scrolling needed */
@media (min-width: 768px) {
    .nav-tabs-mobile-scroll {
        overflow-x: visible;
        flex-wrap: wrap;
    }
}
