:root {
    color-scheme: light;
    --page-bg: #eef4f1;
    --page-bg-alt: #f7f3e8;
    --card-bg: rgba(255, 255, 255, 0.88);
    --card-border: rgba(17, 94, 80, 0.12);
    --heading: #102d28;
    --text: #28483f;
    --muted: #74867f;
    --field-bg: rgba(247, 250, 248, 0.92);
    --field-border: #dce7e2;
    --field-placeholder: #a0aca7;
    --primary: #116b5c;
    --primary-hover: #0b574b;
    --primary-soft: rgba(17, 107, 92, 0.11);
    --accent: #dca33a;
    --danger: #b44040;
    --danger-soft: #fff1ef;
    --success: #20765f;
    --success-soft: #eaf7f1;
    --shadow: 0 30px 80px rgba(27, 64, 55, 0.16), 0 4px 16px rgba(27, 64, 55, 0.06);
    --switch-bg: rgba(255, 255, 255, 0.82);
    --switch-border: rgba(17, 94, 80, 0.12);
}

html[data-theme="dark"] {
    color-scheme: dark;
    --page-bg: #071a17;
    --page-bg-alt: #10251f;
    --card-bg: rgba(12, 35, 30, 0.9);
    --card-border: rgba(212, 233, 225, 0.11);
    --heading: #f2f8f5;
    --text: #d9e9e3;
    --muted: #8ea79e;
    --field-bg: rgba(16, 48, 41, 0.92);
    --field-border: #25483f;
    --field-placeholder: #6f8b82;
    --primary: #45ab96;
    --primary-hover: #32937f;
    --primary-soft: rgba(69, 171, 150, 0.14);
    --accent: #e7b655;
    --danger: #ff918a;
    --danger-soft: rgba(151, 48, 48, 0.22);
    --success: #78d0b5;
    --success-soft: rgba(39, 126, 99, 0.2);
    --shadow: 0 32px 90px rgba(0, 0, 0, 0.42), 0 4px 18px rgba(0, 0, 0, 0.2);
    --switch-bg: rgba(12, 35, 30, 0.82);
    --switch-border: rgba(212, 233, 225, 0.12);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    color: var(--text);
    background:
        radial-gradient(circle at 16% 18%, rgba(220, 163, 58, 0.15), transparent 27%),
        radial-gradient(circle at 83% 82%, rgba(17, 107, 92, 0.16), transparent 31%),
        linear-gradient(145deg, var(--page-bg), var(--page-bg-alt));
    font-family: Samim, Tahoma, sans-serif;
    transition: color 220ms ease, background-color 220ms ease;
}

body.login-page::before {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-image:
        linear-gradient(rgba(16, 45, 40, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(16, 45, 40, 0.03) 1px, transparent 1px);
    background-size: 48px 48px;
    content: "";
    pointer-events: none;
    -webkit-mask-image: radial-gradient(circle at center, #000, transparent 78%);
    mask-image: radial-gradient(circle at center, #000, transparent 78%);
}

html[data-theme="dark"] body.login-page::before {
    background-image:
        linear-gradient(rgba(228, 241, 236, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(228, 241, 236, 0.025) 1px, transparent 1px);
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.login-canvas {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.ambient {
    position: absolute;
    width: 430px;
    height: 430px;
    border-radius: 50%;
    opacity: 0.62;
}

.ambient-one {
    top: -235px;
    right: -145px;
    border: 1px solid rgba(17, 107, 92, 0.13);
    box-shadow: 0 0 0 58px rgba(17, 107, 92, 0.032), 0 0 0 118px rgba(17, 107, 92, 0.018);
}

.ambient-two {
    bottom: -265px;
    left: -125px;
    border: 1px solid rgba(220, 163, 58, 0.14);
    box-shadow: 0 0 0 62px rgba(220, 163, 58, 0.03), 0 0 0 128px rgba(220, 163, 58, 0.018);
}

.theme-switch {
    position: fixed;
    top: 24px;
    left: 26px;
    z-index: 5;
    display: grid;
    width: 68px;
    height: 40px;
    padding: 5px;
    color: var(--muted);
    background: var(--switch-bg);
    border: 1px solid var(--switch-border);
    border-radius: 999px;
    box-shadow: 0 8px 26px rgba(26, 55, 48, 0.08);
    place-items: center;
    cursor: pointer;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: transform 180ms ease, background 220ms ease, border-color 220ms ease;
}

.theme-switch:hover {
    transform: translateY(-2px);
}

.theme-switch:focus-visible {
    outline: 3px solid var(--primary-soft);
    outline-offset: 3px;
}

.theme-switch-track {
    position: relative;
    display: flex;
    width: 56px;
    height: 28px;
    padding: 4px;
    align-items: center;
    justify-content: space-between;
    background: var(--primary-soft);
    border-radius: 999px;
    direction: rtl;
}

.theme-switch-icon {
    position: relative;
    z-index: 1;
    display: grid;
    width: 20px;
    height: 20px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1;
    place-items: center;
    transition: color 180ms ease;
}

.theme-switch-icon .fa {
    display: block;
    width: 1em;
    height: 1em;
    line-height: 1;
    text-align: center;
}

.theme-switch-sun {
    color: var(--accent);
}

.theme-switch-thumb {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: var(--card-bg);
    border-radius: 50%;
    box-shadow: 0 3px 8px rgba(17, 57, 49, 0.2);
    transition: transform 240ms cubic-bezier(0.22, 1, 0.36, 1), background 220ms ease;
}

html[data-theme="dark"] .theme-switch-thumb {
    transform: translateX(-28px);
}

html[data-theme="dark"] .theme-switch-sun {
    color: var(--muted);
}

html[data-theme="dark"] .theme-switch-moon {
    color: var(--accent);
}

.login-shell {
    position: relative;
    z-index: 1;
    display: grid;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 72px 24px;
    place-items: center;
}

.login-card {
    position: relative;
    width: min(440px, 100%);
    overflow: hidden;
    padding: 40px 42px 36px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 28px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    animation: card-enter 560ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.login-card::before {
    position: absolute;
    top: 0;
    right: 25%;
    left: 25%;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent), var(--primary), transparent);
    border-radius: 0 0 4px 4px;
    content: "";
}

.login-card::after {
    position: absolute;
    top: -92px;
    right: -92px;
    width: 220px;
    height: 220px;
    background: radial-gradient(circle, var(--primary-soft), transparent 68%);
    border-radius: 50%;
    content: "";
    pointer-events: none;
}

.login-header,
.auth-messages,
.login-form {
    position: relative;
    z-index: 1;
}

.login-header {
    margin-bottom: 29px;
    text-align: center;
}

.brand-logo-wrap {
    display: grid;
    width: 70px;
    height: 70px;
    margin: 0 auto 13px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--card-border);
    border-radius: 21px;
    box-shadow: 0 12px 28px rgba(17, 78, 67, 0.12);
    place-items: center;
}

html[data-theme="dark"] .brand-logo-wrap {
    background: rgba(244, 249, 246, 0.94);
}

.brand-logo {
    display: block;
    width: 56px;
    height: 56px;
    object-fit: contain;
}

.brand-logo-fallback {
    color: #116b5c;
    font: 800 17px/1 Tahoma, sans-serif;
}

.brand-title {
    display: block;
    max-width: 100%;
    overflow: hidden;
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.login-header h1 {
    margin: 8px 0 0;
    color: var(--heading);
    font-size: 23px;
    font-weight: 800;
    line-height: 1.55;
    letter-spacing: -0.45px;
}

.auth-messages:empty {
    display: none;
}

.auth-messages {
    margin-bottom: 18px;
}

.auth-messages .alert {
    position: relative;
    margin: 0 0 9px;
    padding: 11px 13px;
    color: var(--danger);
    background: var(--danger-soft);
    border: 1px solid rgba(180, 64, 64, 0.16);
    border-radius: 11px;
    font-size: 11px;
    line-height: 1.8;
}

.auth-messages .alert-success {
    color: var(--success);
    background: var(--success-soft);
    border-color: rgba(32, 118, 95, 0.16);
}

.auth-messages .close {
    position: absolute;
    top: 7px;
    left: 9px;
    padding: 2px;
    color: inherit;
    background: transparent;
    border: 0;
    cursor: pointer;
    opacity: 0.68;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.field-group label {
    display: block;
    margin: 0 0 8px;
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
}

.field-control {
    position: relative;
}

.field-control input {
    width: 100%;
    height: 54px;
    padding: 0 46px;
    color: var(--heading);
    background: var(--field-bg);
    border: 1px solid var(--field-border);
    border-radius: 14px;
    outline: none;
    font-size: 13px;
    text-align: right;
    transition: background 180ms ease, border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.field-control input[dir="ltr"] {
    text-align: left;
}

.field-control input::placeholder {
    color: var(--field-placeholder);
    direction: rtl;
    text-align: right;
}

.field-control input:hover {
    border-color: rgba(17, 107, 92, 0.34);
}

.field-control input:focus {
    background: var(--card-bg);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

.field-icon {
    position: absolute;
    top: 50%;
    right: 17px;
    z-index: 1;
    color: var(--muted);
    font-size: 14px;
    transform: translateY(-50%);
    transition: color 180ms ease;
}

.field-control:focus-within .field-icon {
    color: var(--primary);
}

.password-toggle {
    position: absolute;
    top: 50%;
    left: 10px;
    display: grid;
    width: 35px;
    height: 35px;
    padding: 0;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 10px;
    place-items: center;
    transform: translateY(-50%);
    cursor: pointer;
    transition: color 180ms ease, background 180ms ease;
}

.password-toggle:hover {
    color: var(--primary);
    background: var(--primary-soft);
}

.password-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

.caps-lock-message {
    display: block;
    margin-top: 7px;
    color: var(--accent);
    font-size: 10px;
}

.caps-lock-message[hidden] {
    display: none;
}

.caps-lock-message .fa {
    margin-left: 4px;
}

.login-submit {
    position: relative;
    display: flex;
    width: 100%;
    height: 55px;
    margin-top: 3px;
    padding: 0 20px;
    overflow: hidden;
    align-items: center;
    justify-content: center;
    gap: 11px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    border: 0;
    border-radius: 14px;
    box-shadow: 0 13px 27px rgba(17, 107, 92, 0.23);
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    transition: transform 180ms ease, box-shadow 180ms ease, filter 180ms ease;
}

.login-submit::before {
    position: absolute;
    top: -50%;
    left: -24%;
    width: 19%;
    height: 200%;
    background: rgba(255, 255, 255, 0.13);
    content: "";
    transform: rotate(20deg);
    transition: left 480ms ease;
}

.login-submit:hover {
    box-shadow: 0 17px 32px rgba(17, 107, 92, 0.3);
    filter: saturate(1.06);
    transform: translateY(-2px);
}

.login-submit:hover::before {
    left: 115%;
}

.login-submit:active {
    transform: translateY(0);
}

.login-submit:focus-visible {
    outline: 3px solid var(--primary-soft);
    outline-offset: 3px;
}

.login-submit .fa {
    position: absolute;
    left: 19px;
    font-size: 12px;
}

.submit-loading {
    display: none;
}

.login-submit.is-loading {
    cursor: wait;
    opacity: 0.86;
}

.login-submit.is-loading .submit-label,
.login-submit.is-loading .fa {
    display: none;
}

.login-submit.is-loading .submit-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.login-submit.is-loading .submit-loading::before {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    content: "";
    animation: spin 700ms linear infinite;
}

@keyframes card-enter {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 540px) {
    .theme-switch {
        top: 15px;
        left: 15px;
    }

    .login-shell {
        padding: 68px 14px;
    }

    .login-card {
        padding: 34px 24px 29px;
        border-radius: 23px;
    }

    .brand-logo-wrap {
        width: 64px;
        height: 64px;
        border-radius: 19px;
    }

    .brand-logo {
        width: 51px;
        height: 51px;
    }

    .login-header {
        margin-bottom: 25px;
    }

    .login-header h1 {
        font-size: 21px;
    }
}

@media (max-height: 620px) {
    .login-shell {
        align-items: start;
        padding-top: 64px;
    }

    .login-card {
        padding-top: 28px;
        padding-bottom: 27px;
    }

    .brand-logo-wrap {
        width: 58px;
        height: 58px;
        margin-bottom: 9px;
    }

    .brand-logo {
        width: 46px;
        height: 46px;
    }

    .login-header {
        margin-bottom: 21px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
