/* ===========================================
   BETA MUD MAP - Mobile-First CSS
   Google Maps-inspired design system
   =========================================== */

:root {
    /* Colors */
    --bg-dark: #0f172a;
    --bg-card: rgba(15, 23, 42, 0.95);
    --bg-glass: rgba(15, 23, 42, 0.85);
    --primary: #f97316;
    --primary-glow: rgba(249, 115, 22, 0.3);
    --success: #16a34a;
    --warning: #eab308;
    --danger: #dc2626;
    --info: #3b82f6;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --glass-border: rgba(255, 255, 255, 0.1);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

    /* Spacing */
    --header-height: 56px;
    --bottom-nav-height: 64px;
    --bottom-sheet-collapsed: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-main);
}

/* ===========================================
   HEADER - Full Site Navbar
   =========================================== */
.mud-map-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    z-index: 1000;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    height: 100%;
    padding: 0 20px;
}

.header-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-main);
}

.logo img {
    border-radius: 6px;
}

.logo span {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.4rem;
}

.nav-links {
    display: flex;
    gap: 28px;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: color 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--primary);
}

.nav-buttons {
    display: flex;
    gap: 10px;
}

.btn-nav {
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-nav.btn-outline {
    color: var(--text-main);
    background: transparent;
    border: 1px solid var(--glass-border);
}

.btn-nav.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-muted);
}

.btn-nav.btn-primary {
    color: white;
    background: var(--primary);
    border: 1px solid var(--primary);
}

.btn-nav.btn-primary:hover {
    background: #ea580c;
    border-color: #ea580c;
}

/* Mobile header adjustments */
@media (max-width: 768px) {
    .nav-links {
        display: none;
    }

    .logo span {
        font-size: 1.2rem;
    }

    .btn-nav {
        padding: 6px 14px;
        font-size: 0.85rem;
    }

    .btn-nav.btn-outline {
        display: none;
    }
}

/* Legacy beta header support */
.beta-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
}

.beta-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-main);
    font-weight: 600;
    font-size: 1.1rem;
}

.beta-logo img {
    border-radius: 6px;
}

.beta-badge {
    background: var(--primary);
    color: white;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.beta-header-actions {
    display: flex;
    gap: 8px;
}

.btn-header {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    transition: all 0.2s;
}

.btn-header:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-header.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

/* ===========================================
   MAP - Full Screen
   =========================================== */
.beta-map {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
    z-index: 1;
}

/* Leaflet overrides */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow) !important;
    margin-left: 12px !important;
    margin-top: 70px !important;
    /* Clear the search bar */
    margin-bottom: 80px !important;
}

.leaflet-control-zoom a {
    background: var(--bg-card) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--glass-border) !important;
    width: 40px !important;
    height: 40px !important;
    line-height: 40px !important;
    font-size: 18px !important;
}

.leaflet-control-zoom-in {
    border-radius: 10px 10px 0 0 !important;
}

.leaflet-control-zoom-out {
    border-radius: 0 0 10px 10px !important;
}

.leaflet-control-attribution {
    display: none;
}

/* ===========================================
   SEARCH BAR - Floating
   =========================================== */
.search-container {
    position: fixed;
    top: calc(var(--header-height) + 12px);
    left: 12px;
    right: 12px;
    z-index: 900;
}

.search-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    color: var(--text-muted);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.search-trigger:hover,
.search-trigger:focus {
    border-color: var(--primary);
    background: rgba(15, 23, 42, 0.98);
}

.search-input-wrapper {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--primary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg), 0 0 0 3px var(--primary-glow);
    overflow: hidden;
}

.search-input-wrapper.hidden {
    display: none;
}

.search-input-wrapper input {
    width: 100%;
    padding: 16px;
    padding-right: 48px;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1rem;
    outline: none;
}

.search-input-wrapper input::placeholder {
    color: var(--text-muted);
}

.search-close {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 8px;
}

.search-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.search-results {
    list-style: none;
    max-height: 200px;
    overflow-y: auto;
    border-top: 1px solid var(--glass-border);
}

.search-results li {
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-results li:hover {
    background: rgba(255, 255, 255, 0.05);
}

.search-results li svg {
    flex-shrink: 0;
    color: var(--text-muted);
}

/* ===========================================
   FAB STACK - Floating Action Buttons
   =========================================== */
.fab-stack {
    position: fixed;
    right: 12px;
    bottom: calc(var(--bottom-nav-height) + var(--bottom-sheet-collapsed) + var(--safe-bottom) + 20px);
    z-index: 800;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.fab {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: all 0.2s;
}

.fab:hover {
    background: rgba(249, 115, 22, 0.2);
    border-color: var(--primary);
    transform: scale(1.05);
}

.fab:active {
    transform: scale(0.95);
}

.fab.loading {
    pointer-events: none;
    opacity: 0.6;
}

.fab.loading svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

.fab.pulse {
    animation: pulse 2s ease-in-out infinite;
    box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.7);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(249, 115, 22, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(249, 115, 22, 0);
    }
}

/* ===========================================
   MINI LEGEND
   =========================================== */
.mini-legend {
    position: fixed;
    left: 12px;
    bottom: calc(var(--bottom-nav-height) + var(--bottom-sheet-collapsed) + var(--safe-bottom) + 20px);
    z-index: 800;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    font-size: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-dot.green {
    background: var(--success);
}

.legend-dot.yellow {
    background: var(--warning);
}

.legend-dot.red {
    background: var(--danger);
}

.legend-label {
    color: var(--text-muted);
}

.legend-expand {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    margin-left: 4px;
}

.legend-expand:hover {
    color: var(--text-main);
}

/* ===========================================
   PANELS (Legend, Layers, Help)
   =========================================== */
.legend-panel,
.layers-panel,
.help-panel {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 12px);
    z-index: 1100;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    max-width: 320px;
    animation: slideUp 0.2s ease-out;
}

/* Help panel is wider to accommodate more content */
.help-panel {
    max-width: 360px;
    max-height: 70vh;
    overflow-y: auto;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.legend-panel.hidden,
.layers-panel.hidden,
.help-panel.hidden {
    display: none;
}

/* Help Item Styles */
.help-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 0;
}

.help-item:not(:last-of-type) {
    border-bottom: 1px solid var(--glass-border);
}

.help-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
    width: 28px;
    text-align: center;
}

.help-item strong {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.help-item small {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 1.4;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--glass-border);
}

.panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.panel-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.panel-close:hover {
    color: var(--text-main);
}

.panel-content {
    padding: 12px 16px;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
}

.legend-swatch {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    flex-shrink: 0;
}

.legend-swatch.green {
    background: var(--success);
}

.legend-swatch.yellow {
    background: var(--warning);
}

.legend-swatch.red {
    background: var(--danger);
}

.legend-swatch.blue {
    background: var(--info);
}

.legend-row strong {
    font-size: 0.9rem;
}

.legend-row small {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 2px;
}

.panel-content hr {
    border: none;
    border-top: 1px solid var(--glass-border);
    margin: 8px 0;
}

.layer-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    cursor: pointer;
    font-size: 0.9rem;
}

.layer-toggle input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
}

.layer-toggle input:disabled {
    opacity: 0.5;
}

.pro-tag {
    background: var(--primary);
    color: white;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 0.6rem;
    font-weight: 700;
    margin-left: 6px;
    text-transform: uppercase;
}

/* ===========================================
   BOTTOM SHEET - Soil Selector
   =========================================== */
.bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
    z-index: 900;
    background: var(--bg-card);
    border-top: 1px solid var(--glass-border);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.sheet-handle {
    width: 36px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    margin: 10px auto;
}

.sheet-collapsed {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px 12px;
    cursor: pointer;
}

.current-soil {
    display: flex;
    align-items: center;
    gap: 10px;
}

.soil-icon {
    font-size: 1.2rem;
}

.soil-name {
    font-weight: 600;
    font-size: 1rem;
}

.soil-meta {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.expand-icon {
    color: var(--text-muted);
    transition: transform 0.3s;
}

.bottom-sheet.expanded .expand-icon {
    transform: rotate(180deg);
}

.sheet-expanded {
    padding: 0 20px 20px;
}

.sheet-expanded.hidden {
    display: none;
}

.sheet-expanded h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 12px;
}

.soil-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.soil-option {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    color: var(--text-main);
    transition: all 0.2s;
}

.soil-option:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--primary);
}

.soil-option.active {
    background: rgba(249, 115, 22, 0.15);
    border-color: var(--primary);
}

.soil-option .soil-icon {
    font-size: 1.4rem;
}

.soil-info {
    flex: 1;
}

.soil-info strong {
    display: block;
    font-size: 0.95rem;
}

.soil-info small {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 2px;
}

.soil-option .check-icon {
    display: none;
    color: var(--primary);
    font-size: 1.2rem;
    font-weight: bold;
}

.soil-option.active .check-icon {
    display: block;
}

/* ===========================================
   BOTTOM NAVIGATION
   =========================================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    z-index: 1000;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--glass-border);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 16px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.2s;
    min-width: 64px;
}

.nav-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.nav-btn.active {
    color: var(--primary);
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===========================================
   LOADING OVERLAY
   =========================================== */
.loading-overlay {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
}

.loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--glass-border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-overlay p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ===========================================
   TOAST NOTIFICATIONS
   =========================================== */
.toast-container {
    position: fixed;
    top: calc(var(--header-height) + 70px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    font-size: 0.875rem;
    animation: toastIn 0.3s ease-out;
    white-space: nowrap;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--danger);
}

.toast.info {
    border-left: 3px solid var(--info);
}

/* ===========================================
   GUEST BANNER
   =========================================== */
.guest-banner {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--bottom-sheet-collapsed) + var(--safe-bottom) + 80px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 850;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    padding-right: 40px;
    background: var(--bg-card);
    border: 1px solid var(--primary);
    border-radius: 12px;
    box-shadow: var(--shadow);
    font-size: 0.85rem;
    white-space: nowrap;
    animation: slideUp 0.5s ease-out;
}

.guest-banner.hidden {
    display: none;
}

.guest-banner a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.banner-close {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
}

/* ===========================================
   UTILITY CLASSES
   =========================================== */
.hidden {
    display: none !important;
}

/* ===========================================
   DESKTOP ENHANCEMENTS (768px+)
   =========================================== */
@media (min-width: 768px) {
    :root {
        --bottom-nav-height: 64px;
        --bottom-sheet-collapsed: 56px;
    }

    /* Keep bottom nav visible on desktop, just restyle it */
    .bottom-nav {
        display: flex;
        max-width: 500px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 16px 16px 0 0;
        border-left: 1px solid var(--glass-border);
        border-right: 1px solid var(--glass-border);
    }

    .bottom-sheet {
        position: fixed;
        left: 12px;
        bottom: calc(var(--bottom-nav-height) + 12px);
        right: auto;
        width: 280px;
        border-radius: 16px;
    }

    .fab-stack {
        bottom: calc(var(--bottom-nav-height) + var(--bottom-sheet-collapsed) + 30px);
        right: 24px;
    }

    .mini-legend {
        bottom: calc(var(--bottom-nav-height) + var(--bottom-sheet-collapsed) + 30px);
        left: 320px;
    }

    .guest-banner {
        bottom: calc(var(--bottom-nav-height) + var(--bottom-sheet-collapsed) + 100px);
    }

    .search-container {
        max-width: 400px;
    }

    /* Layers panel positioning for desktop */
    .layers-panel,
    .legend-panel {
        left: auto;
        right: 24px;
        bottom: calc(var(--bottom-nav-height) + 20px);
        max-width: 300px;
    }
}