:root {
    --login-bg: #0f172a;
    --login-card-bg: rgba(17, 24, 39, 0.78);
    --login-text: #f1f5f9;
    --login-muted: #94a3b8;
    --login-border: rgba(255, 255, 255, 0.07);
    --login-shadow: 0 14px 36px rgba(2, 6, 23, 0.22);
    --focus-ring: 0 0 0 3px rgba(99, 102, 241, 0.15);
    --focus-border: rgba(99, 102, 241, 0.55);
}

/* Roboto Flex Font */
@font-face {
    font-family: "Roboto Flex";
    src: url("/static/fonts/roboto-flex.woff2") format("woff2");
    font-style: normal;
    font-weight: 100 1000;
    font-stretch: 25% 151%;
    font-display: swap;
}

/* Logo: login page always has a dark background → always render white */
.logo {
    display: block;
    margin-left: auto;
    margin-right: auto;
    max-width: 218px;
    width: 218px;
    color: #fff;
    filter: brightness(0) invert(1);
    opacity: 0;
    transform: translateY(6px);
    animation: logoFadeIn 0.5s ease forwards;
}

@keyframes logoFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-header {
    margin-bottom: auto;
}

.login-message {
    flex: 0 0 auto;
    margin: auto 0;
    padding: 1.5rem 0;
    color: var(--login-muted);
    font-size: 0.95rem;
    line-height: 1.5;
    transition: color 0.2s ease;
}

.login-message p {
    margin: 0;
}

.login-message.error {
    color: #dc3545;
}

#error-alert {
    margin-bottom: 1.25rem;
}

#submit-btn {
    margin-top: 0.5rem;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Roboto Flex", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(99, 102, 241, 0.15), transparent 60%),
        radial-gradient(1000px 500px at 90% 0%, rgba(56, 189, 248, 0.12), transparent 60%),
        radial-gradient(circle at 20% 20%, #20384f 0%, #0f172a 50%, #0b1222 100%);
    background-attachment: fixed;
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
}

body::before,
body::after {
    content: "";
    position: fixed;
    inset: auto;
    pointer-events: none;
    filter: blur(80px);
    opacity: 0.55;
}

body::before {
    top: 7%;
    left: 8%;
    width: 320px;
    height: 320px;
    background: rgba(56, 189, 248, 0.14);
}

body::after {
    right: 6%;
    bottom: 10%;
    width: 360px;
    height: 360px;
    background: rgba(99, 102, 241, 0.18);
}

.login-shell {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: calc(1.5rem + env(safe-area-inset-top, 0px));
    padding-right: calc(1.5rem + env(safe-area-inset-right, 0px));
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    padding-left: calc(1.5rem + env(safe-area-inset-left, 0px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.login-card {
    width: 100%;
    max-width: 520px;
    padding: 3rem;
    border-radius: 24px;
    background: linear-gradient(180deg, rgba(17, 24, 39, 0.9), rgba(15, 23, 42, 0.82));
    background-color: var(--login-card-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.44),
        0 0 0 1px rgba(255, 255, 255, 0.03) inset,
        0 2px 8px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    transform: translateY(0);
    transition:
        transform 0.25s ease,
        box-shadow 0.25s ease,
        border-color 0.2s ease;
    min-height: 480px;
}

@media (hover: hover) and (pointer: fine) {
    .login-card:hover {
        border-color: rgba(99, 102, 241, 0.25);
    }
}

.login-card h1 {
    margin: 0 0 0.35rem 0;
    color: var(--login-text);
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.subtitle {
    margin: 0.3rem 0 1.75rem 0;
    color: var(--login-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.login-kicker {
    margin: 0;
    color: #8bd4ff;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.form-label {
    color: #cbd5e1;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.form-control {
    height: 48px;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--login-text);
    box-shadow: none;
    font-size: 16px;
    -webkit-appearance: none;
    appearance: none;
    transition:
        border-color 0.18s ease,
        background-color 0.18s ease,
        box-shadow 0.18s ease;
}

.form-control,
.btn-primary {
    touch-action: manipulation;
}

.form-control:focus {
    background: rgba(15, 23, 42, 0.9);
    border-color: var(--focus-border);
    box-shadow: var(--focus-ring);
    color: var(--login-text);
}

.form-control::placeholder {
    color: rgba(148, 163, 184, 0.7);
}

/* Focus state for card */
.login-card:focus-within {
    transform: translateY(-2px);
    border-color: var(--focus-border);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--focus-border) 45%, transparent),
        0 14px 44px rgba(0, 0, 0, 0.5),
        0 2px 8px rgba(0, 0, 0, 0.25);
}

.btn-primary {
    height: 54px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #38bdf8 0%, #6366f1 55%, #8b5cf6 100%);
    font-weight: 700;
    letter-spacing: 0.02em;
    box-shadow: 0 12px 30px rgba(99, 102, 241, 0.28), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
    -webkit-tap-highlight-color: transparent;
    transition:
        transform 0.12s ease,
        box-shadow 0.12s ease,
        filter 0.2s ease;
}

.btn-primary:hover {
    transform: translateY(-1px);
    filter: saturate(1.08);
    box-shadow: 0 16px 34px rgba(99, 102, 241, 0.38), 0 0 28px rgba(56, 189, 248, 0.12);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }

    .logo {
        opacity: 1;
        transform: none;
    }
}

@media (max-width: 480px) {
    .login-shell {
        padding-top: calc(1rem + env(safe-area-inset-top, 0px));
        padding-right: calc(1rem + env(safe-area-inset-right, 0px));
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        padding-left: calc(1rem + env(safe-area-inset-left, 0px));
    }

    .login-card {
        max-width: 100%;
        padding: 1.45rem;
    }

    .login-card h1 {
        font-size: 1.65rem;
    }
}

/* iOS blur fallback for performance */
@supports (-webkit-touch-callout: none) {

    html {
        -webkit-text-size-adjust: 100%;
        height: 100%;
    }

    body {
        height: 100%;
        overflow-x: hidden;
        overscroll-behavior-y: none;
        -webkit-overflow-scrolling: touch;
    }

    .login-shell {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }

    .login-card {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: rgba(17, 24, 39, 0.96);
    }
}