/* LokiLock — estilos. CSS plano (sin LESS): variables y anidamiento nativos del navegador. */

:root {
    --verde: #1a5c38;
    --verde-oscuro: #0b2a1c;
    --verde-claro: #2f8f58;
    --oro: #c9972c;
    --oro-claro: #f2d27a;
    --gris: #9c9c9c;
    --negro: #222;
    --blanco: #fff;
    --borde: #c8d3cc;
    --sombra: 0 10px 30px rgba(0, 0, 0, 0.35);
    --fuente: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--fuente);
    color: var(--negro);
    background: radial-gradient(circle at 50% 30%, #1d5f3d 0%, var(--verde-oscuro) 70%) fixed;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* ---------- Tarjeta principal ---------- */
.contenedor {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    max-width: 440px;
    padding: 16px;

    & > .contenido {
        position: relative;
        display: flex;
        flex-direction: column;
        width: 100%;
        min-height: 540px;
        max-height: calc(100dvh - 32px);
        overflow: visible;
        background: var(--blanco);
        border-radius: 14px;
        border-top: 6px solid var(--oro);
        box-shadow: var(--sombra);

        & > .fondo {
            position: absolute;
            right: -30px;
            bottom: -30px;
            width: 220px;
            opacity: 0.08;
            pointer-events: none;
        }
    }
}

/* Ocupa toda la tarjeta: si no, medía solo lo que su contenido y los desplegables abiertos quedaban recortados. */
.lokilock {
    flex: 1 1 auto;
    min-height: 0;
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    padding-bottom: 70px;
}

/* Icono pequeño que asoma por encima de la tarjeta */
.icono-app {
    position: absolute;
    top: -36px;
    left: calc(50% - 36px);
    width: 72px;
    height: 72px;
    padding: 0;
    border-radius: 18px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    background: var(--verde-oscuro);

    /* El logo puede ir suelto o dentro de un botón (administradores: abre la administración). */
    & .icono {
        display: block;
        width: 72px;
        height: 72px;
        border-radius: 18px;
    }

    & > button {
        display: block;
        border: 0;
        padding: 0;
        background: none;
        cursor: pointer;
    }
}

/* ---------- Pantallas ---------- */
.iniciar-sesion, .administrador, .configuracion, .imprimir {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 24px 0;
}

.iniciar-sesion {
    & > .icono {
        width: 112px;
        height: 112px;
        border-radius: 26px;
        margin-bottom: 6px;
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
    }

    & > .nombre {
        margin: 6px 0 2px;
        font-size: 28px;
        letter-spacing: 1px;
        color: var(--verde);

        & > span {
            color: var(--oro);
        }
    }

    & > .lema {
        margin: 0 0 22px;
        color: var(--gris);
        font-size: 13px;
        text-align: center;
    }
}

.administrador, .configuracion, .imprimir {
    padding-top: 56px;

    & > h2 {
        margin: 0 0 18px;
        color: var(--verde);
        font-size: 18px;
    }

    & > .informacion > .nota {
        color: var(--gris);
        text-align: justify;
        font-size: 13px;
    }
}

.gestor {
    padding: 46px 20px 0;
}

.contenido-gestor.inactivo {
    opacity: 0.4;
    pointer-events: none;
}

.seccion {
    width: 100%;
    margin: 10px 0 26px;

    & > .titulo-y-botonera {
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-height: 32px;

        & > .titulo {
            color: var(--verde);
            font-size: 16px;
            font-weight: 600;
        }
    }

    & > .valor {
        margin-top: 6px;
    }

    & > .botonera {
        margin-top: 8px;
        display: flex;
    }
}

/* ---------- Controles ---------- */
.grupo {
    width: 100%;
    display: flex;
    flex-direction: column;

    & > .titulo {
        margin-bottom: 5px;
        color: var(--verde);
        font-size: 15px;
    }
}

.icono-caja, .caja-icono {
    display: flex;
    width: 100%;
    margin-bottom: 14px;
    border: 1px solid var(--verde);
    border-radius: 8px;
    overflow: hidden;

    & > .contenedor-icono {
        display: flex;
        align-items: center;
        padding: 6px 8px;
        background: var(--verde);
        border: 0;
        color: inherit;
        cursor: default;

        &:is(button) {
            cursor: pointer;
        }

        & > .icono {
            height: 24px;

            &.oculto {
                display: none;
            }
        }
    }

    & > .contenedor-caja {
        display: flex;
        width: 100%;

        & > .caja {
            width: 100%;
            border: 0;
            padding: 8px 10px;
            font-size: 15px;
            font-family: inherit;
            outline: none;
        }
    }

    &:focus-within {
        box-shadow: 0 0 0 3px rgba(201, 151, 44, 0.35);
    }
}

.boton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font: 600 14px var(--fuente);
    color: var(--blanco);
    background: var(--verde);
    border: 1px solid var(--verde);
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s ease, transform 0.05s ease;

    &:hover {
        background: var(--verde-claro);
    }

    &:active {
        transform: translateY(1px);
    }

    &:focus-visible {
        outline: 3px solid var(--oro);
        outline-offset: 2px;
    }

    &.dorado {
        background: var(--oro);
        border-color: var(--oro);
        color: var(--verde-oscuro);
    }
}

/* Botones pequeños de icono (editar, añadir, borrar...) */
.botonera {
    display: flex;
    gap: 8px;

    & > .boton-icono {
        display: inline-flex;
        padding: 4px;
        background: var(--blanco);
        border: 1px solid var(--verde);
        border-radius: 6px;
        cursor: pointer;

        & > .icono {
            width: 20px;
            height: 20px;
        }

        &.relleno {
            background: var(--verde);
        }
    }
}

.iniciar-sesion > .botonera, .administrador > .botonera, .configuracion > .botonera, .imprimir > .botonera {
    width: 100%;
    justify-content: center;
    margin-top: 6px;
}

.botonera-general {
    position: absolute;
    left: 20px;
    bottom: 18px;
    display: flex;
    gap: 6px;

    & > .boton {
        padding: 6px 9px;

        & > .icono {
            width: 20px;
            height: 20px;
        }
    }
}

/* ---------- Desplegable con búsqueda ---------- */
.desplegablebuscable {
    position: relative;
    display: flex;
    width: 100%;

    & > .caja {
        flex: 1;
        height: 38px;
        padding: 4px 10px;
        font: 15px var(--fuente);
        color: var(--verde);
        border: 1px solid var(--borde);
        border-right: 0;
        border-radius: 8px 0 0 8px;
        outline: none;

        &:focus {
            border-color: var(--verde);
            box-shadow: 0 0 6px rgba(26, 92, 56, 0.45);
        }
    }

    & > .boton-desplegar {
        width: 42px;
        height: 38px;
        background: var(--verde);
        border: 1px solid var(--verde);
        border-radius: 0 8px 8px 0;
        cursor: pointer;

        & > .icono {
            width: 26px;
            display: none;

            &.visible {
                display: inline;
            }
        }
    }

    & > .elementos {
        display: none;
        position: absolute;
        top: calc(100% + 2px);
        left: 0;
        right: 0;
        max-height: 220px;
        overflow-y: auto;
        z-index: 8;
        padding: 5px;
        background: var(--blanco);
        border: 1px solid var(--borde);
        border-radius: 8px;
        box-shadow: 0 8px 18px rgba(0, 0, 0, 0.15);

        &.visible {
            display: block;
        }

        & > .elemento {
            display: block;
            width: 100%;
            text-align: left;
            padding: 5px 8px;
            border: 0;
            border-radius: 6px;
            background: none;
            font: 15px var(--fuente);
            color: var(--negro);
            cursor: pointer;

            &:hover, &:focus {
                background: var(--verde);
                color: var(--blanco);
                outline: none;

                & > strong {
                    color: var(--oro-claro);
                }
            }

            &.oculto {
                display: none;
            }

            & > strong {
                color: var(--oro);
            }
        }

        & > .vacio {
            padding: 6px 8px;
            color: var(--gris);
        }
    }
}

/* ---------- Mensajes ---------- */
.mensajes {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100040;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(320px, calc(100vw - 40px));
}

.mensaje {
    position: relative;
    padding: 14px 34px 14px 14px;
    border-radius: 10px;
    box-shadow: var(--sombra);
    font-size: 14px;
    opacity: 0;
    transform: translateX(30px);
    transition: opacity 0.3s ease, transform 0.3s ease;

    &.visible {
        opacity: 1;
        transform: none;
    }

    &.informacion {
        background: var(--blanco);
        color: var(--verde);
        border: 1px solid var(--verde);
    }

    &.error {
        background: #7a1f1f;
        color: var(--blanco);
    }

    & > .cerrar {
        position: absolute;
        top: 6px;
        right: 6px;
        border: 0;
        background: none;
        font-size: 18px;
        line-height: 1;
        color: inherit;
        cursor: pointer;
    }
}

/* ---------- Cargando ---------- */
#cargando {
    position: fixed;
    inset: 0;
    z-index: 9999999;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(5, 20, 12, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;

    &.mostrar {
        opacity: 1;
        pointer-events: auto;
    }

    & > img {
        width: min(30vmin, 160px);
        animation: latido 1.2s ease-in-out infinite;
        border-radius: 22%;
    }
}

@keyframes latido {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(242, 210, 122, 0)); }
    50% { transform: scale(1.06); filter: drop-shadow(0 0 18px rgba(242, 210, 122, 0.7)); }
}

/* ---------- Banner de instalación como aplicación ---------- */
.banner-instalar {
    position: fixed;
    bottom: 3vh;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 8px 8px 12px;
    background: var(--blanco);
    border: 1px solid var(--verde);
    border-radius: 10px;
    box-shadow: var(--sombra);
    z-index: 9999;
    transition: opacity 0.3s ease-in-out;

    &.oculto {
        opacity: 0;
        pointer-events: none;
    }

    & .texto {
        color: var(--verde);
    }

    & .cerrar {
        width: 34px;
        height: 34px;
        border: 0;
        border-radius: 8px;
        background: var(--verde);
        cursor: pointer;

        & > img {
            width: 18px;
        }
    }
}

/* ---------- Impresión ---------- */
#impresora {
    display: none;
}

@media print {
    body {
        display: block;
        background: var(--blanco);
        overflow: visible;
    }

    body > *:not(#impresora) {
        display: none !important;
    }

    #impresora {
        display: block;
        font-size: 12px;
        color: #000;

        & h1 {
            font-size: 18px;
        }

        & table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 14px;
            page-break-inside: avoid;
        }

        & th, & td {
            border: 1px solid #999;
            padding: 4px 6px;
            text-align: left;
            font-family: Consolas, "Courier New", monospace;
        }

        & caption {
            text-align: left;
            font-weight: bold;
            padding: 4px 0;
        }
    }
}

/* ---------- Pantallas pequeñas ---------- */
@media (max-width: 380px) {
    .contenedor {
        padding: 8px;
    }

    .gestor {
        padding-left: 12px;
        padding-right: 12px;
    }
}
