/* SIQA Design System v3 · Identidad visual oficial (brand guide 2026).
 *
 * Marca: Azul SIQA #0D6EFD (innovación, confianza, tecnología) + Negro
 * Corporativo #1F2937 (profesionalismo, solidez). Tipografías: Poppins
 * (principal, títulos/marca) + Inter (secundaria, cuerpo/UI). Superficies
 * blancas, claras y nítidas. Logo isólogo (robot + wordmark "siqa").
 */

/* ---------------------------------------------------------------------------
 * Fuentes — self-host vía Bunny Fonts (privacy-friendly, GDPR/Ley 29733).
 * Cargadas con preconnect en base.html: Poppins + Inter.
 * --------------------------------------------------------------------------- */

/* ---------------------------------------------------------------------------
 * Tokens — Sistema de diseño
 * --------------------------------------------------------------------------- */

:root {
    /* Superficies — light mode (default). Blancas y nítidas (brand guide). */
    --surface-base: #FFFFFF;
    --surface-raised: #FFFFFF;
    --surface-sunken: #F4F7FB;
    --surface-overlay: rgba(31, 41, 55, 0.04);

    /* Texto — Negro Corporativo #1F2937 como tinta principal */
    --text-primary: #1F2937;
    --text-secondary: #4B5563;
    --text-tertiary: #9CA3AF;
    --text-on-brand: #FFFFFF;

    /* Marca SIQA — Azul SIQA #0D6EFD (RGB 13,110,253).
       Configurable desde el admin: --siqa-primary y sus tonos derivados se
       inyectan en base.html. Los hex son el respaldo si no hay configuración. */
    --brand-700: var(--siqa-primary-700, #0A4DB0);
    --brand-600: var(--siqa-primary-600, #0B5BD3);
    --brand-500: var(--siqa-primary, #0D6EFD);
    --brand-100: #D6E6FF;
    --brand-50:  #EBF3FF;

    /* Acento académico — verde calidad */
    --accent-700: #15803D;
    --accent-500: #16A34A;
    --accent-100: #DCFCE7;

    /* Semánticos */
    --success-500: #16A34A;
    --warning-500: #D97706;
    --danger-500:  #DC2626;
    --info-500:    #0284C7;

    /* Bordes */
    --border-subtle:  #EEF1F5;
    --border-default: #D9DEE6;
    --border-strong:  #1F2937;

    /* Sombras — sutiles, nunca dramáticas */
    --shadow-xs: 0 1px 2px rgba(31, 41, 55, 0.05);
    --shadow-sm: 0 1px 3px rgba(31, 41, 55, 0.08), 0 1px 2px rgba(31, 41, 55, 0.05);
    --shadow-md: 0 4px 12px -2px rgba(31, 41, 55, 0.10), 0 2px 4px -2px rgba(31, 41, 55, 0.06);
    --shadow-brand: 0 6px 20px -4px rgba(13, 110, 253, 0.30);

    /* Radio */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-pill: 9999px;

    /* Motion — spring suave, nunca >250ms para UI */
    --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 120ms;
    --duration-base: 180ms;
    --duration-slow: 240ms;

    /* Tipografía — Poppins (principal/títulos) + Inter (secundaria/cuerpo). */
    --font-display: "Poppins", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

/* Dark mode preparado (opt-in, sprint posterior). */
[data-theme="dark"] {
    --surface-base: #0B1220;
    --surface-raised: #111827;
    --surface-sunken: #0F172A;
    --text-primary: #F8FAFC;
    --text-secondary: #CBD5E1;
    --text-tertiary: #64748B;
    --border-subtle: #1F2937;
    --border-default: #334155;
}

/* ---------------------------------------------------------------------------
 * Reset suave + cuerpo
 * --------------------------------------------------------------------------- */

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-ui);
    color: var(--text-primary);
    background-color: var(--surface-base);
    font-feature-settings: "cv11", "ss01";
}

/* Display / headings — Poppins SemiBold, tracking ajustado. */
.font-display {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.02em;
}

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

/* ---------------------------------------------------------------------------
 * Alpine.js: ocultar elementos hasta que Alpine cargue
 * --------------------------------------------------------------------------- */

[x-cloak] { display: none !important; }

/* ---------------------------------------------------------------------------
 * Foco accesible — nunca quitar
 * --------------------------------------------------------------------------- */

:focus-visible {
    outline: 2px solid var(--brand-500);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------------------
 * Transiciones default — desactivables con prefers-reduced-motion
 * --------------------------------------------------------------------------- */

a, button {
    transition:
        color var(--duration-fast) var(--ease-out-quart),
        background-color var(--duration-fast) var(--ease-out-quart),
        border-color var(--duration-fast) var(--ease-out-quart),
        opacity var(--duration-fast) var(--ease-out-quart);
}

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

/* ---------------------------------------------------------------------------
 * Scrollbar discreta (no obligatoria pero suma)
 * --------------------------------------------------------------------------- */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: var(--radius-pill);
    border: 2px solid var(--surface-base);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ---------------------------------------------------------------------------
 * Utilidades — barras de progreso "audit" estilo Linear
 * --------------------------------------------------------------------------- */

.audit-bar {
    display: inline-flex;
    gap: 2px;
    align-items: center;
}

.audit-bar__seg {
    width: 10px;
    height: 6px;
    border-radius: 1px;
    background: var(--border-subtle);
}

.audit-bar__seg.is-filled { background: var(--text-primary); }
.audit-bar__seg.is-success { background: var(--accent-500); }
.audit-bar__seg.is-warning { background: var(--warning-500); }
.audit-bar__seg.is-danger  { background: var(--danger-500); }

/* ---------------------------------------------------------------------------
 * Dot semánticos (CBC, hallazgos)
 * --------------------------------------------------------------------------- */

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot--success { background: var(--accent-500); }
.dot--warning { background: var(--warning-500); }
.dot--danger  { background: var(--danger-500); }
.dot--muted   { background: var(--text-tertiary); }

/* ---------------------------------------------------------------------------
 * Chips e indicadores
 * --------------------------------------------------------------------------- */

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    font-size: 12px;
    font-weight: 500;
    line-height: 20px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-subtle);
    background: var(--surface-raised);
    color: var(--text-secondary);
    font-family: var(--font-ui);
}

.chip--success { color: var(--accent-700); border-color: var(--accent-100); background: var(--accent-100); }
.chip--warning { color: #92400E; border-color: #FDE68A; background: #FEF3C7; }
.chip--danger  { color: #991B1B; border-color: #FECACA; background: #FEE2E2; }
.chip--brand   { color: var(--brand-700); border-color: var(--brand-100); background: var(--brand-50); }
.chip--outline { background: transparent; }
.chip--mono    { font-family: var(--font-mono); }

/* ---------------------------------------------------------------------------
 * Sidebar — active state pill con barra izquierda
 * --------------------------------------------------------------------------- */

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 20px;
    font-weight: 500;
}

.nav-item:hover { background: var(--surface-sunken); color: var(--text-primary); }

.nav-item.is-active {
    background: var(--brand-50);
    color: var(--brand-700);
}

.nav-item.is-active::before {
    content: "";
    position: absolute;
    left: -8px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    border-radius: 2px;
    background: var(--brand-500);
}

/* ---------------------------------------------------------------------------
 * Botones primitivos (también disponibles como component partial)
 * --------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 16px;
    border-radius: var(--radius-md);
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
}

.btn--sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: var(--radius-sm); }
.btn--lg { height: 44px; padding: 0 20px; font-size: 15px; border-radius: var(--radius-md); }

.btn--primary {
    background: var(--brand-500);
    color: var(--text-on-brand);
}
.btn--primary:hover { background: var(--brand-600); }
.btn--primary:active { background: var(--brand-700); }

.btn--secondary {
    background: var(--surface-raised);
    color: var(--text-primary);
    border-color: var(--border-default);
}
.btn--secondary:hover { background: var(--surface-sunken); }

.btn--ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn--ghost:hover { background: var(--surface-overlay); color: var(--text-primary); }

.btn--danger {
    background: var(--danger-500);
    color: var(--text-on-brand);
}

.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------------------------------------------------------------------------
 * Inputs
 * --------------------------------------------------------------------------- */

.input {
    height: 44px;
    width: 100%;
    padding: 0 14px;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--border-default);
    background: var(--surface-raised);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 14px;
}

.input::placeholder { color: var(--text-tertiary); }
.input:focus { border-color: var(--brand-500); outline: none; box-shadow: 0 0 0 3px var(--brand-50); }
.input.is-error { border-color: var(--danger-500); }

textarea.input { height: auto; min-height: 88px; padding: 10px 14px; line-height: 22px; resize: vertical; }

/* ---------------------------------------------------------------------------
 * Tarjetas
 * --------------------------------------------------------------------------- */

.card {
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.card--compact { padding: 16px; }
.card--flat { background: var(--surface-sunken); border: none; }

/* ---------------------------------------------------------------------------
 * Dropzone (Analizador)
 * --------------------------------------------------------------------------- */

.dropzone {
    min-height: 320px;
    border: 1.5px dashed var(--border-default);
    border-radius: var(--radius-lg);
    background: var(--surface-raised);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    text-align: center;
    padding: 32px;
    transition: border-color var(--duration-fast), background-color var(--duration-fast);
}
.dropzone:hover, .dropzone.is-dragover {
    border-color: var(--brand-500);
    background: var(--brand-50);
}

/* ---------------------------------------------------------------------------
 * Tabla densa (Dashboard, listas Linear-style)
 * --------------------------------------------------------------------------- */

.table-dense {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table-dense th,
.table-dense td {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.table-dense th {
    font-weight: 500;
    color: var(--text-tertiary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.table-dense tbody tr { height: 44px; }
.table-dense tbody tr:hover { background: var(--surface-sunken); }

/* ---------------------------------------------------------------------------
 * Línea horizontal divisora suave
 * --------------------------------------------------------------------------- */

.hr-soft { border: 0; border-top: 1px solid var(--border-subtle); }

/* ---------------------------------------------------------------------------
 * Selector segmentado (tabs activos = pill suave)
 * --------------------------------------------------------------------------- */

.segmented {
    display: inline-flex;
    padding: 4px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--surface-sunken);
}
.segmented__item {
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: transparent;
    border: none;
    font-family: var(--font-ui);
}
.segmented__item.is-active {
    background: var(--surface-raised);
    color: var(--text-primary);
    box-shadow: var(--shadow-xs);
}

/* ---------------------------------------------------------------------------
 * Tabs minimalistas (Vercel)
 * --------------------------------------------------------------------------- */

.tabs {
    display: flex;
    gap: 24px;
    border-bottom: 1px solid var(--border-subtle);
}
.tabs__item {
    position: relative;
    padding: 10px 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
}
.tabs__item.is-active {
    color: var(--text-primary);
}
.tabs__item.is-active::after {
    content: "";
    position: absolute;
    left: 0; right: 0;
    bottom: -1px;
    height: 2px;
    background: var(--text-primary);
}

/* ---------------------------------------------------------------------------
 * Skip link accesible
 * --------------------------------------------------------------------------- */

.skip-link {
    position: absolute;
    top: -100px;
    left: 16px;
    padding: 8px 12px;
    background: var(--text-primary);
    color: var(--text-on-brand);
    border-radius: var(--radius-sm);
    z-index: 100;
}
.skip-link:focus { top: 16px; }

/* ---------------------------------------------------------------------------
 * Modales (créditos / upgrade / email / registro requerido) + Toast
 * Usados por los parciales HTMX de apps.creditos. Antes las clases no existían
 * y los modales se renderizaban como bloques sin estilo.
 * --------------------------------------------------------------------------- */

.siqa-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.siqa-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(31, 41, 55, 0.55);
}
.siqa-modal__panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 440px;
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle, #E5E7EB);
    border-radius: var(--radius-lg, 16px);
    padding: 24px;
    box-shadow: 0 20px 45px rgba(31, 41, 55, 0.25);
}
.siqa-modal__titulo {
    font-family: var(--font-display, var(--font-ui));
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.siqa-modal__texto {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: 20px;
}
.siqa-modal__acciones {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.siqa-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 18px;
    border-radius: var(--radius-md);
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
}
.siqa-btn--primary { background: var(--brand-500); color: var(--text-on-brand); }
.siqa-btn--primary:hover { background: var(--brand-600); }
.siqa-btn--ghost { background: transparent; color: var(--text-secondary); border-color: var(--border-subtle, #E5E7EB); }
.siqa-btn--ghost:hover { background: var(--surface-overlay); color: var(--text-primary); }

.siqa-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(24px);
    z-index: 300;
    max-width: 90vw;
    padding: 12px 18px;
    background: var(--text-primary);
    color: var(--text-on-brand);
    border-radius: var(--radius-md);
    font-size: 14px;
    box-shadow: 0 10px 30px rgba(31, 41, 55, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.siqa-toast.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------------------------------------------------------------------------
 * Errores de formulario (registro / login / formularios en general)
 * Mensaje de campo con ícono + caja de errores a nivel de formulario.
 * --------------------------------------------------------------------------- */

.form-error {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-top: 6px;
    color: var(--danger-500);
    font-size: 13px;
    line-height: 1.4;
}
.form-error__icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    margin-top: 1px;
}
.form-error ul { margin: 0; padding: 0; list-style: none; }

/* Caja para errores a nivel de formulario (non_field_errors), ej. "ya existe
 * una cuenta con este correo" o credenciales incorrectas. */
.form-alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 20px;
    padding: 12px 14px;
    border: 1px solid #FECACA;
    background: #FEF2F2;
    border-radius: var(--radius-md);
    color: #991B1B;
    font-size: 14px;
    line-height: 1.5;
}
.form-alert__icon { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; color: var(--danger-500); }
.form-alert ul { margin: 0; padding: 0; list-style: none; }

:root[data-theme="dark"] .form-alert {
    background: rgba(220, 38, 38, 0.12);
    border-color: rgba(220, 38, 38, 0.4);
    color: #FCA5A5;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .form-alert {
        background: rgba(220, 38, 38, 0.12);
        border-color: rgba(220, 38, 38, 0.4);
        color: #FCA5A5;
    }
}
