/* Estilos de la aplicación. Los valores salen de tokens.css (se carga antes). */

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

:root {
    color-scheme: light;
    font-family: var(--rg-fuente);
    font-size: 100%;
    color: var(--rg-texto);
    background: var(--rg-fondo);
}

body {
    margin: 0;
    font-size: var(--rg-texto-base);
    line-height: 1.5;
}

/* Cabecera con logotipo */
.cabecera {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--rg-espacio);
    padding: .5rem var(--rg-espacio);
    border-bottom: 4px solid var(--rg-primario);
    background: var(--rg-fondo);
}
.cabecera img { display: block; height: 44px; width: auto; }
.cabecera__titulo { margin: 0; font-size: 1rem; font-weight: 700; }

.contenido { max-width: 40rem; margin: 0 auto; padding: var(--rg-espacio); }
.contenido--estrecho { max-width: 28rem; }

h1 { font-size: var(--rg-texto-titulo); line-height: 1.2; margin: 1rem 0; }
h2 { font-size: var(--rg-texto-grande); margin: 1.5rem 0 .5rem; }

a { color: var(--rg-info); text-underline-offset: .15em; }

/* Formularios y botones: objetivo táctil mínimo 48 px */
label { display: block; margin-top: 1rem; font-weight: 700; }
input, select, textarea {
    width: 100%;
    min-height: var(--rg-tactil-minimo);
    font: inherit;
    font-size: 1.125rem;
    padding: .5rem .75rem;
    color: var(--rg-texto);
    background: var(--rg-fondo);
    border: var(--rg-borde-ancho) solid var(--rg-texto-secundario);
    border-radius: var(--rg-radio);
}

[hidden] { display: none !important; }

button, .boton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    min-height: var(--rg-tactil-minimo);
    min-width: var(--rg-tactil-minimo);
    margin-top: 1rem;
    padding: .5rem 1.25rem;
    font: inherit;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--rg-texto-sobre-primario);
    background: var(--rg-primario);
    border: var(--rg-borde-ancho) solid var(--rg-texto);
    border-radius: var(--rg-radio);
    cursor: pointer;
    text-decoration: none;
}
.boton--secundario { background: var(--rg-fondo); }
.boton--peligro { color: #FFFFFF; background: var(--rg-error); border-color: var(--rg-error); }
button:disabled { cursor: not-allowed; opacity: 1; color: var(--rg-texto-secundario); background: var(--rg-superficie); border-style: dashed; }

:focus-visible { outline: 3px solid var(--rg-foco); outline-offset: 3px; }

/* Mensajes y estados: el color nunca va solo, siempre hay texto */
.error, .aviso, .estado {
    padding: .75rem 1rem;
    border: var(--rg-borde-ancho) solid currentColor;
    border-radius: var(--rg-radio);
}
.error { color: var(--rg-error); background: var(--rg-error-fondo); }
.aviso { color: var(--rg-texto); background: var(--rg-info-fondo); border-color: var(--rg-info); }
.estado--ok { color: var(--rg-ok); background: var(--rg-ok-fondo); }
.estado--aviso { color: var(--rg-aviso); background: var(--rg-aviso-fondo); }
.estado--error { color: var(--rg-error); background: var(--rg-error-fondo); }
.estado--info { color: var(--rg-info); background: var(--rg-info-fondo); }

.secreto { font-family: var(--rg-fuente-mono); font-size: 1.25rem; letter-spacing: .05em; word-break: break-all; }
.secundario { color: var(--rg-texto-secundario); }
.oculto { display: none !important; }

/* Panel de estado del terminal de campo */
.panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
    gap: .75rem;
    margin: 1rem 0;
    padding: 0;
    list-style: none;
}
.panel__item {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    min-height: 5rem;
    padding: .75rem 1rem;
    border: var(--rg-borde-ancho) solid var(--rg-borde);
    border-radius: var(--rg-radio);
    background: var(--rg-fondo);
}
.panel__etiqueta { font-size: .9375rem; color: var(--rg-texto-secundario); }
.panel__valor { font-size: var(--rg-texto-grande); font-weight: 700; }
.panel__valor.estado { padding: .25rem .5rem; font-size: 1.0625rem; align-self: flex-start; }

/* Lista de obras */
.obras { list-style: none; margin: 0; padding: 0; }
.obras li + li { margin-top: .5rem; }
.obra {
    display: flex;
    width: 100%;
    margin: 0;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    background: var(--rg-fondo);
    border-color: var(--rg-borde);
    font-weight: 400;
}
.obra[aria-pressed="true"] { border-color: var(--rg-texto); background: var(--rg-primario-suave); box-shadow: inset 6px 0 0 var(--rg-primario); }
.obra__codigo { font-weight: 700; }
.obra__lugar { font-size: .9375rem; color: var(--rg-texto-secundario); }

/* Tabla de compatibilidad */
.tabla { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.tabla th, .tabla td { padding: .5rem; border-bottom: 1px solid var(--rg-borde); text-align: left; vertical-align: top; }
.tabla td:last-child { white-space: nowrap; }

/* Diálogos */
dialog {
    max-width: min(32rem, 92vw);
    padding: 1.25rem;
    color: var(--rg-texto);
    border: var(--rg-borde-ancho) solid var(--rg-texto);
    border-radius: var(--rg-radio);
}
dialog::backdrop { background: rgb(22 25 34 / 60%); }

/* Editor de croquis: pantalla completa, el lienzo ocupa lo que deja la barra */
.dialogo-croquis[open] {
    display: flex;
    flex-direction: column;
    /* Toda la ventana sin desbordar (100vw incluye la barra de desplazamiento en escritorio) */
    position: fixed;
    inset: 0;
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
    overflow: hidden;
    margin: 0;
    padding: .5rem;
    border: 0;
    border-radius: 0;
    background: var(--rg-fondo);
}
.croquis__barra { font-size: .875rem; }
.croquis__fila { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; margin-bottom: .3rem; }
.croquis__barra h2 { margin: 0 auto 0 0; font-size: 1rem; }
.dialogo-croquis button { margin: 0; min-width: 0; min-height: 36px; padding: .2rem .55rem; font-size: .875rem; border-width: 1px; }
.croquis__barra [aria-pressed="true"] { background: var(--rg-primario); }
.croquis__barra .estado { margin: 0 0 .3rem; padding: .2rem .5rem; font-size: .8rem; }
.croquis__lienzo { flex: 1 1 auto; width: 100%; min-height: 8rem; display: block; touch-action: none; background: #FFFFFF; border: 1px solid var(--rg-borde); }
.croquis__medida { flex: 0 0 auto; max-height: 40dvh; overflow-y: auto; padding-top: .3rem; font-size: .875rem; }
.croquis__medida p { margin: 0 0 .3rem; font-weight: 700; }
.croquis__propuesta { border-top: 3px solid #2563EB; }
/* Vista 3D: los paneles de puertas/ventanas e instalaciones se muestran debajo del lienzo */
.vista3d__panel { flex: 0 0 auto; max-height: 40dvh; overflow-y: auto; font-size: .9rem; }
.vista3d__panel section { margin: 0; padding: .4rem 0 0; }
.vista3d__panel h2 { margin: 0 0 .25rem; font-size: 1rem; }
.en-3d #paso-huecos > p.secundario:first-of-type, .en-3d #paso-instalaciones > p.secundario:first-of-type,
.en-3d #hueco-manual, .en-3d #hueco-posicion, .en-3d #hueco-ar, .en-3d #instalacion-manual, .en-3d #instalacion-posicion { display: none !important; }
.dialogo-3d [data-vista3d][aria-pressed="true"] { background: var(--rg-primario); }
.croquis__verificacion { margin: 0 0 .3rem; padding-left: 1.1rem; font-size: .85rem; }
.croquis__verificacion li { margin: .1rem 0; }
.croquis__campos { display: grid; grid-template-columns: 1fr 6.5rem; gap: .25rem .5rem; align-items: center; margin-bottom: .3rem; }
.croquis__campos label { margin: 0; font-weight: 400; }
.croquis__campos input[data-origen="laser"] { border-color: #15803D; }
.croquis__medida input { width: 7rem; min-height: 36px; padding: .2rem .4rem; font-size: 1rem; }
.acciones { display: flex; flex-wrap: wrap; gap: .75rem; }

/* Banda fija de avisos (actualización, sesión caducada, modo reducido) */
.bandas { display: grid; gap: .5rem; margin-top: .5rem; }
.bandas > p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Captura en realidad aumentada */
.overlay { max-width: 40rem; margin: 0 auto; }
body.en-ar, body.en-ar .contenido { background: transparent; }
body.en-ar .cabecera { display: none; }
body.en-ar .overlay { background: rgb(255 255 255 / 92%); border-radius: var(--rg-radio); padding: .5rem; }
/* Cabecera de la medición y pestañas (manual / realidad aumentada) */
.captura__cabecera { display: flex; align-items: center; gap: .75rem; }
.captura__cabecera h1 { margin: .5rem 0; }
.pestanas { display: flex; gap: 0; margin: .75rem 0; border-bottom: 2px solid var(--rg-borde); }
.pestanas [role="tab"] { flex: 1; margin: 0 0 -2px; border: 0; border-bottom: 4px solid transparent; border-radius: 0; background: none; font-weight: 700; color: var(--rg-texto); }
.pestanas [role="tab"][aria-selected="true"] { border-bottom-color: var(--rg-primario); }
.pestanas [role="tab"][aria-selected="false"] { font-weight: 400; opacity: .75; }
.modos { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }
.modos button { margin: 0; }
.modos button[aria-pressed="true"], [data-herramienta][aria-pressed="true"] { background: var(--rg-primario); border-style: solid; }
.modos button[aria-pressed="false"] { background: var(--rg-fondo); }
.casilla { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.casilla input { width: var(--rg-tactil-minimo); min-height: var(--rg-tactil-minimo); margin: 0; }
.planta { display: block; width: 100%; height: 14rem; margin: 1rem 0; border: var(--rg-borde-ancho) solid var(--rg-borde); border-radius: var(--rg-radio); background: var(--rg-fondo); }
.planta__muro { stroke-width: .06; stroke-linecap: round; }
.planta__muro--laser { stroke: var(--rg-ok); }
.planta__muro--estimada { stroke: var(--rg-primario); }
.planta__muro--inferida { stroke: var(--rg-gris-logo); stroke-dasharray: .15 .1; }
.planta__muro--seleccionado { stroke-width: .12; }
.simulador { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .5rem; border: 3px dashed var(--rg-error); }
.simulador button { margin: 0; }
.tramas { font-family: var(--rg-fuente-mono); font-size: .9375rem; max-height: 20rem; overflow: auto; }

.casillas { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .5rem; margin: .5rem 0; }
.casillas button { margin: 0; flex-direction: column; align-items: flex-start; background: var(--rg-fondo); font-weight: 400; }
.casillas button[aria-pressed="true"] { border-width: 4px; background: var(--rg-primario-suave); }
.casillas strong { font-size: 1.125rem; }
[data-mano][aria-pressed="true"], [data-sentido][aria-pressed="true"] { background: var(--rg-primario); border-style: solid; }
.planta--grande { height: 22rem; }
.planta__cota { font-size: .22px; font-family: var(--rg-fuente); fill: var(--rg-texto); }
.planta__elemento { fill: var(--rg-info); }
.planta__hueco { stroke: var(--rg-fondo); stroke-width: .1; }
.planta__obstaculo { fill: rgb(179 38 30 / 20%); stroke: var(--rg-error); stroke-width: .03; }
.leyenda__laser { color: var(--rg-ok); font-weight: 700; }
.leyenda__estimada { color: var(--rg-aviso); font-weight: 700; }
.leyenda__inferida { color: var(--rg-texto-secundario); font-weight: 700; }

/* Oficina */
.contenido--ancho { max-width: 64rem; }
.levantamiento { margin: 1.5rem 0; padding: 1rem; border: var(--rg-borde-ancho) solid var(--rg-borde); border-radius: var(--rg-radio); }
.levantamiento h2 { margin-top: 0; }
/* Estados dentro del texto de una medición o de la tabla de archivos: compactos y en línea */
.levantamiento .estado { display: inline-block; padding: .05rem .5rem; border-width: 1px; line-height: 1.5; }
.archivo__error { display: block; margin-top: .25rem; font-size: .875rem; color: var(--rg-texto-secundario); }
.tabla--archivos td:last-child { white-space: normal; }
.descartar { margin: .5rem 0; }
.mediciones__quitar { margin: 0 0 0 .25rem; min-height: 28px; padding: 0 .5rem; font-size: .8rem; }
.descartar summary { cursor: pointer; color: var(--rg-error); font-weight: 700; }
.archivo__borrar button { margin: 0; min-height: 32px; padding: .1rem .6rem; font-size: .875rem; }
.generar { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 0 1rem; align-items: end; }
.generar label { margin-top: .5rem; }

/* Identidad corporativa, 2FA y licencias */
.qr { margin: 1rem 0; }
.qr img { display: block; width: 240px; height: 240px; background: #FFFFFF; }
.marca-vista { display: block; max-height: 64px; width: auto; margin: .5rem 0; }
input[type="color"] { width: 6rem; height: var(--rg-tactil-minimo); padding: 2px; }
.licencia { white-space: pre-wrap; font-family: var(--rg-fuente-mono); font-size: .85rem; background: var(--rg-superficie); padding: var(--rg-espacio); border-radius: var(--rg-radio); max-width: 100%; overflow-x: auto; }

/* Conflictos de envío */
.conflicto { border: var(--rg-borde-ancho) solid var(--rg-borde); border-radius: var(--rg-radio); padding: var(--rg-espacio); margin: 1rem 0; }
.conflicto h2 { margin-top: 0; }
.acciones { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.eleccion { display: flex; align-items: center; gap: .5rem; min-height: var(--rg-tactil-minimo); }
.conflicto .tabla td:last-child { white-space: normal; }
.conflicto .tabla td { width: 50%; }
.visualmente-oculto { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.alternativa { margin-top: 1rem; }
.alternativa summary { cursor: pointer; font-weight: 700; color: var(--rg-info); }

/* Móviles: la tabla de archivos pasa a una ficha por archivo (no cabe en 4 columnas) */
@media (max-width: 600px) {
    .tabla--archivos thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .tabla--archivos tr { display: block; padding: .5rem 0; border-bottom: 1px solid var(--rg-borde); }
    .tabla--archivos td { display: grid; grid-template-columns: 5.5rem 1fr; gap: .5rem; padding: .15rem 0; border: 0; }
    .tabla--archivos td::before { content: attr(data-etiqueta); font-weight: 700; color: var(--rg-texto-secundario); }
    .levantamiento { padding: .75rem; }
}

/* Móviles (F8a2): letra y botones algo más pequeños para dejar sitio al trabajo.
   Los campos siguen a 16 px para que el navegador no amplíe la página al escribir. */
@media (max-width: 600px) {
    :root {
        --rg-texto-base: .9375rem;
        --rg-texto-grande: 1.125rem;
        --rg-texto-titulo: 1.375rem;
        --rg-tactil-minimo: 40px;
        --rg-espacio: .75rem;
    }
    label { margin-top: .6rem; }
    input, select, textarea { font-size: 1rem; padding: .35rem .6rem; }
    button, .boton { margin-top: .6rem; padding: .35rem .8rem; font-size: .9375rem; }
    .acciones { gap: .5rem; }
    h2 { margin: 1rem 0 .35rem; }
    .panel__item { padding: .4rem .6rem; }
}
