/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: #001f4e;
    background: #e9ebee;
}

[hidden] { display: none !important; }

/* ===== App Layout ===== */
#app { position: relative; height: 100vh; width: 100%; }
#map { position: absolute; inset: 0; }

/* ===== Step Indicator ===== */
#step-indicator {
    position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
    z-index: 10; display: flex; align-items: center;
    background: rgba(255,255,255,0.95); padding: 8px 16px;
    border-radius: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.step { display: flex; align-items: center; gap: 6px; opacity: 0.4; transition: opacity 0.3s; }
.step.active { opacity: 1; }
.step.completed { opacity: 0.7; }
.step-number {
    display: inline-flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; border-radius: 50%;
    background: #001f4e; color: white; font-size: 0.75rem; font-weight: 700;
}
.step.active .step-number { background: #2962ff; }
.step-label { font-size: 0.8rem; font-weight: 500; }
.step-connector { width: 32px; height: 2px; background: #ccc; margin: 0 8px; }

/* ===== Search Bar ===== */
#search-container {
    position: absolute; top: 12px; left: 12px; z-index: 10; width: 380px;
}
#search-bar {
    display: flex; background: white; border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
#address-input {
    flex: 1; padding: 10px 12px; border: none; border-radius: 8px 0 0 8px;
    font-size: 0.95rem; outline: none;
}
#search-btn {
    padding: 10px 14px; border: none; background: #2962ff; color: white;
    border-radius: 0 8px 8px 0; cursor: pointer; font-size: 1rem;
}
#search-results {
    background: white; border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15); max-height: 240px; overflow-y: auto;
}
.search-result-item {
    padding: 10px 12px; cursor: pointer; border-bottom: 1px solid #f0f0f0; font-size: 0.9rem;
}
.search-result-item:hover { background: #f5f5f5; }

/* Control row: Sites + Filters toggle buttons */
#control-row { display: flex; gap: 6px; margin-top: 8px; }
.ctrl-btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 6px 12px; border: 1px solid #ddd;
    background: white; border-radius: 6px;
    font-size: 0.78rem; font-weight: 500; color: #444;
    cursor: pointer; white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    transition: all 0.15s ease;
    letter-spacing: 0.01em;
}
.ctrl-btn:hover {
    background: #f0f4ff; border-color: #b0b0b0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.ctrl-btn.active {
    background: #e8f0ff; border-color: #2962ff; color: #2962ff;
    box-shadow: 0 2px 6px rgba(41,98,255,0.15);
}
.ctrl-icon { font-size: 0.6rem; opacity: 0.5; }
.ctrl-btn.active .ctrl-icon { opacity: 0.8; color: #2962ff; }
.ctrl-chevron {
    font-size: 0.55rem; opacity: 0.4; margin-left: -1px;
    transition: transform 0.15s ease;
}
.ctrl-btn.active .ctrl-chevron {
    transform: rotate(180deg); opacity: 0.7;
}

/* Dropdown panels */
#preset-bar, #layer-panel {
    margin-top: 6px; padding: 10px 12px;
    background: white; border-radius: 8px;
    border: 1px solid #e8e8e8;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}
#preset-bar { display: flex; gap: 6px; flex-wrap: wrap; }

/* Override display when hidden — must beat ID+display rules above */
#preset-bar[hidden], #layer-panel[hidden] { display: none !important; }

/* Preset site buttons */
.preset-btn {
    padding: 5px 10px; background: #f8f8f8; border: 1px solid #e0e0e0;
    border-radius: 6px; font-size: 0.78rem; color: #444;
    cursor: pointer; white-space: nowrap;
    transition: all 0.12s ease;
}
.preset-btn:hover {
    background: #e8f0ff; border-color: #2962ff; color: #2962ff;
}

/* ===== Loading Overlay ===== */
#loading-overlay {
    position: absolute; inset: 0; z-index: 50;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,0.3); pointer-events: none;
}
.spinner {
    width: 36px; height: 36px; border: 4px solid #e0e0e0;
    border-top-color: #2962ff; border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Map Controls ===== */
#map-controls {
    position: absolute; bottom: 32px; left: 12px; z-index: 10;
    display: flex; gap: 8px;
}
#map-controls button {
    padding: 8px 14px; background: white; border: 1px solid #ccc;
    border-radius: 6px; cursor: pointer; font-size: 0.85rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
#map-controls button:hover { background: #f5f5f5; }

/* ===== Legend ===== */
#legend {
    position: absolute; bottom: 52px; right: 12px; z-index: 10;
    background: rgba(255,255,255,0.95); padding: 10px 14px;
    border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    font-size: 0.8rem; min-width: 160px;
    max-height: calc(100vh - 120px); overflow-y: auto;
}
#legend h4 { margin-bottom: 8px; font-size: 0.85rem; }
.legend-item { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.legend-line { width: 24px; height: 3px; border-radius: 2px; }
.legend-circle { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-circle.large { width: 14px; height: 14px; }
.legend-section-label {
    font-size: 0.7rem; font-weight: 600; color: #9e9e9e;
    text-transform: uppercase; letter-spacing: 0.6px;
    margin: 8px 0 4px;
}
.legend-section-label:first-of-type { margin-top: 0; }


/* ===== Layer Panel ===== */
#layer-panel { width: 220px; max-height: calc(100vh - 200px); overflow-y: auto; }
.toggle-section-label {
    font-size: 0.7rem; font-weight: 600; color: #9e9e9e;
    text-transform: uppercase; letter-spacing: 0.6px;
    margin: 8px 0 4px;
}
.toggle-section-label:first-child { margin-top: 0; }
.toggle-row {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 6px; font-size: 0.85rem; cursor: pointer;
}
.toggle-row input[type="checkbox"] { accent-color: #2962ff; }
.toggle-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}

/* ===== Right Panel (Calculator + Assumptions) ===== */
#right-panel {
    position: absolute; top: 60px; right: 12px; z-index: 10;
    width: 320px; max-height: calc(100vh - 80px); overflow-y: auto;
    background: rgba(255,255,255,0.95); border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.12); padding: 16px;
}
#calculator-panel h3 { font-size: 1rem; margin-bottom: 12px; color: #001f4e; }

#mw-range-display {
    text-align: center; font-size: 2rem; font-weight: 700; color: #2962ff;
    margin-bottom: 16px; padding: 12px; background: #e8f0ff; border-radius: 8px;
}
.mw-unit { font-size: 1rem; font-weight: 400; color: #666; }

.slider-group { margin-bottom: 14px; }
.slider-group label { display: block; font-size: 0.8rem; font-weight: 500; margin-bottom: 4px; color: #444; }
.slider-group input[type="range"] { width: 100%; accent-color: #2962ff; }
.slider-group span { display: block; text-align: right; font-size: 0.8rem; color: #666; }

#host-counts { margin-top: 12px; padding-top: 12px; border-top: 1px solid #eee; font-size: 0.85rem; }
#host-counts > div { margin-bottom: 4px; }
.count-label { color: #666; }

#show-chart-btn {
    margin-top: 12px; width: 100%; padding: 8px; background: #001f4e;
    color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
}

/* Assumptions */
#assumptions-panel { margin-top: 16px; border-top: 1px solid #eee; padding-top: 12px; }
#assumptions-panel summary { cursor: pointer; font-weight: 600; font-size: 0.85rem; color: #444; }
#assumptions-panel ul { margin-top: 8px; padding-left: 18px; font-size: 0.8rem; line-height: 1.5; color: #555; }
#assumptions-panel li { margin-bottom: 6px; }

/* ===== Disclaimer Banner (FR-15a) ===== */
#disclaimer-banner {
    position: absolute; bottom: 0; left: 0; right: 0; z-index: 20;
    display: flex; align-items: center; justify-content: center; gap: 12px;
    background: #e8f0ff; color: #003c71; padding: 10px 16px; font-size: 0.85rem;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
}
#disclaimer-banner a { color: #2962ff; font-weight: 600; }

/* ===== Settings Drawer ===== */
#settings-toggle {
    position: absolute; bottom: 52px; right: 12px; z-index: 10;
    width: 36px; height: 36px; border-radius: 50%; border: 1px solid #ccc;
    background: rgba(255,255,255,0.9); font-size: 1.2rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    opacity: 0.4; transition: opacity 0.2s;
}
#settings-toggle:hover { opacity: 1; }

#settings-drawer {
    position: absolute; top: 0; right: 0; bottom: 0; z-index: 60;
    width: 340px; background: white; box-shadow: -4px 0 16px rgba(0,0,0,0.15);
    overflow-y: auto; padding: 0;
}
.settings-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid #eee;
}
.settings-header h3 { font-size: 1.1rem; }
.settings-header button { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #999; }
.settings-section { padding: 16px 20px; border-bottom: 1px solid #f0f0f0; }
.settings-section h4 { font-size: 0.85rem; color: #999; margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.settings-section label { display: block; margin-bottom: 8px; font-size: 0.9rem; }
.settings-section input[type="number"] { width: 60px; padding: 4px 8px; border: 1px solid #ddd; border-radius: 4px; text-align: right; }

/* Category toggle rows */
.category-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
.toggle-switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0; background: #ccc; border-radius: 11px; cursor: pointer; transition: 0.2s;
}
.toggle-slider::before {
    content: ''; position: absolute; width: 16px; height: 16px;
    left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: #2962ff; }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Preset list in settings */
.preset-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 0.9rem; }
.preset-item button { background: none; border: none; color: #e74c3c; cursor: pointer; font-size: 0.85rem; }
.preset-add { display: flex; gap: 8px; margin-top: 8px; }
.preset-add input { flex: 1; padding: 6px 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 0.85rem; }
.preset-add button { padding: 6px 12px; background: #2962ff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }

/* ===== Chart Popup (lower-left) ===== */
#chart-popup {
    position: absolute; bottom: 48px; left: 12px; z-index: 30;
    width: 400px; max-height: calc(100vh - 100px); overflow-y: auto;
    background: rgba(255,255,255,0.96); border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15); padding: 16px 20px;
}
.chart-popup-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 12px;
}
.chart-popup-title { font-size: 1.1rem; font-weight: 700; color: #001f4e; }
.chart-popup-header button {
    background: none; border: none; font-size: 1.4rem; cursor: pointer;
    color: #97999b; line-height: 1;
}
.chart-popup-header button:hover { color: #001f4e; }
.chart-section-label {
    font-size: 0.8rem; font-weight: 600; color: #97999b;
    text-transform: uppercase; letter-spacing: 0.6px;
    margin: 12px 0 8px; padding-bottom: 4px;
    border-bottom: 1px solid #daddde;
}
.chart-section-label:first-of-type { margin-top: 0; }
.chart-row {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 8px; font-size: 0.95rem; color: #001f4e;
}
.chart-row.presigned { font-weight: 700; }
.chart-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.chart-dot.large { width: 15px; height: 15px; }
.chart-row-label { flex: 1; }
.chart-row-bar { height: 10px; border-radius: 5px; min-width: 2px; }
.chart-row-count { min-width: 48px; text-align: right; font-size: 0.95rem; color: #97999b; }
.chart-row.presigned .chart-row-count { color: #001f4e; }
.chart-total {
    margin-top: 12px; padding-top: 10px; border-top: 1px solid #daddde;
    font-size: 0.95rem; color: #97999b; text-align: right;
}

/* ===== Toast Notifications ===== */
#toast-container {
    position: fixed; top: 16px; right: 16px; z-index: 200;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    padding: 10px 16px; border-radius: 8px; font-size: 0.85rem;
    color: white; opacity: 0; transform: translateX(20px);
    transition: opacity 0.3s, transform 0.3s;
    max-width: 360px;
}
.toast.visible { opacity: 1; transform: translateX(0); }
.toast-error { background: #e74c3c; }
.toast-info { background: #2962ff; }

/* ===== Map Context Menu ===== */
.ctx-menu {
    position: absolute; z-index: 15;
    background: white; border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.18);
    min-width: 200px; overflow: hidden;
}
.ctx-menu-item {
    padding: 10px 14px; font-size: 0.88rem; cursor: pointer;
    color: #001f4e; white-space: nowrap;
}
.ctx-menu-item:hover { background: #e8f0ff; color: #2962ff; }

/* ===== Responsive (FR-26) ===== */
@media (max-width: 1024px) {
    #search-container { width: 300px; }
    #step-indicator { padding: 6px 10px; }
    .step-label { display: none; }
    .step-connector { width: 20px; }
    #right-panel { width: 280px; font-size: 0.85rem; }
    #mw-range-display { font-size: 1.6rem; }
    #layer-panel { width: 190px; }
}

@media (max-width: 768px) {
    #search-container { width: calc(100% - 24px); }
    #right-panel {
        position: fixed; bottom: 0; left: 0; right: 0; top: auto;
        width: 100%; max-height: 50vh; border-radius: 12px 12px 0 0;
    }
    #layer-panel { position: fixed; bottom: 0; left: 0; width: 100%; border-radius: 12px 12px 0 0; }
    #legend { bottom: auto; top: 60px; right: 12px; }
}

/* ===== Print (for canvas snapshot fallback) ===== */
@media print {
    #search-container, #map-controls, #settings-toggle, #layer-panel,
    #step-indicator, #right-panel, #disclaimer-banner { display: none !important; }
}
