/* ============================================================
   K'in Sistema — Plano Público (iframe embebible)
   Modo oscuro por defecto · Light via prefers-color-scheme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700;900&family=Lato:wght@300;400;700&display=swap');

/* ── Design Tokens — Oscuro (por defecto) ─────────────────── */
:root {
    --bg:          #110e03;
    --surface:     #1a130a;
    --surface-2:   #221908;
    --border:      #3D3018;
    --text:        #eae2cc;
    --text-muted:  #9f8e7a;
    --text-inv:    #110e03;
    --primary:     #f5a623;
    --primary-hov: #F5C842;
    --danger:      #f87171;

    /* Estados */
    --disponible:  #4ade80;
    --apartada:    #fbbf24;
    --reservada:   #a78bfa;
    --vendida:     #f87171;
    --no-disp:     #6b7280;

    /* Glass (siempre oscuro — siempre sobre imagen del plano) */
    --glass-bg:    rgba(15,12,5,.82);
    --glass-bg-hi: rgba(15,12,5,.93);
    --glass-bd:    rgba(255,255,255,.10);
    --glass-text:  #eae2cc;
    --glass-muted: #9f8e7a;

    /* Radios */
    --r-sm:   6px;
    --r-md:   10px;
    --r-lg:   14px;
    --r-full: 9999px;
}

/* ── Light override ───────────────────────────────────────── */
@media (prefers-color-scheme: light) {
    :root {
        --bg:          #FBF3DC;
        --surface:     #F8F2E0;
        --surface-2:   #F0E7C8;
        --border:      #E8D8A0;
        --text:        #231D0A;
        --text-muted:  #9F8E7A;
        --text-inv:    #FBF3DC;
        --primary:     #F5A623;
        --primary-hov: #d4891a;
        --danger:      #dc2626;

        --disponible:  #15803d;
        --apartada:    #b45309;
        --reservada:   #7c3aed;
        --vendida:     #b91c1c;
        --no-disp:     #6b7280;
        /* Glass stays dark — always over map image */
    }
}

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

html, body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Lato', system-ui, -apple-system, sans-serif;
    background: transparent;
    color: var(--text);
}

/* ── Contenedor externo (referencia para overlays en desktop) ─ */
#plano-outer { position: relative; }

/* ── Nav overlay (flotante sobre el mapa en desktop) ──────── */
#nav-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 50;
    display: none;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    max-width: calc(100% - 20px);
}
#nav-overlay.visible { display: flex; }

#btn-back {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-bd);
    color: var(--glass-text);
    padding: 6px 12px;
    border-radius: var(--r-md);
    font-size: .78rem;
    font-family: 'Lato', sans-serif;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s;
}
#btn-back:hover { background: rgba(51,40,15,.95); }
#btn-back svg { width: 12px; height: 12px; }

#breadcrumb {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(15,12,5,.75);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-bd);
    border-radius: var(--r-md);
    padding: 5px 10px;
    font-size: .73rem;
    color: var(--glass-muted);
    overflow: hidden;
    max-width: 60%;
}
.crumb { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; transition: color .15s; }
.crumb:hover { color: var(--glass-text); text-decoration: underline; }
.crumb.current { color: var(--glass-text); font-weight: 600; cursor: default; text-decoration: none; }
.bc-sep { color: var(--glass-muted); flex-shrink: 0; }

/* ── Plano wrapper ────────────────────────────────────────── */
#plano-wrap { position: relative; width: 100%; line-height: 0; }
#plano-box  { position: absolute; top: 0; right: 0; bottom: 0; left: 0; transition: opacity .22s ease; }
#plano-box.fading { opacity: 0; pointer-events: none; }
#plano-img  { display: block; width: 100%; height: 100%; object-fit: fill; }
#plano-svg  { position: absolute; inset: 0; width: 100%; height: 100%; cursor: default; }
#no-img {
    display: none;
    width: 100%; height: 100%;
    align-items: center; justify-content: center;
    flex-direction: column; gap: 10px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: .85rem;
}
#no-img svg { opacity: .4; }

/* ── Polígonos ────────────────────────────────────────────── */
.pol {
    fill-opacity: .48;
    stroke: #fff;
    stroke-width: 2.5;
    stroke-opacity: .85;
    filter: drop-shadow(0 0 3px rgba(0,0,0,.55));
    transition: fill-opacity .12s, stroke-opacity .12s;
    cursor: pointer;
}
.pol:hover    { fill-opacity: .72; stroke-opacity: 1; }
.pol.clickable { cursor: pointer; }
.pol.no-click  { cursor: default; }
.pol.locked {
    fill-opacity: .28 !important;
    stroke-opacity: .4 !important;
    cursor: default !important;
    filter: grayscale(.5) drop-shadow(0 0 2px rgba(0,0,0,.35));
}

/* Zona disponibilidad */
.pol.z-verde   { fill: var(--disponible); }
.pol.z-naranja { fill: var(--apartada); }
.pol.z-rojo    { fill: var(--vendida); }
.pol.z-gris    { fill: var(--no-disp); }

/* Estado de unidad */
.pol.u-disponible    { fill: var(--disponible); cursor: pointer; }
.pol.u-apartada      { fill: var(--apartada); cursor: pointer; }
.pol.u-vendida       { fill: var(--vendida); cursor: default; }
.pol.u-no_disponible { fill: var(--no-disp); cursor: default; }
.pol.u-reservada     { fill: var(--reservada); cursor: default; }

/* ── Spinner ──────────────────────────────────────────────── */
#spinner {
    display: none;
    position: absolute; inset: 0;
    background: rgba(15,12,5,.55);
    align-items: center; justify-content: center;
    z-index: 60; border-radius: var(--r-md);
}
#spinner.on { display: flex; }
.spin {
    width: 34px; height: 34px;
    border: 3px solid rgba(255,255,255,.15);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: kin-rot .65s linear infinite;
}
@keyframes kin-rot { to { transform: rotate(360deg); } }

/* ── Banner inactivo ──────────────────────────────────────── */
#banner-inactivo {
    position: absolute;
    top: 10px; left: 50%; transform: translateX(-50%);
    z-index: 30;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-bd);
    border-radius: var(--r-md);
    padding: 7px 16px;
    font-size: .75rem;
    color: var(--glass-muted);
    white-space: nowrap;
    pointer-events: none;
    display: flex; align-items: center; gap: 7px;
}
#banner-inactivo svg { opacity: .7; }

/* ── Leyendas flotantes (desktop: sobre el mapa) ──────────── */
#legend, #legend-unidades {
    position: absolute;
    z-index: 10;
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    background: var(--glass-bg);
    backdrop-filter: blur(6px);
    border: 1px solid var(--glass-bd);
    border-radius: var(--r-md);
    padding: 8px 12px;
    font-size: .7rem;
    color: var(--glass-muted);
    pointer-events: none;
}
#legend         { bottom: 12px; left: 12px; }
#legend-unidades { bottom: 12px; right: 12px; }
.leg { display: flex; align-items: center; gap: 5px; }
.leg-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

/* ── Tooltip ──────────────────────────────────────────────── */
#tt {
    position: fixed;
    z-index: 120;
    display: none;
    pointer-events: none;
    background: var(--glass-bg-hi);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-bd);
    border-radius: var(--r-md);
    padding: 10px 13px;
    font-size: .75rem;
    line-height: 1.55;
    max-width: 210px;
    box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.tt-name { font-weight: 700; font-size: .8rem; margin-bottom: 4px; color: var(--glass-text); }
.tt-row  { display: flex; justify-content: space-between; gap: 12px; color: var(--glass-muted); }
.tt-row b { color: var(--glass-text); font-weight: 600; }
.tt-hint { margin-top: 5px; font-size: .68rem; color: var(--primary); }

/* ── Modal ────────────────────────────────────────────────── */
#modal-bg {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.72);
    backdrop-filter: blur(5px);
    z-index: 200;
    align-items: center; justify-content: center;
    padding: 16px;
}
#modal-bg.on { display: flex; }
#modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 24px 64px rgba(0,0,0,.65);
    animation: kin-mshow .18s ease;
}
@keyframes kin-mshow { from { transform: scale(.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#modal-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0;
    background: var(--surface);
    z-index: 1;
}
#modal-hdr h3 { font-size: 1rem; font-weight: 700; font-family: 'Cinzel', serif; color: var(--text); letter-spacing: .04em; }
#modal-x {
    background: none; border: none;
    color: var(--text-muted); font-size: 1.5rem; line-height: 1;
    cursor: pointer; padding: 2px 6px; border-radius: var(--r-sm);
    transition: color .12s;
}
#modal-x:hover { color: var(--text); }

#modal-grid { display: grid; grid-template-columns: 1fr 1fr; }
@media (max-width: 520px) {
    #modal-grid { grid-template-columns: 1fr; }
    #modal-info { border-right: none !important; border-bottom: 1px solid var(--border); }
}

#modal-info { padding: 18px 20px; border-right: 1px solid var(--border); }
.mi-row { margin-bottom: 13px; }
.mi-lbl {
    font-size: .68rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 700;
    margin-bottom: 2px;
    font-family: 'Lato', sans-serif;
}
.mi-val { font-size: .9rem; font-weight: 600; color: var(--text); font-family: 'Lato', sans-serif; }

/* Badges de estado */
.badge {
    display: inline-block;
    padding: 3px 12px;
    border-radius: var(--r-full);
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-family: 'Lato', sans-serif;
}
.b-disponible    { background: rgba(74,222,128,.12);   color: var(--disponible); }
.b-apartada      { background: rgba(251,191,36,.12);   color: var(--apartada); }
.b-vendida       { background: rgba(248,113,113,.12);  color: var(--vendida); }
.b-reservada     { background: rgba(167,139,250,.12);  color: var(--reservada); }
.b-no_disponible { background: transparent; color: var(--no-disp); border: 1px solid var(--border); }

/* ── Formulario de contacto ───────────────────────────────── */
#modal-lead { padding: 18px 20px; }
#modal-lead h4 {
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    margin-bottom: 13px;
    font-family: 'Lato', sans-serif;
}
.lf { margin-bottom: 10px; }
.lf label {
    display: block;
    font-size: .68rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 3px;
    font-family: 'Lato', sans-serif;
}
.lf-required { color: var(--danger); }
.lf input, .lf textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--r-sm);
    padding: 7px 10px;
    font-size: .83rem;
    font-family: 'Lato', sans-serif;
    outline: none;
    transition: border-color .15s;
}
.lf input::placeholder, .lf textarea::placeholder { color: var(--text-muted); opacity: .6; }
.lf input:focus, .lf textarea:focus { border-color: var(--primary); }
.lf textarea { resize: vertical; min-height: 56px; }

#btn-send {
    width: 100%;
    background: var(--primary);
    color: var(--text-inv);
    border: none;
    padding: 9px;
    border-radius: var(--r-full);
    font-size: .85rem;
    font-weight: 700;
    font-family: 'Lato', sans-serif;
    cursor: pointer;
    transition: background .15s;
    margin-top: 2px;
}
#btn-send:hover:not(:disabled) { background: var(--primary-hov); }
#btn-send:disabled { background: var(--border); color: var(--text-muted); cursor: default; }

#lead-err { display: none; color: var(--danger); font-size: .75rem; margin-top: 6px; }
#lead-ok {
    display: none;
    text-align: center;
    padding: 20px;
    color: var(--disponible);
    font-weight: 700;
    font-size: .9rem;
    font-family: 'Cinzel', serif;
}
#lead-ok svg { display: block; margin: 0 auto 8px; }

/* ── Responsive móvil ─────────────────────────────────────────
 * Estructura nueva (desktop vs móvil):
 *
 * DESKTOP: #plano-outer { position:relative }
 *   ├── #nav-overlay   → position:absolute, top:10px left:10px  (overlay)
 *   ├── #plano-wrap    → padding-top trick (aspect ratio)
 *   │     └── #plano-box → position:absolute, inset:0
 *   ├── #legend        → position:absolute, bottom:12px left:12px (overlay)
 *   └── #legend-unidades → position:absolute, bottom:12px right:12px (overlay)
 *
 * MÓVIL: #plano-outer { display:flex; flex-direction:column }
 *   ├── #nav-overlay   → position:static  ← HEADER (solo visible en sub-planos)
 *   ├── #plano-wrap    → padding-top:0; #plano-box con alto por JS
 *   ├── #legend        → position:static  ← FOOTER
 *   └── #legend-unidades → position:static ← FOOTER
 * ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    html, body { overflow: auto; }

    /* Outer: flex column para apilar nav → mapa → leyendas */
    #plano-outer {
        display: flex;
        flex-direction: column;
    }

    /* Nav: queda en flujo, aparece arriba del mapa cuando está visible */
    #nav-overlay {
        position: static !important;
        max-width: 100% !important;
        padding: 8px 10px;
        background: var(--surface);
        border-bottom: 1px solid var(--glass-bd);
        flex-shrink: 0;
    }

    /* Cancelar el padding-top ratio trick del plano-wrap en móvil
       (JS calcula el alto del #plano-box directamente) */
    #plano-wrap {
        padding-top: 0 !important;
        flex-shrink: 0;
    }

    /* El box del mapa: position relative con alto que pone el JS */
    #plano-box {
        position: relative !important;
        inset: auto !important;
        width: 100%;
    }

    /* Leyendas: salen del flujo absoluto y se convierten en footer */
    #legend,
    #legend-unidades {
        position: static !important;
        width: 100%;
        display: grid !important;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px 12px;
        padding: 10px 14px;
        border-radius: 0;
        backdrop-filter: none;
        border-left: none;
        border-right: none;
        border-bottom: none;
        background: var(--surface) !important;
        pointer-events: auto;
        flex-shrink: 0;
    }
    #legend          { border-top: 1px solid var(--glass-bd); }
    #legend-unidades { border-top: 1px solid var(--glass-bd); }
    .leg { font-size: .75rem; }

    /* Banner inactivo: también en flujo en móvil */
    #banner-inactivo {
        position: static !important;
        transform: none !important;
        justify-content: center;
        border-radius: 0;
        white-space: normal;
    }
}

/* ── Cotizador placeholder ────────────────────────────────── */
#cotizador {
    margin: 0 20px 20px;
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: var(--r-md);
    padding: 18px;
    text-align: center;
}
#cotizador strong {
    display: block;
    font-size: .8rem;
    color: var(--text-muted);
    margin-bottom: 3px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-family: 'Cinzel', serif;
}
#cotizador span { font-size: .75rem; color: var(--text-muted); opacity: .6; }
