/* ==========================================================
   CONFIGURACIÓN GENERAL
   ========================================================== */

:root {
    --background: #0f172a;
    --background-secondary: #111827;

    --card: #1e293b;
    --card-secondary: #273449;

    --border: #334155;

    --text: #f8fafc;
    --text-secondary: #94a3b8;

    --primary: #2563eb;
    --primary-hover: #1d4ed8;

    --success: #22c55e;
    --success-dark: #15803d;

    --warning: #f59e0b;
    --warning-dark: #b45309;

    --danger: #dc2626;
    --danger-hover: #b91c1c;

    --disabled: #475569;

    --shadow:
        0 12px 30px
        rgba(0, 0, 0, 0.25);

    --radius-small: 8px;
    --radius-medium: 12px;
    --radius-large: 18px;
}


* {
    box-sizing: border-box;
}


html {
    min-height: 100%;
}


body {
    margin: 0;

    min-height: 100vh;

    font-family:
        Arial,
        Helvetica,
        sans-serif;

    background:
        linear-gradient(
            135deg,
            var(--background),
            var(--background-secondary)
        );

    color: var(--text);
}


button,
input {
    font: inherit;
}


button {
    border: none;
}


h1,
h2,
h3,
p {
    margin-top: 0;
}


/* ==========================================================
   BOTONES
   ========================================================== */

.button {
    display: inline-flex;

    justify-content: center;
    align-items: center;

    min-height: 44px;

    padding:
        11px
        18px;

    border-radius:
        var(--radius-small);

    font-weight: 600;

    cursor: pointer;

    transition:
        background-color 0.2s ease,
        opacity 0.2s ease,
        transform 0.1s ease;
}


.button:active:not(:disabled) {
    transform: scale(0.98);
}


.button:disabled {
    background:
        var(--disabled);

    color:
        #cbd5e1;

    cursor:
        not-allowed;

    opacity:
        0.65;
}


.button-primary {
    background:
        var(--primary);

    color:
        white;
}


.button-primary:hover:not(:disabled) {
    background:
        var(--primary-hover);
}


.button-secondary {
    background:
        #475569;

    color:
        white;
}


.button-secondary:hover:not(:disabled) {
    background:
        #64748b;
}


.button-danger {
    background:
        var(--danger);

    color:
        white;
}


.button-danger:hover:not(:disabled) {
    background:
        var(--danger-hover);
}


.button-warning {
    background:
        var(--warning-dark);

    color:
        white;
}


.button-warning:hover:not(:disabled) {
    background:
        #92400e;
}


.button-light {
    width: 100%;

    margin-top: 12px;

    background:
        var(--primary);

    color:
        white;
}


.button-light:hover:not(:disabled) {
    background:
        var(--primary-hover);
}


.button-full {
    width: 100%;
}


/* ==========================================================
   LOGIN
   ========================================================== */

.login-page {
    display: flex;

    align-items: center;
    justify-content: center;

    padding: 20px;
}


.login-container {
    width: 100%;

    max-width: 420px;
}


.login-card {
    background:
        rgba(
            30,
            41,
            59,
            0.96
        );

    border:
        1px solid
        var(--border);

    border-radius:
        var(--radius-large);

    padding: 32px;

    box-shadow:
        var(--shadow);
}


.login-header {
    text-align: center;

    margin-bottom: 28px;
}


.login-header h1 {
    margin-bottom: 8px;

    font-size: 30px;
}


.login-header p {
    margin-bottom: 0;

    color:
        var(--text-secondary);
}


.login-form {
    display: flex;

    flex-direction: column;

    gap: 18px;
}


.form-group {
    display: flex;

    flex-direction: column;

    gap: 7px;
}


.form-group label {
    font-weight: 600;

    color:
        #e2e8f0;
}


.form-group input {
    width: 100%;

    padding:
        12px
        13px;

    border:
        1px solid
        var(--border);

    border-radius:
        var(--radius-small);

    outline: none;

    background:
        #0f172a;

    color:
        var(--text);
}


.form-group input:focus {
    border-color:
        var(--primary);

    box-shadow:
        0 0 0 3px
        rgba(
            37,
            99,
            235,
            0.18
        );
}


.login-footer {
    margin-top: 24px;

    text-align: center;

    color:
        var(--text-secondary);

    font-size: 14px;
}


.login-footer p {
    margin-bottom: 0;
}


/* ==========================================================
   MENSAJES
   ========================================================== */

.alert {
    padding:
        12px
        14px;

    margin-bottom: 20px;

    border-radius:
        var(--radius-small);
}


.alert-error {
    background:
        rgba(
            220,
            38,
            38,
            0.15
        );

    border:
        1px solid
        rgba(
            248,
            113,
            113,
            0.5
        );

    color:
        #fecaca;
}


.system-message {
    display: none;

    margin-top: 14px;

    padding: 12px;

    border-radius:
        var(--radius-small);
}


.system-message.visible {
    display: block;
}


.system-message.info {
    background:
        rgba(
            37,
            99,
            235,
            0.15
        );

    border:
        1px solid
        rgba(
            96,
            165,
            250,
            0.4
        );
}


.system-message.success {
    background:
        rgba(
            34,
            197,
            94,
            0.15
        );

    border:
        1px solid
        rgba(
            74,
            222,
            128,
            0.4
        );
}


.system-message.error {
    background:
        rgba(
            220,
            38,
            38,
            0.15
        );

    border:
        1px solid
        rgba(
            248,
            113,
            113,
            0.4
        );
}


/* ==========================================================
   CONTENEDOR PRINCIPAL
   ========================================================== */

.dashboard-page {
    padding-bottom: 40px;
}


.app-container {
    width:
        min(
            1100px,
            calc(
                100% - 32px
            )
        );

    margin:
        0 auto;
}


/* ==========================================================
   ENCABEZADO
   ========================================================== */

.main-header {
    display: flex;

    justify-content: space-between;

    align-items: center;

    gap: 20px;

    padding:
        24px 0;
}


.header-title h1 {
    margin-bottom: 4px;

    font-size: 30px;
}


.header-title p {
    margin-bottom: 0;

    color:
        var(--text-secondary);
}


.header-user {
    display: flex;

    align-items: center;

    gap: 15px;

    color:
        var(--text-secondary);
}


.header-user form {
    margin: 0;
}


/* ==========================================================
   TARJETAS
   ========================================================== */

.card {
    margin-bottom: 18px;

    padding: 22px;

    border:
        1px solid
        var(--border);

    border-radius:
        var(--radius-large);

    background:
        rgba(
            30,
            41,
            59,
            0.96
        );

    box-shadow:
        0 6px 18px
        rgba(
            0,
            0,
            0,
            0.15
        );
}


.card-header {
    display: flex;

    justify-content: space-between;

    align-items: center;

    margin-bottom: 18px;
}


.card-header h2 {
    margin-bottom: 0;

    font-size: 21px;
}


/* ==========================================================
   ESTADOS
   ========================================================== */

.status-grid {
    display: grid;

    grid-template-columns:
        repeat(
            2,
            minmax(
                0,
                1fr
            )
        );

    gap: 12px;
}


.status-item {
    display: flex;

    flex-direction: column;

    gap: 7px;

    padding: 14px;

    border-radius:
        var(--radius-medium);

    background:
        #0f172a;

    border:
        1px solid
        #273449;
}


.status-label {
    color:
        var(--text-secondary);

    font-size: 13px;
}


.status-value {
    font-weight: 700;
}


.status-online {
    color:
        var(--success);
}


.status-offline {
    color:
        #f87171;
}


.status-warning {
    color:
        #fbbf24;
}


/* ==========================================================
   CÁMARA
   ========================================================== */

.camera-container {
    max-width: 720px;

    margin:
        0 auto;
}


.camera-view {
    position: relative;

    width: 100%;

    overflow: hidden;

    aspect-ratio:
        4 / 3;

    border:
        1px solid
        var(--border);

    border-radius:
        var(--radius-medium);

    background:
        black;
}


.camera-view video,
.camera-view canvas {
    position: absolute;

    top: 0;

    left: 0;

    width: 100%;

    height: 100%;

    object-fit: cover;

    transform:
        scaleX(-1);
}


.camera-view canvas {
    pointer-events: none;
}


.camera-placeholder {
    position: absolute;

    inset: 0;

    display: flex;

    align-items: center;

    justify-content: center;

    padding: 20px;

    text-align: center;

    color:
        var(--text-secondary);

    background:
        #020617;
}


.camera-controls {
    display: grid;

    grid-template-columns:
        repeat(
            2,
            minmax(
                0,
                1fr
            )
        );

    gap: 10px;

    margin-top: 12px;
}


/* ==========================================================
   GESTOS
   ========================================================== */

.gesture-information {
    display: grid;

    grid-template-columns:
        repeat(
            2,
            minmax(
                0,
                1fr
            )
        );

    gap: 12px;

    max-width: 720px;

    margin:
        18px auto 0;
}


.gesture-box {
    padding: 14px;

    border:
        1px solid
        #273449;

    border-radius:
        var(--radius-medium);

    background:
        #0f172a;
}


.gesture-label {
    display: block;

    margin-bottom: 7px;

    color:
        var(--text-secondary);

    font-size: 13px;
}


.gesture-value {
    font-size: 18px;
}


.gesture-progress-container {
    grid-column:
        1 / -1;

    width: 100%;

    height: 10px;

    overflow: hidden;

    border-radius: 20px;

    background:
        #334155;
}


.gesture-progress {
    width: 0%;

    height: 100%;

    background:
        var(--success);

    transition:
        width 0.08s linear;
}


.gesture-help {
    max-width: 720px;

    margin:
        22px auto 0;
}


.gesture-help h3 {
    margin-bottom: 12px;
}


.gesture-list {
    display: grid;

    grid-template-columns:
        repeat(
            2,
            minmax(
                0,
                1fr
            )
        );

    gap: 8px;
}


.gesture-list > div {
    display: flex;

    justify-content: space-between;

    gap: 10px;

    padding:
        10px
        12px;

    border-radius:
        var(--radius-small);

    background:
        #0f172a;
}


.gesture-list span {
    color:
        var(--text-secondary);

    text-align: right;
}


/* ==========================================================
   LUCES
   ========================================================== */

.lights-grid {
    display: grid;

    grid-template-columns:
        repeat(
            5,
            minmax(
                0,
                1fr
            )
        );

    gap: 12px;
}


.light-card {
    padding: 16px;

    text-align: center;

    border:
        1px solid
        #273449;

    border-radius:
        var(--radius-medium);

    background:
        #0f172a;
}


.light-card h3 {
    margin-bottom: 10px;

    font-size: 23px;
}


.light-state {
    min-height: 24px;

    font-weight: 700;

    color:
        var(--text-secondary);
}


.light-state.on {
    color:
        var(--success);
}


.light-state.off {
    color:
        #f87171;
}


/* ==========================================================
   PORTÓN
   ========================================================== */

.gate-container {
    display: flex;

    justify-content: space-between;

    align-items: center;

    gap: 20px;
}


.gate-status {
    display: flex;

    flex-direction: column;

    gap: 6px;
}


.gate-status span {
    color:
        var(--text-secondary);
}


.gate-status strong {
    font-size: 20px;
}


/* ==========================================================
   FOTOCELDA
   ========================================================== */

.photocell-grid {
    display: grid;

    grid-template-columns:
        repeat(
            4,
            minmax(
                0,
                1fr
            )
        );

    gap: 12px;
}


.information-text {
    margin:
        16px 0 0;

    color:
        var(--text-secondary);

    line-height: 1.6;
}


/* ==========================================================
   ACCIONES GENERALES
   ========================================================== */

.general-actions {
    display: flex;

    flex-wrap: wrap;

    gap: 10px;

    margin-top: 18px;
}


/* ==========================================================
   RESPONSIVE
   ========================================================== */

@media (
    max-width: 900px
) {

    .lights-grid {
        grid-template-columns:
            repeat(
                3,
                minmax(
                    0,
                    1fr
                )
            );
    }


    .photocell-grid {
        grid-template-columns:
            repeat(
                2,
                minmax(
                    0,
                    1fr
                )
            );
    }

}


@media (
    max-width: 650px
) {

    .app-container {
        width:
            min(
                100% - 20px,
                1100px
            );
    }


    .main-header {
        align-items: flex-start;

        flex-direction: column;
    }


    .header-user {
        width: 100%;

        justify-content: space-between;
    }


    .status-grid {
        grid-template-columns:
            1fr;
    }


    .camera-controls {
        grid-template-columns:
            1fr;
    }


    .gesture-information {
        grid-template-columns:
            1fr;
    }


    .gesture-progress-container {
        grid-column:
            auto;
    }


    .gesture-list {
        grid-template-columns:
            1fr;
    }


    .lights-grid {
        grid-template-columns:
            repeat(
                2,
                minmax(
                    0,
                    1fr
                )
            );
    }


    .gate-container {
        align-items: stretch;

        flex-direction: column;
    }


    .photocell-grid {
        grid-template-columns:
            1fr;
    }


    .general-actions {
        flex-direction: column;
    }


    .general-actions .button {
        width: 100%;
    }

}


@media (
    max-width: 420px
) {

    .login-card {
        padding:
            24px
            18px;
    }


    .card {
        padding: 17px;
    }


    .lights-grid {
        grid-template-columns:
            1fr;
    }

}