:root {
    --fondo: #0a0b0d;
    --tarjeta: #16181d;
    --ficha: #1d2027;
    --ficha-alta: #262a33;
    --borde: #24272f;
    --texto: #f2f4f7;
    --suave: #8b919d;
    --tenue: #626874;
    --acento: #3b82f6;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Evita el zoom por doble toque al pulsar rápido varias veces */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--fondo);
    -webkit-text-size-adjust: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 18px 14px 120px;
    color: var(--texto);
}

.hidden { display: none !important; }

.container {
    width: 100%;
    max-width: 480px;
}

/* ---------- Pantalla de bloqueo ---------- */
#lock-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 70vh;
    width: 100%;
    max-width: 480px;
    gap: 16px;
}

/* El logo late como un corazón: dos golpes seguidos y una pausa */
#lock-screen .logo {
    width: 116px;
    height: 116px;
    animation: latido 1.8s ease-in-out infinite;
    transform-origin: center;
}

@keyframes latido {
    0%   { transform: scale(1); }
    10%  { transform: scale(1.14); }
    20%  { transform: scale(1); }
    30%  { transform: scale(1.09); }
    42%  { transform: scale(1); }
    100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    #lock-screen .logo { animation: none; }
}

#lock-screen h2 { font-size: 19px; font-weight: 600; }
#lock-screen p { font-size: 13.5px; color: var(--suave); max-width: 300px; line-height: 1.5; }

.btn-unlock {
    margin-top: 6px;
    padding: 14px 26px;
    border: none;
    border-radius: 999px;
    background: var(--acento);
    color: #fff;
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
}

.btn-unlock:active { transform: scale(0.97); }
.lock-error { color: #f87171; font-size: 12.5px; min-height: 16px; }

/* Entrar con código de alta: secundario, que la vía normal es el Face ID */
.btn-alta {
    margin-top: 10px;
    padding: 10px 20px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--suave);
    font-family: inherit;
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
}

/* Código de alta, en la pantalla de configuración */
.codigo-alta {
    margin-top: 12px;
    padding: 14px;
    border-radius: 14px;
    background: var(--ficha);
    text-align: center;
}

.codigo-alta-numero {
    margin-bottom: 6px;
    font-size: 34px;
    font-weight: 700;
    letter-spacing: 6px;
    font-variant-numeric: tabular-nums;
}

/* ---------- Cabecera ---------- */
.cabecera {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding: 0 4px;
}

.cabecera h1 { font-size: 27px; font-weight: 700; letter-spacing: -0.6px; }

.cabecera-sub {
    margin-top: 3px;
    color: var(--suave);
    font-size: 13px;
}

.cabecera-derecha {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-ajustes {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--ficha);
    color: var(--suave);
    cursor: pointer;
    transition: transform 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.btn-ajustes svg { width: 20px; height: 20px; }
.btn-ajustes:active { transform: scale(0.92); }

.btn-ajustes.abierto {
    background: rgba(59, 130, 246, 0.18);
    color: #93c5fd;
    transform: rotate(60deg);
}

/* ---------- Ajustes ---------- */
.ajuste-fila {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.ajuste-nombre { font-size: 13.5px; }
.ajuste-pie { margin-top: 3px; color: var(--tenue); font-size: 11.5px; line-height: 1.4; }

.interruptor {
    flex-shrink: 0;
    width: 50px;
    height: 30px;
    padding: 3px;
    border: none;
    border-radius: 999px;
    background: var(--ficha-alta);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.interruptor span {
    display: block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #8b919d;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.interruptor[aria-checked="true"] { background: rgba(59, 130, 246, 0.45); }
.interruptor[aria-checked="true"] span { transform: translateX(20px); background: #dbeafe; }

.faceid-fila {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 8px;
    padding: 11px 14px;
    border-radius: 12px;
    background: var(--ficha);
    font-size: 13px;
}

.faceid-fila .cuando { display: block; margin-top: 2px; color: var(--tenue); font-size: 11px; }

.faceid-borrar {
    flex-shrink: 0;
    padding: 7px 12px;
    border: none;
    border-radius: 999px;
    background: rgba(248, 113, 113, 0.14);
    color: #f87171;
    font-family: inherit;
    font-size: 11.5px;
    cursor: pointer;
}

.punto-estado {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 8px #22c55e;
}

/* ---------- Tarjetas ---------- */
.tarjeta {
    background: var(--tarjeta);
    border-radius: 22px;
    padding: 16px 14px;
    margin-bottom: 14px;
}

/* ---------- Temperaturas: lo primero de la app ---------- */
/* Dos filas en una sola tarjeta: la calle arriba y el salón debajo, para poder
   compararlas de un vistazo, que es justo para lo que sirve tener las dos. */
.clima { padding: 4px 4px; }

.clima-fila {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 14px;
    cursor: pointer;
}

/* Solo entre filas visibles: si una está oculta no debe dejar la raya suelta */
.clima-fila + .clima-fila:not(.hidden) { border-top: 1px solid var(--borde); }

.clima-icono {
    width: 25px;
    height: 25px;
    flex-shrink: 0;
    color: var(--acento);
}

.clima-icono.fuera { color: #fbbf24; }

.clima-datos { flex: 1; min-width: 0; }
.clima-sitio { font-size: 14.5px; font-weight: 600; }

.clima-pie {
    margin-top: 3px;
    color: var(--suave);
    font-size: 12.5px;
}

.clima-pie.aviso { color: #fbbf24; }
.clima-pie.fallo { color: #fca5a5; }

.clima-lectura {
    flex-shrink: 0;
    font-size: 31px;
    font-weight: 700;
    letter-spacing: -1.1px;
    line-height: 1;
}

.clima-lectura i {
    margin-left: 2px;
    color: var(--tenue);
    font-size: 15px;
    font-style: normal;
    font-weight: 600;
}

/* Estado de cada aparato en su cabecera, igual que el del PC */
#aire-situacion.encendido, #tv-situacion.encendido { color: #4ade80; }
#aire-situacion.apagado, #tv-situacion.apagado { color: #f87171; }

.tarjeta-titulo {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin: 2px 4px 14px;
}

.tarjeta-titulo h2 { font-size: 15px; font-weight: 600; }
.tarjeta-titulo span { color: var(--tenue); font-size: 12px; }

.sub-grupo {
    margin: 16px 4px 8px;
    color: var(--tenue);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.4px;
    text-transform: uppercase;
}

.sub-grupo:first-of-type { margin-top: 4px; }

/* ---------- Rejilla de fichas ---------- */
.rejilla {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 9px;
}

.rejilla-3 { grid-template-columns: repeat(3, 1fr); }
.rejilla-2 { grid-template-columns: repeat(2, 1fr); }

.ficha {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    /* min-width: 0 es imprescindible: sin él una etiqueta larga ensancha la
       columna y la rejilla se sale de la pantalla. Y con min-height en vez de
       aspect-ratio la ficha crece si el texto necesita dos líneas. */
    min-width: 0;
    min-height: 84px;
    padding: 11px 10px;
    border: none;
    border-radius: 17px;
    background: var(--ficha);
    color: var(--texto);
    font-family: inherit;
    font-size: 11px;
    line-height: 1.25;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.1s ease;
}

.ficha:active { transform: scale(0.95); }
.ficha:hover { background: var(--ficha-alta); }

.ficha svg {
    width: 21px;
    height: 21px;
    color: var(--suave);
    flex-shrink: 0;
}

.ficha b { font-weight: 500; }

/* Estados de color, al estilo de un panel domótico */
.ficha.encendida { background: rgba(59, 130, 246, 0.16); }
.ficha.encendida svg { color: #93c5fd; }
.ficha.peligro svg { color: #f87171; }
.ficha.aviso svg { color: #fbbf24; }
.ficha.verde svg { color: #4ade80; }
.ficha:disabled { opacity: 0.4; cursor: not-allowed; }

/* Fichas anchas, de dos columnas */
.ficha-ancha {
    min-height: 0;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    grid-column: span 2;
    padding: 14px 14px;
    font-size: 12.5px;
}

/* ---------- Pastillas (accesos rápidos) ---------- */
.pastillas {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
}

.pastilla {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    padding: 11px 14px;
    border: none;
    border-radius: 999px;
    background: var(--ficha);
    color: var(--texto);
    font-family: inherit;
    font-size: 12.5px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.1s ease;
}

.pastilla:active { transform: scale(0.97); }
.pastilla:hover { background: var(--ficha-alta); }

.pastilla svg { width: 17px; height: 17px; flex-shrink: 0; color: var(--suave); }
.pastilla.verde svg { color: #4ade80; }
.pastilla.peligro { color: #fca5a5; }
.pastilla.peligro svg { color: #f87171; }
.pastilla.aviso svg { color: #fbbf24; }
.pastilla.ancha { grid-column: span 2; justify-content: center; }

/* ---------- Aire acondicionado ---------- */
.aire-dial {
    position: relative;
    width: 100%;
    max-width: 236px;
    margin: 2px auto 0;
    touch-action: none;   /* para poder arrastrar sin que la página haga scroll */
}

.aire-dial svg { display: block; width: 100%; cursor: pointer; }

.aire-centro {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

#aire-grados { font-size: 54px; font-weight: 300; letter-spacing: -2px; }

.aire-unidad {
    /* Se centra con el número y luego se sube, como un superíndice */
    align-self: center;
    margin-top: -19px;
    margin-left: 3px;
    font-size: 15px;
    color: var(--suave);
}

.aire-linea {
    margin: 4px 0 16px;
    text-align: center;
    color: var(--tenue);
    font-size: 12.5px;
}

.aire-iconos {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 9px;
}

.aire-icono {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 0;
    border: none;
    background: none;
    color: var(--suave);
    font-family: inherit;
    font-size: 10.5px;
    line-height: 1.25;
    text-align: center;
    cursor: pointer;
}

.aire-icono .circulo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--ficha);
    transition: transform 0.12s ease, background-color 0.15s ease, color 0.15s ease;
}

.aire-icono svg { width: 22px; height: 22px; }
.aire-icono:active .circulo { transform: scale(0.93); }
.aire-icono.activo { color: #93c5fd; }

.aire-icono.activo .circulo {
    background: rgba(59, 130, 246, 0.18);
    color: #93c5fd;
}

.aire-icono:disabled { opacity: 0.35; cursor: not-allowed; }

.aire-ventilador {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 18px;
}

/* Los cinco modos no caben en línea con su título: van debajo */
.aire-modos { margin-top: 18px; }
.aire-modos .aire-vent-titulo { display: block; margin-bottom: 8px; }

/* Con dos clases, para ganarle a .aire-vent-opciones, que va después */
.aire-modos .aire-modos-opciones {
    display: grid;
    /* minmax(0,...) y no 1fr a secas: si no, cada columna se ensancha
       con su texto y los botones salen de anchos distintos */
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.aire-modos .aire-modos-opciones button {
    min-width: 0;
    padding: 9px 2px;
    font-size: 11px;
}

.aire-vent-titulo { color: var(--suave); font-size: 12.5px; }

.aire-vent-opciones {
    display: flex;
    padding: 3px;
    border-radius: 999px;
    background: var(--ficha);
}

.aire-vent-opciones button {
    min-width: 44px;
    padding: 8px 10px;
    border: none;
    border-radius: 999px;
    background: none;
    color: var(--suave);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.aire-vent-opciones button.activo {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

.aire-nota {
    margin-bottom: 12px;
    color: var(--tenue);
    font-size: 11.5px;
    line-height: 1.5;
}

.aire-sensor {
    margin-top: 16px;
    text-align: center;
    color: var(--tenue);
    font-size: 11.5px;
}

.aire-aprendido {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 8px;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--ficha);
    font-size: 13px;
}

.aire-aprendido span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.aire-borrar {
    flex-shrink: 0;
    padding: 7px 12px;
    border: none;
    border-radius: 999px;
    background: rgba(248, 113, 113, 0.14);
    color: #f87171;
    font-family: inherit;
    font-size: 11.5px;
    cursor: pointer;
}

/* ---------- Desplegables ---------- */
.folder { margin-top: 14px; }

.folder > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--ficha);
    color: var(--suave);
    font-size: 12px;
    font-weight: 500;
}

.folder > summary::-webkit-details-marker { display: none; }
.folder-arrow { display: inline-block; transition: transform 0.15s ease; font-size: 9px; color: var(--tenue); }
.folder[open] > summary .folder-arrow { transform: rotate(90deg); }
.folder[open] > summary { margin-bottom: 10px; }
.folder-content { padding: 0 2px; }

/* Desplegable que hace de tarjeta entera: el resumen es el título */
.folder-tarjeta { margin-top: 0; }

.folder-tarjeta > summary {
    padding: 2px 4px;
    background: none;
    color: var(--texto);
    font-size: 15px;
    font-weight: 600;
}

.folder-tarjeta[open] > summary { margin-bottom: 12px; }

/* ---------- Mando a distancia del TV ---------- */
.mando {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.cruceta {
    position: relative;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: radial-gradient(circle at 50% 35%, #262a33 0%, #1b1e24 65%, #15171c 100%);
}

.cruceta .btn-dir {
    position: absolute;
    width: 60px;
    height: 60px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--suave);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
}

.cruceta .btn-dir:active { color: #93c5fd; background: rgba(255,255,255,0.08); }

.dir-arriba    { top: 5px;  left: 50%; transform: translateX(-50%); }
.dir-abajo     { bottom: 5px; left: 50%; transform: translateX(-50%); }
.dir-izquierda { left: 5px;  top: 50%; transform: translateY(-50%); }
.dir-derecha   { right: 5px; top: 50%; transform: translateY(-50%); }

.btn-ok {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80px;
    height: 80px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--ficha-alta);
    color: #93c5fd;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.btn-ok:active { transform: translate(-50%, -50%) scale(0.94); }

.mando-fila {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
}

/* Controles de reproducción, con el play destacado */
.media {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    width: 100%;
    padding: 2px 0;
}

.media button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--ficha);
    color: var(--suave);
    cursor: pointer;
    transition: transform 0.12s ease, background-color 0.15s ease, color 0.15s ease;
}

.media button:hover { background: var(--ficha-alta); }
.media button:active { transform: scale(0.92); }
.media button svg { width: 19px; height: 19px; }

.media .principal {
    width: 60px;
    height: 60px;
    background: rgba(59, 130, 246, 0.18);
    color: #93c5fd;
}

.media .principal:hover { background: rgba(59, 130, 246, 0.26); }
.media .principal svg { width: 23px; height: 23px; }

.mando-teclado { display: flex; gap: 8px; width: 100%; }

.mando-teclado input {
    flex: 1;
    min-width: 0;
    padding: 12px 14px;
    border-radius: 999px;
    border: none;
    background: var(--ficha);
    color: var(--texto);
    font-size: 14px;
    font-family: inherit;
}

.mando-teclado input:focus { outline: 1px solid var(--acento); }

/* ---------- Botón de voz flotante ---------- */
.btn-voz {
    position: fixed;
    right: 20px;
    bottom: 24px;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(145deg, #2563eb, #1d4ed8);
    color: #ffffff;
    cursor: pointer;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 30px rgba(37, 99, 235, 0.45);
}

.btn-voz svg { width: 29px; height: 29px; }
.btn-voz:active { transform: scale(0.93); }

.btn-voz.escuchando {
    background: linear-gradient(145deg, #dc2626, #b91c1c);
    animation: pulso 1.4s ease-out infinite;
}

@keyframes pulso {
    0%   { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.55); }
    70%  { box-shadow: 0 0 0 18px rgba(220, 38, 38, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

/* ---------- Aviso flotante ---------- */
.status {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 104px;
    max-width: 448px;
    margin: 0 auto;
    z-index: 100;
    background: var(--ficha-alta);
    padding: 13px 16px;
    border-radius: 14px;
    font-size: 13px;
    display: flex;
    align-items: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.status.success { color: #a7f3d0; }
.status.error { color: #fca5a5; }
.status.loading { color: #93c5fd; }

/* ---------- Cuando el PC está apagado ---------- */
/* Lo que necesita a Windows se atenúa y deja de responder, en vez de fallar
   con un error cuando lo pulsas. */
.sin-pc {
    opacity: 0.32;
    pointer-events: none;
}

#pc-situacion.apagado { color: #f87171; }
#pc-situacion.encendido { color: #4ade80; }

/* ---------- Programaciones ---------- */
.prog-campo {
    width: 100%;
    padding: 11px 14px;
    border: none;
    border-radius: 12px;
    background: var(--ficha);
    color: var(--texto);
    font-family: inherit;
    font-size: 13.5px;
}

.prog-campo:focus { outline: 1px solid var(--acento); }

.prog-fila {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.prog-fila .prog-campo { flex: 1; min-width: 0; }
.prog-fila .pastilla { flex-shrink: 0; }

/* El micro de las programaciones: mismo pulso rojo que el botón flotante */
.prog-micro { padding: 11px 13px; justify-content: center; }
.prog-micro svg { color: var(--suave); }

.prog-micro.escuchando {
    background: linear-gradient(145deg, #dc2626, #b91c1c);
    animation: pulso 1.4s ease-out infinite;
}

.prog-micro.escuchando svg { color: #ffffff; }

.prog-dias {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 5px;
    margin-top: 10px;
}

.prog-dias button {
    padding: 8px 0;
    border: none;
    border-radius: 9px;
    background: var(--ficha);
    color: var(--suave);
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.prog-dias button.activo {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

.prog-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 8px;
    padding: 11px 14px;
    border-radius: 12px;
    background: var(--ficha);
    font-size: 13px;
}

.prog-item.apagada { opacity: 0.45; }
.prog-item .cuando { display: block; margin-top: 2px; color: var(--tenue); font-size: 11px; }
.prog-item .acciones { display: flex; gap: 6px; flex-shrink: 0; }

.prog-item .acciones button {
    padding: 7px 11px;
    border: none;
    border-radius: 999px;
    font-family: inherit;
    font-size: 11.5px;
    cursor: pointer;
    background: var(--ficha-alta);
    color: var(--suave);
}

.prog-item .acciones .borrar {
    background: rgba(248, 113, 113, 0.14);
    color: #f87171;
}

.prog-evento {
    margin-top: 6px;
    padding: 9px 12px;
    border-radius: 10px;
    background: var(--ficha);
    color: var(--suave);
    font-size: 12px;
}

.prog-evento.fallo { color: #fca5a5; }
