/* --- GLOBAL THEME --- */
:root {
    --primary: #16a34a;
    --bg: #ffffff;
    --surface: #f8fafc;
    --border: #e2e8f0;
    --text-main: #0f172a;
    --text-sub: #64748b;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --accent-bus: #ec4899;
    --accent-school: #f59e0b;
    --accent-park: #10b981;
    --accent-cafe: #8b5cf6;
}

[data-theme="dark"] {
    --primary: #22c55e;
    --bg: #0a0a0a;
    --surface: #151515;
    --border: #2a2a2a;
    --text-main: #e2e8f0;
    --text-sub: #94a3b8;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.6);
}
[data-theme="dark"] body,
[data-theme="dark"] html { background: #0a0a0a; }
[data-theme="dark"] .tab-bar { background: rgba(10, 10, 10, 0.45); }
[data-theme="dark"] .tab-btn.active { background: var(--primary); }
[data-theme="dark"] #search-input { color: var(--text-main); }
[data-theme="dark"] #search-input::placeholder { color: var(--text-sub); }
[data-theme="dark"] .tools-panel { background: rgba(10, 10, 10, 0.45); }
[data-theme="dark"] .legend-panel { background: rgba(10, 10, 10, 0.45); }
[data-theme="dark"] .legal-floating-panel { background: rgba(10, 10, 10, 0.45); }
[data-theme="dark"] .legal-retry-btn { background: var(--surface); color: var(--text-sub); }
[data-theme="dark"] .site-legal { background: var(--surface); }
[data-theme="dark"] .sa-floating-panel { background: rgba(10, 10, 10, 0.35); }
[data-theme="dark"] .sa-layer-sidebar { background: rgba(10, 10, 10, 0.35); }
[data-theme="dark"] .sa-hint-pill { background: rgba(34, 197, 94, 0.9); }
[data-theme="dark"] .sa-export-btn { box-shadow: 0 4px 16px rgba(34, 197, 94, 0.3); }
[data-theme="dark"] .sa-command-form input { background: var(--surface); color: var(--text-main); }
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    color: var(--text-main);
}
[data-theme="dark"] .sa-layer-actions button { background: var(--surface); color: var(--text-sub); }
[data-theme="dark"] .module-popup { background: rgba(10, 10, 10, 0.45); }
[data-theme="dark"] .gen-panel { background: rgba(10, 10, 10, 0.45); }
[data-theme="dark"] .gen-site-panel { background: rgba(10, 10, 10, 0.45); }
[data-theme="dark"] #search-results { background: var(--bg); }
[data-theme="dark"] #search-results [style*="color"] { color: var(--text-sub) !important; }
[data-theme="dark"] .search-item:hover { background: var(--surface); }
[data-theme="dark"] .control-cell { background: var(--surface); }
[data-theme="dark"] input[type=range]::-webkit-slider-runnable-track { background: #2a2a2a; }
[data-theme="dark"] #map {
    background: #000000;
}
/* Dark-mode map inversion — applied via .dark-map-filter class
   so it can be removed when ortho/satellite is active */
[data-theme="dark"] #map .maplibregl-canvas.dark-map-filter {
    filter: invert(92%) hue-rotate(180deg) brightness(0.65) saturate(0.8) contrast(1.1);
}
[data-theme="dark"] .maplibregl-ctrl-attrib,
[data-theme="dark"] .maplibregl-ctrl-attrib a {
    background: rgba(0, 0, 0, 0.8);
    color: #f8fafc;
}
[data-theme="dark"] .maplibregl-popup-content {
    background: var(--surface);
    color: var(--text-main);
}
[data-theme="dark"] .maplibregl-popup-tip {
    border-top-color: var(--surface);
    border-bottom-color: var(--surface);
}
[data-theme="dark"] .search-container .fa-search,
[data-theme="dark"] .legal-floating-head .fa-times {
    color: var(--text-sub) !important;
}
[data-theme="dark"] .tab-btn:not(.active),
[data-theme="dark"] .tool-btn,
[data-theme="dark"] .legend-title,
[data-theme="dark"] .legend-item,
[data-theme="dark"] .sa-floating-panel,
[data-theme="dark"] .sa-layer-sidebar,
[data-theme="dark"] .sa-layer-name,
[data-theme="dark"] .sa-radius-section h4 {
    color: var(--text-main);
}
[data-theme="dark"] .tool-btn:hover,
[data-theme="dark"] .sa-layer-actions button:hover,
[data-theme="dark"] .g-btn:hover,
[data-theme="dark"] .metrics-toggle:hover {
    background: #1f1f1f;
    color: var(--text-main);
}
[data-theme="dark"] .tool-btn.active,
[data-theme="dark"] .opt-item.active,
[data-theme="dark"] .right-variant-card.active {
    background: rgba(34, 197, 94, 0.15);
    color: #93c5fd;
}
[data-theme="dark"] .mp-btn,
[data-theme="dark"] .metrics-toggle,
[data-theme="dark"] .poi-item,
[data-theme="dark"] .results-list,
[data-theme="dark"] .right-variant-card,
[data-theme="dark"] .gen-card,
[data-theme="dark"] .gen-gallery-close,
[data-theme="dark"] .site-legal,
[data-theme="dark"] .sa-layer-actions button {
    background: var(--surface);
    color: var(--text-main);
}
[data-theme="dark"] .right-variants-list,
[data-theme="dark"] .right-variant-thumb,
[data-theme="dark"] .gen-card-thumb,
[data-theme="dark"] .thumb svg,
[data-theme="dark"] .report-header,
[data-theme="dark"] .graph-subcontrols,
[data-theme="dark"] .graph-chip {
    background: #111111;
}
[data-theme="dark"] .gen-overlay,
[data-theme="dark"] .gen-gallery {
    background: rgba(0, 0, 0, 0.94);
}
[data-theme="dark"] .gen-overlay-text,
[data-theme="dark"] .gen-gallery-title,
[data-theme="dark"] .gen-card-title,
[data-theme="dark"] .right-variant-title,
[data-theme="dark"] .report-title,
[data-theme="dark"] .report-value {
    color: var(--text-main);
}
[data-theme="dark"] .gen-timer,
[data-theme="dark"] .gen-gallery-sub,
[data-theme="dark"] .right-variant-sub,
[data-theme="dark"] .report-label {
    color: var(--text-sub);
}
[data-theme="dark"] .color-dot,
[data-theme="dark"] .legal-dot {
    filter: invert(92%) hue-rotate(180deg) brightness(0.65) saturate(0.8) contrast(1.1);
}
[data-theme="dark"] .graph-chip.active {
    background: rgba(34, 197, 94, 0.15);
    color: #93c5fd;
    border-color: var(--primary);
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: 'Inter', sans-serif;
    overflow: hidden;
    color: var(--text-main);
    background: var(--bg);
}

#map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    z-index: 1;
}

/* --- 3D MODULE POPUP --- */
.module-popup {
    position: absolute;
    z-index: 1000;
    background: rgba(225, 228, 235, 0.8);
    backdrop-filter: blur(12px);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    padding: 10px;
    display: none;
    width: 120px;
    transform: translate(-50%, -100%);
    margin-top: -15px;
}

.module-popup::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    margin-left: -6px;
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent;
}

.module-popup-header {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-sub);
    margin-bottom: 8px;
    text-align: center;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mp-btn-row {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
}

.mp-btn {
    flex: 1;
    padding: 6px 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    color: var(--text-main);
    transition: 0.1s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.mp-btn:hover {
    background: var(--surface);
}

.mp-btn:active {
    background: #e2e8f0;
}

.mp-btn.danger {
    color: #ef4444;
    border-color: #fee2e2;
    background: #fef2f2;
    font-size: 11px;
}

.mp-btn.danger:hover {
    background: #fee2e2;
}

/* --- TAB NAVIGATION --- */
.tab-bar {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 100;
    display: flex;
    gap: 8px;
    background: rgba(255, 255, 255, 0.65);
    padding: 6px;
    border-radius: 50px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    backdrop-filter: blur(8px);
}

.tab-btn {
    border: none;
    background: transparent;
    padding: 10px 20px;
    border-radius: 40px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-sub);
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tab-btn.active {
    background: var(--text-main);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.tab-btn:hover:not(.active) {
    background: var(--surface);
}

/* --- MODERN SLIDERS --- */
input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
    margin: 10px 0;
}

input[type=range]:focus {
    outline: none;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: #e2e8f0;
    border-radius: 3px;
}

input[type=range]::-webkit-slider-thumb {
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: var(--bg);
    border: 2px solid var(--primary);
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

/* --- SHARED ELEMENTS --- */
.search-container {
    display: flex;
    align-items: center;
    padding: 4px 14px;
    margin-left: 4px;
    border-left: 1px solid var(--border);
}

#search-input {
    border: none;
    background: transparent;
    font-size: 14px;
    width: 100%;
    outline: none;
    color: #333;
    font-weight: 500;
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    font-size: 15px;
    color: var(--text-sub);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 4px;
    border-left: 1px solid var(--border);
    border-radius: 0 50px 50px 0;
    padding-left: 12px;
    transition: 0.2s;
}
.theme-toggle:hover { color: var(--primary); }

#search-results {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    width: 380px;
    background: white;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    max-height: 300px;
    overflow-y: auto;
    display: none;
    z-index: 51;
}

.search-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--surface);
    cursor: pointer;
    font-size: 13px;
}

.search-item:hover {
    background: var(--surface);
}

/* --- VIEW 1: ZONING UI --- */
#view-zoning {
    display: block;
}

.tools-panel {
    position: absolute;
    top: 100px;
    left: 24px;
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(12px);
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 200px;
    border: 1px solid var(--border);
    max-height: calc(100vh - 380px);
    overflow-y: auto;
}

.tool-btn {
    width: 100%;
    height: 38px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    color: #444;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    padding: 0 8px;
    text-align: left;
}

.tool-btn i {
    width: 24px;
    text-align: center;
    margin-right: 10px;
    font-size: 14px;
}

.tool-btn:hover {
    background: #f5f5f5;
    color: #000;
}

.tool-btn.active {
    background: rgba(22, 163, 74, 0.1);
    color: var(--primary);
}


.status-pill {
    position: absolute;
    bottom: 24px;
    right: 24px;
    background: #222;
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 11px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

/* --- VIEW 2: GENERATOR UI --- */
#view-generator {
    display: none;
}

/* --- Generator Site Data Panel (top-right) --- */
.gen-site-panel {
    position: absolute;
    top: 20px;
    right: 24px;
    width: 380px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;          /* Firefox */
    -ms-overflow-style: none;       /* IE/Edge */
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(12px);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    border: 1px solid var(--border);
    z-index: 50;
    transition: transform 0.3s ease;
}
.gen-site-panel.collapsed {
    transform: translateX(calc(100% + 24px));
}
.gen-site-panel::-webkit-scrollbar {
    display: none;                  /* Chrome/Safari */
}

/* Collapse handle — notched into the panel's left edge */
.gen-panel-collapse {
    position: absolute;
    top: 50%;
    right: 24px;
    transform: translateY(-50%);
    width: 20px;
    height: 56px;
    background: var(--primary);
    border: none;
    border-radius: 8px 0 0 8px;
    box-shadow: -3px 0 10px rgba(0, 0, 0, 0.18);
    z-index: 52;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    font-size: 11px;
    transition: right 0.3s ease, background 0.2s;
}
.gen-panel-collapse:hover {
    filter: brightness(1.12);
}
.gen-panel-collapse i {
    transition: transform 0.3s ease;
}
.gen-panel-collapse.panel-open {
    right: 440px;
}
.gen-panel-collapse.panel-open i {
    transform: rotate(180deg);
}

.gen-site-panel .control-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.gen-site-panel .control-cell {
    border-radius: 10px;
    padding: 6px 8px;
    text-align: center;
}

.gen-site-panel .analysis-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    margin-top: 12px;
}

/* --- METRICS PANEL --- */
.metrics-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 330px;
    background: var(--bg);
    z-index: 1010;
    border-left: 1px solid var(--border);
    display: flex;
    /* Flex but hidden when empty or non-gen tab */
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -4px 0 25px rgba(0, 0, 0, 0.1);
    border-radius: 0;
}

.metrics-panel.collapsed {
    transform: translateX(100%);
}

.metrics-toggle {
    position: absolute;
    top: 50%;
    left: -24px;
    transform: translateY(-50%);
    width: 24px;
    height: 48px;
    background: white;
    border: 1px solid var(--border);
    border-right: none;
    border-radius: 8px 0 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.05);
    color: var(--text-sub);
    transition: background 0.2s;
}

.metrics-toggle:hover {
    background: #f8fafc;
}

.metrics-toggle i {
    transition: transform 0.3s ease;
}

.metrics-panel.collapsed .metrics-toggle i {
    transform: rotate(180deg);
}

.metrics-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--primary);
}

.metrics-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.metric-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.metric-label {
    color: var(--text-sub);
    font-weight: 600;
}

.metric-val {
    font-weight: 700;
    color: var(--text-main);
    font-size: 13px;
}

.metrics-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* --- RIGHT SIDEBAR VARIANTS LIST --- */
.right-variants-list {
    flex: 1;
    overflow-y: auto;
    border-top: 1px dashed var(--border);
    display: flex;
    flex-direction: column;
    background: #f8fafc;
}

.right-variants-title {
    padding: 12px 16px 8px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-sub);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.right-variant-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #e2e8f0;
    background: white;
    transition: background 0.2s;
}

.right-variant-card:hover {
    background: #f1f5f9;
}

.right-variant-card.active {
    background: rgba(22, 163, 74, 0.1);
    border-left: 4px solid var(--primary);
    padding-left: 12px;
}

.right-variant-thumb {
    width: 50px;
    height: 50px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.right-variant-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.right-variant-title {
    font-size: 13px;
    font-weight: 700;
    color: #1e293b;
}

.right-variant-sub {
    font-size: 11px;
    color: #64748b;
}

/* --- GENERATOR OVERLAY & GALLERY --- */
.gen-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.gen-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.gen-spinner {
    width: 56px;
    height: 56px;
    border: 4px solid rgba(34, 197, 94, 0.15);
    border-top-color: #22c55e;
    border-radius: 50%;
    animation: genSpin 0.8s linear infinite;
}

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

.gen-overlay-text {
    color: #1e293b;
    font-size: 15px;
    font-weight: 600;
    margin-top: 16px;
    letter-spacing: 0.5px;
}

.gen-progress-wrap {
    width: 280px;
    margin-top: 20px;
}

.gen-progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(34, 197, 94, 0.12);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.gen-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: -40%;
    width: 40%;
    height: 100%;
    background: linear-gradient(90deg, transparent, #22c55e, transparent);
    border-radius: 3px;
    animation: genProgressScan 1.5s ease-in-out infinite;
}

@keyframes genProgressScan {
    0% {
        left: -40%;
    }

    100% {
        left: 100%;
    }
}

.gen-timer {
    color: #64748b;
    font-size: 13px;
    margin-top: 10px;
    font-variant-numeric: tabular-nums;
}

.gen-gallery {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(248, 250, 252, 0.95);
    backdrop-filter: blur(16px);
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 60px 40px 40px;
    overflow-y: auto;
}

.gen-gallery.active {
    display: flex;
}

.gen-gallery-title {
    color: #0f172a;
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 8px;
}

.gen-gallery-sub {
    color: #64748b;
    font-size: 14px;
    margin-bottom: 32px;
}

.gen-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 24px;
    width: 100%;
    max-width: 1100px;
}

.gen-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}

.gen-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    border-color: #cbd5e1;
}

.gen-card-thumb {
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.gen-card-thumb svg {
    width: 100px;
    height: 100px;
}

.gen-card-body {
    padding: 16px;
}

.gen-card-title {
    color: #1e293b;
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 12px;
}

.gen-card-metrics {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.gen-metric-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f1f5f9;
    color: #475569;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
}

.gen-metric-chip .chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
}

.gen-gallery-close {
    position: fixed;
    top: 20px;
    right: 28px;
    z-index: 9999;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    color: #64748b;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    transition: all 0.2s;
}

.gen-gallery-close.active {
    display: flex;
}

.gen-gallery-close:hover {
    background: #f8fafc;
    color: #0f172a;
    transform: scale(1.05);
}

.gen-panel {
    position: absolute;
    top: 100px;
    left: 20px;
    width: 340px;
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(12px);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 10;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    max-height: 80vh;
    overflow: hidden;
}

.gen-akpt-values {
    display: none !important;
}

#view-generator>.gen-panel>.fa-drafting-compass,
#view-generator>.gen-panel>h2,
#view-generator>.gen-panel>p {
    display: none;
}

.gen-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.gen-header h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.gen-header h2::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
}

.gen-controls {
    padding: 16px;
    overflow-y: auto;
    scrollbar-width: none;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-sub);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.analysis-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
    display: none;
}

.analysis-card.visible {
    display: block;
}

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

.poi-item {
    background: white;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.poi-icon {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.poi-count {
    font-size: 14px;
    font-weight: 700;
}

.poi-lbl {
    font-size: 10px;
    color: var(--text-sub);
}

select {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 13px;
    outline: none;
}

.val-display {
    float: right;
    color: var(--primary);
    font-weight: 700;
    font-size: 12px;
}

.btn-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.g-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    background: var(--surface);
    color: var(--text-main);
    transition: 0.2s;
}

.g-btn:hover {
    background: #e2e8f0;
}

.g-btn.primary {
    background: var(--primary);
    color: white;
    border: none;
    width: 100%;
    margin-top: 12px;
}

.g-btn.primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.g-btn.active {
    background: #333;
    color: white;
}

.graph-subcontrols {
    display: none;
    gap: 6px;
    margin-top: 6px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(248, 250, 252, 0.92);
}

.graph-subcontrols.visible {
    display: flex;
}

.graph-chip {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: var(--text-sub);
    font-size: 10px;
    font-weight: 800;
    cursor: pointer;
}

.graph-chip.active {
    border-color: var(--primary);
    background: rgba(22, 163, 74, 0.1);
    color: var(--primary);
}

/* Generator Results List */
.results-list {
    margin-top: 8px;
    display: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 250px;
    overflow-y: auto;
    background: #fff;
}

.results-list.open {
    display: block;
}

.opt-item {
    padding: 10px;
    border-bottom: 1px solid var(--surface);
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: 0.1s;
}

.opt-item:hover {
    background: var(--surface);
}

.opt-item.active {
    background: rgba(22, 163, 74, 0.1);
    border-left: 3px solid var(--primary);
}

.thumb svg {
    width: 48px;
    height: 48px;
    background: #f1f5f9;
    border-radius: 6px;
    padding: 2px;
}

.opt-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
}

.opt-title {
    font-weight: 700;
    color: var(--text-main);
}

.opt-meta {
    color: var(--text-sub);
    font-size: 11px;
    line-height: 1.4;
}

/* --- POPUP (AKPT STYLE RESTORED & FIXED) --- */
.maplibregl-popup-content {
    border-radius: 12px;
    padding: 0;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    width: 280px;
    max-height: 400px;
    display: flex;
    flex-direction: column;
}

.report-header {
    background: #f8f9fa;
    padding: 12px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.report-title {
    font-weight: 700;
    font-size: 13px;
    color: #333;
}

.report-code {
    background: #16a34a;
    color: white;
    padding: 3px 7px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
}

.report-body {
    padding: 12px;
    overflow-y: auto;
    flex-grow: 1;
}

.report-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 12px;
    border-bottom: 1px dashed #eee;
    padding-bottom: 4px;
}

.report-row:last-child {
    border-bottom: none;
}

.report-label {
    color: #666;
    font-weight: 500;
}

.report-value {
    font-weight: 600;
    color: #222;
    max-width: 60%;
    text-align: right;
}

.measure-cursor {
    cursor: crosshair !important;
}

/* --- COMPARISON SLIDER STYLES --- */
.compare-container {
    position: relative;
    width: 100%;
    height: 300px;
    /* Fixed height for stability */
    overflow: hidden;
    border-radius: 8px;
    cursor: ew-resize;
}

.compare-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Ensures both images align perfectly */
}

#img-after {
    z-index: 2;
    clip-path: inset(0 50% 0 0);
    /* Starts halfway clipped */
}

.slider-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    background: white;
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass through to the container */
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.slider-button {
    position: absolute;
    top: 50%;
    left: -14px;
    /* Center the 28px button */
    width: 28px;
    height: 28px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    color: #333;
    font-size: 12px;
}

.compare-label {
    position: absolute;
    top: 10px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 10px;
    border-radius: 4px;
    z-index: 5;
    font-weight: bold;
    pointer-events: none;
}

/* Hidden input range that covers the whole area for dragging */
/* SHARED SLIDER LOGIC (Sidebar & Full Screen) */
#compare-range,
#fs-range {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    /* Make it invisible */
    z-index: 20;
    /* Sit on top of everything */
    margin: 0;
    cursor: ew-resize;
}

/* --- FULL SCREEN MODAL --- */
.fs-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.95);
    /* Dark overlay */
    z-index: 9999;
    display: none;
    /* Hidden by default */
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.fs-content {
    width: 90%;
    height: 85%;
    /* Large viewport */
    max-width: 1600px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    font-size: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: 0.2s;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Animation */
.fs-modal.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* --- VIEW 4: SITE ANALYSIS UI --- */
#view-siteanalysis {
    display: none;
}

/* Bottom row: floating panel + export button side-by-side */
.sa-bottom-row {
    position: absolute;
    bottom: 32px;
    left: 24px;
    z-index: 50;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    max-width: calc(100vw - 48px);
}

.sa-floating-panel {
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(12px);
    border-radius: 14px;
    padding: 16px 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
}

.sa-floating-panel h3 {
    margin: 0 0 12px;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sa-floating-panel p {
    margin: 0 0 10px;
    font-size: 11px;
    color: var(--text-sub);
}

.sa-command-form {
    display: flex;
    gap: 8px;
}

/* Fullscreen loading overlay — no card, just blur + spinner + text */
#global-loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}
.global-loading-card {
    display: contents;
}
.global-loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.12);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: global-loading-spin 0.8s linear infinite;
}
@keyframes global-loading-spin {
    to { transform: rotate(360deg); }
}
.global-loading-text {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    letter-spacing: 0.3px;
}

/* Pill bar for SA category buttons */
.sa-pill-bar {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: thin;
    padding-bottom: 2px;
}
.sa-pill-bar::-webkit-scrollbar { height: 4px; }
.sa-pill-bar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Export button — same size as sa-pill, green, outside the black panel, aligned with pill row */
.sa-export-detached {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: 999px;
    background: #22c55e;
    color: white;
    border: none;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(34, 197, 94, 0.3);
    font-family: inherit;
    white-space: nowrap;
    flex-shrink: 0;
    align-self: flex-end;
    margin-bottom: 18px;
    transition: filter 0.15s, transform 0.1s;
}
.sa-export-detached:hover { filter: brightness(1.1); }
.sa-export-detached:active { transform: scale(0.97); }
.sa-export-detached:disabled { opacity: 0.55; cursor: not-allowed; }
.sa-pill {
    --pill-c: #64748b;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: var(--surface);
    color: var(--text-main);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, border-color 0.15s, color 0.15s;
    font-family: inherit;
    outline: none;
    white-space: nowrap;
}
.sa-pill:hover {
    background: color-mix(in srgb, var(--pill-c) 15%, var(--surface));
    border-color: var(--pill-c);
    color: var(--pill-c);
}
.sa-pill:active {
    transform: scale(0.96);
}
.sa-pill.loading {
    pointer-events: none;
    position: relative;
    filter: blur(1.5px);
    opacity: 0.7;
}
.sa-pill.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    margin-top: -7px;
    margin-left: -7px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: var(--pill-c);
    border-radius: 50%;
    animation: sa-pill-spin 0.7s linear infinite;
    filter: blur(0);
    z-index: 2;
}
@keyframes sa-pill-spin {
    to { transform: rotate(360deg); }
}
.sa-pill.active {
    background: var(--pill-c);
    color: white;
    border-color: var(--pill-c);
}
.sa-pill i {
    font-size: 10px;
}

.sa-command-form input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 13px;
    outline: none;
    background: var(--surface);
    font-family: inherit;
}

.sa-command-form input:focus {
    border-color: var(--primary);
}

.sa-command-form button {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sa-command-form button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sa-layer-sidebar {
    position: absolute;
    top: 146px;
    left: 24px;
    width: 280px;
    max-height: calc(100vh - 146px - 200px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(12px);
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border);
    z-index: 50;
}
.sa-layer-sidebar::-webkit-scrollbar { width: 5px; }
.sa-layer-sidebar::-webkit-scrollbar-track { background: transparent; }
.sa-layer-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }
.sa-layer-sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

.sa-layer-sidebar h3 {
    margin: 0 0 12px;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sa-layer-item {
    background: var(--surface);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
}

.sa-layer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.sa-layer-name {
    font-size: 12px;
    font-weight: 600;
    text-transform: capitalize;
}

.sa-layer-actions {
    display: flex;
    gap: 4px;
}

.sa-layer-actions button {
    width: 26px;
    height: 26px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-sub);
}

.sa-layer-actions button:hover {
    background: #f1f5f9;
    color: var(--text-main);
}

.sa-layer-actions button.danger {
    color: #ef4444;
    border-color: #fee2e2;
}

.sa-layer-actions button.danger:hover {
    background: #fef2f2;
}

.sa-layer-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sa-layer-controls label {
    font-size: 10px;
    color: var(--text-sub);
    font-weight: 600;
}

.sa-layer-controls input[type=color] {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    padding: 0;
    cursor: pointer;
    background: none;
    -webkit-appearance: none;
    appearance: none;
}
.sa-layer-controls input[type=color]::-webkit-color-swatch-wrapper {
    padding: 0;
    border-radius: 50%;
}
.sa-layer-controls input[type=color]::-webkit-color-swatch {
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
}
.sa-layer-controls input[type=color]::-moz-color-swatch {
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
}

.sa-ctrl-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sa-radius-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.sa-radius-section h4 {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 4px;
}

.sa-export-btn {
    position: absolute;
    bottom: 260px;
    left: 24px;
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 16px rgba(22, 163, 74, 0.3);
}

.sa-export-btn:hover {
    filter: brightness(1.1);
}

.sa-export-btn:disabled {
    opacity: 0.5;
}

.sa-hint-pill {
    position: absolute;
    top: 90px;
    left: 24px;
    background: rgba(22, 163, 74, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    z-index: 50;
    pointer-events: none;
}

@media (max-width: 760px) {
    .sa-bottom-row {
        left: 12px;
        right: 12px;
        flex-wrap: wrap;
    }
    .sa-floating-panel { flex: 1; min-width: 0; }
    .sa-layer-sidebar {
        left: 12px;
        right: 12px;
        width: auto;
    }

    .sa-hint-pill,
    .sa-export-btn {
        left: 12px;
    }

    .sa-layer-sidebar {
        max-height: 34vh;
    }
}

/* --- LEGEND PANEL --- */
.legend-panel {
    position: absolute;
    bottom: 24px;
    left: 24px;
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(12px);
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    z-index: 10;
    font-size: 12px;
    max-width: 200px;
    border: 1px solid var(--border);
}

.legend-title {
    font-weight: 700;
    margin-bottom: 10px;
    color: #333;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    color: #555;
}

.color-dot {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    margin-right: 8px;
    border: 1px solid #ccc;
    flex-shrink: 0;
}

/* --- AKPT LEGAL FLOATING PANEL (top-right) --- */
.legal-floating-panel {
    position: absolute;
    top: 56px;
    right: 24px;
    width: 360px;
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    z-index: 12;
    padding: 12px;
    display: none;
}
.legal-floating-panel.visible { display: block; }
#legal-floating {
    top: 20px;
    left: 380px;
    right: auto;
    width: 360px;
    max-height: calc(100vh - 48px);
    overflow: auto;
}
.legal-floating-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.legal-floating-title {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-main);
    text-transform: uppercase;
}
.legal-retry-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 6px;
    padding: 5px 8px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-sub);
    cursor: pointer;
}
.legal-retry-btn:hover {
    color: var(--primary);
    border-color: #bbf7d0;
    background: rgba(22, 163, 74, 0.08);
}
.site-legal {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
}
.site-legal-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 10px;
}
.site-area-value {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-main);
}
.site-area-label {
    font-size: 10px;
    color: var(--text-sub);
    text-transform: uppercase;
    font-weight: 700;
}
.legal-status {
    font-size: 11px;
    color: var(--text-sub);
    text-align: right;
    line-height: 1.35;
}
.legal-row {
    display: grid;
    grid-template-columns: 10px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 7px 0;
    border-top: 1px solid var(--surface);
    font-size: 11px;
}
.legal-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.12);
}
.legal-main { min-width: 0; }
.legal-title {
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.legal-sub {
    color: var(--text-sub);
    margin-top: 2px;
}
.legal-value {
    font-weight: 800;
    color: var(--primary);
    text-align: right;
}
.legal-value-label {
    display: block;
    margin-top: 1px;
    color: var(--text-sub);
    font-size: 8px;
    font-weight: 800;
    text-transform: uppercase;
}
.legal-layer-heading {
    margin-top: 9px;
    padding-top: 9px;
    border-top: 1px solid var(--border);
    color: var(--text-main);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
}
.planning-controls {
    margin-top: 10px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-bottom: 6px;
}
.planning-controls-title {
    font-size: 10px;
    font-weight: 800;
    color: var(--text-main);
    text-transform: uppercase;
    margin-bottom: 6px;
}
.control-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.control-cell {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 7px;
    padding: 7px;
}
.control-label {
    font-size: 9px;
    font-weight: 800;
    color: var(--text-sub);
    text-transform: uppercase;
}
.control-value {
    font-size: 12px;
    font-weight: 800;
    color: var(--text-main);
    margin-top: 2px;
}
.control-note {
    margin-top: 8px;
    font-size: 10px;
    line-height: 1.35;
    color: var(--text-sub);
}
.compliance-ok { color: #059669; font-weight: 800; }
.compliance-warn { color: #b45309; font-weight: 800; }
.compliance-bad { color: #dc2626; font-weight: 800; }

/* --- Unified gen-panel typography --- */
.gp-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-sub);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
}
.gp-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-sub);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    display: block;
    margin-bottom: 3px;
}
.gp-value {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 2px;
}
.gp-row {
    font-size: 10px;
}
.gp-input {
    width: 100%;
    background: var(--surface-card, var(--surface));
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 7px;
    font-size: 11px;
    color: var(--text-main);
    font-weight: 600;
    outline: none;
    cursor: pointer;
    font-family: inherit;
}
.gp-pill-row {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.gp-toggle-pill {
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    font-family: inherit;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.15s;
    outline: none;
    white-space: nowrap;
}
.gp-toggle-pill:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.gp-toggle-pill.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
/* Section-scoped pill colors */
#gen-analysis-body .gp-toggle-pill.active {
    background: #d946ef;
    border-color: #d946ef;
}
#gen-analysis-body .gp-toggle-pill:hover {
    border-color: #d946ef;
    color: #d946ef;
}
#gen-tuning-body .gp-toggle-pill.active {
    background: #06b6d4;
    border-color: #06b6d4;
}
#gen-tuning-body .gp-toggle-pill:hover {
    border-color: #06b6d4;
    color: #06b6d4;
}
#gen-tuning-body input[type=range]::-webkit-slider-thumb {
    border-color: #06b6d4;
}
#gen-tuning-body input[type=range]::-webkit-slider-runnable-track {
    background: rgba(6,182,212,0.2);
}
.gp-pill-input {
    width: 52px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    font-family: inherit;
    border: 1px solid #06b6d4;
    background: #06b6d4;
    color: #fff;
    text-align: center;
    outline: none;
    -moz-appearance: textfield;
}
.gp-pill-input::-webkit-outer-spin-button,
.gp-pill-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.gp-pill-input:focus {
    box-shadow: 0 0 0 2px rgba(6,182,212,0.2);
}

/* ===================================================================
   RESPONSIVE DESIGN
   =================================================================== */

/* --- ALL SCREENS ≤1024px: tools move to bottom bar --- */
@media (max-width: 1024px) {
    /* Tab bar: tighter */
    .tab-bar {
        top: 8px;
        left: 8px;
        right: 8px;
        padding: 4px;
        gap: 3px;
    }
    .tab-btn {
        padding: 8px 12px;
        font-size: 11px;
        gap: 5px;
    }
    #search-input { width: 100px; font-size: 12px; }

    /* Tools → horizontal bottom bar, icons only */
    .tools-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        flex-direction: row;
        justify-content: center;
        flex-wrap: nowrap;
        border-radius: 0;
        padding: 6px 10px;
        gap: 2px;
        z-index: 100;
        overflow: visible;
    }
    .tool-btn {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
        height: 38px;
        padding: 0;
        font-size: 0;          /* hide text */
        white-space: nowrap;
        justify-content: center;
    }
    .tool-btn i {
        font-size: 15px;
        margin-right: 0;
    }

    /* Legend: above bottom bar */
    .legend-panel {
        bottom: 54px;
        left: 10px;
    }

    /* Right-side panels: narrower */
    .gen-site-panel { right: 10px; width: 320px; }
    .legal-floating-panel { right: 10px; width: 300px; }
    #legal-floating { left: 240px; width: 300px; }
    .gen-panel { left: 10px; width: 300px; }
    .metrics-panel { width: 280px; }
    .status-pill { bottom: 58px; right: 10px; }
    .sa-bottom-row { left: 10px; right: 10px; }
    .sa-floating-panel { flex: 1; min-width: 0; }
    .sa-export-btn { bottom: 62px; }
}

/* --- MOBILE: ≤768px --- */
@media (max-width: 768px) {
    /* Tab bar: icon-only */
    .tab-bar {
        top: 6px;
        left: 6px;
        right: 6px;
        padding: 3px;
        gap: 2px;
        border-radius: 14px;
    }
    .tab-btn {
        padding: 8px 10px;
        font-size: 0;
        gap: 0;
        border-radius: 12px;
    }
    .tab-btn i { font-size: 15px; }
    .search-container { flex: 1; padding: 4px 8px; margin-left: 2px; }
    #search-input { width: 100%; font-size: 13px; }
    #search-results {
        top: 50px; left: 6px; right: 6px;
        width: auto; transform: none;
    }
    .theme-toggle { width: 32px; height: 32px; padding-left: 8px; margin-left: 2px; }

    /* Legend: compact, above bottom bar */
    .legend-panel {
        bottom: 50px;
        left: 6px;
        padding: 8px 10px;
        max-width: 130px;
        font-size: 10px;
        border-radius: 8px;
    }
    .legend-title { font-size: 10px; margin-bottom: 6px; }
    .legend-item { margin-bottom: 3px; font-size: 10px; }
    .color-dot { width: 10px; height: 10px; margin-right: 5px; }

    /* Info panels → bottom sheets (not top overlays) */
    .gen-site-panel,
    .legal-floating-panel,
    #legal-floating {
        top: auto;
        bottom: 50px;
        left: 6px;
        right: 6px;
        width: auto;
        max-height: 40vh;
        overflow-y: auto;
        border-radius: 12px 12px 0 0;
    }
    /* Keep the AKPT click panel (zoning-report-panel) at top-right on mobile too */
    #zoning-report-panel.legal-floating-panel {
        top: 48px;
        bottom: auto;
        max-height: 45vh;
        overflow-y: auto;
        border-radius: 10px;
    }

    .gen-panel {
        top: auto;
        bottom: 50px;
        left: 6px;
        right: 6px;
        width: auto;
        max-height: 40vh;
        border-radius: 12px 12px 0 0;
    }

    /* Metrics: bottom sheet */
    .metrics-panel {
        top: auto; bottom: 0; left: 0; right: 0;
        width: 100%; max-height: 50vh;
        border-radius: 16px 16px 0 0;
        border-left: none;
        border-top: 1px solid var(--border);
    }
    .metrics-toggle {
        top: -20px; left: 50%; transform: translateX(-50%);
        width: 48px; height: 20px;
        border-radius: 8px 8px 0 0;
        border: 1px solid var(--border); border-bottom: none;
    }
    .metrics-toggle i { transform: rotate(90deg); }
    .metrics-panel.collapsed .metrics-toggle i { transform: rotate(-90deg); }

    .status-pill { bottom: 50px; right: 6px; font-size: 10px; padding: 6px 12px; }

    /* Site analysis */
    .sa-bottom-row { left: 6px; right: 6px; flex-wrap: wrap; }
    .sa-floating-panel { flex: 1; min-width: 0; }
    .sa-layer-sidebar { left: 6px; right: 6px; width: auto; max-height: 30vh; }
    .sa-hint-pill { left: 6px; top: 54px; }
    .sa-export-btn { left: 6px; bottom: 56px; }

    .module-popup { width: 100px; }
    .gen-overlay-text { font-size: 14px; }
    .gen-gallery-close { top: 10px; right: 10px; }
}

/* --- SMALL PHONE: ≤480px --- */
@media (max-width: 480px) {
    .tab-bar { top: 4px; left: 4px; right: 4px; gap: 1px; padding: 2px; }
    .tab-btn { padding: 6px 8px; }
    .tab-btn i { font-size: 13px; }

    .tools-panel { padding: 5px 6px; }
    .tool-btn { height: 34px; }
    .tool-btn i { font-size: 14px; }

    .legend-panel {
        bottom: 46px; max-width: 110px;
        padding: 6px 8px; font-size: 9px;
    }
    .legend-title { font-size: 9px; }
    .color-dot { width: 8px; height: 8px; }

    .gen-site-panel, .legal-floating-panel, #legal-floating, .gen-panel {
        max-height: 38vh;
        font-size: 11px;
    }
    .control-grid { grid-template-columns: 1fr 1fr; gap: 4px; }
    .gen-site-panel .control-grid { grid-template-columns: 1fr 1fr; }
}

/* ==========================================================================
   PROXIMITY ANALYSIS STYLES (OSM SURROUNDINGS)
   ========================================================================== */
.proximity-list::-webkit-scrollbar {
    width: 4px;
}
.proximity-list::-webkit-scrollbar-track {
    background: transparent;
}
.proximity-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.proximity-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
}

.proximity-card:hover {
    border-color: #d946ef;
    background: rgba(217, 70, 239, 0.03);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .proximity-card:hover {
    background: rgba(217, 70, 239, 0.05);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
}

.proximity-card.active-hover {
    border-color: #d946ef !important;
    background: rgba(217, 70, 239, 0.06) !important;
    box-shadow: 0 0 0 1px rgba(217, 70, 239, 0.2);
}

.proximity-card-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-width: 75%;
    overflow: hidden;
}

.proximity-card-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.proximity-card-sub {
    font-size: 9px;
    color: var(--text-sub);
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.proximity-card-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    flex-shrink: 0;
}

.proximity-dist-val {
    font-size: 11px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.proximity-dist-lbl {
    font-size: 8px;
    font-weight: 600;
    color: var(--text-sub);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* --- ZONE HEIGHT LEGEND --- */
#zone-legend {
    position: absolute;
    bottom: 24px;
    left: 24px;
    z-index: 100;
    display: none;
    flex-direction: column;
    gap: 6px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    min-width: 0;
}

[data-theme="dark"] #zone-legend {
    background: rgba(10, 10, 10, 0.92);
}

.zone-legend-title {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-sub);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    text-align: center;
}

.zone-legend-bar {
    display: flex;
    gap: 0;
    border-radius: 5px;
    overflow: hidden;
}

.zone-legend-item {
    width: 24px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.zone-legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 8px;
    font-weight: 600;
    color: var(--text-sub);
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

/* --- Phase 3: Interactive Mouse Transform Handles --- */
.handle-center {
    width: 28px;
    height: 28px;
    background: rgba(34, 197, 94, 0.2);
    border: 2px solid #22c55e;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #22c55e;
    font-size: 11px;
    cursor: move;
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.4);
    transition: transform 0.2s, background-color 0.2s;
    z-index: 100;
}
.handle-center:hover {
    transform: scale(1.15);
    background: rgba(34, 197, 94, 0.4);
}

.handle-corner {
    width: 12px;
    height: 12px;
    background: #0ea5e9;
    border: 2px solid #ffffff;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(14, 165, 233, 0.5);
    transition: transform 0.2s, background-color 0.2s;
    z-index: 99;
}
.handle-corner:hover {
    transform: scale(1.3);
    background: #38bdf8;
}

.handle-rotation {
    width: 22px;
    height: 22px;
    background: #f59e0b;
    border: 2px solid #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 9px;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
    transition: transform 0.2s, background-color 0.2s;
    z-index: 98;
}
.handle-rotation:hover {
    transform: scale(1.2);
    background: #fbbf24;
}
