/* Paleta oficial KAPABU: navy, naranja y cuadrícula de plano */
:root {
    --bg: #0B1622; --navy: #0D1B2A; --vidrio: rgba(15, 31, 48, .8); --line: rgba(125, 211, 252, .16);
    --text: #E2E8F0; --muted: #94A3B8; --dim: #64748B;
    --orange: #F97316; --ok: #22C55E; --warn: #F59E0B; --stop: #EF4444; --sky: #38BDF8;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif; color: var(--text);
    background-color: var(--bg);
    background-image: linear-gradient(rgba(125, 211, 252, .045) 1px, transparent 1px), linear-gradient(90deg, rgba(125, 211, 252, .045) 1px, transparent 1px);
    background-size: 36px 36px;
}
button { font-family: inherit; color: inherit; background: none; border: 0; }

/* Una sola escena: todo vive en el mismo cuadro */
.escena {
    position: relative; overflow: hidden;
    display: grid; gap: .8em; padding: 0 1em 1em;
    height: 100vh; height: 100dvh; min-height: 590px;
    font-size: clamp(12.5px, .62vw + 6px, 16px);
    grid-template-columns: clamp(215px, 17.5vw, 310px) minmax(0, 1fr) clamp(320px, 28vw, 540px);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
        "cabeza cabeza cabeza"
        "areas relato obra"
        "areas plano obra"
        "areas hoja equipo";
}

.cabeza { grid-area: cabeza; display: flex; align-items: center; justify-content: space-between; padding: .55em 0; border-bottom: 1px solid var(--line); }
.cabeza img { height: 2.5em; width: auto; display: block; }
.cabeza-der { display: flex; align-items: center; gap: .7em; }
.marca-ejemplo { color: #FDBA74; border: 1px solid rgba(249, 115, 22, .35); background: rgba(249, 115, 22, .1); border-radius: 999px; padding: .25em .8em; font-size: .84em; font-weight: 600; }
.btn-accion { color: #93C5FD; font-size: .92em; font-weight: 600; cursor: pointer; padding: .3em .5em; border-radius: 6px; }
.btn-accion:hover { color: #fff; }

/* Una frase que acompaña todo; no hay pasos ni números */
.relato { grid-area: relato; position: relative; display: flex; align-items: center; justify-content: space-between; gap: 1em; padding-bottom: .55em; min-height: 4.6em; }
.relato-texto { min-width: 0; transition: opacity .18s; }
.relato.cambia .relato-texto { opacity: 0; }
.relato h1 { font-size: clamp(1.45em, 2.15vw, 2.1em); line-height: 1.15; font-weight: 800; letter-spacing: -.012em; }
.relato p { color: var(--muted); font-size: 1em; margin-top: .2em; }
.hilo { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(148, 163, 184, .14); border-radius: 2px; overflow: hidden; }
.hilo i { display: block; height: 100%; width: 100%; transform-origin: left; transform: scaleX(0); background: var(--orange); }
.cta { flex: 0 0 auto; background: var(--orange); color: #fff; text-decoration: none; font-weight: 700; padding: .65em 1.3em; border-radius: 9px; opacity: 0; pointer-events: none; transition: opacity .4s, background .2s; }
.cta:hover { background: #ea6a0e; }
.fin .cta { opacity: 1; pointer-events: auto; }

.tarjeta { background: var(--vidrio); border: 1px solid var(--line); border-radius: 14px; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; position: relative; z-index: 1; backdrop-filter: blur(6px); }
.tarjeta > header { display: flex; align-items: center; justify-content: space-between; gap: .6em; padding: .6em .85em; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.tarjeta h2 { font-size: 1em; font-weight: 700; }
.cifra { color: var(--sky); font-weight: 700; font-variant-numeric: tabular-nums; }

/* Áreas */
.t-areas { grid-area: areas; margin-top: .1em; }
.lista-areas { flex: 1; min-height: 0; overflow-y: auto; padding: .3em .4em; scrollbar-width: thin; scrollbar-color: rgba(148, 163, 184, .25) transparent; }
.fila-area { --c: #38BDF8; display: grid; grid-template-columns: .6em minmax(0, 1fr) auto; align-items: center; gap: .6em; width: 100%; height: clamp(1.75em, 3.6vh, 2.5em); padding: 0 .5em; border-radius: 7px; text-align: left; font-size: .96em; cursor: default; }
.fila-area .punto { width: .6em; height: .6em; border-radius: 3px; background: var(--c); opacity: 0; transition: opacity .25s, background .3s; }
.fila-area .nombre { color: transparent; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: rgba(148, 163, 184, .09); border-radius: 4px; transition: color .25s, background .25s; }
.fila-area .dato { color: transparent; font-size: .9em; font-variant-numeric: tabular-nums; white-space: nowrap; transition: color .25s; }
.fila-area.lista .punto { opacity: 1; }
.fila-area.lista .nombre { color: var(--text); background: transparent; }
.fila-area.lista .dato { color: var(--muted); }
.fila-area.frenada .dato { color: #FCA5A5; font-weight: 600; }
.fila-area.elegida { background: rgba(249, 115, 22, .16); }
.libre .fila-area { cursor: pointer; }
.libre .fila-area:hover { background: rgba(125, 211, 252, .08); }
.fila-area:focus-visible, .piso:focus-visible, .fila-equipo:focus-visible, .btn-accion:focus-visible, .cta:focus-visible { outline: 2px solid var(--orange); outline-offset: 1px; }
.t-areas footer { display: flex; justify-content: space-between; align-items: baseline; gap: .6em; padding: .55em .85em; border-top: 1px solid var(--line); color: var(--muted); font-size: .9em; }
.t-areas footer b { color: var(--text); font-size: 1.1em; font-variant-numeric: tabular-nums; }

/* Plano: va directo sobre la mesa, sin tarjeta */
.t-plano { grid-area: plano; position: relative; min-height: 0; min-width: 0; }
#plano { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.rotulo { position: absolute; left: .2em; top: .1em; z-index: 2; font-size: .9em; font-weight: 600; color: var(--muted); opacity: 0; transition: opacity .3s; }
.rotulo.visible { opacity: 1; }
.rotulo.frenado { color: #FCA5A5; }

.trazo { fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1 1; stroke-dashoffset: 1; opacity: 0; pointer-events: none; }
.trazo.muro { stroke: #E8EEF5; stroke-width: 1.4; stroke-linecap: square; }
.trazo.nucleo { stroke: #FBBF24; stroke-width: .7; }
.trazo.ventana { stroke: #7DD3FC; stroke-width: .7; }
.trazo.baranda { stroke: #7DD3FC; stroke-width: .6; }
.trazo.puerta { stroke: #38BDF8; stroke-width: .6; }
.trazo.mueble { stroke: #8195AD; stroke-width: .5; }
.trazo.cota { stroke: #64748B; stroke-width: .5; }
.trazo.punta { stroke: #F0F9FF; }
#capaCotas text { fill: #7C8FA6; font-size: 6.4px; text-anchor: middle; }

.area { --c: #38BDF8; fill: var(--c); fill-opacity: 0; stroke: var(--c); stroke-opacity: 0; stroke-width: 1; transition: fill-opacity .35s, stroke-opacity .35s, fill .4s, stroke .4s; pointer-events: none; }
.area.vista { fill-opacity: .13; }
.area.con-estado { fill-opacity: .27; }
.area.frenada { animation: alerta 1.7s ease-in-out infinite; }
.area.elegida { fill-opacity: .42; stroke-opacity: 1; animation: none; }
.libre .area { pointer-events: auto; cursor: pointer; }
.libre .area:hover { fill-opacity: .36; }
@keyframes alerta { 0%, 100% { fill-opacity: .3; } 50% { fill-opacity: .6; } }

.etq { opacity: 0; transition: opacity .3s; pointer-events: none; }
.etq.vista { opacity: 1; }
.etq text { fill: #F1F5F9; font-size: 9.4px; font-weight: 600; text-anchor: middle; paint-order: stroke; stroke: rgba(10, 20, 31, .92); stroke-width: 2.6px; stroke-linejoin: round; }
.etq.chica text { font-size: 7.2px; }
.etq text.m2 { fill: #A7B6C8; font-size: 7.6px; font-weight: 500; }

.el { opacity: 0; transform: scale(.2); transform-box: fill-box; transform-origin: center; transition: opacity .2s, transform .25s cubic-bezier(.3, 1.7, .5, 1); pointer-events: none; }
.el.vista { opacity: 1; transform: none; }
.el.vista.tenue { opacity: .1; }
.el circle { stroke: #0A141F; stroke-width: .7; }
#detector { fill: none; stroke: var(--orange); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 4px rgba(249, 115, 22, .8)); opacity: 0; pointer-events: none; }

.soltar { position: absolute; inset: 7% 13%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3em; border: 2px dashed rgba(148, 163, 184, .45); border-radius: 16px; background: rgba(10, 20, 31, .55); color: var(--muted); transition: border-color .2s, background .2s; pointer-events: none; }
.soltar svg { width: 2.6em; height: 2.6em; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; margin-bottom: .3em; }
.soltar b { color: var(--text); font-size: 1.3em; font-weight: 700; }
.soltar.encima { border-color: var(--orange); background: rgba(249, 115, 22, .1); color: #FDBA74; }
.onda { position: absolute; left: 50%; top: 50%; width: 9em; height: 9em; margin: -4.5em 0 0 -4.5em; border-radius: 50%; border: 2px solid var(--orange); opacity: 0; pointer-events: none; }

/* Hoja de cálculo */
.t-hoja { grid-area: hoja; }
.hoja-barra { display: grid; grid-template-columns: 3.4em 1.6em minmax(0, 1fr); align-items: center; height: 2.05em; font-size: .9em; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.celda-nombre { text-align: center; color: var(--muted); border-right: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.fx { text-align: center; color: var(--dim); font-style: italic; font-weight: 600; border-right: 1px solid var(--line); }
.formula { padding: 0 .7em; color: #BBD2E6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, Consolas, monospace; font-size: .95em; }
.hoja-rejilla { flex: 1; min-height: 0; overflow: hidden; }
.t-hoja table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: .9em; }
.c-num { width: 2.3em; }
.c-a { width: 33%; }
.c-b { width: 19%; }
.t-hoja th, .t-hoja td { height: 1.85em; padding: 0 .55em; border: 1px solid rgba(125, 211, 252, .11); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; }
.t-hoja thead th { height: 1.6em; background: rgba(148, 163, 184, .1); color: var(--muted); font-weight: 500; text-align: center; font-size: .9em; }
.t-hoja tbody th { padding: 0; background: rgba(148, 163, 184, .1); color: var(--muted); font-weight: 500; text-align: center; font-size: .9em; }
.t-hoja td.n { text-align: right; font-variant-numeric: tabular-nums; }
.t-hoja .titulos td { color: var(--muted); font-weight: 600; }
.t-hoja .total td { font-weight: 700; color: #fff; }
.t-hoja td.sel { outline: 2px solid var(--ok); outline-offset: -2px; background: rgba(34, 197, 94, .1); }
.t-hoja td.sel::after { content: ""; position: absolute; right: 0; bottom: 0; width: 5px; height: 5px; background: var(--ok); }
.libre .fila-hoja { cursor: pointer; }
.libre .fila-hoja:hover td { background: rgba(125, 211, 252, .07); }
.fila-hoja.elegida td { background: rgba(249, 115, 22, .15); }
.fila-hoja:focus-visible { outline: 2px solid var(--orange); outline-offset: -2px; }

/* Edificio */
.t-obra { grid-area: obra; margin-top: .1em; }
.t-obra > header span { color: var(--muted); font-size: .92em; }
.visor { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); }
.lienzo-caja { position: relative; min-width: 0; min-height: 0; }
#lienzo3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; cursor: grab; }
#lienzo3d:active { cursor: grabbing; }
.sin-3d { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 1em; }
.ascensor { display: flex; flex-direction: column; justify-content: center; gap: .16em; padding: .5em 0 2.4em .55em; z-index: 2; }
.piso { --c: rgba(148, 163, 184, .4); width: 2em; height: 1.45em; flex: 0 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; font-size: .86em; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--dim); border-radius: 5px; border: 1px solid transparent; background: rgba(148, 163, 184, .08); cursor: default; opacity: 0; transition: opacity .25s, background .3s, color .3s, border-color .2s; }
.piso.asomado { opacity: 1; }
.piso.pintado { background: color-mix(in srgb, var(--c) 26%, transparent); color: #fff; }
.piso.elegido { border-color: #fff; }
.libre .piso { cursor: pointer; }
.libre .piso:hover { border-color: var(--c); }
.globo { position: absolute; z-index: 3; left: 0; top: 0; background: rgba(10, 20, 31, .94); border: 1px solid var(--line); border-radius: 7px; padding: .3em .6em; font-size: .9em; font-weight: 600; white-space: nowrap; pointer-events: none; }
.leyenda { position: absolute; left: .7em; right: .7em; bottom: .5em; display: flex; flex-wrap: wrap; justify-content: center; gap: .15em .85em; font-size: .86em; color: var(--muted); pointer-events: none; opacity: 0; transition: opacity .4s; }
.leyenda.visible { opacity: 1; }
.leyenda i { display: inline-block; width: .62em; height: .62em; border-radius: 3px; margin-right: .35em; }

/* Equipo */
.t-equipo { grid-area: equipo; }
.t-equipo .avance { color: #4ADE80; font-size: 1.3em; font-weight: 800; font-variant-numeric: tabular-nums; }
.barra { height: 4px; background: rgba(148, 163, 184, .14); flex: 0 0 auto; }
.barra i { display: block; height: 100%; width: 100%; transform-origin: left; transform: scaleX(0); background: var(--ok); }
.lista-equipo { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: space-evenly; padding: .25em .45em; }
.fila-equipo { display: grid; grid-template-columns: 2.25em minmax(0, 1fr) auto; align-items: center; gap: .6em; width: 100%; padding: .22em .4em; border-radius: 8px; text-align: left; transition: background .2s; cursor: default; }
.fila-equipo .avatar, .fila-equipo .quien b, .fila-equipo .quien span, .fila-equipo .chip { transition: color .3s, background .3s, opacity .3s; }
.fila-equipo:not(.visible) .avatar { color: transparent; background: rgba(148, 163, 184, .09); }
.fila-equipo:not(.visible) .quien b, .fila-equipo:not(.visible) .quien > span { color: transparent; background: rgba(148, 163, 184, .09); border-radius: 4px; }
.fila-equipo:not(.visible) .quien > span { margin-top: .25em; width: 70%; }
.fila-equipo:not(.visible) .chip { opacity: 0; }
.fila-equipo .avatar { width: 2.25em; height: 2.25em; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .86em; font-weight: 700; background: rgba(56, 189, 248, .18); color: #BAE6FD; }
.fila-equipo .quien { min-width: 0; line-height: 1.25; }
.fila-equipo .quien b { display: block; font-size: .97em; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fila-equipo .quien span { display: block; color: var(--muted); font-size: .86em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fila-equipo .chip { --c: #22C55E; font-size: .84em; font-weight: 600; color: color-mix(in srgb, var(--c) 68%, white); background: color-mix(in srgb, var(--c) 17%, transparent); border-radius: 999px; padding: .15em .65em; white-space: nowrap; }
.libre .fila-equipo { cursor: pointer; }
.libre .fila-equipo:hover { background: rgba(125, 211, 252, .08); }
.fila-equipo.elegida { background: rgba(249, 115, 22, .14); }

.vuelos { position: absolute; left: 0; top: 0; z-index: 6; pointer-events: none; }

/* Cursor que arrastra el plano */
.arrastre { position: absolute; left: 0; top: 0; z-index: 7; opacity: 0; pointer-events: none; will-change: transform; }
.ficha { position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: .6em; padding: .55em .8em; white-space: nowrap; font-weight: 600; background: var(--navy); border: 1px solid var(--orange); border-radius: 10px; box-shadow: 0 14px 30px rgba(0, 0, 0, .5); }
.ficha .ext { background: var(--orange); color: #fff; font-weight: 800; font-size: .78em; border-radius: 5px; padding: .35em .5em; }
.cursor { position: absolute; left: 0; top: 0; width: 26px; height: 26px; }
.cursor path { fill: #fff; stroke: #0A141F; stroke-width: 1.4; stroke-linejoin: round; }

@media (max-width: 1150px) {
    .c-a { width: 31%; }
    .c-b { width: 18%; }
    .t-hoja th, .t-hoja td { padding: 0 .4em; }
}
@media (max-width: 860px) {
    .escena {
        height: auto; min-height: 100dvh; overflow: visible; gap: .55em; padding: 0 .7em .7em;
        font-size: 12.5px;
        grid-template-columns: minmax(0, .82fr) minmax(0, 1fr);
        grid-template-rows: auto auto minmax(190px, 30vh) 270px auto auto;
        grid-template-areas:
            "cabeza cabeza"
            "relato relato"
            "plano plano"
            "areas obra"
            "hoja hoja"
            "equipo equipo";
    }
    .relato h1 { font-size: 1.6em; }
    .relato { min-height: 4.2em; }
    .col-esp, .c-b { display: none; }
    .c-a { width: 36%; }
    .t-areas footer { font-size: .8em; white-space: nowrap; }
    .fila-area { height: 1.75em; font-size: .92em; }
    .ascensor { display: none; }
    .visor { grid-template-columns: minmax(0, 1fr); }
    .leyenda { display: none; }
    .soltar { inset: 6% 8%; }
    .t-areas, .t-obra { margin-top: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .area.frenada { animation: none; }
}
