/* ========================================
   Wadi Al-Dawasir Vegetation Analysis
   Dark satellite-observatory theme
   ======================================== */

:root {
    --bg-dark: #060b18;
    --panel-bg: rgba(8, 14, 30, 0.92);
    --panel-border: rgba(255, 255, 255, 0.07);
    --green-primary: #22c55e;
    --green-secondary: #10b981;
    --green-glow: rgba(34, 197, 94, 0.12);
    --blue-accent: #3b82f6;
    --purple-accent: #a855f7;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --divider: rgba(255, 255, 255, 0.06);
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: rgba(255, 255, 255, 0.06);
    --card-hover: rgba(255, 255, 255, 0.06);
    --panel-width: 340px;
    --radius: 16px;
    --radius-sm: 10px;
}

/* ===== Reset ===== */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ===== Loading Screen ===== */

#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.6s ease, visibility 0.6s ease;
}

#loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader {
    text-align: center;
}

.loader-ring {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.06);
    border-top-color: var(--green-primary);
    animation: spin 1s linear infinite;
    margin: 0 auto 28px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.loader-sub {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 400;
}

/* ===== Map ===== */

#map {
    width: 100vw;
    height: 100vh;
    position: fixed;
    inset: 0;
    z-index: 1;
}

/* Default cursor on map */
.leaflet-container {
    cursor: default !important;
}

.leaflet-grab {
    cursor: default !important;
}

.leaflet-dragging .leaflet-grab {
    cursor: grabbing !important;
}

/* Leaflet control overrides */

.leaflet-control-zoom {
    border: none !important;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45) !important;
    border-radius: 10px !important;
    overflow: hidden;
}

.leaflet-control-zoom a {
    background: var(--panel-bg) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--panel-border) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
    transition: background 0.2s ease !important;
}

.leaflet-control-zoom a:hover {
    background: rgba(20, 30, 60, 0.95) !important;
}

.leaflet-control-zoom-in {
    border-radius: 10px 10px 0 0 !important;
}

.leaflet-control-zoom-out {
    border-radius: 0 0 10px 10px !important;
    border-top: none !important;
}

.leaflet-control-attribution {
    background: rgba(0, 0, 0, 0.5) !important;
    color: var(--text-muted) !important;
    font-size: 10px !important;
    padding: 3px 8px !important;
    border-radius: 6px 0 0 0 !important;
    backdrop-filter: blur(10px) !important;
}

.leaflet-control-attribution a {
    color: var(--text-secondary) !important;
}

/* Hide Leaflet.draw default toolbar */
.leaflet-draw-toolbar {
    display: none !important;
}

/* Style drawn shapes popup */
.leaflet-popup-content-wrapper {
    background: var(--panel-bg) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--panel-border) !important;
    border-radius: 10px !important;
    backdrop-filter: blur(20px) !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4) !important;
    font-family: "Inter", sans-serif !important;
    font-size: 13px !important;
}

.leaflet-popup-content {
    margin: 14px 16px !important;
    line-height: 1.6 !important;
}

.leaflet-popup-tip {
    background: var(--panel-bg) !important;
    border: 1px solid var(--panel-border) !important;
}

.leaflet-popup-close-button {
    color: var(--text-muted) !important;
}

/* ===== Panel ===== */

#panel {
    position: fixed;
    left: 20px;
    top: 20px;
    bottom: 20px;
    width: var(--panel-width);
    z-index: 1000;
    background: var(--panel-bg);
    backdrop-filter: blur(24px) saturate(1.2);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.02),
        0 8px 40px rgba(0, 0, 0, 0.5),
        0 0 120px rgba(34, 197, 94, 0.02);
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

#panel.visible {
    opacity: 1;
    transform: translateX(0);
}

/* Scrollbar */

#panel::-webkit-scrollbar {
    width: 4px;
}

#panel::-webkit-scrollbar-track {
    background: transparent;
}

#panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
}

#panel::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.14);
}

/* ===== Panel Header ===== */

.panel-header {
    padding: 28px 24px 20px;
}

.panel-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--green-primary);
    background: var(--green-glow);
    border: 1px solid rgba(34, 197, 94, 0.18);
    padding: 5px 10px;
    border-radius: 6px;
    margin-bottom: 16px;
}

.panel-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.panel-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 400;
}

.panel-subtitle-ar {
    font-size: 15px;
    color: var(--text-muted);
    margin-top: 4px;
    direction: rtl;
    text-align: left;
}

/* ===== Divider ===== */

.panel-divider {
    height: 1px;
    background: var(--divider);
    margin: 0 24px;
    flex-shrink: 0;
}

/* ===== Generic Section ===== */

.section {
    padding: 18px 24px;
}

.section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.section-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.5;
}

/* ===== Stats ===== */

.stats-grid {
    padding: 18px 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    animation: fadeInUp 0.5s ease backwards;
}

.stat-card:nth-child(1) { animation-delay: 0.1s; }
.stat-card:nth-child(2) { animation-delay: 0.2s; }
.stat-card:nth-child(3) { animation-delay: 0.3s; }

.stat-card:hover {
    background: var(--card-hover);
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateX(2px);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 20px;
    height: 20px;
}

.green-icon {
    background: rgba(34, 197, 94, 0.12);
    color: var(--green-primary);
}

.total-icon {
    background: rgba(59, 130, 246, 0.12);
    color: var(--blue-accent);
}

.pct-icon {
    background: rgba(168, 85, 247, 0.12);
    color: var(--purple-accent);
}

.stat-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.stat-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 2px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.stat-unit {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 400;
    margin-top: 2px;
}

/* ===== Base Map Grid ===== */

.basemap-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.basemap-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 12px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-family: "Inter", sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.basemap-name {
    font-size: 12px;
    font-weight: 500;
}

.basemap-date {
    font-size: 9px;
    color: var(--text-muted);
    font-weight: 400;
}

.basemap-btn:hover {
    background: var(--card-hover);
    border-color: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
}

.basemap-btn.active {
    background: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.3);
    color: var(--green-primary);
}

.basemap-btn.active .basemap-name {
    font-weight: 600;
}

.basemap-btn.active .basemap-date {
    color: rgba(34, 197, 94, 0.6);
}

/* ===== Layer Toggles ===== */

.layer-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 7px 0;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.layer-toggle input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle-track {
    position: relative;
    width: 38px;
    height: 20px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    transition: background 0.25s ease;
    flex-shrink: 0;
}

.toggle-thumb {
    position: absolute;
    width: 14px;
    height: 14px;
    background: rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: transform 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

input:checked + .toggle-track {
    background: rgba(34, 197, 94, 0.25);
}

input:checked + .toggle-track .toggle-thumb {
    transform: translateX(18px);
    background: var(--green-primary);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
}

.toggle-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

.layer-toggle:hover .toggle-label {
    color: var(--text-primary);
}

/* ===== Draw & Measure ===== */

.draw-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.draw-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-family: "Inter", sans-serif;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.draw-btn:hover {
    background: rgba(34, 197, 94, 0.08);
    border-color: rgba(34, 197, 94, 0.2);
    color: var(--green-primary);
}

.draw-btn-clear {
    margin-left: auto;
}

.draw-btn-clear:hover {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* Draw Results */

.draw-results {
    margin-top: 14px;
    padding: 14px;
    background: rgba(34, 197, 94, 0.05);
    border: 1px solid rgba(34, 197, 94, 0.12);
    border-radius: 10px;
    animation: fadeInUp 0.3s ease;
}

.draw-results.hidden {
    display: none;
}

.draw-result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.draw-result-label {
    font-size: 12px;
    color: var(--text-muted);
}

.draw-result-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* ===== Legends ===== */

.legend-bar {
    height: 10px;
    border-radius: 5px;
    margin-bottom: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.legend-ndvi {
    background: linear-gradient(
        to right,
        #d73027, #f46d43, #fdae61, #fee08b,
        #d9ef8b, #a6d96a, #66bd63, #1a9850
    );
}

.legend-ndmi {
    background: linear-gradient(
        to right,
        #8B4513, #CD853F, #F0E68C,
        #90EE90, #4682B4, #000080
    );
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.legend-threshold {
    position: relative;
    height: 22px;
}

.threshold-marker {
    position: absolute;
    left: 33%;
    top: 0;
    width: 2px;
    height: 10px;
    background: var(--text-primary);
    border-radius: 1px;
}

.threshold-label {
    position: absolute;
    left: 33%;
    top: 13px;
    transform: translateX(-50%);
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ===== Footer ===== */

.panel-footer {
    padding: 18px 24px;
    margin-top: auto;
    border-top: 1px solid var(--divider);
}

.footer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0;
}

.footer-label {
    font-size: 11px;
    color: var(--text-muted);
}

.footer-value {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== Draw Result Divider ===== */

.draw-result-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: 6px 0;
}

/* ===== Draw Vertex Styling ===== */

.draw-vertex-icon {
    background: var(--green-primary);
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
}

.leaflet-draw-guide-dash {
    background: none;
    border: 1px dashed rgba(34, 197, 94, 0.6) !important;
}

/* ===== Probe Tooltip ===== */

.probe-tooltip {
    position: fixed;
    z-index: 9000;
    width: 220px;
    background: rgba(8, 14, 30, 0.94);
    backdrop-filter: blur(20px) saturate(1.2);
    -webkit-backdrop-filter: blur(20px) saturate(1.2);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.02),
        0 12px 40px rgba(0, 0, 0, 0.55);
    pointer-events: none;
    opacity: 0;
    transform: translateY(6px) scale(0.97);
    transition: opacity 0.2s ease, transform 0.2s ease;
    font-family: "Inter", sans-serif;
}

.probe-tooltip.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.probe-loading {
    font-size: 12px;
    color: var(--text-muted);
    padding: 8px 0 2px;
    animation: probePulse 1.2s ease infinite;
}

@keyframes probePulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.probe-header {
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.probe-coords {
    font-size: 10px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.probe-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
}

.probe-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 6px currentColor;
}

.probe-data {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.probe-label {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.03em;
}

.probe-value {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.probe-tag {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 3px 7px;
    border-radius: 5px;
    flex-shrink: 0;
}

.tag-red {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.tag-orange {
    background: rgba(249, 115, 22, 0.15);
    color: #f97316;
}

.tag-yellow {
    background: rgba(234, 179, 8, 0.15);
    color: #eab308;
}

.tag-lime {
    background: rgba(132, 204, 22, 0.15);
    color: #84cc16;
}

.tag-green {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.tag-cyan {
    background: rgba(6, 182, 212, 0.15);
    color: #06b6d4;
}

.tag-blue {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

/* ===== Responsive ===== */

@media (max-width: 768px) {
    #panel {
        left: 10px;
        right: 10px;
        top: auto;
        bottom: 10px;
        width: auto;
        max-height: 55vh;
        border-radius: 14px;
        transform: translateY(20px);
    }

    #panel.visible {
        transform: translateY(0);
    }

    .panel-header {
        padding: 20px 20px 16px;
    }

    .panel-title {
        font-size: 18px;
    }

    .stats-grid {
        padding: 16px 20px;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .stat-card {
        flex: 1 1 calc(50% - 5px);
        min-width: 0;
    }

    .stat-card:last-child {
        flex: 1 1 100%;
    }

    .stat-value {
        font-size: 20px;
    }

    .section {
        padding: 14px 20px;
    }

    .panel-footer {
        padding: 14px 20px;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        flex-direction: column;
    }

    .stat-card {
        flex: 1 1 100%;
    }

    .basemap-grid {
        grid-template-columns: 1fr 1fr;
    }
}
