* { 
    box-sizing: border-box; 
}

body { 
    margin: 0; 
    padding: 0; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
    display: flex; 
    flex-direction: column; 
    height: 100vh; 
}

#header {
    padding: 12px 20px;
    background: #68246d;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    z-index: 1000;
}

.title {
    font-size: 16px;
    margin: 0;
    font-weight: 600;
}

#header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

#recenter-map {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 6px;
    border: 1px solid rgba(255, 255, 255, 0.65);
    border-radius: 4px;
    color: #ffffff;
    background: transparent;
    cursor: pointer;
}

#recenter-map svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
}

#recenter-map:hover,
#recenter-map:focus-visible {
    color: #68246d;
    background: #ffffff;
}

#classified-toggle {
    padding: 7px 10px;
    border: 1px solid rgba(255, 255, 255, 0.65);
    border-radius: 4px;
    color: #ffffff;
    background: transparent;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

#classified-toggle[aria-pressed="true"] {
    color: #68246d;
    background: #ffffff;
}

#weight-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-left: auto;
    margin-right: 18px;
}

#risk-settings {
    position: relative;
}

#risk-settings summary {
    cursor: pointer;
    padding: 7px 10px;
    border: 1px solid rgba(255, 255, 255, 0.65);
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.settings-panel {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1100;
    display: grid;
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    gap: 12px;
    width: min(680px, calc(100vw - 24px));
    padding: 14px;
    color: #202124;
    background: #ffffff;
    border: 1px solid #d5d9df;
    border-radius: 6px;
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.22);
    max-height: calc(100vh - 82px);
    overflow-y: auto;
}

.settings-panel #weight-controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(112px, 1fr));
    gap: 12px;
    width: auto;
    margin: 0;
}

#weight-settings {
    grid-column: 1 / -1;
}

.settings-panel .weight-control label {
    color: #202124;
}

.settings-panel .weight-control input {
    accent-color: #68246d;
}

.settings-panel .weight-control input::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: #c7ccd3;
}

.settings-panel .weight-control input::-webkit-slider-thumb {
    margin-top: -5px;
}

.settings-panel .weight-control input::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: #c7ccd3;
}

.settings-panel .weight-control input::-moz-range-progress {
    height: 4px;
    border-radius: 2px;
    background: #68246d;
}

.settings-panel fieldset {
    min-width: 0;
    margin: 0;
    padding: 8px;
    border: 1px solid #d5d9df;
}

.settings-panel legend {
    padding: 0 4px;
    font-size: 11px;
    font-weight: 700;
}

.settings-panel label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 7px 0;
    font-size: 11px;
}

.settings-panel input {
    width: 64px;
    padding: 3px 4px;
    border: 1px solid #aeb6c1;
    border-radius: 3px;
    color: #202124;
    background: #ffffff;
}

.weight-control {
    width: 112px;
}

.weight-control label {
    display: flex;
    justify-content: space-between;
    color: #ffffff;
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 3px;
}

.weight-control output {
    font-variant-numeric: tabular-nums;
}

.weight-control input {
    display: block;
    width: 100%;
    accent-color: #ffffff;
}

.badge-container {
    display: flex;
    gap: 10px;
    align-items: center;
    background: transparent;
}

.badge {
    color: white;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

button.badge {
    border: 0;
    cursor: pointer;
    font: inherit;
}

button.badge[aria-pressed="false"] {
    opacity: 0.55;
}

.badge-blue {
    background: #0078d4;
}

.badge-red {
    background: #e74c3c;
}

.badge-black {
    background: #000000;
    color: #ffffff;
}

#map { 
    flex: 1; 
    width: 100%; 
}

.substation-marker {
    fill-opacity: 0.8;
    stroke: #ffffff;
    stroke-width: 1.5px;
    stroke-opacity: 1;
}

.live-power-cut-icon-wrapper {
    background: transparent;
    border: none;
    box-shadow: none;
}

.live-power-cut-icon-wrapper svg {
    display: block;
    width: 22px;
    height: 22px;
    filter: none;
}

.substation-marker-csv-icon svg {
    display: block;
    width: 18px;
    height: 18px;
    filter: none;
}

.substation-marker-icon {
    background: transparent;
    border: none;
}

.substation-marker-icon svg {
    display: block;
    width: 18px;
    height: 18px;
}

.leaflet-popup-content-wrapper {
    border-radius: 8px;
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 14px 16px;
    width: auto !important;
    max-width: 680px;
    max-height: 75vh;
    overflow-y: auto; 
    overflow-x: hidden;  
}

.popup-content {
    font-family: inherit;
    width: 100%;
}

.popup-content h4 {
    margin: 0 0 10px 0;
    font-size: 15px;
}

.popup-content div {
    font-size: 12px;
    line-height: 1.4;
    margin-bottom: 4px;
}

.popup-substation h4 {
    color: #68246d;
}

.popup-substation-layout {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: start;
}

.popup-substation-main {
    flex: 0 0 190px;
    min-width: 170px;
}


.popup-csv-section {
    flex: 1 1 360px;
    margin-top: 0;
    padding: 8px 10px;
    border-left: 4px solid var(--risk-color);
    background: var(--risk-background);
    border-radius: 6px;
    min-width: 0;
}

.popup-csv-title {
    font-weight: 700;
    color: var(--risk-color);
    margin-bottom: 6px;
    font-size: 13px;
}


.popup-csv-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px 12px;
}

.popup-csv-item {
    min-width: 0;
    margin-bottom: 0;
    font-size: 11px;
    line-height: 1.35;
    overflow-wrap: anywhere;
    word-break: break-word;  
}

@media (max-width: 640px) {
    #header {
        flex-wrap: wrap;
        gap: 8px;
    }

    #header-actions {
        margin-left: auto;
    }

    #weight-controls {
        order: 3;
        width: 100%;
        margin: 4px 0 0;
        gap: 8px;
    }

    #risk-settings {
        order: 2;
    }

    .settings-panel {
        grid-template-columns: 1fr;
    }

    .settings-panel #weight-controls {
        grid-template-columns: repeat(2, minmax(112px, 1fr));
    }

    .weight-control {
        flex: 1 1 25%;
        width: auto;
    }

    .popup-substation-main,
    .popup-csv-section {
        flex: 1 1 100%;
    }

    .popup-csv-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.popup-powercut {
    border-left: 4px solid #000000;
    padding-left: 10px;
}

.popup-powercut h4 {
    color: #000000;
}

.popup-csv-scroll .leaflet-popup-content {
    max-height: 280px; 
}


.popup-powercut {
    border-left: 4px solid #000000;
    padding-left: 12px;
}

.popup-powercut h4 {
    color: #000000;
    margin: 0 0 8px 0;
    white-space: nowrap; 
}


.pc-row {
    display: flex;
    flex-direction: row;
    gap: 3px;
    margin-bottom: 5px;
    white-space: nowrap;
}
