/* ============================================================
   Base · reset, tipografía y utilidades
   ============================================================ */

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

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.55;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body.app-page {
    background:
        radial-gradient(1000px 620px at 100% -10%, var(--color-primary-soft), transparent 60%),
        radial-gradient(820px 520px at -10% 105%, var(--color-accent-soft), transparent 55%),
        var(--color-bg);
    background-attachment: fixed;
}

body.auth-page {
    background: var(--color-bg);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    margin: 0;
    line-height: 1.15;
    letter-spacing: -0.02em;
    font-weight: 700;
}

h1 {
    font-size: var(--text-2xl);
    font-weight: 800;
}

h2 {
    font-size: var(--text-xl);
    font-weight: 700;
}

h3 {
    font-size: var(--text-lg);
    font-weight: 700;
}

p {
    margin: 0;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    text-decoration: underline;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

img,
svg {
    max-width: 100%;
}

ul,
ol {
    margin: 0;
    padding: 0;
}

::selection {
    background: var(--color-primary);
    color: var(--color-on-primary);
}

:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 3px;
    border-radius: 4px;
}

[hidden] {
    display: none !important;
}

.icon {
    display: inline-block;
    width: 1.25em;
    height: 1.25em;
    vertical-align: -0.18em;
    flex: 0 0 auto;
}

.icon-xs {
    width: 0.95em;
    height: 0.95em;
}

.icon-lg {
    width: 1.6em;
    height: 1.6em;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: fixed;
    top: -120px;
    left: 1rem;
    z-index: 200;
    padding: 0.65rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--color-primary);
    color: var(--color-on-primary);
    font-weight: 600;
    transition: top var(--transition);
}

.skip-link:focus {
    top: 1rem;
    text-decoration: none;
}

.eyebrow {
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-primary);
}

.eyebrow-on-brand {
    color: rgba(255, 255, 255, 0.66);
}

.text-muted {
    color: var(--color-muted);
}

.text-right {
    text-align: right;
}

.text-center {
    text-align: center;
}

.text-danger {
    color: var(--color-danger);
}

.text-success {
    color: var(--color-success);
}

.mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* Scrollbars discretos */
* {
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--color-muted) 35%, transparent) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--color-muted) 35%, transparent);
    border: 2px solid transparent;
    border-radius: var(--radius-full);
    background-clip: padding-box;
}

/* Toasts */
.toast-stack {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: min(360px, calc(100vw - 2rem));
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.8rem 1rem;
    border-radius: 10px;
    background: var(--color-text);
    color: var(--color-bg);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-sm);
    animation: toast-in 200ms ease-out;
}

.toast .icon {
    color: var(--color-accent);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Página de error */
.error-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(700px 500px at 50% -10%, var(--color-primary-soft), transparent 65%),
        var(--color-bg);
}

.error-card {
    width: 100%;
    max-width: 500px;
    padding: 2.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.error-mark {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: var(--color-danger-soft);
    color: var(--color-danger);
}

.error-mark .icon {
    width: 30px;
    height: 30px;
}

.error-card h1 {
    margin: 0.35rem 0 0.6rem;
    font-size: 1.6rem;
}

.error-message {
    color: var(--color-muted);
    font-size: var(--text-sm);
}

.error-meta {
    margin-top: 1rem;
    font-size: var(--text-xs);
    color: var(--color-muted);
}

.error-meta code {
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
    background: var(--color-surface-2);
    font-family: var(--font-mono);
}

.error-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.error-brand {
    margin-top: 1.5rem;
    font-size: var(--text-xs);
    color: var(--color-muted);
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
