/* ==========================================================================
   Urdume — base: tokens de design, reset e componentes partilhados
   Paleta inspirada em tintas têxteis naturais: anil, cochonilha e açafrão.
   ========================================================================== */

:root {
    /* Marca */
    --anil-900: #12125c;
    --anil-700: #1f22a8;
    --anil-600: #2b2fd9;
    --anil-500: #4a4ff0;
    --anil-100: #e8e9ff;
    --anil-50: #f4f4ff;
    --cochonilha-600: #c2185b;
    --cochonilha-500: #e0457b;
    --cochonilha-100: #fde7ef;
    --acafrao-500: #f2a900;
    --acafrao-400: #ffc233;
    --acafrao-100: #fff5d6;
    --verde-600: #0f8a5f;
    --verde-100: #dcf5ea;

    /* Neutros (tinta sobre linho) */
    --ink-900: #0b1026;
    --ink-800: #1a2040;
    --ink-700: #2e3558;
    --ink-600: #4a5176;
    --ink-500: #6b7194;
    --ink-400: #9197b3;
    --ink-300: #c5c9dc;
    --ink-200: #e3e6f0;
    --ink-100: #f0f2f8;
    --ink-50: #f7f8fc;
    --white: #ffffff;

    /* Semântica */
    --color-bg: var(--white);
    --color-surface: var(--white);
    --color-surface-muted: var(--ink-50);
    --color-text: var(--ink-900);
    --color-text-muted: var(--ink-600);
    --color-border: var(--ink-200);
    --color-primary: var(--anil-600);
    --color-primary-hover: var(--anil-700);
    --color-accent: var(--cochonilha-600);
    --color-success: var(--verde-600);
    --color-warning: #b86e00;
    --color-danger: #c62828;
    --focus-ring: 0 0 0 3px rgba(74, 79, 240, 0.35);

    /* Gradiente de marca */
    --gradient-brand: linear-gradient(120deg, var(--anil-600) 0%, var(--cochonilha-500) 50%, var(--acafrao-500) 100%);

    /* Tipografia (fontes do sistema: sem pedidos a terceiros) */
    --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --font-mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Menlo, Consolas, monospace;
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.375rem;
    --text-2xl: 1.75rem;
    --text-3xl: clamp(1.9rem, 1.4rem + 2vw, 2.6rem);
    --text-display: clamp(2.4rem, 1.4rem + 4.4vw, 4.6rem);

    /* Espaçamento e forma */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --space-8: 4.5rem;
    --space-9: 7rem;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-pill: 999px;
    --shadow-sm: 0 1px 2px rgba(11, 16, 38, 0.06);
    --shadow: 0 4px 16px rgba(11, 16, 38, 0.08), 0 1px 3px rgba(11, 16, 38, 0.06);
    --shadow-lg: 0 24px 60px -12px rgba(18, 18, 92, 0.25), 0 8px 20px -8px rgba(11, 16, 38, 0.12);
    --container: 1180px;
    --gutter: clamp(1rem, 4vw, 2rem);
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
h1, h2, h3, h4 { line-height: 1.15; margin: 0 0 var(--space-4); letter-spacing: -0.02em; }
p { margin: 0 0 var(--space-4); }
a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-hover); }
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: var(--font-mono); font-size: 0.9em; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

.muted { color: var(--color-text-muted); }
.visually-hidden {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: -9999px; top: 0; }
.skip-link:focus { left: var(--space-4); top: var(--space-4); z-index: 100; background: var(--white); padding: var(--space-2) var(--space-4); }

/* ---------- logótipo (texto) ---------- */
.logo {
    display: inline-flex; align-items: center; gap: 0.5rem;
    font-weight: 800; font-size: 1.35rem; letter-spacing: -0.04em; color: var(--ink-900);
}
.logo::before {
    content: ""; width: 1.25rem; height: 1.25rem; border-radius: 6px;
    background: var(--gradient-brand);
    box-shadow: inset 0 -4px 0 rgba(255, 255, 255, 0.35);
}
.logo:hover { color: var(--ink-900); }
.logo-light, .logo-light:hover { color: var(--white); }

/* ---------- botões ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    padding: 0.6rem 1.1rem; border-radius: var(--radius-pill); border: 1px solid transparent;
    font-weight: 600; font-size: var(--text-sm); line-height: 1.2; cursor: pointer;
    transition: background-color .15s ease, color .15s ease, box-shadow .15s ease, transform .15s ease;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--color-primary); color: var(--white); }
.btn-primary:hover { background: var(--color-primary-hover); color: var(--white); }
.btn-dark { background: var(--ink-900); color: var(--white); }
.btn-dark:hover { background: var(--ink-700); color: var(--white); }
.btn-secondary { background: var(--white); color: var(--ink-900); border-color: var(--color-border); }
.btn-secondary:hover { border-color: var(--ink-300); color: var(--ink-900); }
.btn-ghost { background: transparent; color: var(--color-primary); }
.btn-ghost:hover { background: var(--anil-50); }
.btn-danger { background: var(--color-danger); color: var(--white); }
.btn-lg { padding: 0.8rem 1.4rem; font-size: var(--text-base); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: var(--text-xs); }
.btn-ghost-danger { background: transparent; color: var(--color-danger); }
.btn-ghost-danger:hover { background: #fdeceb; color: var(--color-danger); }
.small { font-size: var(--text-sm); }
.block { display: block; }
.nowrap { white-space: nowrap; }

/* barras de progresso (<progress>: sem estilos inline, compatível com a CSP) */
progress.meter {
    -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 6px;
    border: 0; border-radius: var(--radius-pill); background: var(--ink-100); overflow: hidden;
}
progress.meter::-webkit-progress-bar { background: var(--ink-100); border-radius: var(--radius-pill); }
progress.meter::-webkit-progress-value { background: var(--gradient-brand); border-radius: var(--radius-pill); }
progress.meter::-moz-progress-bar { background: var(--gradient-brand); border-radius: var(--radius-pill); }

/* códigos de recuperação (onboarding e definições) */
.recovery-codes {
    list-style: none; margin: 0 0 var(--space-4); padding: var(--space-4); display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-2) var(--space-4);
    background: var(--ink-50); border: 1px dashed var(--ink-300); border-radius: var(--radius-lg);
}
.recovery-codes code { font-size: var(--text-base); letter-spacing: 0.06em; }
.recovery-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-5); }
.recovery-actions[hidden] { display: none; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 5.5rem; }
.password-toggle {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    border: 0; background: transparent; color: var(--anil-600); font-weight: 600; font-size: var(--text-sm);
    padding: 0.35rem 0.6rem; border-radius: var(--radius-sm); cursor: pointer;
}
.password-toggle:hover { background: var(--anil-50); }
@media (max-width: 400px) { .recovery-codes { grid-template-columns: 1fr; } }
.btn-block { width: 100%; }
.btn[disabled], .btn.is-disabled { opacity: .55; cursor: not-allowed; }
.btn .arrow { transition: transform .15s ease; }
.btn:hover .arrow { transform: translateX(3px); }

/* ---------- layout ---------- */
.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 var(--gutter); }
.narrow { max-width: 820px; }
.center { text-align: center; }

/* ---------- ícones ---------- */
.icon { width: 1.25rem; height: 1.25rem; flex-shrink: 0; display: inline-block; vertical-align: middle; }
.icon-xs { width: 0.85rem; height: 0.85rem; }
.icon-sm { width: 1rem; height: 1rem; }
.icon-lg { width: 1.6rem; height: 1.6rem; }

/* ---------- pills ---------- */
.pill {
    display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.15rem 0.6rem;
    border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 600; line-height: 1.6;
    background: var(--ink-100); color: var(--ink-700); white-space: nowrap; vertical-align: middle;
}
.pill-success { background: var(--verde-100); color: var(--verde-600); }
.pill-warning { background: var(--acafrao-100); color: #8a5a00; }
.pill-danger { background: #fde8e8; color: var(--color-danger); }
.pill-info { background: var(--anil-100); color: var(--anil-700); }
.pill-muted { background: var(--ink-100); color: var(--ink-600); }

/* ---------- alertas ---------- */
.alert {
    display: flex; gap: var(--space-3); align-items: flex-start;
    padding: var(--space-3) var(--space-4); border-radius: var(--radius); margin: var(--space-4) 0;
    border: 1px solid; font-size: var(--text-sm);
}
.alert p { margin: 0; }
.alert-success { background: var(--verde-100); border-color: #a8e3c8; color: #0b5e41; }
.alert-error { background: #fdeceb; border-color: #f5c2bf; color: #9b1c1c; }
.alert-warning { background: var(--acafrao-100); border-color: #f3d98a; color: #6e4700; }
.alert-info { background: var(--anil-50); border-color: var(--anil-100); color: var(--anil-900); }

/* ---------- formulários ---------- */
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: var(--space-4); }
.field label { font-size: var(--text-sm); font-weight: 600; color: var(--ink-800); }
.field-optional { font-weight: 400; color: var(--ink-500); }
.field input, .field select, .field textarea {
    width: 100%; padding: 0.65rem 0.8rem; border: 1px solid var(--ink-300); border-radius: var(--radius);
    background: var(--white); font-size: var(--text-base); line-height: 1.4;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.field textarea { resize: vertical; min-height: 7rem; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--anil-500); box-shadow: var(--focus-ring); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--color-danger); }
.field-error { margin: 0; color: var(--color-danger); font-size: var(--text-sm); }
.field-hint { margin: 0; color: var(--ink-500); font-size: var(--text-sm); }
.form-row { display: grid; gap: 0 var(--space-4); }
.form-note { font-size: var(--text-sm); color: var(--ink-600); }
.checkbox { display: flex; gap: var(--space-3); align-items: flex-start; font-size: var(--text-sm); margin-bottom: var(--space-3); }
.checkbox input { width: 1.1rem; height: 1.1rem; margin-top: 0.2rem; accent-color: var(--color-primary); flex-shrink: 0; }
.hp-field { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
@media (min-width: 640px) {
    .form-row--2 { grid-template-columns: 1fr 1fr; }
}

/* ---------- páginas de erro ---------- */
.error-shell {
    min-height: 100vh; display: grid; place-items: center; padding: var(--space-6) var(--gutter);
    background: radial-gradient(1200px 500px at 10% -10%, var(--anil-50), transparent),
                radial-gradient(900px 400px at 110% 110%, var(--acafrao-100), transparent);
}
.error-card {
    width: 100%; max-width: 520px; text-align: center; background: var(--white);
    border: 1px solid var(--color-border); border-radius: var(--radius-lg);
    padding: var(--space-7) var(--space-6); box-shadow: var(--shadow);
}
.error-card .logo { margin-bottom: var(--space-5); }
.error-code {
    font-size: 3.5rem; font-weight: 800; margin: 0; line-height: 1;
    background: var(--gradient-brand); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.error-ref { font-size: var(--text-sm); color: var(--ink-500); }
