:root {
    --navy: #0A2240;
    --orange: #FF9408;
    --bg: #f5f7fb;
    --card: #ffffff;
    --muted: #6b7280;
    --border: #e5e7eb;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial;
    background: var(--bg);
    color: #0b1220;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ---------- Layout shell ---------- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
}

main.container {
    padding-top: 16px;
    padding-bottom: 28px;
}

.topbar {
    background: var(--navy);
    color: #fff;
    padding: 14px 0;
    position: sticky;
    top: 0;
    z-index: 9999;
    /* keep above Leaflet */
}

/* ---------- Topbar layout (brand | home | search) ---------- */
/* FIXED: middle column is now 1fr so Home can be centred */
.topbar-grid {
    display: grid;
    grid-template-columns: auto 1fr minmax(280px, 460px);
    align-items: center;
    gap: 16px;
}

/* Center the Home button in the middle column */
.topbar-grid .home-btn {
    justify-self: center;
}

/* Keep search aligned right, but not stretching stupidly */
.topbar-grid .search {
    width: 100%;
    min-width: 0;      /* prevents overflow in grid */
    max-width: 460px;
    justify-self: end; /* keep it to the right edge */
}

.topbar-grid .search input {
    width: 100%;
}

.brand {
    font-weight: 800;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

.home-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.08);
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    line-height: 1;
    white-space: nowrap;
}

.home-btn:hover {
    background: rgba(255, 255, 255, 0.14);
}

/* Keep Leaflet elements under the navbar */
.leaflet-pane,
.leaflet-control,
.leaflet-top,
.leaflet-bottom {
    z-index: 400;
}

/* ---------- Search ---------- */
.search {
    position: relative;
    min-width: 0;
    max-width: 520px;
    width: 100%;
}

.search input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    outline: none;
}

.search input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

.search-results {
    display: none;
    position: absolute;
    top: 44px;
    left: 0;
    right: 0;
    background: #fff;
    color: #111;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.12);
}

.search-item {
    display: block;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.search-item:hover {
    background: #f3f4f6;
}

/* ---------- Main grid (map-first) ---------- */
.layout {
    display: grid;
    grid-template-columns: 3.2fr 1.4fr;
    gap: 16px;
    padding: 0 0 28px;
    align-items: stretch;
}

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 6px 18px rgba(10, 34, 64, 0.06);
    overflow: hidden;
}

.card-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card h1 {
    margin: 0;
    font-size: 18px;
}

.card h2 {
    margin: 0;
    font-size: 16px;
}

.card p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 13px;
}

/* ---------- Map ---------- */
#map {
    position: relative;
    height: calc(100vh - 200px);
    min-height: 560px;
    width: 100%;
}

/* Legend overlay inside the map */
.map-legend {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 450;
    pointer-events: auto;
}

/* Slight translucency + blur so it sits nicely on the map */
.map-legend .legend-box {
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(6px);
}

/* ---------- Ranking tabs ---------- */
.rank-tabs {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: #fff;

    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}

.rank-tabs::-webkit-scrollbar {
    display: none;
}

.rank-tab {
    appearance: none;
    border: 1px solid var(--border);
    background: #fff;
    color: #111;
    font-size: 12px;
    font-weight: 700;
    padding: 7px 10px;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
}

.rank-tab:hover {
    background: #f8fafc;
}

.rank-tab.is-active {
    border-color: rgba(255, 148, 8, 0.45);
    background: rgba(255, 148, 8, 0.12);
}

/* ---------- Rankings list ---------- */
.rankings {
    max-height: calc(100vh - 200px);
    overflow: auto;
}

.rank-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.rank-row:hover {
    background: #f8fafc;
}

.rank-left {
    display: flex;
    gap: 10px;
    align-items: center;
}

.rank-num {
    width: 28px;
    height: 28px;
    border-radius: 10px;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    color: #1f2937;
}

.rank-name {
    font-weight: 650;
}

.rank-right {
    text-align: right;
}

.rank-price {
    font-weight: 750;
}

.rank-change {
    font-size: 12px;
    color: var(--muted);
}

/* ---------- Legend (compact + collapsible) ---------- */
.legend-box {
    display: inline-block;
    text-align: left;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 10px;
    box-shadow: 0 6px 16px rgba(10, 34, 64, 0.06);
    min-width: 170px;
}

.legend-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: transparent;
    border: 0;
    padding: 0;
    cursor: pointer;
    font-weight: 800;
    color: #111;
    font-size: 12px;
}

.legend-caret {
    transition: transform 0.15s ease;
    color: var(--muted);
    font-weight: 900;
}

.legend-box.is-collapsed .legend-body {
    display: none;
}

.legend-box:not(.is-collapsed) .legend-caret {
    transform: rotate(180deg);
}

.legend-body {
    margin-top: 8px;
}

.legend-sub {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

.legend-grid {
    margin-top: 8px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    line-height: 1.1;
}

.legend-swatch {
    width: 18px;
    height: 10px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    flex: 0 0 auto;
}

.legend-text {
    color: #111;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ---------- Area intro ---------- */
.area-intro {
    padding: 12px 16px 6px;
    border-bottom: 1px solid var(--border);
    background: #fbfcfe;
    color: #374151;
    font-size: 14px;
    line-height: 1.65;
}

.area-intro p {
    margin: 0 0 10px;
}

.area-intro p:last-child {
    margin-bottom: 0;
}

.area-intro strong {
    color: #0b1220;
}

/* ---------- Area page ---------- */
.area-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 14px 16px;
}

/* Area stats: 4 across on desktop, 2 on mobile */
.area-grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
}

.stat .label {
    font-size: 12px;
    color: var(--muted);
}

.stat .value {
    font-size: 22px;
    font-weight: 800;
    margin-top: 6px;
    color: #111;
}

.chart-wrap {
    padding: 0 16px 16px;
}

.neighbors {
    padding: 18px 16px 16px;
    border-top: 1px solid var(--border);
}

.neighbors-title {
    margin: 0 0 12px;
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 0.2px;
    color: #0b1220;
}

.neighbors-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.neighbor {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 10px;
    background: #fff;
}

.neighbor:hover {
    background: #f8fafc;
}

.neighbor-name {
    font-weight: 800;
    font-size: 13px;
}

.neighbor-meta {
    margin-top: 6px;
    font-size: 12px;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.neighbor-change {
    color: #111;
}

/* ---------- A–Z areas page (tidy) ---------- */
.az-wrap {
    padding: 14px 16px 16px;
}

.az-nav {
    position: sticky;
    top: 86px;
    z-index: 20;
    background: var(--card);
    padding: 10px 0 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.az-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #fff;
    font-weight: 800;
    font-size: 12px;
}

.az-letter:hover {
    background: #f8fafc;
}

.az-letter.is-disabled {
    opacity: 0.35;
    pointer-events: none;
}

.az-content {
    padding-top: 14px;
    display: grid;
    gap: 20px;
}

.az-group {
    scroll-margin-top: 140px;
}

.az-heading {
    margin: 0 0 10px;
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 0.2px;
}

.az-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.az-item {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    background: #fff;
    font-weight: 750;
    font-size: 13px;
    line-height: 1.2;
}

.az-item:hover {
    background: #f8fafc;
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .layout {
        grid-template-columns: 1fr;
    }

    /* Stack brand / home / search nicely on mobile */
    .topbar-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .topbar-grid .home-btn {
        justify-self: start;
    }

    .search {
        width: 100%;
        min-width: unset;
    }

    #map {
        height: 520px;
        min-height: unset;
    }

    .rankings {
        max-height: 520px;
    }

    .legend-box {
        min-width: 160px;
    }

    .neighbors-list {
        grid-template-columns: 1fr;
    }

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

    .az-grid {
        grid-template-columns: 1fr;
    }
}
