/* ==========================================================================
   MAPA DE LOTES — sistema de diseño
   Mobile-first · vidrio esmerilado moderado · sombras suaves · alto contraste
   ========================================================================== */

:root {
    /* Paleta base (claro) */
    --bg: #e9eef4;
    --bg-2: #dfe7ef;
    --surface: rgba(255, 255, 255, 0.78);
    --surface-strong: rgba(255, 255, 255, 0.94);
    --surface-solid: #ffffff;
    --surface-sunken: rgba(15, 23, 42, 0.04);
    --border: rgba(15, 23, 42, 0.12);
    --border-strong: rgba(15, 23, 42, 0.2);

    --text: #0f1b2d;
    --text-muted: #52657c;
    --text-faint: #7b8ca1;

    --brand: #0d6f8a;
    --brand-strong: #0a5a71;
    --brand-soft: rgba(13, 111, 138, 0.12);
    --on-brand: #ffffff;
    --focus: #0ea5b7;

    /* Estatus de lote */
    --st-disponible: #12876a;
    --st-disponible-soft: rgba(18, 135, 106, 0.14);
    --st-apartado: #b4700a;
    --st-apartado-soft: rgba(180, 112, 10, 0.14);
    --st-vendido: #b23a48;
    --st-vendido-soft: rgba(178, 58, 72, 0.14);
    --st-proceso: #6b52b4;
    --st-proceso-soft: rgba(107, 82, 180, 0.14);

    /* Sombras (capas suaves, nunca duras) */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 2px 8px -2px rgba(15, 23, 42, 0.1);
    --shadow-md: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px -8px rgba(15, 23, 42, 0.22);
    --shadow-lg: 0 2px 4px rgba(15, 23, 42, 0.06), 0 20px 48px -16px rgba(15, 23, 42, 0.32);

    --blur: saturate(150%) blur(14px);

    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 20px;
    --r-full: 999px;

    --tap: 44px;
    --header-h: 60px;

    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);

    --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0a121e;
        --bg-2: #0e1826;
        --surface: rgba(19, 30, 46, 0.78);
        --surface-strong: rgba(21, 33, 50, 0.95);
        --surface-solid: #16212f;
        --surface-sunken: rgba(255, 255, 255, 0.06);
        --border: rgba(255, 255, 255, 0.13);
        --border-strong: rgba(255, 255, 255, 0.24);

        --text: #e8eff8;
        --text-muted: #a3b4c8;
        --text-faint: #7f92a8;

        --brand: #3fb6d0;
        --brand-strong: #6fd2e6;
        --brand-soft: rgba(63, 182, 208, 0.18);
        --on-brand: #06222c;
        --focus: #5cd0e0;

        --st-disponible: #34d3a6;
        --st-disponible-soft: rgba(52, 211, 166, 0.18);
        --st-apartado: #f0b44a;
        --st-apartado-soft: rgba(240, 180, 74, 0.18);
        --st-vendido: #f5808f;
        --st-vendido-soft: rgba(245, 128, 143, 0.18);
        --st-proceso: #a795ea;
        --st-proceso-soft: rgba(167, 149, 234, 0.18);

        --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 10px -2px rgba(0, 0, 0, 0.5);
        --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.45), 0 10px 28px -10px rgba(0, 0, 0, 0.7);
        --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.5), 0 24px 56px -18px rgba(0, 0, 0, 0.8);
    }
}

/* Tema forzado desde el botón */
:root[data-theme="dark"] {
    --bg: #0a121e;
    --bg-2: #0e1826;
    --surface: rgba(19, 30, 46, 0.78);
    --surface-strong: rgba(21, 33, 50, 0.95);
    --surface-solid: #16212f;
    --surface-sunken: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.13);
    --border-strong: rgba(255, 255, 255, 0.24);
    --text: #e8eff8;
    --text-muted: #a3b4c8;
    --text-faint: #7f92a8;
    --brand: #3fb6d0;
    --brand-strong: #6fd2e6;
    --brand-soft: rgba(63, 182, 208, 0.18);
    --on-brand: #06222c;
    --focus: #5cd0e0;
    --st-disponible: #34d3a6;
    --st-disponible-soft: rgba(52, 211, 166, 0.18);
    --st-apartado: #f0b44a;
    --st-apartado-soft: rgba(240, 180, 74, 0.18);
    --st-vendido: #f5808f;
    --st-vendido-soft: rgba(245, 128, 143, 0.18);
    --st-proceso: #a795ea;
    --st-proceso-soft: rgba(167, 149, 234, 0.18);
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 10px -2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.45), 0 10px 28px -10px rgba(0, 0, 0, 0.7);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.5), 0 24px 56px -18px rgba(0, 0, 0, 0.8);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overscroll-behavior: none;
}

body {
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p, ul, ol { margin: 0; }
ul { list-style: none; padding: 0; }

:where(button, a, input, select, textarea):focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

/* --------------------------------------------------------------- Mapa --- */

#map {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(120% 90% at 50% 0%, var(--bg-2) 0%, var(--bg) 70%);
}

.ol-viewport canvas { outline: none; }

/* Controles nativos de OpenLayers ocultos: usamos los propios */
.ol-control { display: none !important; }

/* --------------------------------------------------------- Superficies --- */

.glass {
    background: var(--surface);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
}

/* ------------------------------------------------------------ Encabezado --- */

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 10px;
    height: calc(var(--header-h) + var(--sat));
    padding: var(--sat) calc(10px + var(--sar)) 0 calc(10px + var(--sal));
    background: linear-gradient(to bottom, var(--surface-strong) 60%, transparent);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.brand-mark {
    flex: none;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    color: var(--on-brand);
    background: linear-gradient(145deg, var(--brand) 0%, var(--brand-strong) 100%);
    box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.brand-mark svg { width: 20px; height: 20px; }

.brand-text { min-width: 0; }

.brand-title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-sub {
    font-size: 11.5px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: none;
}

/* ------------------------------------------------------------- Botones --- */

.btn {
    appearance: none;
    -webkit-appearance: none;
    font: inherit;
    font-weight: 600;
    color: var(--text);
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 10px 14px;
    min-height: var(--tap);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s var(--ease), box-shadow 0.2s var(--ease),
                background-color 0.2s var(--ease), border-color 0.2s var(--ease);
}

.btn:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.btn:active { transform: scale(0.97); box-shadow: var(--shadow-xs); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

.btn svg { width: 18px; height: 18px; flex: none; }

.btn-icon {
    width: var(--tap);
    height: var(--tap);
    min-height: var(--tap);
    padding: 0;
    border-radius: var(--r-md);
}

.btn-primary {
    color: var(--on-brand);
    background: linear-gradient(145deg, var(--brand) 0%, var(--brand-strong) 100%);
    border-color: transparent;
    box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.btn-ghost {
    background: transparent;
    box-shadow: none;
    border-color: transparent;
    color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-sunken); box-shadow: none; }

.btn-danger { color: var(--st-vendido); border-color: var(--st-vendido-soft); }

.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 8px 12px; font-size: 13.5px; border-radius: var(--r-sm); }

.btn.is-active {
    color: var(--on-brand);
    background: linear-gradient(145deg, var(--brand) 0%, var(--brand-strong) 100%);
    border-color: transparent;
}

/* ------------------------------------- Contador de filtros activos --- */

.btn-badge-wrap { position: relative; }
.btn-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    display: none;
    place-items: center;
    border-radius: var(--r-full);
    font-size: 11px;
    font-weight: 800;
    color: var(--on-brand);
    background: var(--brand);
    box-shadow: 0 0 0 2px var(--surface-strong);
}

/* ------------------------------- Origen de los datos (cotizaciones) --- */

/* Pastilla del encabezado: dice de dónde salen la disponibilidad y los
   precios, y al tocarla vuelve a consultar el Sistema de Cotizaciones. */
.sync-chip {
    appearance: none;
    -webkit-appearance: none;
    font: inherit;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 40px;
    padding: 0 13px;
    border-radius: var(--r-full);
    cursor: pointer;
    color: var(--text-muted);
    background: var(--surface);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    transition: transform 0.15s var(--ease), color 0.2s var(--ease);
}
.sync-chip:active { transform: scale(0.96); }
.sync-chip:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.sync-chip .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: none;
    background: var(--text-muted);
}
.sync-chip.is-ok .dot {
    background: var(--st-disponible);
    box-shadow: 0 0 0 3px var(--st-disponible-soft);
}
.sync-chip.is-local .dot { background: var(--st-apartado); box-shadow: 0 0 0 3px var(--st-apartado-soft); }
.sync-chip.is-error .dot { background: var(--st-vendido); box-shadow: 0 0 0 3px var(--st-vendido-soft); }
.sync-chip.is-error { color: var(--st-vendido); }

/* En pantallas chicas queda sólo el punto de color: el texto se recupera
   al tocarlo (title) y en la barra de conteos. */
@media (max-width: 560px) {
    .sync-chip { padding: 0 11px; gap: 0; }
    .sync-chip .txt { display: none; }
}

/* ------------------------------------------------- Barra de estadísticas --- */

.stats-bar {
    position: fixed;
    z-index: 30;
    top: calc(var(--header-h) + var(--sat) + 8px);
    left: 0;
    right: 0;
    display: flex;
    gap: 8px;
    padding: 2px calc(10px + var(--sar)) 2px calc(10px + var(--sal));
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
}
.stats-bar::-webkit-scrollbar { display: none; }

.stat-chip {
    flex: none;
    scroll-snap-align: start;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 13px;
    min-height: 40px;
    border-radius: var(--r-full);
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    background: var(--surface);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s var(--ease), box-shadow 0.2s var(--ease), opacity 0.2s var(--ease);
}
.stat-chip:active { transform: scale(0.96); }
.stat-chip[aria-pressed="false"] { opacity: 0.5; }
.stat-chip.is-static { cursor: default; }
.stat-chip.is-static:active { transform: none; }

.stat-chip .swatch {
    width: 12px;
    height: 12px;
    border-radius: 4px;
    flex: none;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.swatch-disponible { background: var(--st-disponible); }
.swatch-apartado   { background: var(--st-apartado); }
.swatch-vendido    { background: var(--st-vendido); }
.swatch-proceso    { background: var(--st-proceso); }

.stat-chip .count {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}
.stat-chip .label { color: var(--text-muted); font-weight: 600; }

/* ------------------------------------------------- Controles flotantes --- */

.map-tools {
    position: fixed;
    z-index: 30;
    right: calc(10px + var(--sar));
    bottom: calc(16px + var(--sab));
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: transform 0.3s var(--ease);
}

.map-tools .btn-icon {
    background: var(--surface);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
}

.zoom-group {
    display: flex;
    flex-direction: column;
    border-radius: var(--r-md);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}
.zoom-group .btn-icon {
    border-radius: 0;
    box-shadow: none;
    border-bottom-width: 0;
}
.zoom-group .btn-icon:last-child { border-bottom-width: 1px; }

/* Escala + créditos */
.map-footer {
    position: fixed;
    z-index: 25;
    left: calc(10px + var(--sal));
    bottom: calc(10px + var(--sab));
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-muted);
    pointer-events: none;
    transition: transform 0.3s var(--ease), opacity 0.3s var(--ease);
}

.scale-bar {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 5px 9px;
    border-radius: var(--r-sm);
    background: var(--surface);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
}
.scale-bar .bar {
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--text-muted), var(--brand));
    transition: width 0.2s var(--ease);
}
.scale-bar .txt { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ----------------------------------------------------- Paneles / sheets --- */

.scrim {
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(8, 15, 26, 0.42);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s var(--ease), visibility 0.25s var(--ease);
}
.scrim.is-open { opacity: 1; visibility: visible; }

.sheet {
    position: fixed;
    z-index: 50;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 86dvh;
    display: flex;
    flex-direction: column;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    background: var(--surface-strong);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    border-bottom: 0;
    box-shadow: var(--shadow-lg);
    transform: translateY(101%);
    visibility: hidden;
    transition: transform 0.32s var(--ease), visibility 0.32s var(--ease);
    padding-bottom: var(--sab);
}
.sheet.is-open { transform: translateY(0); visibility: visible; }

/* La ficha del lote deja ver el plano detrás */
#panel-lote { max-height: 68dvh; }

.sheet-handle {
    flex: none;
    padding: 8px 0 2px;
    display: grid;
    place-items: center;
    cursor: grab;
    touch-action: none;
}
.sheet-handle::before {
    content: "";
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-strong);
}

.sheet-head {
    flex: none;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 6px 14px 10px;
    border-bottom: 1px solid var(--border);
}
.sheet-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.sheet-sub { font-size: 12.5px; color: var(--text-muted); }
.sheet-head .btn-icon { margin-left: auto; flex: none; }

.sheet-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.sheet-foot {
    flex: none;
    display: flex;
    gap: 8px;
    padding: 10px 14px calc(12px + var(--sab));
    border-top: 1px solid var(--border);
    background: var(--surface-strong);
}
.sheet-foot .btn { flex: 1; }

/* ------------------------------------------------- Detalle del lote (UI) --- */

.lot-hero {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-radius: var(--r-md);
    background: var(--surface-sunken);
    border: 1px solid var(--border);
}

.lot-hero .id {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.1;
}
.lot-hero .mz { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--r-full);
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    border: 1px solid transparent;
}
.badge::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}
.badge-disponible { color: var(--st-disponible); background: var(--st-disponible-soft); border-color: var(--st-disponible-soft); }
.badge-apartado   { color: var(--st-apartado);   background: var(--st-apartado-soft);   border-color: var(--st-apartado-soft); }
.badge-proceso    { color: var(--st-proceso);    background: var(--st-proceso-soft);    border-color: var(--st-proceso-soft); }
.badge-vendido    { color: var(--st-vendido);    background: var(--st-vendido-soft);    border-color: var(--st-vendido-soft); }

.price-card {
    padding: 14px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: linear-gradient(150deg, var(--brand-soft), transparent 70%), var(--surface-sunken);
}
.price-card .price {
    font-size: 27px;
    font-weight: 800;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}
.price-card .per-m2 { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }

.data-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.data-item {
    padding: 10px 12px;
    border-radius: var(--r-sm);
    background: var(--surface-sunken);
    border: 1px solid var(--border);
}
.data-item dt {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    font-weight: 700;
}
.data-item dd {
    margin: 2px 0 0;
    font-size: 15px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    word-break: break-word;
}

/* -------------------------------------------------------- Formularios --- */

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

.field > label,
.field-label {
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.input, select.input, textarea.input {
    font: inherit;
    color: var(--text);
    background: var(--surface-solid);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    padding: 11px 12px;
    min-height: var(--tap);
    width: 100%;
    box-shadow: var(--shadow-xs) inset;
    transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.input:focus { border-color: var(--focus); box-shadow: 0 0 0 3px var(--brand-soft); outline: none; }
.input::placeholder { color: var(--text-faint); }

select.input {
    -webkit-appearance: none;
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                      linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    padding-right: 34px;
}

/* Deslizadores de rango con área táctil cómoda */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 32px;
    margin: 0;
    background: transparent;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 3px;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
}
input[type="range"]::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    margin-top: -10px;
    border-radius: 50%;
    background: var(--surface-solid);
    border: 2px solid var(--brand);
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s var(--ease);
}
input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--surface-solid);
    border: 2px solid var(--brand);
    box-shadow: var(--shadow-sm);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.12); }
input[type="range"]:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; border-radius: var(--r-sm); }

.input-group { display: flex; align-items: center; gap: 8px; }
.input-affix {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    flex: none;
}

/* Interruptores */
.switch-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--tap);
    padding: 8px 12px;
    border-radius: var(--r-sm);
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    cursor: pointer;
}
.switch-row .txt { flex: 1; font-size: 13.5px; font-weight: 600; }
.switch-row .hint { display: block; font-size: 11.5px; font-weight: 500; color: var(--text-muted); }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
    flex: none;
    width: 46px;
    height: 28px;
    border-radius: var(--r-full);
    background: var(--border-strong);
    position: relative;
    transition: background-color 0.22s var(--ease);
}
.switch-track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform 0.22s var(--ease);
}
.switch-row input:checked + .switch-track { background: var(--brand); }
.switch-row input:checked + .switch-track::after { transform: translateX(18px); }
.switch-row input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Casillas de filtro */
.check-list { display: flex; flex-direction: column; gap: 6px; }
.check {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 6px 12px;
    border-radius: var(--r-sm);
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: border-color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.check:hover { border-color: var(--border-strong); }
.check input { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
.check .tally { margin-left: auto; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Secciones de panel */
.panel-section { display: flex; flex-direction: column; gap: 10px; }
.panel-section > h3 {
    font-size: 11.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-faint);
}

.divider { height: 1px; background: var(--border); border: 0; margin: 2px 0; }

.note {
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--text-muted);
    padding: 10px 12px;
    border-radius: var(--r-sm);
    background: var(--brand-soft);
    border: 1px solid var(--border);
}
.note strong { color: var(--text); }

/* --------------------------------------------------------- Resultados --- */

.result-list { display: flex; flex-direction: column; gap: 6px; }

.result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    min-height: 56px;
    border-radius: var(--r-sm);
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    cursor: pointer;
    font: inherit;
    color: var(--text);
    transition: transform 0.15s var(--ease), border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.result-item:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.result-item:active { transform: scale(0.99); }
.result-item .r-main { flex: 1; min-width: 0; }
.result-item .r-title { display: block; font-weight: 700; font-size: 14.5px; }
.result-item .r-sub { display: block; font-size: 12px; color: var(--text-muted); }
.result-item .r-price { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.result-item .r-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex: none;
    box-shadow: 0 0 0 3px var(--surface-sunken);
}

.empty-state {
    text-align: center;
    padding: 28px 14px;
    color: var(--text-muted);
    font-size: 13.5px;
}

/* ------------------------------------------------------------- Toasts --- */

.toast-stack {
    position: fixed;
    z-index: 80;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(24px + var(--sab));
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(420px, calc(100vw - 24px));
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--r-md);
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    background: var(--surface-strong);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s var(--ease);
}
.toast.is-out { animation: toast-out 0.25s var(--ease) forwards; }
.toast .bar { width: 4px; align-self: stretch; border-radius: 2px; background: var(--brand); flex: none; }
.toast.ok .bar { background: var(--st-disponible); }
.toast.warn .bar { background: var(--st-apartado); }
.toast.err .bar { background: var(--st-vendido); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}
@keyframes toast-out {
    to { opacity: 0; transform: translateY(8px) scale(0.98); }
}

/* --------------------------------------------------------- Cargando --- */

.boot {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 14px;
    background: var(--bg);
    transition: opacity 0.4s var(--ease), visibility 0.4s var(--ease);
}
.boot.is-done { opacity: 0; visibility: hidden; }
.boot .ring {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 3px solid var(--border-strong);
    border-top-color: var(--brand);
    animation: spin 0.9s linear infinite;
}
.boot .txt { font-size: 13px; font-weight: 600; color: var(--text-muted); }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------- Escritorio --- */

@media (min-width: 900px) {
    :root { --header-h: 66px; }

    body { font-size: 15.5px; }

    .brand-title { font-size: 17px; }

    /* El sheet se convierte en panel lateral */
    .sheet {
        top: calc(var(--header-h) + var(--sat) + 12px);
        bottom: 12px;
        left: auto;
        right: 12px;
        width: 392px;
        max-height: none;
        border-radius: var(--r-lg);
        border-bottom: 1px solid var(--border);
        transform: translateX(calc(100% + 24px));
    }
    .sheet.is-open { transform: translateX(0); }
    #panel-lote { max-height: none; }
    .sheet#panel-filtros,
    .sheet#panel-buscar {
        left: 12px;
        right: auto;
        transform: translateX(calc(-100% - 24px));
    }
    .sheet#panel-filtros.is-open,
    .sheet#panel-buscar.is-open { transform: translateX(0); }

    .sheet-handle { display: none; }
    .sheet-head { padding: 16px 16px 12px; }

    /* El scrim sólo oscurece en móvil */
    .scrim { display: none; }

    .stats-bar { justify-content: flex-start; }

    /* Desplazar controles cuando hay panel derecho abierto */
    body.panel-right-open .map-tools { transform: translateX(-404px); }

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

@media (min-width: 1280px) {
    .sheet { width: 420px; }
    body.panel-right-open .map-tools { transform: translateX(-432px); }
}

/* Pantallas muy angostas */
@media (max-width: 359px) {
    .brand-sub { display: none; }
    .data-grid { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------ Accesibilidad --- */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

@media (prefers-contrast: more) {
    :root {
        --surface: rgba(255, 255, 255, 0.97);
        --surface-strong: #ffffff;
        --border: rgba(15, 23, 42, 0.35);
        --border-strong: rgba(15, 23, 42, 0.55);
        --text-muted: #33465c;
    }
    .glass, .sheet, .stat-chip, .app-header {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Impresión: mapa limpio */
@media print {
    .app-header, .stats-bar, .map-tools, .sheet, .scrim, .toast-stack,
    .map-footer { display: none !important; }
}
