:root {
    --bg-dark: #070B14;
    --panel-bg: #0B111F;
    --card-bg: rgba(255, 255, 255, 0.02);
    --card-border: rgba(255, 255, 255, 0.05);
    
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #6366f1;
    --secondary-hover: #4f46e5;
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --color-green: #10b981;
    --color-blue: #3b82f6;
    --color-orange: #f97316;
    --color-red: #ef4444;

    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
    --glass-blur: blur(12px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Roboto', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

body.fullscreen-active {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Base Utility Classes */
.text-green { color: var(--color-green); }
.text-blue { color: var(--color-blue); }
.text-orange { color: var(--color-orange); }
.text-red { color: var(--color-red); }

.glass-panel {
    background: rgba(11, 17, 31, 0.75);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--card-border);
    box-shadow: var(--glass-shadow);
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Left Sidebar (Data Panel) */
.data-panel {
    width: 45%;
    max-width: 650px;
    min-width: 400px;
    background: var(--panel-bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--card-border);
    z-index: 10;
    box-shadow: 15px 0 40px rgba(0,0,0,0.5);
}

/* Header */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2rem 2rem 1.5rem 2rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-logo {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    object-fit: cover;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.brand-text h1 {
    font-size: 1.4rem;
    font-weight: 700;
    background: linear-gradient(135deg, #60a5fa, #34d399);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.brand-text p {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: 2px;
}

.actions {
    display: flex;
    gap: 0.5rem;
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.2s ease;
}

.btn.primary {
    background-color: rgba(59, 130, 246, 0.15);
    color: var(--primary-color);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.btn.primary:hover {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

.btn.secondary {
    background-color: rgba(99, 102, 241, 0.15);
    color: var(--secondary-color);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.btn.secondary:hover {
    background-color: var(--secondary-color);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    padding: 0 2rem 1rem 2rem;
}

.kpi-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    transition: transform 0.2s, background 0.2s;
}

.kpi-card:hover {
    background: rgba(255,255,255,0.04);
    transform: translateY(-2px);
}

.kpi-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1;
}

/* Filters */
.filter-tabs {
    display: flex;
    gap: 0.5rem;
    padding: 0 2rem 1rem 2rem;
    border-bottom: 1px solid var(--card-border);
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-main);
    background: rgba(255,255,255,0.05);
}

.tab-btn.active {
    background: var(--card-border);
    color: var(--text-main);
}

/* Table Wrapper */
.table-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    padding: 0 2rem;
}

/* Custom Scrollbar for modern look */
.table-wrapper::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.table-wrapper::-webkit-scrollbar-track {
    background: transparent;
}
.table-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
}
.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    margin-bottom: 2rem;
}

th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 1rem 0.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    position: sticky;
    top: 0;
    background: var(--panel-bg);
    z-index: 5;
}

th.sortable {
    cursor: pointer;
    transition: color 0.2s;
    user-select: none;
}

th.sortable:hover {
    color: var(--text-main);
}

th.sortable .sort-icon {
    display: inline-block;
    width: 10px;
    margin-left: 4px;
}

th.active-sort {
    color: var(--primary-color);
}

td {
    padding: 1rem 0.5rem;
    font-size: 0.85rem;
    color: var(--text-main);
    border-bottom: 1px solid rgba(255,255,255,0.03);
    transition: background 0.2s;
}

tr:hover td {
    background: rgba(255,255,255,0.03);
}

tr td:first-child { font-weight: 500; }
tr td:last-child { font-weight: 600; color: var(--primary-color); }

/* Right Map Panel */
.map-panel {
    flex: 1;
    position: relative;
    background: #1e293b;
}

#map {
    width: 100%;
    height: 100%;
}

/* Map Legend */
.map-legend {
    position: absolute;
    bottom: 40px;
    right: 40px;
    padding: 1.5rem;
    border-radius: 16px;
    z-index: 1000;
}

.map-legend h4 {
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: var(--text-main);
    font-weight: 600;
    letter-spacing: 0.5px;
}

.legend-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.legend-item span {
    display: block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
}

/* Leaflet Overrides */
.leaflet-container {
    background: #0b0f19 !important;
}

.leaflet-popup-content-wrapper, .leaflet-popup-tip {
    background: rgba(11, 17, 31, 0.9) !important;
    backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(255,255,255,0.1) !important;
    color: var(--text-main) !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5) !important;
    border-radius: 12px !important;
}

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

.leaflet-popup-content b {
    color: var(--primary-color);
    font-size: 1rem;
    display: block;
    margin-bottom: 4px;
}

.map-panel.fullscreen-map {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: -webkit-fill-available !important;
    height: 100dvh !important;
    z-index: 9999 !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Responsive */
@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
        overflow-y: auto;
    }
    
    .data-panel {
        width: 100%;
        max-width: 100%;
        height: auto;
        min-height: 60vh;
        box-shadow: none;
        border-right: none;
        border-top: 1px solid var(--card-border);
        order: 2;
    }
    
    .map-panel {
        height: 60vh;
        min-height: 400px;
        flex: none;
        order: 1;
    }
    
    .table-wrapper {
        overflow: visible;
    }
    
    body {
        overflow-y: auto;
    }
}

@media (max-width: 768px) {
    .panel-header {
        flex-direction: row;
        align-items: center;
        gap: 1rem;
        padding: 1rem 1rem 0.5rem 1rem;
    }
    
    .actions {
        display: none;
    }
    
    .kpi-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        padding: 0 1rem 0.75rem 1rem;
    }
    
    .kpi-card {
        padding: 0.5rem;
    }
    
    .kpi-title {
        font-size: 0.65rem;
    }
    
    .kpi-value {
        font-size: 1.2rem;
    }
    
    .filter-tabs {
        padding: 0 1rem 0.75rem 1rem;
    }
    
    .map-legend {
        bottom: 10px;
        left: 10px;
        right: 10px;
        padding: 0.75rem 1rem;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .map-legend h4 {
        margin: 0;
        font-size: 0.8rem;
    }
    
    .legend-list {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem 1rem;
    }
    
    .legend-item {
        font-size: 0.75rem;
    }
}
