/* =========================
   CONFIGURACIÓN GENERAL
========================= */

:root {
    --petrol: #216477;
    --petrol-light: #3a8ba8;
    --petrol-dark: #153e4a;

    --black: #080b0d;
    --panel: #11171b;
    --panel-light: #192329;

    --white: #ffffff;
    --text-muted: #b5c0c5;

    --border: #34434a;

    --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
    --ink: #080b0d;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    width: 100%;

    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--white);

    background-color: #ffffff;
    background-image: url("./assets/images/background.jpg");
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;

    zoom: 80%;
}

/* =========================
   CONTENEDOR PRINCIPAL
========================= */

main {
    width: 100%;
    min-height: 100vh;

    display: flex;
    justify-content: center;
    align-items: center;

    padding: 40px 20px;
}

/* =========================
   TARJETA OSCURA
========================= */

.login-box {
    position: relative;

    width: 100%;
    max-width: 600px;

    padding: 45px 38px;

    background: linear-gradient(
        145deg,
        var(--panel-light),
        var(--black) 75%
    );

    border: 1px solid #293b43;
    border-radius: 4px;

    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.28),
        0 5px 15px rgba(0, 0, 0, 0.16),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);

    overflow: hidden;
}

/* Línea decorativa superior */
.login-box::before {
    content: "";

    position: absolute;
    top: 0;
    left: 0;

    width: 100%;
    height: 4px;

    background: linear-gradient(
        90deg,
        var(--petrol-dark),
        var(--petrol-light),
        var(--petrol-dark)
    );
}


/* =========================
   FORMULARIO
========================= */

.login-form {
    position: relative;
    z-index: 1;

    width: 100%;

    display: flex;
    flex-direction: column;
    align-items: stretch;

    gap: 12px;
    border: none;
}

/* =========================
   LOGOTIPO
========================= */

.image {
    display: block;

    width: 65px !important;
    height: 65px !important;

    min-width: 0;
    min-height: 0;

    max-width: 65px !important;
    max-height: 65px !important;

    flex: 0 0 65px;

    object-fit: contain;
    object-position: center;

    margin: 0 auto 5px;
}

/* =========================
   TÍTULOS
========================= */

.login-form h1 {
    color: var(--white);

    text-align: center;
    font-size: clamp(25px, 4vw, 32px);
    font-weight: 600;
    letter-spacing: 1px;
}

.subtitle {
    color: var(--text-muted);

    text-align: center;
    font-size: 14px;

    margin-bottom: 22px;
}

/* =========================
   ETIQUETAS
========================= */

.login-form label {
    color: #dce8ec;

    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.4px;

    margin-top: 5px;
}

/* =========================
   CAMPOS DE TEXTO
========================= */

.login-form input {
    display: block;

    width: 100%;
    min-width: 0;
    height: 58px;

    padding: 0 17px;

    color: var(--white);
    background: #0c1114;

    border: 1px solid var(--border);
    border-radius: 4px;

    outline: none;

    font-family: inherit;
    font-size: 15px;

    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        background-color 0.2s ease;

    /* Corte diagonal en la esquina inferior derecha */
    clip-path: polygon(
        0 0,
        100% 0,
        100% calc(100% - 10px),
        calc(100% - 10px) 100%,
        0 100%
    );
}

.login-form input::placeholder {
    color: #89969c;
    opacity: 1;
}

.login-form input:hover {
    border-color: #54717c;
}

.login-form input:focus {
    background-color: #101b20;

    border-color: var(--petrol-light);

    box-shadow: 0 0 0 3px rgba(58, 139, 168, 0.15);
}

/* =========================
   BOTÓN PRINCIPAL
========================= */

.login-form button {
    position: relative;

    width: 100%;
    min-height: 58px;

    margin-top: 18px;
    padding: 14px 20px;

    color: var(--white);
    background: var(--petrol);

    border: 1px solid #347e94;
    border-radius: 4px;

    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;

    cursor: pointer;

    /* Corte diagonal en la esquina superior derecha */
    clip-path: polygon(
        0 0,
        calc(100% - 12px) 0,
        100% 12px,
        100% 100%,
        0 100%
    );

    transition:
        background-color 0.2s ease,
        transform 0.2s ease;
}

.login-form button:hover {
    background: var(--petrol-light);
}

.login-form button:active {
    transform: scale(0.99);
}

.login-form button:focus-visible {
    outline: 2px solid var(--white);
    outline-offset: 4px;
}

/* =========================
   REGISTRO
========================= */

.register-text {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;

    gap: 6px;

    margin-top: 18px;

    color: var(--text-muted);
    text-align: center;
    font-size: 13px;
}

.register-text a {
    color: #75c5df;

    font-weight: 600;
    text-decoration: none;

    transition: color 0.2s ease;
}

.register-text a:hover {
    color: var(--white);
    text-decoration: underline;
}

/* =========================
   RESPONSIVE: TABLET Y MÓVIL
========================= */

@media (max-width: 600px) {
    main {
        padding: 25px 16px;
    }

    .login-box {
        max-width: 430px;
        padding: 35px 24px;
    }

    .image {
        width: 55px !important;
        height: 55px !important;

        max-width: 55px !important;
        max-height: 55px !important;

        flex-basis: 55px;
    }

    .login-form input {
        height: 54px;
        font-size: 14px;
    }

    .login-form button {
        min-height: 54px;
        font-size: 14px;
    }
}

/* =========================
   RESPONSIVE: POCA ALTURA
========================= */

@media (max-height: 600px) {
    main {
        align-items: flex-start;
    }

    .login-box {
        margin: auto 0;
        padding-top: 28px;
        padding-bottom: 28px;
    }

    .subtitle {
        margin-bottom: 10px;
    }

    .login-form {
        gap: 8px;
    }

    .login-form button {
        margin-top: 10px;
    }
}

/* =====================================================
   MEJORAS DE INTERFAZ
   - Transiciones entre páginas
   - Más detalle visual
   - Hover en negativo (negro <-> blanco)
===================================================== */

/* =========================
   TRANSICIONES DE PÁGINA
========================= */

@keyframes bodyIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes bodyOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

@keyframes cardIn {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.98);
        filter: blur(6px);
    }
    to {
        opacity: 1;
        transform: none;
        filter: blur(0);
    }
}

@keyframes cardOut {
    from {
        opacity: 1;
        transform: none;
        filter: blur(0);
    }
    to {
        opacity: 0;
        transform: translateY(-18px) scale(0.98);
        filter: blur(6px);
    }
}

@keyframes riseIn {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: none; }
}

body {
    animation: bodyIn 0.5s ease both;
}

.login-box {
    animation: cardIn 0.75s var(--ease-out) both;
    transition:
        border-color 0.4s ease,
        box-shadow 0.4s ease;
}

/* Salida: la clase la agrega transitions.js */
body.page-leaving {
    animation: bodyOut 0.38s ease forwards;
    pointer-events: none;
}

body.page-leaving .login-box {
    animation: cardOut 0.38s ease forwards;
}

/* Elementos del formulario aparecen en cascada */
.login-form > * {
    animation: riseIn 0.6s var(--ease-out) both;
}

.login-form > :nth-child(1)  { animation-delay: 0.10s; }
.login-form > :nth-child(2)  { animation-delay: 0.16s; }
.login-form > :nth-child(3)  { animation-delay: 0.22s; }
.login-form > :nth-child(4)  { animation-delay: 0.28s; }
.login-form > :nth-child(5)  { animation-delay: 0.34s; }
.login-form > :nth-child(6)  { animation-delay: 0.40s; }
.login-form > :nth-child(7)  { animation-delay: 0.46s; }
.login-form > :nth-child(8)  { animation-delay: 0.52s; }
.login-form > :nth-child(9)  { animation-delay: 0.58s; }
.login-form > :nth-child(10) { animation-delay: 0.64s; }
.login-form > :nth-child(11) { animation-delay: 0.70s; }

/* =========================
   FONDO CON MÁS PROFUNDIDAD
========================= */

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;

    background:
        radial-gradient(ellipse at 50% 40%, rgba(33, 100, 119, 0.18), transparent 60%),
        radial-gradient(ellipse at center, transparent 35%, rgba(0, 0, 0, 0.55) 100%);
}

/* Rejilla técnica muy sutil */
body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;

    background-image:
        linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
    background-size: 48px 48px;

    -webkit-mask-image: radial-gradient(ellipse at center, #000 20%, transparent 75%);
            mask-image: radial-gradient(ellipse at center, #000 20%, transparent 75%);
}

main {
    position: relative;
    z-index: 1;
}

/* =========================
   TARJETA: MÁS DETALLE
========================= */

.login-box {
    backdrop-filter: blur(2px);
}

.login-box:hover {
    border-color: #3d5a66;
    box-shadow:
        0 28px 70px rgba(0, 0, 0, 0.38),
        0 8px 22px rgba(0, 0, 0, 0.2),
        0 0 0 1px rgba(58, 139, 168, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* Barra superior con brillo que recorre la tarjeta */
@keyframes barSweep {
    0%   { background-position: 0% 0; }
    100% { background-position: 200% 0; }
}

.login-box::before {
    background: linear-gradient(
        90deg,
        var(--petrol-dark),
        var(--petrol-light),
        #ffffff,
        var(--petrol-light),
        var(--petrol-dark)
    );
    background-size: 200% 100%;
    animation: barSweep 5s linear infinite;
}

/* Esquina inferior izquierda: marca decorativa */
.login-form::after {
    content: "";
    position: absolute;
    left: -38px;
    bottom: -45px;
    width: 90px;
    height: 90px;
    z-index: -1;
    pointer-events: none;

    border-left: 1px solid rgba(58, 139, 168, 0.35);
    border-bottom: 1px solid rgba(58, 139, 168, 0.35);
}

/* =========================
   LOGOTIPO
========================= */

@keyframes floaty {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-4px); }
}

.image {
    filter: drop-shadow(0 4px 14px rgba(58, 139, 168, 0.45));
    animation: riseIn 0.6s var(--ease-out) both, floaty 4.5s ease-in-out 0.8s infinite;
    transition: filter 0.35s ease;
    cursor: pointer;
}

/* Hover en negativo */
.image:hover {
    filter: invert(1) drop-shadow(0 4px 14px rgba(255, 255, 255, 0.35));
}

/* =========================
   TÍTULO
========================= */

.login-form h1::after {
    content: "";
    display: block;
    width: 44px;
    height: 2px;
    margin: 12px auto 0;

    background: linear-gradient(90deg, transparent, var(--petrol-light), transparent);
    transition: width 0.4s var(--ease-out);
}

.login-box:hover .login-form h1::after {
    width: 90px;
}

/* =========================
   ETIQUETAS
========================= */

.login-form label {
    transition: color 0.25s ease, transform 0.25s ease;
}

.login-form label:has(+ input:focus),
.login-form label:has(+ input:hover) {
    color: var(--petrol-light);
    transform: translateX(3px);
}

/* =========================
   CAMPOS: NEGATIVO EN HOVER / FOCUS
   (fondo oscuro -> blanco, texto blanco -> negro)
========================= */

.login-form input {
    transition:
        background-color 0.3s ease,
        color 0.3s ease,
        border-color 0.3s ease,
        box-shadow 0.3s ease,
        transform 0.3s var(--ease-out);
}

.login-form input:hover,
.login-form input:focus {
    background-color: #ffffff;
    color: var(--ink);
    border-color: #ffffff;
}

.login-form input:hover::placeholder,
.login-form input:focus::placeholder {
    color: #6d7b82;
}

.login-form input:focus {
    box-shadow: 0 0 0 3px rgba(58, 139, 168, 0.4);
    transform: translateY(-1px);
}

/* Autocompletado del navegador: mantiene el estilo oscuro */
.login-form input:-webkit-autofill {
    -webkit-text-fill-color: var(--white);
    box-shadow: 0 0 0 1000px #0c1114 inset;
    caret-color: var(--white);
}

.login-form input:-webkit-autofill:hover,
.login-form input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--ink);
    box-shadow: 0 0 0 1000px #ffffff inset;
    caret-color: var(--ink);
}

/* =========================
   BOTÓN: PETRÓLEO -> BLANCO / NEGRO
========================= */

.login-form button {
    overflow: hidden;
    transition:
        background-color 0.3s ease,
        color 0.3s ease,
        border-color 0.3s ease,
        transform 0.25s var(--ease-out),
        box-shadow 0.3s ease;
}

/* Destello que cruza el botón */
.login-form button::after {
    content: "";
    position: absolute;
    top: 0;
    left: -80%;
    width: 50%;
    height: 100%;
    pointer-events: none;

    background: linear-gradient(
        100deg,
        transparent,
        rgba(255, 255, 255, 0.28),
        transparent
    );
    transform: skewX(-20deg);
}

.login-form button:hover::after {
    left: 140%;
    transition: left 0.7s ease;
}

.login-form button:hover {
    background: #ffffff;
    color: var(--ink);
    border-color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.login-form button:active {
    transform: translateY(0) scale(0.99);
}

/* =========================
   ENLACES (registro / login)
========================= */

.register-text a {
    padding: 3px 9px;
    border: 1px solid transparent;
    border-radius: 3px;

    transition:
        background-color 0.25s ease,
        color 0.25s ease,
        border-color 0.25s ease,
        transform 0.25s var(--ease-out);
}

.register-text a:hover {
    background-color: #ffffff;
    color: var(--ink) !important;
    border-color: #ffffff;
    text-decoration: none;
    transform: translateY(-1px);
}

/* =========================
   SELECTOR DE IDIOMA (negativo)
========================= */

.login-top-bar button,
.login-top-bar a,
.login-top-bar select {
    transition:
        background-color 0.25s ease,
        color 0.25s ease,
        border-color 0.25s ease,
        transform 0.25s var(--ease-out);
}

.login-top-bar button:hover,
.login-top-bar a:hover,
.login-top-bar select:hover {
    background-color: #ffffff !important;
    color: var(--ink) !important;
    border-color: #ffffff !important;
    transform: translateY(-1px);
}

.first-title {
    width: 250px;
    height: auto;
    display: block;
    margin: 0 auto;
    object-fit: contain;
}

#toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.toast {
    background-color: #000;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 16px;
    color: white;
    opacity: 0;
    transform: translateY(-20%);
}

.toast.show {
    opacity: 1;
    transform: translateY(0%);
}

/* =========================
   AVISO DE ERROR
========================= */

@keyframes alertShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

#loginAlert:not([style*="display:none"]):not([style*="display: none"]),
#registerAlert:not([style*="display:none"]):not([style*="display: none"]) {
    animation: alertShake 0.4s ease;
}

/* =========================
   ACCESIBILIDAD
========================= */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Pantallas táctiles: sin efectos hover pegajosos */
@media (hover: none) {
    .login-form input:hover:not(:focus) {
        background-color: #0c1114;
        color: var(--white);
        border-color: var(--border);
    }

    .login-form input:hover:not(:focus)::placeholder {
        color: #89969c;
    }

    .login-form button:hover {
        background: var(--petrol);
        color: var(--white);
        border-color: #347e94;
        transform: none;
        box-shadow: none;
    }
}

/* =====================================================
   PARCHE RESPONSIVE MÓVIL
===================================================== */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body { overflow-x: hidden; min-height: 100vh; min-height: 100dvh; }
main { min-height: 100vh; min-height: 100dvh; }

.login-box { min-width: 0; }
.login-form h1 { overflow-wrap: anywhere; }
.first-title { max-width: 80%; }

#toast-container {
    width: calc(100% - 24px);
    max-width: 420px;
    top: calc(12px + env(safe-area-inset-top));
}
.toast {
    max-width: 100%;
    padding: 12px 16px;
    border-radius: 4px;
    text-align: center;
    font-size: 14px;
}

@media (max-width: 600px) {
    body { background-attachment: scroll; }

    main { padding: 20px 14px; }

    .login-box { padding: 30px 20px; max-width: 100%; }

    .login-form { gap: 10px; }
    .login-form h1 { font-size: clamp(22px, 7vw, 28px); }
    .subtitle { margin-bottom: 14px; }

    /* 16px evita el zoom automático de iOS al enfocar un campo */
    .login-form input { font-size: 16px; height: 54px; }
    .login-form button { font-size: 14px; letter-spacing: 0.8px; }

    .register-text { font-size: 14px; }
    .register-text a { padding: 10px 12px; min-height: 40px; display: inline-flex; align-items: center; }

    /* La marca decorativa se sale de la tarjeta en pantallas pequeñas */
    .login-form::after { display: none; }
}

@media (max-width: 360px) {
    .login-box { padding: 26px 16px; }
    .first-title { max-width: 90%; }
}

/* Táctil: sin efectos hover pegajosos en etiquetas, enlaces, logo y título */
@media (hover: none) {
    .login-form label:has(+ input:hover) {
        color: #dce8ec;
        transform: none;
    }
    .login-form label:has(+ input:focus) {
        color: var(--petrol-light);
        transform: none;
    }
    .register-text a:hover {
        background-color: transparent;
        color: #75c5df !important;
        border-color: transparent;
        transform: none;
    }
    .image:hover {
        filter: drop-shadow(0 4px 14px rgba(58, 139, 168, 0.45));
    }
    .login-box:hover .login-form h1::after { width: 44px; }
    .login-top-bar button:hover,
    .login-top-bar a:hover,
    .login-top-bar select:hover {
        transform: none;
    }
}


/* ==========================================================================
   SELECTOR DE IDIOMA UNIFICADO (SOPORTE MULTI-PESTAÑA Y TOUCH)
   ========================================================================== */
.lang-toggle-wrapper,
.lang-selector-pill {
    display: inline-flex;
    align-items: center;
    background: rgba(17, 23, 27, 0.92);
    border: 1px solid rgba(52, 67, 74, 0.85);
    border-radius: 20px;
    padding: 3px 6px;
    gap: 3px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.lang-btn,
.lang-pill-btn {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.6px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 14px;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    line-height: 1.2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.lang-btn:hover,
.lang-pill-btn:hover {
    color: var(--white);
    background: rgba(255, 255, 255, 0.08);
}

.lang-btn.active,
.lang-pill-btn.active {
    background: var(--petrol);
    color: var(--white);
    box-shadow: 0 0 10px var(--petrol-glow);
    font-weight: 700;
}

.lang-sep,
.lang-pill-sep {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.2);
    margin: 0 1px;
    user-select: none;
}