* { box-sizing: border-box; }

:root {
    --blue: var(--color-primary);
    --blue-dark: var(--color-primary-dark);
    /* Control borders must clear 3:1 (WCAG 1.4.11); see --color-border-control
       in tokens.css. Only used by .input-wrap input here. */
    --border: var(--color-border-control, #868d96);
    --text-body: #1e293b;
    --text-label: #374151;
    --text-muted: var(--color-text-muted);

    /* Split-screen brand panel. Light theme keeps the panel on-brand but
       genuinely light; dark theme uses the deep navy gradient. Every value
       the panel paints with is routed through these so neither theme
       hardcodes the other's colours. */
    --auth-panel-faint: rgba(20, 41, 77, 0.58);
    --auth-tile-bg:     rgba(255, 255, 255, 0.58);
    --auth-tile-border: rgba(20, 41, 77, 0.12);
    --auth-tile-icon:   rgba(255, 255, 255, 0.85);
    --auth-icon-fg:     #1d4ed8;
    --auth-chip-bg:     rgba(255, 255, 255, 0.72);
    --auth-chip-border: rgba(20, 41, 77, 0.16);
    --auth-chip-fg:     #1d4ed8;
    --auth-chip-hover:  rgba(255, 255, 255, 0.95);
}

html[data-theme="dark"] {
    --auth-panel-faint: rgba(255, 255, 255, 0.6);
    --auth-tile-bg:     rgba(255, 255, 255, 0.06);
    --auth-tile-border: rgba(255, 255, 255, 0.08);
    --auth-tile-icon:   rgba(255, 255, 255, 0.14);
    --auth-icon-fg:     #93c5fd;
    --auth-chip-bg:     rgba(255, 255, 255, 0.14);
    --auth-chip-border: rgba(255, 255, 255, 0.28);
    --auth-chip-fg:     #ffffff;
    --auth-chip-hover:  rgba(255, 255, 255, 0.24);
}

/* ── Base ── */
body {
    margin: 0;
    font-family: 'Poppins', Arial, sans-serif;
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    overflow-x: hidden;
    background: var(--color-bg);
    display: flex;
    align-items: stretch;
}

/* ── Back link — text-and-arrow style so it reads as navigation, not a FAB ── */
.back-home {
    position: fixed;
    top: 1.6rem;
    left: 1.6rem;
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.8rem 1.4rem;
    color: #1d4ed8;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(37, 99, 235, 0.15);
    border-radius: 9999px;
    font-size: 1.3rem;
    font-weight: 600;
    z-index: 100;
    transition: background 0.2s, box-shadow 0.2s, transform 0.15s;
}
.back-home:hover {
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.12);
    transform: translateX(-2px);
}
.back-home svg { flex-shrink: 0; }
@media (min-width: 780px) {
    .back-home {
        background: var(--auth-chip-bg);
        border-color: var(--auth-chip-border);
        color: var(--auth-chip-fg);
    }
    .back-home:hover {
        background: var(--auth-chip-hover);
    }
}

/* ── Page layout ── */
.login-page {
    display: flex;
    width: 100%;
    min-width: 0;
    min-height: 100vh;
    min-height: 100dvh;
    /* Below the 780px split-screen breakpoint .login-brand is hidden, and the
       page had no background of its own — so phones and tablets got a bare
       white screen with a form on it while desktop got the full brand panel.
       Reusing --auth-panel rather than a new colour means dark mode is already
       handled: the token has a deep-navy variant. */
    background: var(--auth-panel);
    align-items: center;
    justify-content: center;
    /* Top padding clears the fixed .back-home chip. */
    padding: 8rem 1.6rem 3.2rem;
}

/* Brand panel — desktop only */
.login-brand { display: none; }

/* A real floating card on small screens, not a full-bleed white sheet. */
.login-card {
    width: 100%;
    max-width: 44rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3.2rem 2.4rem 3.6rem;
    background: var(--color-surface);
    border-radius: var(--r-xl);
    box-shadow: 0 18px 40px rgba(20, 41, 77, 0.18);
}

/* Mini logo shown on mobile */
.card-logo {
    width: 8rem;
    height: 8rem;
    margin-bottom: 1.6rem;
}

/* ── Headings ── */
h1 {
    font-size: 2.8rem;
    font-weight: 700;
    color: var(--blue);
    margin: 0 0 0.4rem;
    text-align: center;
}

.auth-sub {
    font-size: 1.4rem;
    color: var(--text-muted);
    margin: 0 0 3.2rem;
    text-align: center;
}

/* ── Form ── */
.login_form {
    width: 100%;
    max-width: 36rem;
    display: flex;
    flex-direction: column;
    gap: 1.8rem;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

label {
    font-size: 1.4rem;
    font-weight: 500;
    color: var(--text-label);
    display: block;
}

.input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrap input {
    width: 100%;
    height: 4.8rem;
    border: 1.5px solid var(--border);
    border-radius: 1.2rem;
    background: #fff;
    padding: 0 4.4rem 0 4.4rem;
    font-family: 'Poppins', Arial, sans-serif;
    font-size: 1.5rem;
    color: var(--text-body);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrap input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.input-wrap input::placeholder {
    color: #c0c9d6;
}

.input-icon {
    position: absolute;
    left: 1.4rem;
    width: 1.8rem;
    height: 1.8rem;
    pointer-events: none;
    stroke: #9ca3af;
    flex-shrink: 0;
}

.pwd-toggle {
    position: absolute;
    right: 1rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.4rem;
    display: flex;
    align-items: center;
    height: auto;
    width: auto;
    border-radius: 0;
}
.pwd-toggle svg { stroke: #9ca3af; transition: stroke 0.15s; }
.pwd-toggle:hover svg { stroke: #6b7280; }

.login-options {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.2rem;
    margin-top: -0.4rem;
}

.remember-me {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 0.7rem;
    width: auto;
    color: var(--text-muted);
    font-size: 1.3rem;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.remember-me input {
    appearance: none;
    -webkit-appearance: none;
    width: 1.8rem;
    height: 1.8rem;
    border: 1.5px solid var(--color-border-control, #868d96);
    border-radius: 0.5rem;
    background: #fff;
    display: inline-grid;
    place-items: center;
    margin: 0;
    cursor: pointer;
    transition: background 0.18s, border-color 0.18s, box-shadow 0.18s;
}

.remember-me input::after {
    content: '';
    width: 0.9rem;
    height: 0.55rem;
    border-left: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: rotate(-45deg) scale(0);
    margin-top: -0.1rem;
    transition: transform 0.18s;
}

.remember-me input:checked {
    background: var(--blue);
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.remember-me input:checked::after {
    transform: rotate(-45deg) scale(1);
}

.forgot-link {
    font-size: 1.3rem;
    color: var(--blue);
    text-decoration: none;
    text-align: right;
    display: block;
    transition: opacity 0.15s;
}
.forgot-link:hover { text-decoration: underline; opacity: 0.8; }

/* ── Submit button ── */
.login_form [type="submit"] {
    width: 100%;
    height: 5rem;
    border: none;
    border-radius: 9999px;
    background: var(--blue);
    color: #fff;
    font-family: 'Poppins', Arial, sans-serif;
    font-size: 1.6rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 0.4rem;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    padding: 0;
}
.login_form [type="submit"]:hover {
    background: var(--blue-dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.28);
}
.login_form [type="submit"]:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ── Auth switch ── */
.auth-switch {
    font-size: 1.3rem;
    color: #6b7280;
    text-align: center;
    margin-top: 2.4rem;
}
.auth-switch a {
    color: var(--blue);
    font-weight: 600;
    text-decoration: underline;
}

/* ── Error messages (injected by login.js into .input-wrap) ── */
.field-error {
    display: block;
    font-size: 1.2rem !important;
    color: #ef4444 !important;
    margin-top: 0.4rem;
    padding-left: 0.4rem !important;
    width: auto !important;
    max-width: none !important;
}

/* ── Desktop (≥780px) ── */
@media (min-width: 780px) {
    body {
        background: var(--color-bg);
    }

    .login-page {
        background: var(--auth-panel);
    }

    .login-brand {
        display: flex;
        flex: 1;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2.4rem;
        padding: 4rem;
        min-width: 0;
        background: var(--auth-panel);
    }

    .brand-logo {
        width: 12rem;
        height: 12rem;
        filter: var(--auth-logo-filter);
    }

    .brand-name {
        font-size: 5.6rem;
        font-weight: 800;
        letter-spacing: 0.1em;
        color: var(--auth-panel-fg);
        margin: 0;
        line-height: 1;
    }

    .brand-tagline {
        font-size: 1.7rem;
        color: var(--auth-panel-soft);
        text-align: center;
        line-height: 1.8;
        margin: 0;
        max-width: 28rem;
    }

    .login-card {
        width: 52rem;
        min-width: 52rem;
        /* max-width is reset because the mobile rule caps the card at 44rem to
           keep it a card; left in place it would clamp this 52rem panel too. */
        max-width: none;
        flex: 0 0 52rem;
        min-height: 100vh;
        min-height: 100dvh;
        border-radius: 0;
        padding: 4rem 5.6rem;
        box-shadow: -24px 0 64px rgba(0, 0, 0, 0.14);
        justify-content: center;
    }

    /* The page itself no longer needs padding once the panel takes over. */
    .login-page {
        padding: 0;
        align-items: stretch;
    }

    .card-logo { display: none; }

    h1 { font-size: 3.2rem; }
}

/* Login brand-panel trust content (visible ≥780px, mobile keeps compact) */
.brand-trust-list,
.brand-quote { display: none; }

@media (min-width: 780px) {
    .brand-trust-list {
        display: flex;
        flex-direction: column;
        gap: 1.4rem;
        list-style: none;
        margin: 1.4rem 0 0;
        padding: 0;
        max-width: 34rem;
        width: 100%;
    }

    .brand-trust-item {
        display: flex;
        align-items: flex-start;
        gap: 1.4rem;
        padding: 1.4rem 1.6rem;
        border-radius: 1.2rem;
        background: var(--auth-tile-bg);
        border: 1px solid var(--auth-tile-border);
        color: var(--auth-panel-fg);
        backdrop-filter: blur(6px);
    }

    .brand-trust-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 3.4rem;
        height: 3.4rem;
        flex: 0 0 auto;
        border-radius: 0.9rem;
        background: var(--auth-tile-icon);
        color: var(--auth-icon-fg);
    }

    .brand-trust-icon svg {
        width: 1.8rem;
        height: 1.8rem;
    }

    .brand-trust-item strong {
        display: block;
        font-size: 1.35rem;
        font-weight: 700;
        color: var(--auth-panel-fg);
        margin-bottom: 0.2rem;
    }

    .brand-trust-item span {
        font-size: 1.2rem;
        color: var(--auth-panel-soft);
        line-height: 1.5;
    }

    .brand-quote {
        display: block;
        max-width: 34rem;
        font-size: 1.3rem;
        color: var(--auth-panel-faint);
        font-style: italic;
        line-height: 1.6;
        text-align: center;
        margin-top: 0.8rem;
    }
}

/* ── PHP redirect toast ── */
.toast {
    position: fixed;
    bottom: 2.4rem;
    left: 50%;
    transform: translateX(-50%) translateY(2rem);
    background: #1f2937;
    color: #fff;
    padding: 1.2rem 2.4rem;
    border-radius: 9999px;
    font-size: 1.4rem;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 9999;
    white-space: nowrap;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast.toast-error { background: #ef4444; }

@media (max-width: 380px) {
    .login-options {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.8rem;
    }

    .forgot-link {
        text-align: left;
    }
}
