/* ==========================================================================
   Dashboard Santa Cruz Bienes Raíces
   ========================================================================== */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f1f3f6;
    --surface-3: #e8ebf0;
    --text: #0f1729;
    --text-2: #4b5567;
    --text-3: #7c8698;
    --border: #e3e6ec;
    --border-strong: #cfd5de;
    --brand: #6d28d9;
    --brand-2: #8b5cf6;
    --brand-soft: #f1eafe;
    --brand-contrast: #ffffff;
    --ink: #111827;
    --ink-contrast: #ffffff;
    --venta: #6d28d9;
    --alquiler: #0891b2;
    --anticretico: #d97706;
    --otro: #64748b;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --shadow-md: 0 6px 16px rgba(16, 24, 40, .08), 0 2px 4px rgba(16, 24, 40, .05);
    --shadow-lg: 0 18px 40px rgba(16, 24, 40, .16);
    --skeleton-base: #dde1e7;
    --skeleton-shine: #eef0f3;
    --radius: 14px;
    --radius-sm: 10px;
    --topbar-h: 68px;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #0b0e14;
    --surface: #141922;
    --surface-2: #1b212c;
    --surface-3: #252c39;
    --text: #e8ebf1;
    --text-2: #aab2c0;
    --text-3: #7d8697;
    --border: #262d3a;
    --border-strong: #343d4d;
    --brand: #a78bfa;
    --brand-2: #c4b5fd;
    --brand-soft: rgba(167, 139, 250, .14);
    --brand-contrast: #160c2e;
    --ink: #f3f4f6;
    --ink-contrast: #111827;
    --venta: #a78bfa;
    --alquiler: #22d3ee;
    --anticretico: #fbbf24;
    --otro: #94a3b8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, .35);
    --shadow-lg: 0 18px 40px rgba(0, 0, 0, .55);
    --skeleton-base: #1f2632;
    --skeleton-shine: #2c3442;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
input, select { font: inherit; color: inherit; }
svg { flex-shrink: 0; }

/* ---------- Topbar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 0 20px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
    width: 40px; height: 40px; border-radius: 10px;
    display: grid; place-items: center;
    padding: 5px;
    background: #111827;
    flex-shrink: 0;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-text { line-height: 1.15; white-space: nowrap; }
.brand-text strong { display: block; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.brand-text span { font-size: 12px; color: var(--text-3); }

.search {
    flex: 1;
    max-width: 560px;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 42px;
    padding: 0 6px 0 14px;
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: 999px;
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.search:focus-within {
    background: var(--surface);
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-soft);
}
.search svg { color: var(--text-3); }
.search input {
    flex: 1; min-width: 0; height: 100%;
    background: transparent; border: none; outline: none;
}
.search input::placeholder { color: var(--text-3); }
.search-clear {
    width: 30px; height: 30px; border-radius: 50%;
    display: none; place-items: center; color: var(--text-3);
}
.search-clear:hover { background: var(--surface-3); color: var(--text); }
.search.has-value .search-clear { display: grid; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.icon-btn {
    width: 40px; height: 40px; border-radius: 50%;
    display: grid; place-items: center;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .icon-moon { display: none; }
:root[data-theme="dark"] .icon-btn .icon-sun { display: none; }
:root[data-theme="dark"] .icon-btn .icon-moon { display: block; }

/* ---------- Toolbar ---------- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.chip-group { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    height: 34px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
    display: inline-flex; align-items: center; gap: 6px;
    transition: all .15s;
}
.chip:hover { border-color: var(--text-3); color: var(--text); }
.chip.is-active { background: var(--ink); border-color: var(--ink); color: var(--ink-contrast); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.chip .count { font-size: 11px; opacity: .65; font-variant-numeric: tabular-nums; }

.price-filter {
    display: flex; align-items: center; gap: 6px;
    height: 34px; padding: 0 4px 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    font-size: 13px; color: var(--text-2);
}
.price-filter input {
    width: 92px; height: 26px; padding: 0 8px;
    border: none; border-radius: 999px;
    background: var(--surface-2); outline: none;
    font-size: 13px;
}
.price-filter input:focus { box-shadow: 0 0 0 2px var(--brand); }

.select {
    height: 34px; padding: 0 30px 0 12px;
    border: 1px solid var(--border-strong); border-radius: 999px;
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237c8698' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
    appearance: none;
    font-size: 13px; color: var(--text-2);
    outline: none;
}

.toolbar-stats { margin-left: auto; display: flex; gap: 16px; font-size: 13px; color: var(--text-3); }
.toolbar-stats strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar, .toolbar { flex-shrink: 0; }

.layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(420px, 46%) 1fr;
}

.list-pane {
    overflow-y: auto;
    padding: 18px 20px 28px;
    scrollbar-gutter: stable;
}
.list-head {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: 12px; margin-bottom: 14px;
}
.list-head h2 { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.list-head p { font-size: 13px; color: var(--text-3); }

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
}

.map-pane { position: relative; border-left: 1px solid var(--border); }
#map { position: absolute; inset: 0; background: var(--surface-2); }

/* ---------- Property card ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex; flex-direction: column;
    transition: box-shadow .2s, transform .2s, border-color .2s;
    cursor: pointer;
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card.is-active { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft), var(--shadow-md); }

.gallery {
    position: relative;
    aspect-ratio: 4 / 3;
    background: var(--surface-3);
    overflow: hidden;
}
.gallery img {
    width: 100%; height: 100%; object-fit: cover; display: block;
    transition: opacity .25s;
}
.gallery.is-loading img { opacity: .4; }
.gallery.broken img, .gallery.empty img { display: none; }
.gallery-placeholder {
    position: absolute; inset: 0;
    display: none; place-items: center;
    color: var(--text-3); font-size: 12px; text-align: center;
}
.gallery-placeholder svg { display: block; margin: 0 auto 6px; opacity: .6; }
.gallery.broken .gallery-placeholder, .gallery.empty .gallery-placeholder { display: grid; }

.gallery-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center;
    background: rgba(255, 255, 255, .92); color: #111827;
    box-shadow: var(--shadow-sm);
    opacity: 0; transition: opacity .15s, transform .15s;
    z-index: 2;
}
.gallery-nav:hover { transform: translateY(-50%) scale(1.08); }
.gallery-nav.prev { left: 8px; }
.gallery-nav.next { right: 8px; }
.gallery:hover .gallery-nav, .gallery:focus-within .gallery-nav { opacity: 1; }
@media (hover: none) { .gallery-nav { opacity: 1; } }

.gallery-count {
    position: absolute; right: 8px; bottom: 8px;
    padding: 2px 8px; border-radius: 999px;
    background: rgba(17, 24, 39, .72); color: #fff;
    font-size: 11px; font-weight: 500; font-variant-numeric: tabular-nums;
}
.gallery-tags { position: absolute; left: 8px; top: 8px; display: flex; gap: 6px; z-index: 1; }

.tag {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 9px; border-radius: 999px;
    font-size: 11px; font-weight: 600; letter-spacing: .01em;
    background: rgba(255, 255, 255, .95); color: #111827;
    box-shadow: var(--shadow-sm);
}
.tag .dot { width: 7px; height: 7px; border-radius: 50%; }
.tag.featured { background: #111827; color: #fde68a; }

.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-price { font-size: 20px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.card-price small { font-size: 12px; font-weight: 500; color: var(--text-3); margin-right: 2px; }
.card-price small.per { margin: 0 0 0 2px; }
.card-title {
    font-size: 13.5px; font-weight: 500; color: var(--text);
    display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-addr {
    display: flex; align-items: center; gap: 4px;
    font-size: 12px; color: var(--text-3);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-addr span { overflow: hidden; text-overflow: ellipsis; }

.specs { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--text-2); }
.specs span { display: inline-flex; align-items: center; gap: 4px; }
.specs svg { color: var(--text-3); }

.card-foot {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    font-size: 12px; color: var(--text-3);
}
.code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 11.5px; color: var(--text-2); }
.agent { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-details { font-size: 12px; color: var(--text-2); }
.card-details summary {
    list-style: none; cursor: pointer; color: var(--brand); font-weight: 600;
    display: inline-flex; align-items: center; gap: 4px;
}
.card-details summary::-webkit-details-marker { display: none; }
.card-details summary svg { transition: transform .15s; }
.card-details[open] summary svg { transform: rotate(180deg); }
.card-details dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin-top: 8px; }
.card-details dt { color: var(--text-3); }
.card-details dd { color: var(--text); overflow-wrap: anywhere; }
.card-links { display: flex; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.card-links a { color: var(--brand); font-weight: 600; }
.card-links a:hover { text-decoration: underline; }

/* ---------- Pagination ---------- */
.pagination { display: flex; justify-content: center; align-items: center; gap: 6px; margin-top: 24px; flex-wrap: wrap; }
.page-btn {
    min-width: 36px; height: 36px; padding: 0 10px;
    border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface);
    font-size: 13px; font-weight: 500; color: var(--text-2);
    display: inline-flex; align-items: center; justify-content: center;
    font-variant-numeric: tabular-nums;
}
.page-btn:hover:not(:disabled):not(.is-active) { background: var(--surface-2); color: var(--text); }
.page-btn.is-active { background: var(--ink); border-color: var(--ink); color: var(--ink-contrast); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-gap { color: var(--text-3); padding: 0 4px; }

/* ---------- Empty / loading ---------- */
.state {
    grid-column: 1 / -1;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-3);
}
.state strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

.skeleton {
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    overflow: hidden;
}
.skeleton::before {
    content: ""; display: block; aspect-ratio: 4 / 3;
    background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-shine) 50%, var(--skeleton-base) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
}
.skeleton::after {
    content: ""; display: block; height: 70px; margin: 14px;
    border-radius: 8px;
    background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-shine) 50%, var(--skeleton-base) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Map overlays ---------- */
.map-overlay {
    position: absolute; z-index: 500;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: var(--shadow-md);
    font-size: 13px;
}
.map-toggle {
    top: 14px; left: 14px;
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px 8px 10px;
    cursor: pointer; user-select: none;
    font-weight: 500;
}
.map-toggle input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

.map-legend {
    left: 14px; bottom: 26px;
    display: flex; gap: 12px;
    padding: 7px 14px;
    color: var(--text-2); font-size: 12px;
}
.map-legend:empty { display: none; }
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.map-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.map-hint {
    top: 14px; left: 50%; transform: translateX(-50%);
    padding: 7px 14px; color: var(--text-2); font-size: 12px;
    pointer-events: none;
    transition: opacity .3s;
}
.map-hint.is-hidden { opacity: 0; }

/* ---------- Leaflet overrides ---------- */
.leaflet-container { font-family: inherit; background: var(--surface-2); }
.leaflet-bar { border: none !important; box-shadow: var(--shadow-md) !important; border-radius: 12px !important; overflow: hidden; }
.leaflet-bar a {
    width: 36px !important; height: 36px !important; line-height: 36px !important;
    background: var(--surface) !important; color: var(--text) !important;
    border-bottom-color: var(--border) !important;
}
.leaflet-bar a:hover { background: var(--surface-2) !important; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--text-3) !important; }
.leaflet-control-attribution a { color: var(--text-2) !important; }
.base-tiles { filter: grayscale(.85) contrast(.92) brightness(1.04); }
:root[data-theme="dark"] .base-tiles { filter: invert(1) hue-rotate(180deg) grayscale(.9) brightness(.85) contrast(.9); }

/* Price pills */
.pill-icon { background: none; border: none; }
.pill {
    position: absolute;
    left: 0; top: 0;
    transform: translate(-50%, -50%);
    white-space: nowrap;
    padding: 4px 9px;
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    border: 1.5px solid var(--pill-color, var(--brand));
    box-shadow: 0 2px 6px rgba(16, 24, 40, .18);
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.01em;
    cursor: pointer;
    animation: pill-in .18s ease-out;
    transition: background .12s, color .12s, transform .12s;
}
.pill:hover, .pill.is-active {
    background: var(--pill-color, var(--brand));
    color: #fff;
    transform: translate(-50%, -50%) scale(1.1);
    z-index: 2;
}
.pill.group {
    background: var(--ink);
    color: var(--ink-contrast);
    border-color: var(--ink);
    font-weight: 600;
}
.pill.group:hover, .pill.group.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pill.cluster {
    width: var(--size); height: var(--size);
    padding: 0;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--brand);
    border: 3px solid color-mix(in srgb, var(--brand) 30%, var(--surface));
    background-clip: padding-box;
    color: #fff;
    font-size: 12.5px;
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent), 0 2px 6px rgba(16, 24, 40, .2);
}
.pill.cluster:hover, .pill.cluster.is-active { background: var(--ink); color: var(--ink-contrast); }
:root[data-theme="dark"] .pill.cluster { color: var(--brand-contrast); }
.pill.visited:not(:hover):not(.is-active) { background: var(--surface-3); color: var(--text-3); }
.pill.still { animation: none; }
@keyframes pill-in {
    from { opacity: 0; transform: translate(-50%, -30%) scale(.85); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* Popup */
.prop-popup .leaflet-popup-content-wrapper {
    padding: 0;
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.prop-popup .leaflet-popup-content { margin: 0; width: 290px !important; font-size: 13px; line-height: 1.45; }
.prop-popup .leaflet-popup-tip { background: var(--surface); }
.prop-popup a.leaflet-popup-close-button {
    top: 8px; right: 8px; z-index: 3;
    width: 28px; height: 28px; border-radius: 50%;
    background: rgba(255, 255, 255, .95); color: #111827;
    font-size: 18px; line-height: 27px; text-align: center;
    box-shadow: var(--shadow-sm);
}
.prop-popup a.leaflet-popup-close-button:hover { color: #000; background: #fff; }

.pp .gallery { aspect-ratio: 16 / 10; }
.pp-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.pp-title { font-size: 14px; font-weight: 600; line-height: 1.35; }
.pp-actions { display: flex; gap: 8px; margin-top: 6px; }
.pp-actions a {
    flex: 1; text-align: center;
    padding: 8px 10px; border-radius: 10px;
    font-size: 12.5px; font-weight: 600;
    border: 1px solid var(--border-strong);
    color: var(--text);
}
.pp-actions a.primary { background: var(--ink); border-color: var(--ink); color: var(--ink-contrast); }
.pp-actions a:hover { filter: brightness(1.08); }
.pp-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-3); }

.pp-group-head { padding: 14px 44px 10px 14px; font-weight: 700; font-size: 14px; border-bottom: 1px solid var(--border); }
.pp-group-head span { font-weight: 500; color: var(--text-3); font-size: 12px; display: block; }
.pp-group-list { max-height: 300px; overflow-y: auto; }
.pp-unit {
    display: flex; gap: 10px; align-items: center;
    width: 100%; text-align: left;
    padding: 9px 14px;
    border-bottom: 1px solid var(--border);
}
.pp-unit:last-child { border-bottom: none; }
.pp-unit:hover { background: var(--surface-2); }
.pp-unit img, .pp-unit .thumb-ph {
    width: 54px; height: 42px; border-radius: 8px; object-fit: cover; flex-shrink: 0;
    background: var(--surface-3);
}
.pp-unit div { min-width: 0; }
.pp-unit strong { display: block; font-size: 13px; font-variant-numeric: tabular-nums; }
.pp-unit span { display: block; font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pp-back { padding: 8px 14px; font-size: 12px; font-weight: 600; color: var(--brand); border-bottom: 1px solid var(--border); width: 100%; text-align: left; }

/* ---------- Responsive ---------- */
@media (max-width: 1600px) {
    .toolbar-stats { display: none; }
}

@media (max-width: 1100px) {
    .layout { grid-template-columns: minmax(360px, 50%) 1fr; }
}

@media (max-width: 860px) {
    .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
    .brand-text span { display: none; }
    .search { order: 3; flex-basis: 100%; max-width: none; }
    .toolbar { padding: 10px 16px; overflow-x: auto; flex-wrap: nowrap; }
    .toolbar > * { flex-shrink: 0; }
    .app { height: auto; }
    .topbar { position: sticky; }
    .layout { display: flex; flex-direction: column; }
    .map-pane { order: -1; position: relative; height: 55vh; flex-shrink: 0; border-left: none; border-bottom: 1px solid var(--border); }
    .list-pane { overflow: visible; padding: 16px; }
    .cards { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
    .map-legend { display: none; }
    .map-hint { top: auto; bottom: 26px; white-space: nowrap; }
    .prop-popup .leaflet-popup-content { width: 260px !important; }
}
