/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --brand: #f97316;
    --brand-dark: #ea6808;
    --brand-light: #fff7ed;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e8edf2;
    --text: #1a2332;
    --text-2: #64748b;
    --text-3: #94a3b8;
    --success: #10b981;
    --danger: #ef4444;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --radius: 10px;
    --sidebar-w: 320px;
    --header-h: 64px;
    --font: 'Plus Jakarta Sans', sans-serif;
    --mono: 'JetBrains Mono', monospace;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* ===== APP LAYOUT ===== */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease, min-width 0.3s ease;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
}

.sidebar-header {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--brand);
    background: linear-gradient(135deg, #f97316, #fb923c);
    flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 24px; }
.brand-name { font-size: 16px; font-weight: 800; color: white; letter-spacing: -0.3px; }
.brand-sub { font-size: 11px; color: rgba(255,255,255,0.75); font-weight: 500; }

.sidebar-toggle {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.3); }

/* ===== TABS ===== */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: #fafbfc;
    flex-shrink: 0;
}
.tab {
    flex: 1;
    padding: 10px 4px;
    border: none;
    background: none;
    font-family: var(--font);
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-2);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}
.tab.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
    background: var(--surface);
}
.tab:hover:not(.active) { color: var(--text); background: #f0f2f5; }

/* ===== TAB CONTENT ===== */
.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.tab-content.active { display: flex; flex-direction: column; gap: 4px; }

/* ===== FORM ===== */
.section-label {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-3);
    margin: 8px 0 8px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.form-group .optional { font-weight: 400; color: var(--text-3); font-size: 11px; }
.form-row { display: flex; gap: 8px; }
.form-row .form-group { flex: 1; }

input[type="text"],
input[type="number"] {
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-family: var(--font);
    font-size: 13px;
    color: var(--text);
    background: var(--bg);
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}
input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(249,115,22,0.12);
    background: white;
}

.color-picker-row {
    display: flex; align-items: center; gap: 10px;
}
input[type="color"] {
    width: 40px; height: 36px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    padding: 2px;
    background: white;
}
#colorHex {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-2);
}

/* ===== BUTTONS ===== */
.btn-primary {
    width: 100%;
    padding: 11px;
    background: linear-gradient(135deg, var(--brand), #fb923c);
    color: white;
    border: none;
    border-radius: 8px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 2px 8px rgba(249,115,22,0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(249,115,22,0.4); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    width: 100%;
    padding: 10px;
    background: white;
    color: var(--text-2);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    margin-top: 8px;
}
.btn-secondary:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-light); }

.btn-danger-sm {
    padding: 5px 10px;
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
    border-radius: 6px;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-danger-sm:hover { background: var(--danger); color: white; }

/* ===== UPLOAD ZONE ===== */
.divider {
    text-align: center;
    color: var(--text-3);
    font-size: 12px;
    font-weight: 600;
    margin: 12px 0;
    position: relative;
}
.divider::before, .divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 42%;
    height: 1px;
    background: var(--border);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 20px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafbfc;
}
.upload-zone:hover, .upload-zone.dragging {
    border-color: var(--brand);
    background: var(--brand-light);
}
.upload-icon { font-size: 28px; margin-bottom: 6px; }
.upload-text { font-size: 13px; font-weight: 600; color: var(--text-2); }
.upload-sub { font-size: 11px; color: var(--text-3); margin-top: 4px; font-family: var(--mono); }

/* ===== DATA LIST ===== */
.data-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.data-count { font-size: 12px; font-weight: 700; color: var(--text-2); }
.data-count span { color: var(--brand); }

.location-list { display: flex; flex-direction: column; gap: 6px; }

.location-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.2s ease;
    transition: all 0.15s;
}
.location-item:hover { border-color: #cbd5e1; box-shadow: var(--shadow-sm); }

.loc-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.08);
}
.loc-info { flex: 1; min-width: 0; }
.loc-name { font-size: 12.5px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loc-val { font-size: 11px; font-family: var(--mono); color: var(--text-2); margin-top: 1px; }
.loc-coords { font-size: 10px; color: var(--text-3); font-family: var(--mono); }

.loc-actions { display: flex; gap: 4px; }
.loc-btn {
    width: 26px; height: 26px;
    border: 1px solid var(--border);
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.loc-btn:hover { border-color: var(--danger); color: var(--danger); background: #fef2f2; }
.loc-btn.zoom:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-light); }

.empty-state {
    text-align: center;
    padding: 30px 16px;
    color: var(--text-3);
    font-size: 28px;
}
.empty-state p { font-size: 13px; margin-top: 8px; line-height: 1.5; }

/* ===== STYLE TAB ===== */
.slider-group { margin-bottom: 14px; }
.slider-group label { font-size: 12px; font-weight: 600; color: var(--text-2); display: block; margin-bottom: 6px; }
.slider-group strong { color: var(--brand); }
input[type="range"] {
    width: 100%;
    accent-color: var(--brand);
    cursor: pointer;
}
.toggle-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px; font-weight: 500; color: var(--text);
}
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0;
    background: #e2e8f0; border-radius: 20px; cursor: pointer;
    transition: 0.2s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 14px; height: 14px;
    left: 3px; top: 3px;
    background: white; border-radius: 50%;
    transition: 0.2s;
    box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle-slider { background: var(--brand); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

.basemap-selector { display: flex; flex-wrap: wrap; gap: 6px; }
.basemap-btn {
    padding: 7px 10px;
    border: 1.5px solid var(--border);
    background: white;
    border-radius: 7px;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    cursor: pointer;
    transition: all 0.15s;
}
.basemap-btn:hover { border-color: var(--brand); color: var(--brand); }
.basemap-btn.active { border-color: var(--brand); background: var(--brand-light); color: var(--brand); }

/* ===== SIDEBAR FOOTER ===== */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    background: #fafbfc;
}
.btn-export {
    flex: 1; padding: 10px;
    background: linear-gradient(135deg, #0ea5e9, #38bdf8);
    color: white; border: none;
    border-radius: 8px;
    font-family: var(--font);
    font-size: 12px; font-weight: 700;
    cursor: pointer; transition: all 0.15s;
    box-shadow: 0 2px 6px rgba(14,165,233,0.3);
}
.btn-export:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(14,165,233,0.4); }
.btn-export-csv {
    flex: 1; padding: 10px;
    background: linear-gradient(135deg, var(--success), #34d399);
    color: white; border: none;
    border-radius: 8px;
    font-family: var(--font);
    font-size: 12px; font-weight: 700;
    cursor: pointer; transition: all 0.15s;
    box-shadow: 0 2px 6px rgba(16,185,129,0.3);
}
.btn-export-csv:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(16,185,129,0.4); }

/* ===== MAP AREA ===== */
.map-area {
    flex: 1;
    position: relative;
    overflow: hidden;
}
#map {
    width: 100%;
    height: 100%;
}

/* ===== STATS BAR ===== */
.stats-bar {
    position: absolute;
    top: 14px; left: 50%;
    transform: translateX(-50%);
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 20px;
    display: flex;
    gap: 28px;
    box-shadow: var(--shadow-lg);
    z-index: 800;
    backdrop-filter: blur(10px);
}
.stat-item { text-align: center; }
.stat-num {
    font-size: 18px;
    font-weight: 800;
    color: var(--brand);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.stat-label { font-size: 10px; color: var(--text-3); font-weight: 600; margin-top: 2px; }

/* ===== LEGEND ===== */
.legend-panel {
    position: absolute;
    bottom: 30px; right: 14px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    z-index: 800;
    box-shadow: var(--shadow);
    min-width: 140px;
}
.legend-title { font-size: 11px; font-weight: 700; color: var(--text-2); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.legend-items { display: flex; flex-direction: column; gap: 5px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--text-2); }
.legend-bubble { border-radius: 50%; opacity: 0.65; border: 1px solid rgba(0,0,0,0.15); flex-shrink: 0; }

/* ===== SIDEBAR SHOW BUTTON ===== */
.sidebar-show-btn {
    position: absolute;
    top: 14px; left: 14px;
    z-index: 900;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 16px;
    box-shadow: var(--shadow);
    transition: all 0.15s;
    display: none;
}
.sidebar-show-btn:hover { background: var(--brand-light); border-color: var(--brand); }
.sidebar.collapsed ~ .map-area .sidebar-show-btn { display: block; }

/* ===== TOAST ===== */
.toast {
    position: absolute;
    bottom: 30px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1a2332;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
    z-index: 1000;
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== POPUP ===== */
.leaflet-popup-content-wrapper {
    border-radius: 10px !important;
    box-shadow: var(--shadow-lg) !important;
    border: 1px solid var(--border);
    font-family: var(--font) !important;
}
.leaflet-popup-content { margin: 12px 16px !important; }
.popup-name { font-size: 14px; font-weight: 800; color: var(--text); margin-bottom: 6px; }
.popup-val { font-size: 22px; font-weight: 800; color: var(--brand); }
.popup-label { font-size: 11px; color: var(--text-3); }
.popup-coords { font-size: 11px; font-family: var(--mono); color: var(--text-3); margin-top: 6px; border-top: 1px solid var(--border); padding-top: 6px; }

/* ===== ANIMATIONS ===== */
@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* ===== SCROLLBAR ===== */
.tab-content::-webkit-scrollbar { width: 4px; }
.tab-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    :root { --sidebar-w: 100vw; }
    .stats-bar { gap: 16px; padding: 8px 14px; font-size: 12px; }
    .stat-num { font-size: 15px; }
}