:root {
    --header-height: 66px;
    --toolbar-height: 58px;
    --background: #f3f4f6;
    --surface: rgba(255, 255, 255, 0.96);
    --surface-solid: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #d1d5db;
    --accent: #e85d2a;
    --accent-dark: #b93814;
    --visited: #6b7280;
    --shadow: 0 10px 30px rgba(17, 24, 39, 0.18);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body,
#app {
    width: 100%;
    height: 100%;
    height: 100dvh;
    margin: 0;
    overflow: hidden;
    background: var(--background);
    color: var(--text);
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

.topbar {
    position: fixed;
    z-index: 1100;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #111827;
    color: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.topbar h1 {
    margin: 0;
    font-size: clamp(16px, 4.5vw, 21px);
    line-height: 1.15;
}

.topbar p {
    margin: 3px 0 0;
    font-size: 12px;
    color: #d1d5db;
}

.icon-button {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: inherit;
    font-size: 22px;
}

.icon-button.small {
    width: 34px;
    height: 34px;
    color: var(--text);
    background: #f3f4f6;
}

.toolbar {
    position: fixed;
    z-index: 1050;
    top: var(--header-height);
    left: 0;
    right: 0;
    min-height: var(--toolbar-height);
    padding: 8px;
    display: flex;
    gap: 7px;
    align-items: center;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
}

.search-box {
    min-width: 150px;
    flex: 1;
    height: 40px;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 0 11px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
}

.search-box span {
    font-size: 22px;
    color: var(--muted);
}

.search-box input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    color: var(--text);
    background: transparent;
}

.toolbar-button,
.text-button,
.popup-button {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font-weight: 650;
}

.toolbar-button {
    height: 40px;
    padding: 0 11px;
    white-space: nowrap;
}

.toolbar-button.primary,
.popup-button.primary {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.toolbar-button[aria-pressed="true"] {
    border-color: #111827;
    background: #111827;
    color: #fff;
}

#map {
    position: fixed;
    inset: calc(var(--header-height) + var(--toolbar-height)) 0 0 0;
    background: #dbeafe;
}

.map-status {
    position: fixed;
    z-index: 1000;
    left: 50%;
    top: calc(var(--header-height) + var(--toolbar-height) + 10px);
    transform: translateX(-50%);
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.88);
    color: #fff;
    font-size: 12px;
    box-shadow: var(--shadow);
    pointer-events: none;
    transition: opacity 180ms ease;
}

.map-status:empty {
    opacity: 0;
}

.location-list-panel {
    position: fixed;
    z-index: 1150;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: min(58dvh, 620px);
    padding-bottom: var(--safe-bottom);
    display: flex;
    flex-direction: column;
    background: var(--surface-solid);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(17, 24, 39, 0.22);
    transform: translateY(105%);
    transition: transform 220ms ease;
}

.location-list-panel.open {
    transform: translateY(0);
}

.panel-heading {
    padding: 13px 14px 11px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.panel-heading strong,
.panel-heading span {
    display: block;
}

.panel-heading span {
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
}

.location-list {
    overflow-y: auto;
    overscroll-behavior: contain;
}

.location-row {
    width: 100%;
    padding: 12px 14px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 12px;
    text-align: left;
    border: 0;
    border-bottom: 1px solid #e5e7eb;
    background: #fff;
    color: var(--text);
}

.location-row:hover,
.location-row:focus-visible {
    background: #f9fafb;
}

.location-row.visited {
    opacity: 0.58;
}

.location-row-title {
    font-weight: 700;
}

.location-row-note,
.location-row-distance {
    color: var(--muted);
    font-size: 12px;
}

.location-row-distance {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
    white-space: nowrap;
}

.geocode-panel {
    position: fixed;
    z-index: 1200;
    left: 12px;
    right: 12px;
    bottom: calc(12px + var(--safe-bottom));
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
}

.geocode-heading {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 10px;
}

.geocode-heading strong,
.geocode-heading span {
    display: block;
}

.geocode-heading span {
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
}

.geocode-panel progress {
    width: 100%;
    height: 9px;
    margin-top: 10px;
    accent-color: var(--accent);
}

.geocode-actions {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.text-button {
    padding: 7px 10px;
    font-size: 12px;
}

.toast {
    position: fixed;
    z-index: 1400;
    left: 50%;
    bottom: calc(22px + var(--safe-bottom));
    max-width: calc(100vw - 30px);
    padding: 9px 14px;
    border-radius: 999px;
    transform: translate(-50%, 18px);
    opacity: 0;
    pointer-events: none;
    background: #111827;
    color: #fff;
    font-size: 13px;
    box-shadow: var(--shadow);
    transition: 180ms ease;
}

.toast.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.market-marker {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border: 3px solid #fff;
    border-radius: 50% 50% 50% 8px;
    transform: rotate(-45deg);
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 7px rgba(0, 0, 0, 0.35);
}

.market-marker span {
    transform: rotate(45deg);
    font-size: 12px;
    font-weight: 800;
}

.market-marker.visited {
    background: var(--visited);
}

.market-marker.approximate {
    border-style: dashed;
}

.user-marker {
    width: 22px;
    height: 22px;
    border: 4px solid #fff;
    border-radius: 50%;
    background: #2563eb;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.25), 0 2px 8px rgba(0, 0, 0, 0.4);
}

.leaflet-popup-content-wrapper {
    border-radius: 14px;
}

.leaflet-popup-content {
    margin: 14px;
    min-width: 220px;
}

.popup-title {
    margin: 0 0 5px;
    font-size: 16px;
}

.popup-note,
.popup-distance {
    margin: 5px 0;
    color: var(--muted);
    font-size: 12px;
}

.popup-actions {
    margin-top: 11px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
}

.popup-button {
    min-height: 38px;
    padding: 7px 9px;
    text-align: center;
    text-decoration: none;
    display: grid;
    place-items: center;
}

.popup-button.full {
    grid-column: 1 / -1;
}

dialog {
    width: min(560px, calc(100vw - 24px));
    max-height: calc(100dvh - 40px);
    padding: 0;
    border: 0;
    border-radius: 18px;
    color: var(--text);
    box-shadow: var(--shadow);
}

dialog::backdrop {
    background: rgba(17, 24, 39, 0.68);
}

dialog form {
    position: relative;
    padding: 22px;
    overflow-y: auto;
}

dialog h2 {
    margin: 0 38px 14px 0;
}

dialog p,
dialog li {
    line-height: 1.5;
}

.dialog-close {
    position: absolute;
    right: 12px;
    top: 10px;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: #f3f4f6;
    font-size: 24px;
}

.small-print {
    color: var(--muted);
    font-size: 12px;
}

@media (max-width: 720px) {
    .toolbar {
        flex-wrap: wrap;
        min-height: auto;
    }

    .search-box {
        flex-basis: 100%;
    }

    .toolbar-button {
        flex: 1;
        padding-inline: 7px;
        font-size: 13px;
    }

    #map {
        top: calc(var(--header-height) + 104px);
    }

    .map-status {
        top: calc(var(--header-height) + 114px);
    }
}

@media (min-width: 900px) {
    .location-list-panel {
        top: calc(var(--header-height) + var(--toolbar-height) + 12px);
        right: 12px;
        left: auto;
        bottom: 12px;
        width: 390px;
        max-height: none;
        border-radius: 16px;
        transform: translateX(calc(100% + 30px));
    }

    .location-list-panel.open {
        transform: translateX(0);
    }

    .geocode-panel {
        right: auto;
        width: 440px;
    }
}
