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

:root {
    --bg: #1a1a2e;
    --bg-panel: #16213e;
    --bg-control: #0f3460;
    --text: #e6e6e6;
    --text-muted: #a0a0b8;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --buy-color: #2ecc71;     /* green = buying favored */
    --rent-color: #e74c3c;    /* red = renting favored */
    --neutral-color: #f1c40f; /* yellow = breakeven */
    --border: rgba(255,255,255,0.1);
    --radius: 8px;
    --transition: 0.2s ease;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

/* Dark theme for all native <select> dropdown menus */
select {
    background: var(--bg);
    color: var(--text);
}
select option {
    background: var(--bg);
    color: var(--text);
}

/* ── Header ───────────────────────────────────────────────── */
#header {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    height: 52px;
}

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

.header-left h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    white-space: nowrap;
}

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

/* ── City Tabs ────────────────────────────────────────────── */
#city-tabs {
    display: flex;
    gap: 4px;
}

.city-tab {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.city-tab:hover {
    color: var(--text);
    border-color: var(--accent);
}

.city-tab.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ── Search ───────────────────────────────────────────────── */
.search-container {
    position: relative;
}

#search-input {
    width: 220px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255,255,255,0.05);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
}

#search-input:focus {
    border-color: var(--accent);
}

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

/* ── Legend ────────────────────────────────────────────────── */
.legend {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
}

.legend-bar {
    width: 100px;
    height: 10px;
    border-radius: 5px;
    background: linear-gradient(to right,
        var(--rent-color),
        var(--neutral-color) 40%,
        var(--neutral-color) 60%,
        var(--buy-color)
    );
}

.legend-label {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Map ──────────────────────────────────────────────────── */
#map {
    position: fixed;
    top: 52px;
    left: 0; right: 0;
    bottom: 0;
}

/* Override Mapbox attribution */
.mapboxgl-ctrl-attrib { font-size: 10px !important; }

/* ── Controls (bottom bar) ────────────────────────────────── */
#controls {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 10;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    padding: 10px 16px;
    max-height: 40vh;
    overflow-y: auto;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

#play-btn {
    width: 32px; height: 32px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

#play-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
}

#play-btn.playing {
    background: var(--accent);
    border-color: var(--accent);
}

#year-label {
    font-size: 24px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-width: 55px;
    text-align: center;
}

#year-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: rgba(255,255,255,0.15);
    outline: none;
}

#year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid white;
}

#year-slider::-moz-range-thumb {
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid white;
}

.param-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
}

.param {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.param label {
    font-weight: 600;
    white-space: nowrap;
}

.param select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
}

/* ── Inflation toggle ────────────────────────────────────── */
.toggle-param label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.toggle-param input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
    cursor: pointer;
}

#inflation-label {
    font-size: 11px;
    white-space: nowrap;
}

/* ── Advanced toggle ────────────────────────────────────── */
.advanced-toggle-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 11px;
    padding: 3px 10px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}
.advanced-toggle-btn:hover { color: var(--text); border-color: var(--text-muted); }
.advanced-toggle-btn.active { color: var(--accent); border-color: var(--accent); }

.advanced-row {
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.advanced-row .param { font-size: 11px; }
.advanced-row .param select { font-size: 11px; padding: 3px 6px; }
.advanced-row.hidden { display: none !important; }

/* ── Search autocomplete ────────────────────────────────── */
.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 240px;
    overflow-y: auto;
    z-index: 30;
}

.search-results.hidden { display: none; }

.search-result-item {
    padding: 8px 12px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: background var(--transition);
}

.search-result-item:hover {
    background: rgba(255,255,255,0.08);
}

.search-result-item .result-addr {
    font-weight: 600;
    color: var(--text);
}

.search-result-item .result-meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* ── Property detail in panel ────────────────────────────── */
.property-header {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.property-header .property-addr {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.property-attrs {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.property-attr {
    background: rgba(255,255,255,0.06);
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.property-attr strong {
    color: var(--text);
}

.luxury-badge {
    background: linear-gradient(135deg, #d4af37, #f5d060);
    color: #1a1a2e;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.amenity-badge {
    background: rgba(96, 165, 250, 0.15);
    color: #60a5fa;
    font-weight: 600;
}

/* ── Risk indicators (flood, fire) ──────────────────────── */
.risk-indicators {
    margin: 8px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.risk-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 11px;
}

.risk-item.risk-high {
    background: rgba(231, 76, 60, 0.15);
    border-left: 3px solid #e74c3c;
}

.risk-item.risk-med {
    background: rgba(241, 196, 15, 0.12);
    border-left: 3px solid #f1c40f;
}

.risk-item.risk-low {
    background: rgba(96, 165, 250, 0.08);
    border-left: 3px solid #60a5fa;
}

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

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

/* ── Unit type selector (multi-unit buildings) ───────────── */
.unit-type-selector {
    margin: 6px 0 8px;
}
.unit-type-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.unit-type-label {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}
.unit-type-select {
    background: var(--bg-control);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 12px;
    cursor: pointer;
}
.unit-type-inferred {
    font-size: 11px;
    color: var(--accent);
    margin-left: 4px;
}

/* ── Violation indicator ─────────────────────────────────── */
.violation-indicator {
    margin-top: 10px;
    padding: 8px;
    border-radius: 6px;
    font-size: 12px;
    background: rgba(255,255,255,0.03);
}

.violation-indicator .viol-title {
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.violation-indicator .viol-count {
    font-size: 18px;
    font-weight: 700;
}

.violation-indicator .viol-trend {
    font-size: 11px;
    color: var(--text-muted);
}

.viol-high { color: var(--rent-color); }
.viol-medium { color: var(--neutral-color); }
.viol-low { color: var(--buy-color); }

/* ── Unit Listings Table ─────────────────────────────────── */
.unit-listings {
    margin-top: 10px;
    border-top: 1px solid var(--border);
    padding-top: 8px;
}

.unit-listings-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.unit-listings-table {
    font-size: 11px;
}

.unit-row {
    display: flex;
    align-items: center;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.unit-row.unit-header {
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
    margin-bottom: 2px;
}

.unit-col-price { flex: 0 0 70px; }
.unit-col-beds  { flex: 0 0 35px; text-align: center; }
.unit-col-baths { flex: 0 0 35px; text-align: center; }
.unit-col-sqft  { flex: 0 0 50px; text-align: right; }
.unit-col-type  { flex: 1 1 auto; padding: 0 6px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unit-col-date  { flex: 0 0 60px; text-align: right; color: var(--text-muted); }

.unit-row:not(.unit-header) .unit-col-price {
    color: var(--accent);
    font-weight: 600;
}

.unit-row.unit-more {
    color: var(--text-muted);
    font-style: italic;
    justify-content: center;
    padding: 4px 0;
    border-bottom: none;
}

/* ── Tooltip ──────────────────────────────────────────────── */
#tooltip {
    position: fixed;
    z-index: 20;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    pointer-events: none;
    max-width: 280px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    font-size: 13px;
    line-height: 1.5;
}

#tooltip.hidden { display: none; }

#tooltip .zip-code {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 4px;
}

#tooltip .metric {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

#tooltip .metric-label { color: var(--text-muted); }
#tooltip .metric-value { font-weight: 600; }

.tooltip-verdict {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    font-weight: 700;
    text-align: center;
}

.verdict-buy { color: var(--buy-color); }
.verdict-rent { color: var(--rent-color); }
.verdict-tossup { color: var(--neutral-color); }

/* ── Detail Panel ─────────────────────────────────────────── */
#detail-panel {
    position: fixed;
    bottom: var(--controls-height, 90px); right: 0;
    z-index: 15;
    width: 380px;
    max-height: calc(100vh - 52px - var(--controls-height, 90px));
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    border-top: 1px solid var(--border);
    border-radius: var(--radius) 0 0 0;
    overflow-y: auto;
    padding: 16px;
    transition: transform 0.3s ease;
}

#detail-panel.hidden {
    transform: translateX(100%);
}

#close-detail {
    position: absolute;
    top: 8px; right: 8px;
    width: 28px; height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#close-detail:hover {
    background: var(--accent);
}

#detail-content h2 {
    font-size: 16px;
    margin-bottom: 12px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.detail-item {
    padding: 8px;
    background: rgba(255,255,255,0.03);
    border-radius: 6px;
}

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

.detail-item .value {
    font-size: 18px;
    font-weight: 700;
}

.detail-item .value.buy { color: var(--buy-color); }
.detail-item .value.rent { color: var(--rent-color); }

.detail-note {
    grid-column: 1 / -1;
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
    padding: 2px 0 4px;
    line-height: 1.4;
}

.info-tip {
    display: inline-block;
    width: 14px;
    height: 14px;
    line-height: 14px;
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    border: 1px solid var(--text-muted);
    border-radius: 50%;
    cursor: help;
    vertical-align: middle;
    margin-left: 3px;
}

.breakeven-chart {
    width: 100%;
    height: 120px;
    margin-top: 12px;
    border-radius: 6px;
    background: rgba(255,255,255,0.03);
}

/* ── Loading ──────────────────────────────────────────────── */
#loading {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    gap: 16px;
    transition: opacity 0.3s;
}

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

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

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

/* ── Responsive ───────────────────────────────────────────── */
/* ── About link ──────────────────────────────────────────── */
.about-link {
    font-size: 11px;
    color: var(--text-muted);
    text-decoration: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color var(--transition);
}

.about-link:hover {
    color: var(--text);
}

/* ── About modal ─────────────────────────────────────────── */
#about-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
}

#about-modal.hidden { display: none; }

.about-content {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    max-width: 520px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.about-content h2 {
    font-size: 18px;
    margin-bottom: 12px;
}

.about-content p,
.about-content ul {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.about-content ul {
    padding-left: 18px;
}

.about-content li { margin-bottom: 4px; }

.about-content .close-about {
    position: absolute;
    top: 12px; right: 12px;
    width: 28px; height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.about-content .close-about:hover {
    background: var(--accent);
}

/* ── Data source label ───────────────────────────────────── */
.data-source {
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.6;
    text-align: center;
    padding: 4px 0 0;
}

/* ── Browse toggle ───────────────────────────────────────── */
.browse-toggle {
    padding: 6px 16px;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    letter-spacing: 0.3px;
}

.browse-toggle:hover {
    background: rgba(99, 102, 241, 0.3);
    color: white;
    border-color: var(--accent);
}

.browse-toggle.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ── Browse panel ───────────────────────────────────────── */
#browse-panel {
    position: fixed;
    top: 52px; left: 0;
    z-index: 15;
    width: 340px;
    max-height: calc(100vh - 52px - var(--controls-height, 90px));
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    border-radius: 0 0 var(--radius) 0;
    overflow-y: auto;
    padding: 16px;
    transition: transform 0.3s ease;
}

#browse-panel.hidden {
    transform: translateX(-100%);
}

#browse-panel h3 {
    font-size: 15px;
    margin-bottom: 12px;
    padding-right: 28px;
}

#close-browse {
    position: absolute;
    top: 8px; right: 8px;
    width: 28px; height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#close-browse:hover {
    background: var(--accent);
}

.browse-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.browse-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.browse-field label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.browse-field select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
}

.browse-search-wrap {
    position: relative;
}

#neighborhood-search {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: rgba(255,255,255,0.05);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
}

#neighborhood-search:focus {
    border-color: var(--accent);
}

#neighborhood-search::placeholder {
    color: var(--text-muted);
}

.neighborhood-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 30;
}

.neighborhood-results.hidden { display: none; }

.neighborhood-item {
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: background var(--transition);
}

.neighborhood-item:hover {
    background: rgba(255,255,255,0.08);
}

.neighborhood-item .nb-name {
    font-weight: 600;
    color: var(--text);
}

.neighborhood-item .nb-meta {
    font-size: 10px;
    color: var(--text-muted);
}

.browse-placeholder {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 20px 0;
}

#browse-results .detail-grid {
    grid-template-columns: 1fr 1fr;
}

#browse-results .browse-header {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 4px;
}

#browse-results .browse-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* ── Cost Breakdown ─────────────────────────────────────── */
.cost-breakdown {
    margin-top: 12px;
    padding: 10px 12px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.cost-breakdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.cost-breakdown-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}
.cost-year-select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 11px;
    cursor: pointer;
}

.cost-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
    margin-top: 4px;
}

.cost-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    font-size: 12px;
}

.cost-row.cost-total {
    border-top: 1px solid var(--border);
    margin-top: 4px;
    padding-top: 4px;
    font-weight: 700;
}

.cost-label {
    min-width: 100px;
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 11px;
}

.cost-bar-wrap {
    flex: 1;
    height: 8px;
    background: rgba(255,255,255,0.05);
    border-radius: 4px;
    overflow: hidden;
}

.cost-bar {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.cost-amount {
    min-width: 65px;
    text-align: right;
    font-weight: 600;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}


/* ── Responsive ──────────────────────────────────────────── */

/* ── Tablet (≤768px) ────────────────────────────────────── */
@media (max-width: 768px) {
    /* Safe area insets for notched devices */
    #header {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    #controls {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    /* Header: wrap into two rows */
    #header {
        flex-wrap: wrap;
        height: auto;
        padding-top: 8px;
        padding-bottom: 8px;
        gap: 6px;
    }
    .header-left {
        flex: 1 1 100%;
        justify-content: space-between;
    }
    .header-left h1 { font-size: 15px; }
    .header-right {
        flex: 1 1 100%;
        justify-content: flex-start;
        gap: 10px;
        flex-wrap: wrap;
    }
    .header-right .legend { display: none; }
    .header-right .search-container { flex: 1; min-width: 0; }
    #search-input { width: 100%; }

    /* Map: account for taller header */
    #map { top: 86px; }

    /* Controls: reduce gap */
    .param-row { gap: 6px 10px; }

    /* Touch targets: ensure minimum 44px height */
    .param select, .browse-field select, .cost-year-select {
        min-height: 36px;
        font-size: 13px;
    }

    /* Browse panel: full width */
    #browse-panel {
        width: 100%;
        border-radius: 0;
        top: 86px;
    }

    /* Detail panel: full width, bottom sheet style */
    #detail-panel {
        width: 100%;
        bottom: var(--controls-height, 90px);
        max-height: 50vh;
        border-radius: var(--radius) var(--radius) 0 0;
        border-left: none;
    }

    /* Keep detail grid at 2 columns on tablet */
    .detail-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ── Phone (≤480px) ─────────────────────────────────────── */
@media (max-width: 480px) {
    /* Header: compact single row */
    #header {
        padding: 6px 10px;
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        gap: 4px;
    }
    .header-left {
        flex: 1 1 100%;
        gap: 8px;
    }
    .header-left h1 { font-size: 14px; }
    .city-tab { padding: 5px 10px; font-size: 11px; }
    .header-right {
        flex: 1 1 100%;
        gap: 6px;
    }
    /* Hide less essential header items on phone */
    .header-right .browse-toggle,
    .header-right .view-toggle,
    .header-right .about-link { display: none; }
    #search-input {
        font-size: 16px; /* prevent iOS zoom on focus */
        padding: 8px 10px;
        min-height: 40px;
    }

    /* Map: taller header */
    #map { top: 80px; }

    /* Controls: 2-column grid for params */
    #controls {
        padding: 8px 10px;
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
    .slider-row { gap: 8px; margin-bottom: 6px; }
    #year-label { font-size: 20px; min-width: 48px; }
    #play-btn { width: 36px; height: 36px; }

    /* Year slider: larger thumb for touch */
    #year-slider::-webkit-slider-thumb {
        width: 24px; height: 24px;
    }
    #year-slider::-moz-range-thumb {
        width: 24px; height: 24px;
    }

    /* Params: 2-column grid */
    .param-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .param {
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
    }
    .param label { font-size: 11px; }
    .param select {
        width: 100%;
        min-height: 40px;
        font-size: 14px; /* prevent iOS zoom */
        padding: 6px 8px;
    }
    .toggle-param { flex-direction: row; align-items: center; }
    .toggle-param input[type="checkbox"] { width: 18px; height: 18px; }
    .advanced-toggle-btn { min-height: 36px; font-size: 12px; padding: 6px 12px; }

    /* Advanced row: 2-column grid */
    .advanced-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .advanced-row .param { font-size: 11px; }
    .advanced-row .param select {
        font-size: 13px;
        min-height: 38px;
        padding: 4px 6px;
    }

    /* Data source footer: smaller */
    .data-source { font-size: 8px; padding: 2px 0 0; }

    /* Detail panel: taller, single column */
    #detail-panel {
        max-height: 60vh;
        padding: 12px;
    }
    .detail-grid { grid-template-columns: 1fr; }
    .detail-item .value { font-size: 16px; }
    #detail-content h2 { font-size: 14px; }

    /* Browse panel */
    #browse-panel {
        top: 80px;
        padding: 12px;
    }
    #browse-panel h3 { font-size: 14px; }
    .browse-field select { min-height: 40px; font-size: 14px; }
    #neighborhood-search {
        font-size: 16px; /* prevent iOS zoom */
        min-height: 40px;
        padding: 8px 10px;
    }

    /* Tooltip: wider, constrained to viewport */
    #tooltip {
        max-width: min(280px, calc(100vw - 24px));
        font-size: 12px;
        padding: 8px 10px;
    }
    #tooltip .zip-code { font-size: 13px; }

    /* Cost breakdown: tighter */
    .cost-breakdown { padding: 8px; }
    .cost-label { min-width: 80px; font-size: 10px; }
    .cost-amount { min-width: 55px; font-size: 10px; }

    /* Compare section */
    .comparison-table { font-size: 11px; }
    .comparison-table th,
    .comparison-table td { padding: 3px 4px; }

    /* Property attrs wrap better */
    .property-attr { font-size: 10px; padding: 2px 6px; }
    .risk-item { font-size: 10px; padding: 4px 8px; }

    /* About modal */
    .about-content { padding: 16px; }
    .about-content h2 { font-size: 16px; }
    .about-content p, .about-content ul { font-size: 12px; }
}

/* ── Small phone (≤360px) ───────────────────────────────── */
@media (max-width: 360px) {
    .header-left h1 { font-size: 13px; }
    .city-tab { padding: 4px 8px; font-size: 10px; }

    /* Single-column params on very small screens */
    .param-row {
        grid-template-columns: 1fr;
    }
    .advanced-row {
        grid-template-columns: 1fr;
    }

    #year-label { font-size: 18px; }

    .detail-item .value { font-size: 14px; }
    .detail-item .label { font-size: 9px; }

    .cost-label { min-width: 70px; }
    .cost-amount { min-width: 50px; }
}

/* ── View Toggle (ZIP / Neighborhood) ─────────────────────── */

.view-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.view-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.view-btn:not(:last-child) { border-right: 1px solid var(--border); }
.view-btn:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.view-btn.active { background: var(--accent); color: #fff; }

/* ── Compare Section ───────────────────────────────────────── */

.detail-header-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    justify-content: space-between;
}

.detail-header-row h2 { margin: 0; flex: 1; }

.detail-sub {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 400;
}

.compare-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}
.compare-btn:hover { background: var(--accent-hover); }
.compare-btn.active { background: #51cf66; }

.compare-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.compare-section.hidden { display: none; }

.compare-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.compare-search-wrap {
    position: relative;
    margin-bottom: 8px;
}

.compare-search-input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: rgba(255,255,255,0.05);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
}
.compare-search-input:focus { border-color: var(--accent); }
.compare-search-input::placeholder { color: var(--text-muted); }

.compare-search-results {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    max-height: 200px;
    overflow-y: auto;
    z-index: 30;
}
.compare-search-results.hidden { display: none; }

.compare-search-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: background var(--transition);
}
.compare-search-item:hover { background: rgba(255,255,255,0.08); }

.compare-item-label { font-weight: 600; color: var(--text); }
.compare-item-metro { font-size: 10px; color: var(--text-muted); }

.compare-scenario {
    display: flex;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.compare-radio {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-muted);
    cursor: pointer;
}
.compare-radio input[type="radio"] {
    accent-color: var(--accent);
    cursor: pointer;
}

.compare-result-panel { margin-top: 8px; }

.compare-verdict-summary {
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    margin-top: 8px;
    padding: 6px;
    background: rgba(255,255,255,0.03);
    border-radius: 4px;
}

.compare-no-data {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    padding: 12px 0;
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.comparison-table th,
.comparison-table td {
    padding: 5px 8px;
    text-align: right;
    border-bottom: 1px solid var(--border);
}

.comparison-table th:first-child,
.comparison-table td:first-child {
    text-align: left;
    color: var(--text-muted);
    font-weight: 400;
}

.comparison-table thead th {
    font-size: 12px;
    font-weight: 600;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
}

.compare-zip {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-muted);
}

/* ── Rent Regulation Badges ───────────────────────────────── */

.reg-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius);
    margin: 6px 0;
    font-size: 12px;
    flex-wrap: wrap;
}

.reg-stabilized { background: rgba(81, 207, 102, 0.12); border: 1px solid rgba(81, 207, 102, 0.3); }
.reg-controlled { background: rgba(64, 192, 240, 0.12); border: 1px solid rgba(64, 192, 240, 0.3); }
.reg-subsidized { background: rgba(230, 126, 34, 0.12); border: 1px solid rgba(230, 126, 34, 0.3); }

.reg-badge {
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.reg-stabilized .reg-badge { background: rgba(81, 207, 102, 0.2); color: #51cf66; }
.reg-controlled .reg-badge { background: rgba(64, 192, 240, 0.2); color: #40c0f0; }
.reg-subsidized .reg-badge { background: rgba(230, 126, 34, 0.2); color: #e67e22; }

.reg-programs {
    color: var(--text-muted);
    font-size: 11px;
}

.reg-rent {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
}

/* ── Disabled property type options ──────────────────────── */
#property-type option:disabled {
    color: #555;
}

/* ── Rental availability warning ─────────────────────────── */
.rental-warning {
    background: rgba(231, 76, 60, 0.15);
    border-left: 3px solid #e74c3c;
    padding: 6px 10px;
    margin: 8px 0;
    font-size: 11px;
    color: var(--text-muted);
}
