/* Japan Power Grid Map */
* { margin:0; padding:0; box-sizing:border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
    width: 360px;
    min-width: 360px;
    height: 100vh;
    background: #1a1a2e;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    z-index: 1000;
}

#sidebar h1 {
    font-size: 1.05rem;
    padding: 14px 16px;
    background: #16213e;
    border-bottom: 1px solid #0f3460;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
#sidebar h1 span.icon { font-size: 1.3rem; }

/* ── Tabs ── */
.tab-bar {
    display: flex;
    border-bottom: 2px solid #0f3460;
    flex-shrink: 0;
}
.tab-btn {
    flex: 1;
    padding: 10px 0;
    text-align: center;
    background: #16213e;
    color: #7f8c8d;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.15s;
}
.tab-btn:hover { color: #bbb; }
.tab-btn.active {
    color: #fff;
    background: #1a1a2e;
    border-bottom: 2px solid #e94560;
    margin-bottom: -2px;
}

.tab-panel {
    display: none;
    flex: 1;
    overflow-y: auto;
}
.tab-panel.active { display: flex; flex-direction: column; }

/* ── Region list ── */
.section { padding: 12px 16px; border-bottom: 1px solid #0f3460; }
.section h2 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #7f8c8d;
    margin-bottom: 8px;
}

.region-list { display: flex; flex-direction: column; gap: 3px; }

.region-btn {
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 5px;
    padding: 7px 10px;
    color: #e0e0e0;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
    transition: background 0.12s;
}
.region-btn:hover { background: #0f3460; }
.region-btn.active { background: #e94560; border-color: #e94560; color: #fff; }
.region-btn .count { font-size: 0.72rem; color: #7f8c8d; }
.region-btn.active .count { color: rgba(255,255,255,0.8); }

/* ── Layer toggles ── */
.layer-toggles { display: flex; flex-direction: column; gap: 4px; }
.layer-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    padding: 4px 0;
}
.layer-toggle input[type="checkbox"] {
    accent-color: #e94560;
    width: 15px;
    height: 15px;
    cursor: pointer;
}
.toggle-label { flex: 1; }
.inline-select {
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 4px;
    padding: 2px 6px;
    color: #e0e0e0;
    font-size: 0.75rem;
    cursor: pointer;
}

/* ── Voltage filter ── */
.filter-row {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}
.filter-row label { font-size: 0.8rem; color: #aaa; white-space: nowrap; }
.filter-row select {
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 4px;
    padding: 4px 8px;
    color: #e0e0e0;
    font-size: 0.82rem;
    flex: 1;
}

/* ── PF controls ── */
.pf-controls { display: flex; flex-direction: column; gap: 8px; }
.pf-controls label { font-size: 0.78rem; color: #aaa; }
.pf-controls select, .pf-controls input {
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 4px;
    padding: 6px 10px;
    color: #e0e0e0;
    font-size: 0.82rem;
    width: 100%;
}
.pf-controls select:focus, .pf-controls input:focus { outline:none; border-color:#e94560; }

.btn-primary {
    background: #e94560; color: #fff; border: none;
    border-radius: 6px; padding: 10px; font-size: 0.88rem;
    font-weight: 600; cursor: pointer; transition: background 0.12s;
}
.btn-primary:hover { background: #c53b52; }
.btn-primary:disabled { background: #555; cursor: not-allowed; }

.btn-secondary {
    background: #0f3460; color: #e0e0e0; border: 1px solid #0f3460;
    border-radius: 6px; padding: 8px; font-size: 0.78rem;
    cursor: pointer; transition: background 0.12s;
}
.btn-secondary:hover { background: #16213e; }

/* ── Results grid ── */
.result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
}
.result-item { background: #16213e; border-radius: 4px; padding: 7px; }
.result-item .label { font-size: 0.68rem; color: #7f8c8d; }
.result-item .value { font-size: 0.95rem; font-weight: 600; color: #e0e0e0; }
.result-item .value.success { color: #2ecc71; }
.result-item .value.fail { color: #e74c3c; }

/* ── Status bar ── */
#status-bar {
    padding: 8px 16px;
    font-size: 0.72rem;
    color: #7f8c8d;
    border-top: 1px solid #0f3460;
    flex-shrink: 0;
}

/* ── Spinner ── */
.spinner {
    display: inline-block; width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #e94560; border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 6px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Map ── */
#map { flex: 1; height: 100vh; }

/* ── Legend ── */
.legend {
    background: rgba(26,26,46,0.92); color: #e0e0e0;
    padding: 10px 14px; border-radius: 6px;
    font-size: 0.72rem; line-height: 1.5;
    backdrop-filter: blur(4px);
}
.legend h4 { font-size: 0.78rem; margin-bottom: 4px; color: #fff; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-color {
    width: 18px; height: 3px; border-radius: 2px; display: inline-block;
}

/* ── Download buttons ── */
.download-section { margin-top: auto; }
.download-btns { display: flex; flex-direction: column; gap: 4px; }
.btn-download {
    background: #0f3460; color: #e0e0e0; border: 1px solid #0f3460;
    border-radius: 5px; padding: 7px 10px; font-size: 0.8rem;
    cursor: pointer; transition: background 0.12s; text-align: left;
}
.btn-download:hover { background: #16213e; border-color: #e94560; }

/* ── Detail popup (generators & substations) ── */
.detail-popup { font-size: 0.78rem; line-height: 1.6; max-width: 320px; }
.detail-popup h3 { font-size: 0.92rem; margin-bottom: 4px; }
.detail-popup .popup-meta { color: #888; font-size: 0.72rem; margin-bottom: 4px; }
.detail-popup .popup-section { margin-top: 6px; }
.detail-popup .popup-section-title {
    font-size: 0.7rem; text-transform: uppercase;
    letter-spacing: 0.5px; color: #888; margin-bottom: 2px;
}
.detail-popup table { width: 100%; border-collapse: collapse; }
.detail-popup td { padding: 1px 4px; }
.detail-popup td:first-child { color: #666; white-space: nowrap; }
.detail-popup td:last-child { text-align: right; font-weight: 500; }

/* ── Area tab ── */
.area-desc {
    font-size: 0.78rem;
    color: #bbb;
    line-height: 1.5;
    margin-bottom: 4px;
}

/* ── Loading overlay (shared) ── */
.pf-info {
    font-size: 0.78rem;
    color: #bbb;
    padding: 6px 0;
    line-height: 1.4;
}

/* ── Plant divIcon reset ── */
.leaflet-marker-icon.leaflet-div-icon {
    background: none;
    border: none;
}

/* ── Flow arrow markers ── */
.flow-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    line-height: 0;
}
.flow-arrow svg {
    display: block;
}
