/* ============================================================
   GB Power System Explorer - Main Stylesheet
   ============================================================ */

:root {
    --bg-primary: #0f1923;
    --bg-secondary: #162231;
    --bg-tertiary: #1a2a3a;
    --bg-card: #1e3044;
    --border-color: #2a4560;
    --text-primary: #e8edf2;
    --text-secondary: #8fa3b8;
    --text-muted: #5c7a94;
    --accent-blue: #2196F3;
    --accent-blue-glow: rgba(33, 150, 243, 0.3);
    --accent-red: #e74c3c;
    --accent-green: #2ecc71;
    --accent-purple: #9b59b6;
    --accent-orange: #f39c12;
    --accent-cyan: #00bcd4;
    --sidebar-width: 300px;
    --header-height: 56px;
    --scrollbar-thumb: #2a4560;
    --scrollbar-track: #162231;
}

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

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

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}
::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #3a5a7a;
}

/* ============================================================
   Header
   ============================================================ */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
}

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

.header-logo {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-logo svg {
    width: 28px;
    height: 28px;
}

.header-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.header-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 12px;
    padding-left: 12px;
    border-left: 1px solid var(--border-color);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-badge {
    font-size: 11px;
    color: var(--accent-blue);
    background: rgba(33, 150, 243, 0.12);
    padding: 4px 10px;
    border-radius: 12px;
    border: 1px solid rgba(33, 150, 243, 0.25);
    font-weight: 500;
}

.header-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-btn:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--accent-blue);
}

/* ============================================================
   Main Layout
   ============================================================ */
.main-container {
    display: flex;
    margin-top: var(--header-height);
    height: calc(100vh - var(--header-height));
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    transition: width 0.3s ease;
}

.sidebar.collapsed {
    width: 0;
    border-right: none;
}

.sidebar-toggle {
    position: fixed;
    left: var(--sidebar-width);
    top: calc(var(--header-height) + 12px);
    z-index: 1001;
    width: 24px;
    height: 40px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 14px;
}

.sidebar.collapsed + .map-container .sidebar-toggle,
.sidebar-toggle.collapsed {
    left: 0;
}

.sidebar-toggle:hover {
    color: var(--accent-blue);
    background: var(--bg-card);
}

/* Search */
.search-container {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 10px;
    color: var(--text-muted);
    font-size: 14px;
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 6px 10px 6px 30px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 7px;
    color: var(--text-primary);
    font-size: 10px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.search-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px var(--accent-blue-glow);
}

.search-input::placeholder {
    color: var(--text-muted);
}

/* Tabs */
.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    padding: 0 4px;
}

.sidebar-tab {
    flex: 1;
    padding: 8px 6px;
    text-align: center;
    font-size: 10px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}

.sidebar-tab:hover {
    color: var(--text-secondary);
}

.sidebar-tab.active {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
}

/* Filters */
.filters-section {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
}

.filter-group {
    margin-bottom: 10px;
}

.filter-group:last-child {
    margin-bottom: 0;
}

.filter-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 6px;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.filter-chip {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 14px;
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    transition: all 0.2s;
}

.filter-chip:hover {
    border-color: var(--text-muted);
}

.filter-chip.active {
    border-color: var(--accent-blue);
    background: rgba(33, 150, 243, 0.12);
    color: var(--accent-blue);
}

.filter-chip .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.filter-chip .toggle-status {
    margin-left: 4px;
    padding: 1px 5px;
    border-radius: 999px;
    font-size: 10px;
    line-height: 1.2;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

.filter-chip.active .toggle-status {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

/* Substation list */
.list-container {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.list-header {
    padding: 3px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.list-count {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 500;
}

.list-sort {
    font-size: 10px;
    color: var(--accent-blue);
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
}

.substation-item {
    padding: 6px 10px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.substation-item:hover {
    background: var(--bg-tertiary);
}

.substation-item.selected {
    background: var(--bg-card);
    border-left-color: var(--accent-blue);
}

.substation-voltage-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.substation-info {
    flex: 1;
    min-width: 0;
}

.substation-name {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.substation-meta {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
}

.substation-voltage-badge {
    font-size: 9px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}

/* Stats panel in sidebar */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.stat-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

/* ============================================================
   Map Container
   ============================================================ */
.map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
}

/* Leaflet overrides for dark theme */
.leaflet-control-zoom {
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-bottom: 1px solid var(--border-color) !important;
    width: 32px !important;
    height: 32px !important;
    line-height: 32px !important;
    font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-card) !important;
    color: var(--accent-blue) !important;
}

.leaflet-control-layers {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    color: var(--text-primary) !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
}

.leaflet-control-layers-expanded {
    padding: 8px 12px !important;
}

.leaflet-control-layers label {
    color: var(--text-secondary) !important;
    font-size: 12px !important;
}

.leaflet-control-layers-separator {
    border-color: var(--border-color) !important;
}

.leaflet-control-attribution {
    background: rgba(15, 25, 35, 0.85) !important;
    color: var(--text-muted) !important;
    font-size: 10px !important;
    border-radius: 4px 0 0 0 !important;
}

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

/* Custom popup */
.leaflet-popup-content-wrapper {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-radius: 10px !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4) !important;
    padding: 0 !important;
}

.leaflet-popup-content {
    margin: 0 !important;
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif !important;
    font-size: 13px !important;
    min-width: 220px !important;
}

.leaflet-popup-tip {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: none !important;
}

.leaflet-popup-close-button {
    color: var(--text-muted) !important;
    font-size: 18px !important;
    padding: 6px 8px 0 0 !important;
}

.leaflet-popup-close-button:hover {
    color: var(--accent-blue) !important;
}

/* Custom popup content */
.popup-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.popup-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.popup-title {
    font-size: 14px;
    font-weight: 600;
}

.popup-body {
    padding: 10px 14px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    padding: 4px 0;
    font-size: 12px;
}

.popup-label {
    color: var(--text-muted);
    flex: 0 0 86px;
    min-width: 86px;
}

.popup-value {
    color: var(--text-primary);
    font-weight: 500;
    flex: 1 1 auto;
    text-align: right;
    overflow-wrap: anywhere;
    line-height: 1.35;
}

.popup-row.popup-row-stack {
    display: block;
}

.popup-row.popup-row-stack .popup-label {
    display: block;
    margin-bottom: 2px;
}

.popup-row.popup-row-stack .popup-value {
    display: block;
    text-align: left;
}

.popup-footer {
    padding: 8px 14px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.popup-scroll-list {
    max-height: 120px;
    overflow-y: auto;
    padding-right: 4px;
}

.popup-link {
    color: var(--accent-blue);
    font-size: 11px;
    text-decoration: none;
    cursor: pointer;
}

.popup-link:hover {
    text-decoration: underline;
}

/* Map legend */
.map-legend {
    position: absolute;
    bottom: 30px;
    left: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 16px;
    z-index: 999;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
    min-width: 180px;
}

.overlay-controls {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 900;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
    padding: 7px 8px;
    min-width: 190px;
    max-width: 235px;
    max-height: calc(100% - 22px);
    overflow-y: auto;
}

.overlay-controls-title {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
}

.overlay-controls-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.overlay-controls .filter-chip {
    width: 100%;
    justify-content: flex-start;
    font-size: 10px;
    padding: 3px 7px;
    gap: 4px;
}

.legend-title {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    font-size: 10px;
    color: var(--text-secondary);
}

.legend-line {
    width: 18px;
    height: 3px;
    border-radius: 2px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid;
}

.legend-ref {
    align-items: center;
    justify-content: center;
}

.legend-link {
    font-size: 11px;
    color: var(--accent-cyan);
    text-decoration: none;
    white-space: nowrap;
}

.legend-link:hover {
    text-decoration: underline;
    color: var(--accent-blue);
}

.leaflet-tooltip.etys-boundary-label {
    background: transparent;
    border: none;
    box-shadow: none;
    color: #ffb74d;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.85);
    padding: 0;
}

/* Info panel overlay */
.info-panel {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 14px 18px;
    z-index: 999;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
    max-width: 280px;
    display: none;
}

.info-panel.visible {
    display: block;
}

.info-panel-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-panel-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
}

.info-panel-close:hover {
    color: var(--text-primary);
}

.info-detail {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    font-size: 12px;
    border-bottom: 1px solid rgba(42, 69, 96, 0.4);
}

.info-detail:last-child {
    border-bottom: none;
}

.info-detail-label {
    color: var(--text-muted);
}

.info-detail-value {
    color: var(--text-primary);
    font-weight: 500;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    margin-top: 16px;
    color: var(--text-muted);
    font-size: 14px;
}

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

/* ETYS-standard voltage colors: 400kV = blue, 275kV = red */
.voltage-400 { background: var(--accent-blue); }
.voltage-275 { background: var(--accent-red); }
.voltage-132 { background: var(--accent-green); }
.voltage-hvdc { background: var(--accent-purple); }

.badge-400 { 
    background: rgba(33, 150, 243, 0.15); 
    color: var(--accent-blue); 
    border: 1px solid rgba(33, 150, 243, 0.3); 
}
.badge-275 { 
    background: rgba(231, 76, 60, 0.15); 
    color: var(--accent-red); 
    border: 1px solid rgba(231, 76, 60, 0.3); 
}
.badge-132 { 
    background: rgba(46, 204, 113, 0.15); 
    color: var(--accent-green); 
    border: 1px solid rgba(46, 204, 113, 0.3); 
}
.badge-hvdc { 
    background: rgba(155, 89, 182, 0.15); 
    color: var(--accent-purple); 
    border: 1px solid rgba(155, 89, 182, 0.3); 
}

/* Connection list items */
.connection-item {
    padding: 6px 12px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(42, 69, 96, 0.3);
}

.connection-item:hover {
    background: var(--bg-tertiary);
}

.connection-line-indicator {
    width: 24px;
    height: 3px;
    border-radius: 2px;
    flex-shrink: 0;
}

.connection-info {
    flex: 1;
    min-width: 0;
}

.connection-name {
    font-size: 11px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.connection-meta {
    font-size: 9px;
    color: var(--text-muted);
    margin-top: 1px;
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 13px;
    z-index: 9999;
    transition: transform 0.3s ease;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
}

/* Data source badge */
.data-source {
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
}

.data-source a {
    color: var(--accent-blue);
    text-decoration: none;
}

.data-source a:hover {
    text-decoration: underline;
}

.disclaimer-note {
    margin-top: 8px;
    font-size: 10px;
    line-height: 1.35;
    color: var(--text-muted);
}

.map-disclaimer {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 6px;
    z-index: 850;
    font-size: 11px;
    line-height: 1.35;
    color: var(--text-muted);
    background: rgba(15, 25, 35, 0.78);
    border: 1px solid var(--border-color);
    border-radius: 7px;
    padding: 4px 8px;
    text-align: center;
    width: max-content;
    max-width: min(92%, 760px);
    pointer-events: none;
}

/* ============================================================
   Generation panel items
   ============================================================ */
.generation-item {
    padding: 6px 10px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(42, 69, 96, 0.25);
}

.generation-item:hover {
    background: var(--bg-tertiary);
}

.gen-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 26px;
    text-align: center;
}

.generation-info {
    flex: 1;
    min-width: 0;
}

.generation-name {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.generation-meta {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.generation-capacity {
    text-align: right;
    flex-shrink: 0;
}

.gen-mw-value {
    font-size: 10px;
    font-weight: 600;
    color: var(--accent-cyan);
}

.gen-connected-value {
    font-size: 10px;
    color: var(--text-muted);
}

.gen-mw {
    color: var(--accent-cyan) !important;
    font-weight: 600;
}

.gen-panel-header {
    flex-shrink: 0;
}

/* Generation type filter chips in gen panel */
#genFiltersContainer .filter-chip {
    font-size: 10px;
    padding: 3px 8px;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: var(--header-height);
        bottom: 0;
        z-index: 999;
        width: 320px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .header-subtitle {
        display: none;
    }

    .overlay-controls {
        top: 8px;
        left: 10px;
        min-width: 170px;
        max-width: 205px;
        padding: 6px 7px;
    }

    .overlay-controls .filter-chip {
        font-size: 10px;
        padding: 2px 6px;
    }
}
