/* ==========================================================================
 * PlateChain auth pages
 *
 * Shared by: /login, /register/contractor, /register/check-inbox,
 *            /verify-email, and the legacy config-error page.
 *
 * Design language: slate + brand-blue, generous whitespace, large touch
 * targets, WCAG AA contrast, visible focus rings, dark-mode + reduced-motion
 * respected. Legacy .login-* rules are preserved at the bottom so the
 * existing config-error page stays unchanged.
 * ========================================================================== */

:root {
    --bg: #f1f5f9;
    --bg-accent: #e0e7ff;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --muted: #475569;
    --muted-2: #64748b;
    --brand: #1d4ed8;
    --brand-hover: #1e40af;
    --brand-soft: #eef2ff;
    --success: #047857;
    --success-soft: #d1fae5;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --danger: #991b1b;
    --danger-soft: #fee2e2;
    --ring: #93c5fd;
    --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 24px rgba(15, 23, 42, 0.04);
    --radius-card: 16px;
    --radius-input: 10px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
}

body {
    font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.55;
}

a {
    color: var(--brand);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
    border-radius: 6px;
}

/* --- Page scaffolds ------------------------------------------------------ */

.auth-body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    background: linear-gradient(135deg, #eef2ff 0%, var(--bg) 55%, #f8fafc 100%);
    background-attachment: fixed;
}

/* Full-viewport gradient + blobs (not clipped by the form column) */
.auth-backdrop {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.auth-page,
.auth-footer {
    position: relative;
    z-index: 1;
}

.auth-skip {
    z-index: 2;
}

.auth-skip {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.auth-skip:focus {
    position: fixed;
    left: 16px;
    top: 16px;
    z-index: 100;
    width: auto;
    height: auto;
    padding: 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-input);
    box-shadow: var(--shadow-card);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    color: var(--brand);
}

.auth-page {
    flex: 1 1 auto;
    display: grid;
    gap: 28px;
    padding: 40px clamp(20px, 4vw, 40px);
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
}

.auth-page--two-column {
    grid-template-columns: minmax(0, 1fr);
    place-items: center;
    justify-items: center;
    align-content: center;
}

.auth-page--centered {
    grid-template-columns: minmax(0, 1fr);
    place-items: center;
    justify-items: center;
    align-content: center;
}

.auth-main {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    min-width: 0;
    scroll-margin-top: 16px;
}

/* Brand block sits above Welcome back / form - all breakpoints */
.auth-page--two-column .auth-main {
    width: 100%;
    max-width: 520px;
    gap: 0;
}

.auth-page--two-column .auth-main > .auth-brand-inline,
.auth-page--two-column .auth-main > .auth-card {
    width: 100%;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
}

.auth-brand-inline {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
    box-shadow: var(--shadow-card);
    padding: 24px 28px 0;
}

.auth-brand-inline-title {
    margin: 0;
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--brand);
}

.auth-brand-inline-lede {
    margin: 0;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.auth-brand-inline + .auth-card {
    border-top: none;
    border-radius: 0 0 var(--radius-card) var(--radius-card);
    margin-top: 0;
    padding-top: 18px;
}

.auth-brand-inline + .auth-card--form .auth-card-head {
    padding-top: 0;
    margin-top: 0;
    border-top: none;
}

/* --- Decor blobs (subtle background interest) ---------------------------- */

.decor-blob {
    position: absolute;
    width: 360px;
    height: 360px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    filter: blur(40px);
    opacity: 0.45;
}

.decor-blob--tl {
    top: -140px;
    left: -140px;
    background: radial-gradient(closest-side, rgba(99, 102, 241, 0.35), transparent);
}

.decor-blob--br {
    bottom: -120px;
    right: -120px;
    background: radial-gradient(closest-side, rgba(56, 189, 248, 0.35), transparent);
}

.auth-main {
    position: relative;
    z-index: 1;
}

/* --- Brand (inline above form) ------------------------------------------- */

.brand-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
}

.brand-row > div {
    text-align: center;
}

.brand-row h1 {
    margin: 0;
    font-size: 32px;
    letter-spacing: -0.01em;
}

.brand-tagline {
    margin: 2px 0 0 0;
    color: var(--muted);
    font-size: 13px;
}

.auth-info-lede {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.7;
}

.auth-info-lede.auth-brand-inline-lede {
    margin-top: 10px;
    text-align: center;
    line-height: 1.45;
}

/* --- Auth card (right side) --------------------------------------------- */

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: clamp(24px, 3vw, 36px);
    display: flex;
    flex-direction: column;
    gap: 18px;
    animation: card-fade-in 240ms ease-out both;
}

@keyframes card-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.auth-status-card {
    text-align: center;
    align-items: center;
}

.auth-page--centered .auth-status-card {
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

.auth-card-head h2,
.auth-card h2 {
    margin: 0;
    font-size: 24px;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.auth-card-sub {
    margin: 4px 0 0 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
}

.status-card-lede {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.6;
}

.auth-card-foot {
    margin-top: 4px;
    text-align: center;
}

.auth-link {
    color: var(--brand);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
}

.auth-link:hover {
    color: var(--brand-hover);
    text-decoration: underline;
}

/* --- Status icons -------------------------------------------------------- */

.status-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    margin: 4px auto 4px;
}

.status-icon svg {
    width: 32px;
    height: 32px;
}

.status-icon--success { background: var(--success-soft); color: var(--success); }
.status-icon--info    { background: var(--brand-soft);   color: var(--brand); }
.status-icon--warn    { background: var(--warn-soft);    color: var(--warn); }
.status-icon--danger  { background: var(--danger-soft);  color: var(--danger); }

/* --- Form scaffolding --------------------------------------------------- */

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.auth-form--compact {
    gap: 14px;
    max-width: 360px;
    margin: 16px auto 0 auto;
    text-align: left;
}

.auth-fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--surface-2);
}

.auth-fieldset legend {
    padding: 0 6px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
}

.auth-field-label {
    font-weight: 600;
    color: var(--text);
}

/* --- Inputs ------------------------------------------------------------- */

.input-with-icon {
    position: relative;
    display: block;
}

.input-with-icon > input,
.input-with-icon > select {
    width: 100%;
    height: 44px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-input);
    background: var(--surface);
    color: var(--text);
    padding: 10px 12px 10px 40px;
    font-size: 14px;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.input-with-icon--with-action > input {
    padding-right: 44px;
}

.input-with-icon > input:focus {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
    border-color: var(--brand);
}

.input-with-icon > input::placeholder {
    color: var(--muted-2);
}

.input-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    display: grid;
    place-items: center;
    pointer-events: none;
}

.input-icon svg {
    width: 18px;
    height: 18px;
}

.password-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: grid;
    place-items: center;
    border-radius: 6px;
}

.password-toggle:hover {
    background: var(--surface-2);
    color: var(--text);
}

.password-toggle[aria-pressed="true"] {
    color: var(--brand);
}

.password-toggle svg {
    width: 18px;
    height: 18px;
}

/* --- Helpers, errors, strength meter ------------------------------------ */

.field-helper {
    color: var(--muted);
    font-size: 13px;
    font-weight: 400;
    line-height: 1.5;
}

.field-error {
    color: var(--danger);
    font-size: 13px;
    font-weight: 500;
}

.field-feedback {
    display: block;
    min-height: 0;
    line-height: 1.5;
}

.field-feedback[hidden] {
    display: none;
}

.field-feedback[data-tone="checking"] {
    color: var(--muted);
    font-weight: 400;
}

.auth-field--invalid .input-with-icon input {
    border-color: var(--danger);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--danger) 35%, transparent);
}

.strength-meter {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin-top: 6px;
}

.strength-meter-bar {
    height: 4px;
    border-radius: 999px;
    background: var(--border);
    transition: background-color 160ms ease;
}

.strength-meter[data-level="1"] .strength-meter-bar:nth-child(-n+1),
.strength-meter[data-level="2"] .strength-meter-bar:nth-child(-n+2),
.strength-meter[data-level="3"] .strength-meter-bar:nth-child(-n+3),
.strength-meter[data-level="4"] .strength-meter-bar { background: var(--brand); }

.strength-meter[data-level="1"] .strength-meter-bar:nth-child(-n+1) { background: var(--danger); }
.strength-meter[data-level="2"] .strength-meter-bar:nth-child(-n+2) { background: var(--warn); }
.strength-meter[data-level="3"] .strength-meter-bar:nth-child(-n+3) { background: var(--brand); }
.strength-meter[data-level="4"] .strength-meter-bar { background: var(--success); }

.strength-label {
    margin-left: 6px;
    font-weight: 600;
    color: var(--muted);
}

.strength-label[data-tone="weak"]   { color: var(--danger); }
.strength-label[data-tone="fair"]   { color: var(--warn); }
.strength-label[data-tone="good"]   { color: var(--brand); }
.strength-label[data-tone="strong"] { color: var(--success); }

/* --- Buttons ------------------------------------------------------------- */

.btn-primary,
.btn-secondary,
.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 48px;
    padding: 0 18px;
    border-radius: var(--radius-input);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background-color 120ms ease, color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.btn-primary {
    background: var(--brand);
    color: #ffffff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.btn-primary:hover {
    background: var(--brand-hover);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary[disabled],
.btn-primary[aria-disabled="true"] {
    background: var(--muted-2);
    cursor: not-allowed;
    transform: none;
    pointer-events: none;
}

.btn-secondary {
    background: var(--brand-soft);
    color: var(--brand);
    border-color: var(--brand-soft);
}

.btn-secondary:hover {
    background: #e0e7ff;
}

.btn-ghost {
    background: transparent;
    color: var(--brand);
    border-color: var(--border-strong);
}

.btn-ghost:hover {
    background: var(--surface-2);
    border-color: var(--brand);
}

.btn-spinner {
    display: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #ffffff;
    animation: spin 700ms linear infinite;
}

button[data-loading="true"] .btn-spinner {
    display: inline-block;
}

button[data-loading="true"] .btn-label::after {
    content: "\2026";
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.auth-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
}

.auth-actions--center {
    justify-content: center;
    margin-top: 6px;
}

.auth-fineprint {
    margin: 4px 0 0 0;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.6;
}

/* --- Banners ------------------------------------------------------------- */

.banner {
    border-radius: var(--radius-input);
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.5;
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.banner ul {
    margin: 4px 0 0 0;
    padding-left: 18px;
}

.banner--success { background: var(--success-soft); color: var(--success); border-color: rgba(4, 120, 87, 0.18); }
.banner--info    { background: var(--brand-soft);   color: var(--brand);   border-color: rgba(29, 78, 216, 0.18); }
.banner--warn    { background: var(--warn-soft);    color: var(--warn);    border-color: rgba(180, 83, 9, 0.22); }
.banner--danger  { background: var(--danger-soft);  color: var(--danger);  border-color: rgba(153, 27, 27, 0.22); }

/* --- Disclosure / resend block ------------------------------------------ */

.auth-disclosure {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    text-align: left;
    color: var(--muted);
    font-size: 14px;
}

.auth-disclosure summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
    list-style: none;
}

.auth-disclosure summary::-webkit-details-marker { display: none; }

.auth-disclosure summary::before {
    content: "+";
    display: inline-block;
    width: 18px;
    color: var(--brand);
    font-weight: 700;
    margin-right: 6px;
}

.auth-disclosure[open] summary::before { content: "\2212"; }

.auth-disclosure-list {
    margin: 10px 0 12px 0;
    padding-left: 20px;
}

.auth-resend-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

/* --- Footer -------------------------------------------------------------- */

.auth-footer {
    flex-shrink: 0;
    text-align: center;
    padding: 16px 24px 20px;
    font-size: 12px;
    color: var(--muted-2);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.auth-footer-sep {
    color: var(--border-strong);
}

/* --- Responsive ---------------------------------------------------------- */

@media (max-width: 960px) {
    .auth-main {
        justify-content: flex-start;
    }

    .auth-brand-inline {
        padding: 20px 22px 16px;
    }

    .auth-brand-inline-title,
    .brand-row h1 {
        font-size: 28px;
    }

    .decor-blob {
        opacity: 0.25;
        filter: blur(50px);
    }
}

@media (max-width: 540px) {
    .auth-page {
        padding: 16px 14px 12px;
        gap: 14px;
    }

    .auth-footer {
        padding: 12px 16px 16px;
    }
    .auth-brand-inline,
    .auth-card {
        padding: 20px;
    }
    .auth-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .auth-actions .btn-ghost,
    .auth-actions .btn-primary {
        width: 100%;
    }
}

/* --- Reduced motion ------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
    .btn-primary:hover { transform: none; }
}

/* ==========================================================================
 * Legacy classes kept for the (rarely-shown) config-error page so its layout
 * doesn't change. The login page is built with the new tokens above.
 * ========================================================================== */

.login-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 28px;
    padding: 34px;
}

.login-info,
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
}

.login-error {
    background: var(--danger-soft);
    border: 1px solid rgba(153, 27, 27, 0.22);
    color: var(--danger);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
    font-size: 14px;
}

.login-form {
    display: grid;
    gap: 12px;
}

.login-form label {
    display: grid;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
}

.login-form input {
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    padding: 10px 11px;
    font-size: 14px;
}

.login-form button {
    margin-top: 4px;
    border: 0;
    border-radius: 10px;
    background: var(--brand);
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    padding: 11px 14px;
    cursor: pointer;
}

.login-form button:hover { background: var(--brand-hover); }

.login-links {
    margin-top: 16px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.login-links a {
    color: var(--brand);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
}

.muted { color: var(--muted); }

@media (max-width: 960px) {
    .login-page {
        grid-template-columns: 1fr;
        padding: 20px;
    }
}
