/* Single light theme that matches the OpenStreetMap tiles and the Leaflet controls. */
:root {
    --bg: #f2efe9;
    --panel: rgba(255, 255, 255, 0.94);
    --input-bg: #ffffff;
    --text: #1f2933;
    --muted: #5b6573;
    --border: rgba(0, 0, 0, 0.18);
    --accent: #2563eb;
    --accent-text: #ffffff;
    --focus: #f59e0b;
    --shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
}

.app {
    position: relative;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* Each view is its own stacking context, so Leaflet panes stay under the floating panels. */
.view {
    position: absolute;
    inset: 0;
    z-index: 0;
    isolation: isolate;
}

.hidden {
    display: none !important;
}

/* Compact floating panel, styled like the Leaflet controls. */
.toolbar {
    position: absolute;
    z-index: 10;
    top: 12px;
    left: 12px;
    width: min(340px, calc(100% - 24px));
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.toolbar h1 {
    margin: 0 0 8px;
    font-size: 0.95rem;
    font-weight: 600;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.panel-header h1 {
    margin-bottom: 0;
}

.toggle {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
}

.toggle:hover {
    background: rgba(0, 0, 0, 0.06);
}

.icon {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.toolbar.collapsed {
    width: auto;
    padding-bottom: 8px;
}

.toolbar.collapsed .panel-body {
    display: none;
}

.toolbar.collapsed .panel-header h1 {
    font-size: 0.9rem;
}

.search {
    display: flex;
    gap: 6px;
}

.search input {
    flex: 1;
    min-width: 0;
}

input,
select,
button {
    font: inherit;
    font-size: 0.85rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    padding: 5px 8px;
    background: var(--input-bg);
    color: var(--text);
}

input::placeholder {
    color: var(--muted);
    opacity: 1;
}

button {
    cursor: pointer;
}

button.primary,
.search button {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
    margin-top: 10px;
}

.controls #locate-btn {
    flex: 1 1 100%;
    padding: 6px 10px;
}

/* UF multi-select: chips and search share one input box. */
.uf-field {
    position: relative;
    flex: 1 1 100%;
}

.field-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
}

.field-head button {
    padding: 0 4px;
    border: none;
    background: none;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 600;
}

.uf-box {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    min-height: 34px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--input-bg);
    cursor: text;
}

.uf-box:focus-within {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.uf-chips {
    display: contents;
}

.uf-chip {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 3px 2px 9px;
    border-radius: 999px;
    background: #dbeafe;
    color: #1e3a8a;
    font-size: 0.78rem;
    font-weight: 700;
}

.uf-chip-remove {
    padding: 0 5px;
    border: none;
    background: transparent;
    color: #1e3a8a;
    font-size: 0.95rem;
    line-height: 1;
}

.uf-box input {
    flex: 1 1 110px;
    min-width: 110px;
    padding: 3px 2px;
    border: none;
    background: transparent;
    font-size: 0.85rem;
}

.uf-box input:focus-visible {
    outline: none;
}

.uf-list {
    position: absolute;
    z-index: 30;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 220px;
    overflow-y: auto;
    margin: 4px 0 0;
    padding: 4px;
    list-style: none;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.uf-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    user-select: none;
}

.uf-option.active {
    background: #eff6ff;
}

.uf-option .check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex: none;
    border: 1.5px solid var(--border);
    border-radius: 4px;
    color: #ffffff;
    font-size: 0.7rem;
    font-weight: 700;
}

.uf-option.checked .check {
    background: var(--accent);
    border-color: var(--accent);
}

.uf-option .uf-code {
    width: 24px;
    font-weight: 700;
}

.uf-option .uf-name {
    color: var(--muted);
}

.uf-empty {
    padding: 6px 8px;
    color: var(--muted);
    font-size: 0.8rem;
}

/* Field filter: a select that picks the field, next to a value input. */
.field-filter {
    flex: 1 1 100%;
}

.field-filter .field-head label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
}

.field-row {
    display: flex;
    gap: 6px;
}

.field-row select {
    flex: 0 0 auto;
    max-width: 45%;
}

.field-row input {
    flex: 1;
    min-width: 0;
}


.status {
    margin: 8px 0 0;
    font-size: 0.78rem;
    color: var(--muted);
    min-height: 1em;
}

/* Info card for the selected municipality, bottom right. */
.info {
    position: absolute;
    z-index: 10;
    right: 12px;
    bottom: 34px; /* sits above the Leaflet attribution bar */
    width: min(280px, calc(100% - 24px));
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.info h2 {
    margin: 0 0 8px;
    font-size: 0.95rem;
    font-weight: 600;
    padding-right: 20px;
}

.info dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 3px 10px;
    margin: 0;
    font-size: 0.8rem;
}

.info dt {
    color: var(--muted);
}

.info dd {
    margin: 0;
}

.info .close {
    position: absolute;
    top: 6px;
    right: 6px;
    padding: 0 6px;
    line-height: 1.4;
    font-size: 1rem;
}

/* Phone layout: 8px gutters, no horizontal scroll. */
@media (max-width: 600px) {
    .toolbar {
        top: 8px;
        left: 8px;
        width: calc(100% - 16px);
    }

    .info {
        right: 8px;
        bottom: 30px;
        width: calc(100% - 16px);
    }

}

/* Search: input and button share one height; suggestions use the same dropdown style as the UF list. */
.search {
    align-items: stretch;
}

.search-field {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
}

.search-field input {
    flex: 1;
    width: 100%;
    min-width: 0;
    height: 34px;
}

.search button {
    height: 34px;
    padding: 0 14px;
    font-weight: 600;
}

.search-list {
    position: absolute;
    z-index: 30;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 240px;
    overflow-y: auto;
    margin: 4px 0 0;
    padding: 4px;
    list-style: none;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.search-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    user-select: none;
}

.search-option.active {
    background: #eff6ff;
}

.search-option .search-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Hide the browser's own clear and picker decorations, in case a native search field is used. */
input[type="search"]::-webkit-search-cancel-button,
input::-webkit-calendar-picker-indicator {
    display: none;
}

/* Space between the header (title and toggle button) and the search row. */
.panel-body {
    margin-top: 12px;
}
