/* ===================================
   MOBILE FULL-SCREEN MAP LAYOUT
   Inspired by onthegomap.com mobile UX
   =================================== */

/* ===================================
   MOBILE - FULL SCREEN MAP
   =================================== */
@media (max-width: 767.98px) {
    /* Hide header completely on mobile for full-screen map */
    body > header,
    body > .header,
    .navbar,
    nav.navbar {
        display: none !important;
    }
    
    /* Hide top banner ad on mobile for full screen experience */
    #top-banner-ad {
        display: none !important;
    }
    
    /* Hide desktop sidebar completely on mobile */
    #mapSidebar {
        display: none !important;
    }
    
    #desktop-sidebar-toggle {
        display: none !important;
    }
    
    /* Map takes full viewport - no margins, starts at 0,0 */
    #map-section {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important; /* Dynamic viewport height for mobile browsers */
        margin: 0 !important;
        padding: 0 !important;
        transition: none !important; /* Prevent any animations */
    }
    
    #banner {
        width: 100% !important;
        height: 100% !important;
        transition: none !important; /* Prevent any animations */
    }
    
    /* Hide Google Maps fullscreen control on mobile */
    .gm-fullscreen-control {
        display: none !important;
    }
    
    /* Distance display - floating at bottom center, BIGGER and more visible */
    body #distance-display-box,
    #distance-display-box {
        position: fixed !important;
        bottom: 90px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        z-index: 1000 !important;
        background: white !important;
        padding: 12px 28px !important;
        border-radius: 24px !important;
        box-shadow: 0 3px 12px rgba(0,0,0,0.3) !important;
        right: auto !important;
        top: auto !important;
        transition: none !important;
    }
    
    body #distance-display-box .distance-display,
    #distance-display-box .distance-display {
        font-size: 1.8rem !important;
        font-weight: 700 !important;
        margin: 0 !important;
        color: #333 !important;
    }
    
    /* Map tools - TOP RIGHT, just left of hamburger menu */
    body #map-tools,
    #map-tools {
        position: fixed !important;
        top: 10px !important;
        right: 60px !important;
        left: auto !important;
        bottom: auto !important;
        z-index: 1000 !important;
        max-width: none !important;
        width: auto !important;
        transition: none !important;
    }
    
    body #map-tools .map-tools-toggle,
    #map-tools .map-tools-toggle {
        padding: 10px 18px !important;
        font-size: 0.95rem !important;
        border-radius: 8px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.25) !important;
    }
    
    /* Hamburger Menu Button - Far Top Right */
    .mobile-nav-toggle {
        position: fixed !important;
        top: 10px !important;
        right: 10px !important;
        z-index: 1051 !important;
        width: 44px !important;
        height: 44px !important;
        background: white !important;
        border: none !important;
        border-radius: 8px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.25) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
    }
    
    .mobile-nav-toggle i {
        font-size: 1.3rem !important;
        color: #333 !important;
    }
    
    .mobile-nav-toggle:active {
        background: #f0f0f0 !important;
    }
    
    /* Elevation toggle - bottom left, out of the way */
    body #elevation-toggle-btn,
    #elevation-toggle-btn {
        position: fixed !important;
        bottom: 90px !important;
        left: 10px !important;
        right: auto !important;
        top: auto !important;
        z-index: 1000 !important;
        border-radius: 50% !important;
        width: 48px !important;
        height: 48px !important;
        padding: 0 !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.25) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        transition: none !important; /* No animations */
    }
    
    /* Elevation section - slides up from bottom */
    #elevation-section {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 999 !important;
        max-height: 40vh !important;
        padding-bottom: env(safe-area-inset-bottom, 20px) !important;
    }
    
    /* Hide default Google Maps controls on mobile */
    .gm-style .gm-style-mtc {
        display: none !important; /* Hide default map type control */
    }
    
    .gm-bundled-control {
        display: none !important; /* Hide default zoom control */
    }
    
    /* Custom Map Type Dropdown - Top Left */
    .mobile-map-type-control {
        position: fixed !important;
        top: 10px !important;
        left: 10px !important;
        z-index: 1000 !important;
        background: white !important;
        border-radius: 8px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.25) !important;
        overflow: hidden !important;
    }
    
    .mobile-map-type-control select {
        border: none !important;
        padding: 10px 32px 10px 12px !important;
        font-size: 0.95rem !important;
        font-weight: 500 !important;
        background: white !important;
        color: #333 !important;
        cursor: pointer !important;
        appearance: none !important;
        -webkit-appearance: none !important;
        -moz-appearance: none !important;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E") !important;
        background-repeat: no-repeat !important;
        background-position: right 10px center !important;
    }
    
    .mobile-map-type-control select:focus {
        outline: 2px solid #0d6efd !important;
        outline-offset: -2px !important;
    }
    
    /* Mobile Navigation Menu - Slide in from right */
    .mobile-nav-menu {
        position: fixed;
        top: 0;
        right: 0;
        width: 280px;
        height: 100vh;
        background: white;
        box-shadow: -2px 0 8px rgba(0,0,0,0.3);
        z-index: 1052;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        display: flex;
        flex-direction: column;
    }
    
    .mobile-nav-menu.active {
        transform: translateX(0);
    }
    
    .mobile-nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1051;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    
    .mobile-nav-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    .mobile-nav-header {
        padding: 16px;
        border-bottom: 2px solid #60830E;
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: #60830E;
        flex-shrink: 0;
    }
    
    .mobile-nav-header .mobile-nav-logo {
        height: 40px;
        width: auto;
        object-fit: contain;
    }
    
    .mobile-nav-header .btn-close {
        filter: brightness(0) invert(1);
        opacity: 0.9;
    }
    
    .mobile-nav-header .btn-close:hover {
        opacity: 1;
    }
    
    .mobile-nav-content {
        padding: 0;
        flex: 1;
        overflow-y: auto;
    }
    
    .mobile-nav-item {
        list-style: none;
        border-bottom: 1px solid #e9ecef;
    }
    
    .mobile-nav-link {
        display: block;
        padding: 14px 20px;
        color: #333;
        text-decoration: none;
        font-size: 1rem;
        font-weight: 400;
        transition: background 0.2s ease;
    }
    
    .mobile-nav-link:hover,
    .mobile-nav-link.active {
        background: #f8f9fa;
        color: #60830E;
        font-weight: 500;
    }
    
    .mobile-nav-section {
        padding: 12px 20px 8px;
        font-size: 0.75rem;
        font-weight: 700;
        color: white;
        text-transform: uppercase;
        letter-spacing: 0.8px;
        background: #60830E;
        border-bottom: none;
        margin-top: 0;
    }
    
    .mobile-nav-section:first-of-type {
        margin-top: 0;
    }
    
    .mobile-nav-submenu {
        list-style: none;
        padding: 0;
        margin: 0;
        background: white;
    }
    
    .mobile-nav-submenu .mobile-nav-link {
        padding-left: 32px;
        font-size: 0.95rem;
        font-weight: 400;
    }
    
    .mobile-nav-auth {
        padding: 16px;
        border-top: 2px solid #e9ecef;
        background: #f8f9fa;
        flex-shrink: 0;
    }
    
    .mobile-nav-auth .btn {
        width: 100%;
        margin-bottom: 8px;
    }
    
    .mobile-nav-auth .btn-outline-primary {
        border-color: #60830E;
        color: #60830E;
    }
    
    .mobile-nav-auth .btn-outline-primary:hover {
        background: #60830E;
        border-color: #60830E;
        color: white;
    }
    
    .mobile-nav-auth .btn-primary {
        background: #60830E;
        border-color: #60830E;
    }
    
    .mobile-nav-auth .btn-primary:hover {
        background: #57770D;
        border-color: #57770D;
    }
    
    /* Custom Zoom Controls - Bottom Right */
    .mobile-zoom-controls {
        position: fixed !important;
        bottom: 90px !important;
        right: 10px !important;
        z-index: 1000 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 2px !important;
    }
    
    .mobile-zoom-btn {
        width: 44px !important;
        height: 44px !important;
        background: white !important;
        border: none !important;
        border-radius: 8px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.25) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 1.5rem !important;
        font-weight: 600 !important;
        color: #333 !important;
        cursor: pointer !important;
        line-height: 1 !important;
        padding: 0 !important;
    }
    
    .mobile-zoom-btn:active {
        background: #f0f0f0 !important;
    }
}

/* ===================================
   MOBILE CONTROL PANEL OVERLAY
   =================================== */

/* Main toggle button - floating at bottom */
.mobile-control-toggle {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    background: #60830E;
    color: white;
    border: none;
    border-radius: 24px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.mobile-control-toggle:hover {
    background: #57770D;
    transform: translateX(-50%) scale(1.05);
}

.mobile-control-toggle:active {
    transform: translateX(-50%) scale(0.95);
}

/* Hide toggle button when panel is active */
.mobile-control-toggle.hidden {
    display: none !important;
}

/* Control panel overlay */
.mobile-control-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
    z-index: 1050;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.mobile-control-panel.active {
    transform: translateY(0);
}

/* Control panel overlay backdrop */
.mobile-control-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1049;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-control-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Control panel header */
.mobile-control-header {
    padding: 16px 20px 12px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.mobile-control-handle {
    padding: 12px 0 8px;
    cursor: grab;
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}

.mobile-control-handle-bar {
    width: 40px;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
}

.mobile-control-handle:active {
    cursor: grabbing;
}

.mobile-control-header h5 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

/* Control panel content */
.mobile-control-content {
    padding: 12px 16px;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

/* Tighter form spacing for mobile */
.mobile-control-content .mb-2 {
    margin-bottom: 0.75rem !important;
}

.mobile-control-content .form-label {
    margin-bottom: 0.25rem !important;
    font-size: 0.875rem;
}

.mobile-control-content .form-control-sm,
.mobile-control-content .form-select-sm {
    height: calc(1.5em + 0.5rem + 2px);
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

.mobile-control-content textarea.form-control-sm {
    padding: 0.375rem 0.5rem;
}

.mobile-control-content .btn-sm {
    padding: 0.375rem 0.5rem;
    font-size: 0.8125rem;
}

/* Fix Select2 dropdown positioning for Activity field */
.mobile-control-content .select2-container {
    width: 100% !important;
}

.mobile-control-content .select2-container--default .select2-selection--single {
    height: calc(1.5em + 0.5rem + 2px);
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    border: 1px solid #ced4da;
}

.mobile-control-content .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: calc(1.5em + 0.5rem);
    padding-left: 0;
    padding-right: 0;
}

.mobile-control-content .select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #6c757d;
}

.mobile-control-content .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: calc(1.5em + 0.5rem);
    top: 50%;
    transform: translateY(-50%);
}


/* Safe area support */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .mobile-control-content {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
}

/* ===================================
   MOBILE TABS
   =================================== */

.mobile-tabs .nav-tabs {
    border-bottom: 2px solid #dee2e6;
    margin-bottom: 20px;
}

.mobile-tabs .nav-tabs .nav-link {
    font-size: 0.95rem;
    padding: 12px 16px;
    color: #666;
    border: none;
    border-bottom: 3px solid transparent;
    background: none;
}

.mobile-tabs .nav-tabs .nav-link:hover {
    border-bottom-color: #dee2e6;
}

.mobile-tabs .nav-tabs .nav-link.active {
    color: var(--bs-primary);
    border-bottom-color: var(--bs-primary);
    background: none;
    font-weight: 600;
}

.mobile-tabs .nav-tabs .nav-link i {
    font-size: 1.1rem;
    margin-right: 6px;
}

/* ===================================
   MOBILE FORM STYLES
   =================================== */

@media (max-width: 767.98px) {
    /* Sticky auth buttons at top */
    .mobile-auth-buttons {
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
        padding-bottom: 16px;
        margin-bottom: 16px;
        border-bottom: 1px solid #e9ecef;
    }
    
    /* Larger touch targets */
    .mobile-control-content .btn,
    .mobile-control-content .form-control,
    .mobile-control-content .form-select {
        font-size: 1rem;
        padding: 14px;
        min-height: 48px;
    }
    
    .mobile-control-content .btn-group .btn {
        padding: 14px 12px;
    }
    
    .mobile-control-content .input-group .btn {
        padding: 14px 16px;
    }
    
    /* Better spacing */
    .mobile-control-content .mb-3 {
        margin-bottom: 1.75rem !important;
    }
    
    /* Form labels */
    .mobile-control-content .form-label {
        font-size: 1rem;
        font-weight: 600;
        margin-bottom: 8px;
        color: #333;
    }
    
    /* Select2 for mobile */
    .select2-container {
        width: 100% !important;
    }
    
    .select2-container--default .select2-selection--single {
        height: 48px;
        padding: 12px;
        border-radius: 8px;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 24px;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__arrow {
        height: 46px;
    }
    
    /* Number inputs for time */
    input[type="number"] {
        -moz-appearance: textfield;
        text-align: center;
        font-size: 1.1rem;
    }
    
    input[type="number"]::-webkit-inner-spin-button,
    input[type="number"]::-webkit-outer-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }
}

/* ===================================
   TABLET - Keep existing sidebar
   =================================== */
@media (min-width: 768px) {
    .mobile-control-toggle,
    .mobile-control-panel,
    .mobile-control-overlay {
        display: none !important;
    }
}

/* ===================================
   LOADING OVERLAY FIX
   =================================== */
@media (max-width: 767.98px) {
    #Overlay {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 9999 !important;
    }
}

/* ===================================
   PREVENT PAGE ZOOM ON MOBILE MAP
   =================================== */
@media (max-width: 767.98px) {
    html, body {
        touch-action: pan-x pan-y;
        -ms-touch-action: pan-x pan-y;
    }
    
    /* Prevent double-tap zoom */
    #banner, #map-section, .mobile-control-panel {
        touch-action: manipulation;
    }
}

/* ===================================
   MOBILE BOTTOM SHEET FIXES
   Add to mobile-create-route.css
   =================================== */

/* Fix Select2 icon clipping in mobile panel */
.mobile-control-panel .select2-container--default .select2-selection--single {
    height: auto;
    min-height: 32px;
    padding: 4px 8px;
}

.mobile-control-panel .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 1.4;
    padding-left: 0;
    overflow: visible;
}

.mobile-control-panel .select2-container--default .select2-selection--single .select2-selection__rendered img {
    vertical-align: middle;
    margin-right: 6px;
}

/* Compact form controls for mobile - reduce vertical space */
.mobile-control-panel .form-control-sm,
.mobile-control-panel .form-select-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    min-height: 32px;
    height: auto;
}

.mobile-control-panel .form-label {
    margin-bottom: 0.25rem;
    font-size: 0.8rem;
}

.mobile-control-panel .mb-2 {
    margin-bottom: 0.5rem !important;
}

/* Compact input groups */
.mobile-control-panel .input-group-sm > .form-control,
.mobile-control-panel .input-group-sm > .btn {
    padding: 0.25rem 0.5rem;
}

/* Reduce padding in workout section */
.mobile-control-panel #workoutSection-mobile .border {
    padding: 0.5rem !important;
}

.mobile-control-panel #workoutSection-mobile h6 {
    font-size: 0.85rem;
    margin-bottom: 0.5rem !important;
}

/* Compact time inputs */
.mobile-control-panel .row.g-1 > div {
    padding-left: 2px;
    padding-right: 2px;
}

/* Textarea compact */
.mobile-control-panel textarea.form-control-sm {
    min-height: 50px;
}

/* Log as Workout toggle bar - more compact */
.mobile-control-panel .bg-primary.p-2 {
    padding: 0.4rem 0.5rem !important;
}

/* Select2 dropdown in mobile panel - ensure icons show */
.select2-container--open .select2-dropdown {
    z-index: 1060;
}

.select2-results__option img {
    vertical-align: middle;
    margin-right: 6px;
}

/* ===================================
   MAP TOOLS PANEL FIXES
   =================================== */

/* Prevent scrolling in tools panel - make it fit content */
#map-tools .map-tools-body {
    max-height: none !important;
    overflow: visible !important;
}

#map-tools .card-body {
    padding: 0.5rem !important;
}

/* Fix clickable area - only cover the actual content, not empty space */
@media (min-width: 768px) {
    #map-tools {
        width: auto !important;
        max-width: none !important;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        pointer-events: none; /* Allow clicks through the container */
    }
    
    #map-tools > * {
        pointer-events: auto; /* But not through the actual content */
    }
    
    #map-tools .map-tools-body {
        width: 240px;
    }
}

/* Compact all controls in tools panel */
#map-tools .control-group {
    margin-bottom: 0.4rem !important;
}

#map-tools .mb-2 {
    margin-bottom: 0.4rem !important;
}

#map-tools hr.my-2 {
    margin-top: 0.4rem !important;
    margin-bottom: 0.4rem !important;
}

/* Make search input same height as other controls */
#map-tools .input-group-sm > .form-control,
#map-tools .input-group-sm > .btn {
    padding: 0.2rem 0.4rem;
    font-size: 0.8rem;
    height: 28px;
}

#map-tools .form-select-sm {
    padding: 0.2rem 0.4rem;
    font-size: 0.8rem;
    height: 28px;
}

/* Compact labels */
#map-tools .map-tools-label {
    font-size: 0.75rem !important;
    margin-bottom: 0.2rem !important;
}

/* Compact buttons */
#map-tools .map-tools-btn {
    padding: 0.2rem 0.3rem;
    font-size: 0.7rem;
}

#map-tools .buttons .row.g-1 {
    --bs-gutter-x: 0.25rem;
    --bs-gutter-y: 0.25rem;
}

/* Compact switches */
#map-tools .form-check {
    margin-bottom: 0.2rem;
    min-height: 1.2rem;
}

#map-tools .form-check-label {
    font-size: 0.75rem;
}

/* Travel mode buttons compact */
#map-tools .map-tools-mode-btn {
    padding: 0.2rem 0.4rem;
    font-size: 0.75rem;
}
