:root {
    --bg-dark: #0b0f17;
    --bg-card: #131b28;
    --bg-card-hover: #1b2638;
    --border-color: #212e44;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-wind: #10b981;
    --accent-cyan: #06b6d4;
    --accent-gas: #f59e0b;
    --accent-hydro: #3b82f6;
    --accent-coal: #ef4444;
    --accent-inter: #a855f7;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.top-nav {
    height: 64px;
    background: rgba(19, 27, 40, 0.95);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pulse-indicator {
    width: 10px;
    height: 10px;
    background-color: var(--accent-wind);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-wind);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.brand h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.brand h1 span {
    color: var(--accent-cyan);
    font-weight: 400;
    font-size: 0.95rem;
}

.header-stats {
    display: flex;
    gap: 16px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 14px;
    display: flex;
    flex-direction: column;
    min-width: 130px;
}

.stat-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-val {
    font-family: var(--font-mono);
    font-size: 1.05rem;
    font-weight: 600;
}

.text-green { color: var(--accent-wind); }
.text-cyan { color: var(--accent-cyan); }

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.last-sync-badge {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    background: #0f172a;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.btn-refresh {
    background: var(--accent-wind);
    color: #052e16;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 6px 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-refresh:hover {
    background: #34d399;
    transform: translateY(-1px);
}

/* Layout */
.main-container {
    display: flex;
    flex: 1;
    height: calc(100vh - 64px);
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 360px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 500;
}

.panel-section {
    background: #0d1420;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 14px;
}

.panel-section h3 {
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 12px;
    letter-spacing: 0.05em;
}

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

.toggle-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-primary);
    cursor: pointer;
    background: #141f30;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.toggle-pill input {
    accent-color: var(--accent-wind);
}

.pill-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.wind-dot { background: var(--accent-wind); }
.thermal-dot { background: var(--accent-gas); }
.hydro-dot { background: var(--accent-hydro); }
.inter-dot { background: var(--accent-inter); }

.search-input {
    width: 100%;
    background: #141f30;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    padding: 8px 12px;
    font-size: 0.82rem;
    outline: none;
}
.search-input:focus {
    border-color: var(--accent-cyan);
}

/* Interconnectors List */
.inter-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.inter-item {
    background: #141f30;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
}

.inter-name {
    font-weight: 600;
    display: flex;
    flex-direction: column;
}

.inter-route {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.inter-val {
    font-family: var(--font-mono);
    font-weight: 600;
    text-align: right;
}

/* Fuel breakdown */
.progress-bar-container {
    height: 12px;
    background: #1a2333;
    border-radius: 6px;
    display: flex;
    overflow: hidden;
    margin-bottom: 12px;
}

.bar-segment {
    height: 100%;
    transition: width 0.5s ease;
}
.bar-renew { background: var(--accent-wind); }
.bar-gas { background: var(--accent-gas); }
.bar-other { background: #64748b; }

.fuel-legend {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.78rem;
}
.fuel-legend li {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.fuel-legend strong {
    font-family: var(--font-mono);
}

.dot-renew { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-wind); margin-right: 6px; }
.dot-gas { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-gas); margin-right: 6px; }
.dot-coal { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-coal); margin-right: 6px; }
.dot-import { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-inter); margin-right: 6px; }

/* Top Wind Farms */
.top-farms-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 220px;
    overflow-y: auto;
}

.farm-row {
    background: #141f30;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.15s;
}
.farm-row:hover {
    background: var(--bg-card-hover);
}
.farm-meta {
    display: flex;
    flex-direction: column;
}
.farm-title {
    font-weight: 600;
}
.farm-sub {
    font-size: 0.68rem;
    color: var(--text-muted);
}
.farm-metric {
    font-family: var(--font-mono);
    text-align: right;
    font-weight: 600;
    color: var(--accent-wind);
}

/* Map Wrapper */
.map-wrapper {
    flex: 1;
    position: relative;
    height: 100%;
}

#map {
    width: 100%;
    height: 100%;
    background: #090d14;
}

/* Map Legend */
.map-legend {
    position: absolute;
    bottom: 24px;
    right: 24px;
    background: rgba(19, 27, 40, 0.92);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.75rem;
    z-index: 1000;
    min-width: 200px;
}
.map-legend h4 {
    font-size: 0.72rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.cf-gradient {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 0.68rem;
    color: var(--text-muted);
}
.gradient-strip {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, #475569, #eab308, #10b981, #06b6d4);
}
.marker-legend {
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
}
.legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
}
.swatch-gas { background: var(--accent-gas); }
.swatch-hydro { background: var(--accent-hydro); }
.swatch-inter { background: var(--accent-inter); }

/* Custom Popup Styles */
.leaflet-popup-content-wrapper {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color);
    border-radius: 8px !important;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5) !important;
}
.leaflet-popup-tip {
    background: var(--bg-card) !important;
    border: 1px solid var(--border-color);
}
.popup-card {
    padding: 4px;
    font-size: 0.8rem;
}
.popup-card h4 {
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.popup-badge {
    display: inline-block;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-bottom: 8px;
    font-weight: 600;
}
.badge-wind { background: rgba(16, 185, 129, 0.2); color: var(--accent-wind); }
.badge-thermal { background: rgba(245, 158, 11, 0.2); color: var(--accent-gas); }
.badge-hydro { background: rgba(59, 130, 246, 0.2); color: var(--accent-hydro); }
.popup-table {
    width: 100%;
    margin-top: 6px;
    border-collapse: collapse;
}
.popup-table td {
    padding: 3px 0;
    color: var(--text-secondary);
}
.popup-table td.val {
    text-align: right;
    font-family: var(--font-mono);
    color: var(--text-primary);
    font-weight: 600;
}

/* Layer Control Dark Mode */
.leaflet-control-layers {
    background: rgba(19, 27, 40, 0.95) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    font-family: var(--font-sans) !important;
    font-size: 0.75rem !important;
    padding: 8px 12px !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4) !important;
}
.leaflet-control-layers-expanded {
    color: var(--text-primary) !important;
}
.leaflet-control-layers label {
    color: var(--text-secondary) !important;
    cursor: pointer;
    margin-bottom: 4px;
}
.leaflet-control-layers label:hover {
    color: var(--text-primary) !important;
}
