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

:root {
    /* Paleta base (claro) — blanco crema, rojo óxido y verde olivo */
    --bg: #f4ece0;
    --bg-2: #ebe0cf;
    --surface: rgba(255, 252, 246, 0.80);
    --surface-strong: rgba(255, 252, 246, 0.94);
    --surface-solid: #fffdf8;
    --surface-sunken: rgba(74, 54, 38, 0.05);
    --border: rgba(74, 54, 38, 0.14);
    --border-strong: rgba(74, 54, 38, 0.24);

    --text: #2c2118;
    --text-muted: #6b5847;
    --text-faint: #93806c;

    --brand: #9e4526;
    --brand-strong: #7d3419;
    --brand-soft: rgba(158, 69, 38, 0.12);
    --on-brand: #fff7ee;
    --focus: #b0801a;

    /* Estatus de lote */
    --st-disponible: #5f7a2e;
    --st-disponible-soft: rgba(95, 122, 46, 0.16);
    --st-apartado: #b0801a;
    --st-apartado-soft: rgba(176, 128, 26, 0.16);
    --st-vendido-pp: #c0662f;
    --st-vendido-pp-soft: rgba(192, 102, 47, 0.16);
    --st-vendido: #9b3320;
    --st-vendido-soft: rgba(155, 51, 32, 0.14);

    /* Sombras (capas suaves, nunca duras) */
    --shadow-xs: 0 1px 2px rgba(60, 42, 28, 0.07);
    --shadow-sm: 0 1px 2px rgba(60, 42, 28, 0.07), 0 2px 8px -2px rgba(60, 42, 28, 0.12);
    --shadow-md: 0 1px 2px rgba(60, 42, 28, 0.07), 0 8px 24px -8px rgba(60, 42, 28, 0.24);
    --shadow-lg: 0 2px 4px rgba(60, 42, 28, 0.07), 0 20px 48px -16px rgba(60, 42, 28, 0.34);

    --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: #17120e;
        --bg-2: #1f1813;
        --surface: rgba(40, 31, 25, 0.80);
        --surface-strong: rgba(45, 35, 28, 0.95);
        --surface-solid: #241c16;
        --surface-sunken: rgba(255, 245, 232, 0.06);
        --border: rgba(255, 240, 225, 0.13);
        --border-strong: rgba(255, 240, 225, 0.24);
        --text: #f5ece0;
        --text-muted: #c4b09b;
        --text-faint: #9c8974;
        --brand: #e08a63;
        --brand-strong: #f0a684;
        --brand-soft: rgba(224, 138, 99, 0.18);
        --on-brand: #2a1108;
        --focus: #e2b34f;
        --st-disponible: #a8c46a;
        --st-disponible-soft: rgba(168, 196, 106, 0.18);
        --st-apartado: #e2b34f;
        --st-apartado-soft: rgba(226, 179, 79, 0.18);
        --st-vendido-pp: #ea9358;
        --st-vendido-pp-soft: rgba(234, 147, 88, 0.18);
        --st-vendido: #dd6a52;
        --st-vendido-soft: rgba(221, 106, 82, 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: #17120e;
    --bg-2: #1f1813;
    --surface: rgba(40, 31, 25, 0.80);
    --surface-strong: rgba(45, 35, 28, 0.95);
    --surface-solid: #241c16;
    --surface-sunken: rgba(255, 245, 232, 0.06);
    --border: rgba(255, 240, 225, 0.13);
    --border-strong: rgba(255, 240, 225, 0.24);
    --text: #f5ece0;
    --text-muted: #c4b09b;
    --text-faint: #9c8974;
    --brand: #e08a63;
    --brand-strong: #f0a684;
    --brand-soft: rgba(224, 138, 99, 0.18);
    --on-brand: #2a1108;
    --focus: #e2b34f;
    --st-disponible: #a8c46a;
    --st-disponible-soft: rgba(168, 196, 106, 0.18);
    --st-apartado: #e2b34f;
    --st-apartado-soft: rgba(226, 179, 79, 0.18);
    --st-vendido-pp: #ea9358;
    --st-vendido-pp-soft: rgba(234, 147, 88, 0.18);
    --st-vendido: #dd6a52;
    --st-vendido-soft: rgba(221, 106, 82, 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;
}

/* Indicador de modo administrador en el botón */
.btn .dot-live {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--st-disponible);
    box-shadow: 0 0 0 3px var(--st-disponible-soft);
}

/* ------------------------------------------------- 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 .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_pp { background: var(--st-vendido-pp); }
.swatch-vendido    { background: var(--st-vendido); }

.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(46, 30, 18, 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-VENDIDO_PP { color: var(--st-vendido-pp); background: var(--st-vendido-pp-soft); border-color: var(--st-vendido-pp-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;
}

/* Selector de estatus tipo segmented control */
.status-picker {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 5px;
    border-radius: var(--r-md);
    background: var(--surface-sunken);
    border: 1px solid var(--border);
}
.status-opt { position: relative; }
.status-opt input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}
.status-opt span {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 56px;
    padding: 8px 4px;
    border-radius: var(--r-sm);
    font-size: 11.5px;
    font-weight: 700;
    text-align: center;
    color: var(--text-muted);
    border: 1px solid transparent;
    transition: all 0.2s var(--ease);
}
.status-opt span::before {
    content: "";
    width: 14px;
    height: 14px;
    border-radius: 5px;
    background: currentColor;
    opacity: 0.55;
}
.status-opt input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.status-opt input:checked + span {
    background: var(--surface-solid);
    box-shadow: var(--shadow-sm);
    border-color: var(--border);
}
.status-opt[data-status="DISPONIBLE"] input:checked + span { color: var(--st-disponible); }
.status-opt[data-status="APARTADO"]   input:checked + span { color: var(--st-apartado); }
.status-opt[data-status="VENDIDO_PP"] input:checked + span { color: var(--st-vendido-pp); }
.status-opt[data-status="VENDIDO"]    input:checked + span { color: var(--st-vendido); }
.status-opt input:checked + span::before { opacity: 1; }

/* 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); } }

/* ------------------------------------------------ Etiqueta modo edición --- */

.admin-flag {
    position: fixed;
    z-index: 35;
    left: 50%;
    transform: translateX(-50%);
    top: calc(var(--header-h) + var(--sat) + 56px);
    display: none;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border-radius: var(--r-full);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--st-apartado);
    background: var(--surface-strong);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border: 1px solid var(--st-apartado-soft);
    box-shadow: var(--shadow-md);
}
body.admin-on .admin-flag { display: inline-flex; }
body.admin-on .app-header { box-shadow: var(--shadow-sm), inset 0 -2px 0 var(--st-apartado); }

.admin-flag .pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--st-apartado-soft); }
    50%      { box-shadow: 0 0 0 6px transparent; }
}

/* Selección múltiple */
.multi-tray {
    position: fixed;
    z-index: 44;
    left: 50%;
    transform: translateX(-50%) translateY(120%);
    bottom: calc(16px + var(--sab));
    width: min(560px, calc(100vw - 20px));
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--r-lg);
    background: var(--surface-strong);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s var(--ease);
}
.multi-tray.is-open { transform: translateX(-50%) translateY(0); }
.multi-tray .n {
    font-size: 13px;
    font-weight: 700;
    padding-left: 4px;
    flex: 1;
    min-width: 0;
}
.multi-tray .n small { display: block; font-weight: 500; color: var(--text-muted); font-size: 11.5px; }

@media (max-width: 560px) {
    .multi-tray { flex-wrap: wrap; }
    .multi-tray .n { flex: 1 0 100%; }
    .multi-tray #multi-estatus { flex: 1; }
}

/* --------------------------------------------------------- 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,
    .multi-tray, .admin-flag, .map-footer { display: none !important; }
}
