/* --- Variables: light (default) & dark --- */
:root {
    --bg: #faf8f6;
    --bg-card: #ffffff;
    --text: #1a1a1a;
    --text-muted: #5c5c5c;
    --accent: #c45c3e;
    --accent-hover: #a84a2f;
    --accent-soft: rgba(196, 92, 62, 0.12);
    --border: rgba(0, 0, 0, 0.08);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
    --input-bg: #f5f3f0;
    --focus-ring: var(--accent);
    --error: #c23d3d;
    --icon-sun-opacity: 1;
    --icon-moon-opacity: 0.35;
}

[data-theme="dark"] {
    --bg: #0f1419;
    --bg-card: #1a2129;
    --text: #e8eaed;
    --text-muted: #9aa0a6;
    --accent: #e07d5a;
    --accent-hover: #f0906e;
    --accent-soft: rgba(224, 125, 90, 0.18);
    --border: rgba(255, 255, 255, 0.08);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    --input-bg: #252d36;
    --focus-ring: var(--accent);
    --error: #f08080;
    --icon-sun-opacity: 0.4;
    --icon-moon-opacity: 1;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f1419;
        --bg-card: #1a2129;
        --text: #e8eaed;
        --text-muted: #9aa0a6;
        --accent: #e07d5a;
        --accent-hover: #f0906e;
        --accent-soft: rgba(224, 125, 90, 0.18);
        --border: rgba(255, 255, 255, 0.08);
        --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
        --input-bg: #252d36;
        --error: #f08080;
        --icon-sun-opacity: 0.4;
        --icon-moon-opacity: 1;
    }
}

/* --- Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "DM Sans", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background-color 0.4s ease, color 0.3s ease;
}

/* --- Theme toggle --- */
.theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10;
}

.theme-btn {
    width: 2.75rem;
    height: 2.75rem;
    border: none;
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.3s ease;
}

.theme-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] .theme-btn:hover,
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-btn:hover {
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    }
}

.theme-btn .icon-sun {
    opacity: var(--icon-sun-opacity);
    position: absolute;
    transition: opacity 0.3s ease;
}

.theme-btn .icon-moon {
    opacity: var(--icon-moon-opacity);
    position: absolute;
    transition: opacity 0.3s ease;
}

.theme-btn .icon-sun::after {
    content: "☀";
    font-size: 1.25rem;
}

.theme-btn .icon-moon::after {
    content: "☽";
    font-size: 1.15rem;
}

/* --- Layout --- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    position: relative;
    overflow: hidden;
}

.login-bg {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 100% 80% at 50% -20%, var(--accent-soft), transparent 50%),
        radial-gradient(ellipse 80% 60% at 90% 50%, var(--accent-soft), transparent 45%),
        radial-gradient(ellipse 60% 80% at 10% 80%, var(--accent-soft), transparent 45%);
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.login-card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 22rem;
    padding: 2.75rem 2.25rem;
    background: var(--bg-card);
    border-radius: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: box-shadow 0.3s ease, border-color 0.3s ease, transform 0.3s ease;
}

.login-card:hover {
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .login-card:hover,
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .login-card:hover {
        box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
    }
}

/* --- Header --- */
.login-header {
    text-align: center;
    margin-bottom: 2.25rem;
}

.login-title {
    font-family: "Fraunces", Georgia, serif;
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0 0 0.4em;
    letter-spacing: -0.02em;
    color: var(--text);
}

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

/* --- Form --- */
.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

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

.field label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
}

.field input {
    width: 100%;
    padding: 0.85rem 1.15rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text);
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.field input::placeholder {
    color: var(--text-muted);
    opacity: 0.8;
}

.field input:hover {
    border-color: rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] .field input:hover,
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .field input:hover {
        border-color: rgba(255, 255, 255, 0.15);
    }
}

.field input:focus {
    outline: none;
    border-color: var(--focus-ring);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-error {
    font-size: 0.875rem;
    color: var(--error);
    margin: -0.25rem 0 0;
    min-height: 1.25em;
}

.form-error:not([hidden]) {
    display: block;
}

/* --- Button --- */
.btn-submit {
    margin-top: 0.75rem;
    padding: 0.95rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: background 0.25s ease, transform 0.15s ease, box-shadow 0.2s ease;
    position: relative;
}

.btn-submit:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--accent-soft);
}

.btn-submit:active:not(:disabled) {
    transform: translateY(0);
}

.btn-submit:disabled {
    cursor: not-allowed;
    opacity: 0.8;
}

.btn-submit .btn-loader {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
}

.btn-submit.loading .btn-text {
    visibility: hidden;
}

.btn-submit.loading .btn-loader {
    display: flex;
}

.btn-loader::after {
    content: "";
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* --- Mobile --- */
@media (max-width: 380px) {
    .login-wrap {
        padding: 1.25rem;
    }
    .login-card {
        padding: 2rem 1.5rem;
    }
    .login-title {
        font-size: 1.5rem;
    }
    .login-header {
        margin-bottom: 1.75rem;
    }
}

@media (min-width: 600px) {
    .theme-toggle {
        top: 1.5rem;
        right: 1.5rem;
    }
    .login-wrap {
        padding: 2.5rem;
    }
    .login-card {
        padding: 3rem 2.5rem;
        max-width: 24rem;
    }
    .login-header {
        margin-bottom: 2.5rem;
    }
}
