:root {
    color-scheme: light;
    --bg: #f4f3ef;
    --panel: #ffffff;
    --ink: #161815;
    --muted: #68706a;
    --line: #d9ded7;
    --accent: #1f7a54;
    --accent-dark: #15593d;
    --danger: #9c432f;
}

* {
    box-sizing: border-box;
}

html,
body,
#root,
#map {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
    font: inherit;
}

.shell {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    height: 100%;
    overflow: hidden;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-width: 0;
    padding: 22px;
    border-right: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel) 94%, var(--bg));
    overflow: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 8px;
}

.brand > div {
    min-width: 0;
}

.brand-mark {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    border-radius: 7px;
    background:
        linear-gradient(135deg, transparent 0 38%, rgba(255, 255, 255, .74) 38% 45%, transparent 45%),
        var(--accent);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
}

h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.1;
    font-weight: 760;
    letter-spacing: 0;
}

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

.logout-link {
    margin-left: auto;
    color: var(--accent-dark);
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
}

.logout-link:hover {
    text-decoration: underline;
}

.login-page {
    display: grid;
    min-height: 100%;
    place-items: center;
    padding: 24px;
}

.login-shell {
    width: 100%;
    max-width: 380px;
}

.login-form {
    display: grid;
    width: 100%;
    gap: 12px;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 20px 60px rgba(30, 35, 28, .12);
}

.login-brand {
    margin-bottom: 8px;
}

.login-button {
    margin-top: 6px;
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    font-weight: 800;
}

.login-button:hover {
    background: var(--accent-dark);
}

.login-error {
    margin: 0;
    border: 1px solid rgba(156, 67, 47, .22);
    border-radius: 7px;
    background: rgba(255, 250, 246, .96);
    color: var(--danger);
    padding: 9px 10px;
}

.filter-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.filter-group {
    display: grid;
    gap: 7px;
}

label {
    color: #3f4741;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

input,
select {
    width: 100%;
    min-width: 0;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fbfbf8;
    color: var(--ink);
    padding: 0 10px;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(31, 122, 84, .13);
}

.range-row,
.actions,
.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.search-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 58px;
    gap: 10px;
}

button {
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fbfbf8;
    color: var(--ink);
    cursor: pointer;
}

button:hover {
    border-color: #b7c0b8;
    background: #fff;
}

button#fit {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.go-button {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    font-weight: 800;
}

.go-button:hover {
    background: var(--accent-dark);
}

button#fit:hover {
    background: var(--accent-dark);
}

.stats {
    margin: auto 0 0;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.stats div {
    min-width: 0;
}

dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

dd {
    margin: 2px 0 0;
    font-size: 24px;
    font-weight: 780;
    line-height: 1;
}

.map-wrap {
    position: relative;
    min-width: 0;
}

#map {
    background: #dfe6dc;
}

.notice {
    position: absolute;
    right: 18px;
    bottom: 18px;
    z-index: 500;
    max-width: min(360px, calc(100vw - 36px));
    border: 1px solid rgba(156, 67, 47, .25);
    border-radius: 7px;
    background: rgba(255, 250, 246, .96);
    color: var(--danger);
    padding: 10px 12px;
    font-size: 13px;
    box-shadow: 0 14px 30px rgba(30, 35, 28, .14);
}

.section-title {
    margin: 0;
    color: #5b635d;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.floating-basemap-card {
    position: absolute;
    top: 18px;
    left: 18px;
    z-index: 500;
    width: 188px;
    padding: 12px;
    border: 1px solid rgba(22, 24, 21, .12);
    border-radius: 8px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 18px 42px rgba(30, 35, 28, .16);
    backdrop-filter: blur(18px);
}

.floating-basemap-card.is-expanded {
    width: 300px;
}

.floating-basemap-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.floating-basemap-summary {
    min-width: 0;
}

.floating-basemap-active {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    min-height: 27px;
    margin-top: 4px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(31, 122, 84, .12);
    color: var(--accent-dark);
    font-size: 12px;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.basemap-toggle {
    flex: 0 0 auto;
    width: auto;
    min-width: 58px;
    height: 34px;
    padding: 0 11px;
    border-color: rgba(22, 24, 21, .08);
    border-radius: 999px;
    background: rgba(22, 24, 21, .06);
    color: var(--ink);
    font-size: 12px;
    font-weight: 800;
}

.basemap-toggle:hover {
    background: rgba(22, 24, 21, .1);
}

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

.basemap-option {
    display: flex;
    height: auto;
    flex-direction: column;
    gap: 7px;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.basemap-thumb {
    width: 100%;
    aspect-ratio: 1;
    border: 1px solid rgba(22, 24, 21, .14);
    border-radius: 8px;
    box-shadow: 0 10px 22px rgba(30, 35, 28, .1);
    transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.basemap-option:hover .basemap-thumb {
    transform: translateY(-1px);
}

.basemap-option.is-active .basemap-thumb {
    border-color: rgba(31, 122, 84, .72);
    box-shadow: 0 14px 28px rgba(31, 122, 84, .2);
}

.basemap-thumb-default {
    background:
        linear-gradient(180deg, rgba(134, 239, 172, .25), rgba(186, 230, 253, .18)),
        linear-gradient(135deg, #f8fafc 0%, #dbeafe 42%, #dcfce7 42%, #dcfce7 68%, #fde68a 68%, #fde68a 100%);
}

.basemap-thumb-roadmap {
    position: relative;
    background:
        linear-gradient(180deg, rgba(59, 130, 246, .22), rgba(59, 130, 246, .04)),
        linear-gradient(135deg, #dbeafe 0%, #dbeafe 26%, #fef3c7 26%, #fef3c7 42%, #bbf7d0 42%, #bbf7d0 66%, #e2e8f0 66%, #e2e8f0 100%);
}

.basemap-thumb-roadmap::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background:
        linear-gradient(110deg, transparent 0 22%, rgba(255, 255, 255, .78) 22% 25%, transparent 25% 58%, rgba(255, 255, 255, .78) 58% 61%, transparent 61% 100%),
        linear-gradient(20deg, transparent 0 46%, rgba(255, 255, 255, .78) 46% 49%, transparent 49% 100%);
}

.basemap-thumb-hybrid {
    position: relative;
    background:
        linear-gradient(180deg, rgba(16, 24, 40, .1), rgba(16, 24, 40, .35)),
        linear-gradient(135deg, #365314 0%, #4d7c0f 24%, #854d0e 24%, #854d0e 48%, #166534 48%, #166534 72%, #3f3f46 72%);
}

.basemap-thumb-hybrid::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    opacity: .95;
    background:
        linear-gradient(110deg, transparent 0 28%, rgba(255, 255, 255, .78) 28% 30%, transparent 30% 58%, rgba(255, 255, 255, .78) 58% 60%, transparent 60% 100%),
        linear-gradient(15deg, transparent 0 44%, rgba(255, 255, 255, .78) 44% 46%, transparent 46% 100%);
}

.basemap-thumb-satellite {
    background:
        linear-gradient(180deg, rgba(16, 24, 40, .1), rgba(16, 24, 40, .35)),
        linear-gradient(135deg, #365314 0%, #4d7c0f 24%, #854d0e 24%, #854d0e 48%, #166534 48%, #166534 72%, #3f3f46 72%);
}

.basemap-thumb-carto_dark {
    position: relative;
    background:
        linear-gradient(180deg, rgba(15, 23, 42, .1), rgba(15, 23, 42, .42)),
        linear-gradient(135deg, #0f172a 0%, #1e293b 38%, #334155 38%, #334155 58%, #172554 58%, #172554 100%);
}

.basemap-thumb-carto_dark::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background:
        linear-gradient(120deg, transparent 0 28%, rgba(148, 163, 184, .72) 28% 30%, transparent 30% 62%, rgba(148, 163, 184, .72) 62% 64%, transparent 64% 100%);
}

.basemap-label {
    color: rgba(22, 24, 21, .7);
    font-size: 12px;
    font-weight: 800;
    line-height: 1.15;
    text-align: center;
}

.basemap-option.is-active .basemap-label {
    color: var(--ink);
}

.map-legend {
    position: absolute;
    left: 18px;
    bottom: 18px;
    z-index: 500;
    min-width: 178px;
    padding: 12px;
    border: 1px solid rgba(22, 24, 21, .12);
    border-radius: 8px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 18px 42px rgba(30, 35, 28, .14);
    backdrop-filter: blur(18px);
}

.legend-items {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #343b36;
    font-size: 13px;
    font-weight: 750;
    line-height: 1.2;
}

.legend-swatch {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    border: 2px solid var(--legend-color);
    border-radius: 4px;
    background: color-mix(in srgb, var(--legend-color) 28%, transparent);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .4);
}

.parcel-list-panel {
    position: absolute;
    top: 18px;
    right: 18px;
    z-index: 510;
    display: flex;
    width: min(360px, calc(100vw - 36px));
    max-height: min(520px, calc(100% - 36px));
    flex-direction: column;
    border: 1px solid rgba(22, 24, 21, .12);
    border-radius: 8px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 18px 42px rgba(30, 35, 28, .16);
    backdrop-filter: blur(18px);
    overflow: hidden;
}

.parcel-list-panel.is-expanded {
    min-height: 160px;
}

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

.parcel-list-header strong {
    display: block;
    margin-top: 4px;
    font-size: 15px;
    line-height: 1.1;
}

.parcel-list-toggle {
    width: auto;
    min-width: 58px;
    height: 34px;
    padding: 0 11px;
    border-radius: 999px;
    background: rgba(22, 24, 21, .06);
    font-size: 12px;
    font-weight: 800;
}

.parcel-list-meta {
    padding: 9px 12px;
    border-bottom: 1px solid rgba(217, 222, 215, .7);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.parcel-list-scroll {
    display: grid;
    gap: 0;
    overflow: auto;
}

.parcel-list-item {
    display: grid;
    height: auto;
    min-height: 58px;
    gap: 4px;
    padding: 10px 12px;
    border: 0;
    border-bottom: 1px solid rgba(217, 222, 215, .72);
    border-radius: 0;
    background: transparent;
    text-align: left;
}

.parcel-list-item:hover {
    background: #f5f7f3;
}

.parcel-list-uprn {
    color: var(--ink);
    font-size: 13px;
    font-weight: 850;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.parcel-list-sub {
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.empty-list {
    margin: 0;
    padding: 14px 12px;
    color: var(--muted);
    font-size: 13px;
}

.parcel-drawer {
    position: absolute;
    top: 18px;
    right: 18px;
    bottom: 18px;
    z-index: 520;
    display: flex;
    width: min(390px, calc(100vw - 36px));
    flex-direction: column;
    border: 1px solid rgba(22, 24, 21, .12);
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 22px 54px rgba(30, 35, 28, .2);
    backdrop-filter: blur(18px);
    overflow: hidden;
}

.parcel-drawer-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--line);
}

.parcel-drawer-header h2 {
    margin: 4px 0 0;
    font-size: 20px;
    line-height: 1.2;
    letter-spacing: 0;
    overflow-wrap: anywhere;
}

.drawer-close {
    width: auto;
    min-width: 62px;
    height: 34px;
    padding: 0 11px;
    border-radius: 999px;
    background: rgba(22, 24, 21, .06);
    font-size: 12px;
    font-weight: 800;
}

.drawer-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
}

.drawer-summary div {
    min-width: 0;
    padding: 10px;
    border-radius: 8px;
    background: #f5f7f3;
}

.drawer-summary span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.drawer-summary strong {
    display: block;
    margin-top: 4px;
    font-size: 14px;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.drawer-editor {
    display: grid;
    gap: 8px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    background: #fbfbf8;
}

.drawer-editor select {
    background: #fff;
}

.save-state {
    min-height: 17px;
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.save-state.is-saved {
    color: var(--accent-dark);
}

.save-state.is-error {
    color: var(--danger);
}

.parcel-info-list {
    display: grid;
    gap: 0;
    margin: 0;
    padding: 2px 18px 18px;
    overflow: auto;
}

.parcel-info-list div {
    display: grid;
    grid-template-columns: 128px minmax(0, 1fr);
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(217, 222, 215, .82);
}

.parcel-info-list dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    line-height: 1.3;
    text-transform: none;
}

.parcel-info-list dd {
    margin: 0;
    font-size: 13px;
    font-weight: 650;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.popup-table {
    border-collapse: collapse;
    min-width: 230px;
}

.popup-table th,
.popup-table td {
    padding: 4px 0;
    text-align: left;
    vertical-align: top;
}

.popup-table th {
    width: 94px;
    color: #5e665f;
    font-weight: 700;
}

.leaflet-popup-content {
    margin: 12px 14px;
}

@media (max-width: 760px) {
    .shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .sidebar {
        max-height: 45svh;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: 16px;
    }

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

    .floating-basemap-card {
        top: 12px;
        left: 12px;
        width: 178px;
    }

    .floating-basemap-card.is-expanded {
        width: min(292px, calc(100vw - 24px));
    }

    .basemap-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .map-legend {
        left: 12px;
        bottom: 12px;
    }

    .parcel-list-panel {
        top: 12px;
        right: 12px;
        width: min(320px, calc(100vw - 24px));
        max-height: 38svh;
    }

    .parcel-drawer {
        top: auto;
        right: 12px;
        bottom: 12px;
        left: 12px;
        width: auto;
        max-height: 48svh;
    }

    .drawer-summary {
        grid-template-columns: 1fr;
    }

    .parcel-info-list div {
        grid-template-columns: 112px minmax(0, 1fr);
    }
}
