/* ==========================================================================
   Admin Sence Otec — Design System
   --------------------------------------------------------------------------
   Estilo      : Minimalismo / Swiss  (ui-ux-pro-max → minimalism-and-swiss-style)
   Tipografía  : IBM Plex Sans + IBM Plex Mono  (ui-ux-pro-max → "Financial Trust")
   Paleta      : KeysCITI — navy #0E2841 · navy deep #122A50 · blue #0E3A6B
                 accent amarillo #FFC900
   Reglas      : contraste AA (4.5:1), objetivos táctiles ≥44px, foco visible,
                 animaciones solo en transform/opacity <300ms, respeto de
                 prefers-reduced-motion, sin emojis como iconos.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
    color-scheme: light;

    /* Marca KeysCITI (constantes de marca, iguales en ambos temas) */
    --kc-navy: #0e2841;
    --kc-navy-deep: #122a50;
    --kc-blue: #0e3a6b;
    --kc-yellow: #ffc900;

    /* Superficies */
    --bg: #f5f7fa;
    --bg-subtle: #eef2f7;
    --surface: #ffffff;
    --surface-2: #fafbfd;
    --surface-3: #eef2f7;

    /* Bordes */
    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    /* Texto */
    --text: #0e2841;
    --text-muted: #475569;
    --text-faint: #64748b;
    --text-invert: #ffffff;

    /* Acciones */
    --brand: #0e3a6b;
    --brand-hover: #0b2e55;
    --brand-active: #092445;
    --on-brand: #ffffff;

    --accent: #ffc900;
    --accent-ink: #0e2841;

    /* Estados */
    --focus: #0e3a6b;
    --danger: #b42318;
    --danger-bg: #fef3f2;
    --danger-border: #fecdca;
    --success: #067647;
    --success-bg: #ecfdf3;
    --success-border: #abefc6;

    /* Elevación consistente (escala de 3 niveles) */
    --shadow-1: 0 1px 2px rgba(14, 40, 65, 0.06);
    --shadow-2: 0 4px 12px -4px rgba(14, 40, 65, 0.1), 0 1px 3px rgba(14, 40, 65, 0.05);
    --shadow-3: 0 18px 44px -20px rgba(14, 40, 65, 0.28), 0 2px 8px rgba(14, 40, 65, 0.06);

    /* Radios */
    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 999px;

    /* Espaciado (escala de 4px) */
    --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: 4rem;

    /* Movimiento */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --dur-fast: 120ms;
    --dur-base: 180ms;

    /* Acento de marca en la barra reglada de las tarjetas */
    --rule-a: #0e3a6b;

    /* Layout */
    --shell-max: 72rem;
    --topbar-h: 64px;

    /* Capas */
    --z-bg: 0;
    --z-content: 10;
    --z-topbar: 40;
    --z-skip: 100;
}

[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0a1322;
    --bg-subtle: #0d1a2d;
    --surface: #111e33;
    --surface-2: #0e1a2c;
    --surface-3: #16233a;

    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.18);

    --text: #e8eef7;
    --text-muted: #9fb0c6;
    --text-faint: #7c8da6;
    --text-invert: #0e2841;

    /* En oscuro el CTA usa el amarillo de marca (alto contraste) */
    --brand: #ffc900;
    --brand-hover: #ffd533;
    --brand-active: #f2be00;
    --on-brand: #0e2841;

    --accent: #ffc900;
    --accent-ink: #0e2841;

    --focus: #ffc900;
    --danger: #ff8a80;
    --danger-bg: rgba(255, 138, 128, 0.1);
    --danger-border: rgba(255, 138, 128, 0.32);
    --success: #5bd6a0;
    --success-bg: rgba(91, 214, 160, 0.1);
    --success-border: rgba(91, 214, 160, 0.32);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 4px 14px -6px rgba(0, 0, 0, 0.5);
    --shadow-3: 0 24px 56px -24px rgba(0, 0, 0, 0.7);

    /* Azul de marca aclarado para que la barra siga siendo visible sobre fondo oscuro */
    --rule-a: #5b93d8;
}

/* --------------------------------------------------------------------------
   2. Base / reset
   -------------------------------------------------------------------------- */

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

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

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 1rem;
    line-height: 1.6;
    font-weight: 400;
    color: var(--text);
    background-color: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
    margin: 0;
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.02em;
    text-wrap: balance;
}

p {
    margin: 0;
}

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

ul {
    list-style: none;
}

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

a {
    color: inherit;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

button {
    font: inherit;
    color: inherit;
}

/* Foco visible y consistente en todos los elementos interactivos */
:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
}

/* --------------------------------------------------------------------------
   3. Utilidades
   -------------------------------------------------------------------------- */

.skip-link {
    position: absolute;
    top: var(--space-3);
    left: var(--space-3);
    z-index: var(--z-skip);
    padding: var(--space-3) var(--space-4);
    background: var(--brand);
    color: var(--on-brand);
    border-radius: var(--radius-sm);
    font-weight: 600;
    text-decoration: none;
    transform: translateY(-200%);
    transition: transform var(--dur-base) var(--ease-out);
}

.skip-link:focus-visible {
    transform: translateY(0);
}

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

.mono {
    font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.eyebrow {
    margin: 0 0 var(--space-2);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.section-title {
    margin: 0 0 var(--space-4);
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.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;
}

/* --------------------------------------------------------------------------
   4. Marca
   -------------------------------------------------------------------------- */

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    text-decoration: none;
    color: inherit;
    border-radius: var(--radius-sm);
}

.brand__mark {
    display: grid;
    place-items: center;
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    background: var(--kc-navy);
    color: var(--kc-yellow);
    box-shadow: var(--shadow-1);
}

[data-theme="dark"] .brand__mark {
    background: var(--surface-3);
    color: var(--kc-yellow);
    border: 1px solid var(--border);
}

.brand__text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.brand__name {
    font-size: 0.9375rem;
    font-weight: 700;
    letter-spacing: -0.015em;
}

.brand__product {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
    letter-spacing: 0.01em;
}

/* --------------------------------------------------------------------------
   5. Botones
   -------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    min-height: 44px;
    padding: 0.6875rem var(--space-5);
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    white-space: nowrap;
    transition:
        background-color var(--dur-base) var(--ease-out),
        border-color var(--dur-base) var(--ease-out),
        color var(--dur-base) var(--ease-out),
        transform var(--dur-fast) var(--ease-out),
        box-shadow var(--dur-base) var(--ease-out);
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Primario */
.btn--primary {
    background: var(--brand);
    color: var(--on-brand);
    font-weight: 600;
    box-shadow: var(--shadow-1);
}

.btn--primary:hover {
    background: var(--brand-hover);
    box-shadow: var(--shadow-2);
}

/* Secundario */
.btn--ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--border-strong);
    font-weight: 500;
}

.btn--ghost:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}

/* Google — respeta la guía de marca pero se integra al design system */
.btn--google {
    width: 100%;
    min-height: 48px;
    padding: 0.75rem var(--space-5);
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border-strong);
    font-weight: 500;
    box-shadow: var(--shadow-1);
}

.btn--google:hover {
    background: var(--surface-3);
    box-shadow: var(--shadow-2);
}

.btn__logo {
    flex: none;
}

/* --------------------------------------------------------------------------
   6. Botón de icono (toggle de tema)
   -------------------------------------------------------------------------- */

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex: none;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    transition:
        background-color var(--dur-base) var(--ease-out),
        color var(--dur-base) var(--ease-out),
        border-color var(--dur-base) var(--ease-out);
}

.icon-btn:hover {
    background: var(--surface-3);
    color: var(--text);
    border-color: var(--border-strong);
}

/* Solo se muestra el icono del tema al que se cambiará */
[data-theme="light"] .icon--sun { display: none; }
[data-theme="dark"]  .icon--moon { display: none; }

/* --------------------------------------------------------------------------
   7. Tarjeta, alertas, badges
   -------------------------------------------------------------------------- */

.card {
    position: relative;
    width: 100%;
    max-width: 26rem;
    padding: clamp(1.5rem, 5vw, 2.25rem);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
}

.card--center {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
}

.card__rule {
    display: block;
    width: 48px;
    height: 4px;
    margin-bottom: var(--space-5);
    border-radius: var(--radius-full);
    background: linear-gradient(90deg, var(--rule-a) 0 62%, var(--kc-yellow) 62% 100%);
}

.card--center .card__rule {
    margin-bottom: var(--space-2);
    background: linear-gradient(90deg, var(--rule-a) 0 62%, var(--kc-yellow) 62% 100%);
}

.card__title {
    margin-bottom: var(--space-2);
    font-size: clamp(1.375rem, 4vw, 1.5rem);
    font-weight: 600;
    letter-spacing: -0.025em;
}

.card__sub {
    color: var(--text-muted);
    font-size: 0.9375rem;
    line-height: 1.6;
}

.card__note {
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
    font-size: 0.8125rem;
    line-height: 1.6;
    color: var(--text-faint);
}

.card .btn--google {
    margin-top: var(--space-5);
}

/* Alertas */
.alert-stack {
    display: grid;
    gap: var(--space-3);
    margin-top: var(--space-5);
}

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-3);
    color: var(--text);
    font-size: 0.875rem;
    line-height: 1.5;
}

.alert__icon {
    flex: none;
    margin-top: 0.15em;
}

.alert--error {
    background: var(--danger-bg);
    border-color: var(--danger-border);
    color: var(--danger);
}

.alert--success {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success);
}

/* Badges y pills */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0.1875rem var(--space-3);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge--admin {
    background: rgba(255, 201, 0, 0.16);
    color: var(--accent-ink);
    border-color: rgba(255, 201, 0, 0.5);
}

[data-theme="dark"] .badge--admin {
    color: var(--kc-yellow);
}

.badge--operator {
    background: rgba(14, 58, 107, 0.1);
    color: var(--brand);
    border-color: rgba(14, 58, 107, 0.24);
}

[data-theme="dark"] .badge--operator {
    background: rgba(255, 201, 0, 0.1);
    color: var(--kc-yellow);
    border-color: rgba(255, 201, 0, 0.28);
}

.badge--auditor {
    background: var(--surface-3);
    color: var(--text-muted);
    border-color: var(--border);
}

.pill {
    display: inline-flex;
    align-items: center;
    flex: none;
    padding: 0.1875rem var(--space-3);
    border-radius: var(--radius-full);
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* --------------------------------------------------------------------------
   8. Layout de autenticación
   -------------------------------------------------------------------------- */

.page-auth {
    position: relative;
    isolation: isolate;
    display: grid;
    grid-template-rows: auto 1fr auto;
    overflow-x: hidden;
}

/* Decoración de fondo: dos halos muy sutiles, sin color-mix (compatibilidad) */
.page-auth::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(56rem 36rem at 88% -12%, rgba(14, 58, 107, 0.14), transparent 62%),
        radial-gradient(46rem 34rem at -8% 108%, rgba(255, 201, 0, 0.12), transparent 60%);
}

[data-theme="dark"] .page-auth::before {
    background:
        radial-gradient(56rem 36rem at 88% -12%, rgba(14, 58, 107, 0.4), transparent 62%),
        radial-gradient(46rem 34rem at -8% 108%, rgba(255, 201, 0, 0.09), transparent 60%);
}

.auth {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 100vh;
    min-height: 100dvh;
    padding: clamp(1.25rem, 4vw, 2.5rem);
}

.auth__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
}

.auth__main {
    display: grid;
    place-items: center;
    padding: var(--space-7) 0;
}

.auth__foot,
.app-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
    font-size: 0.8125rem;
    color: var(--text-faint);
}

/* --------------------------------------------------------------------------
   9. Layout de la aplicación
   -------------------------------------------------------------------------- */

.page-app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
}

/* Fondo translúcido solo si el navegador soporta backdrop-filter (respaldo sólido) */
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .topbar {
        background: rgba(255, 255, 255, 0.86);
    }

    [data-theme="dark"] .topbar {
        background: rgba(17, 30, 51, 0.86);
    }
}

[data-theme="dark"] .topbar {
    background: #111e33;
}

.topbar__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    max-width: var(--shell-max);
    min-height: var(--topbar-h);
    margin: 0 auto;
    padding: var(--space-2) clamp(1rem, 4vw, 2rem);
}

.topbar__actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1);
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    font-weight: 500;
}

.user-chip__avatar {
    width: 28px;
    height: 28px;
    flex: none;
    border-radius: 50%;
    object-fit: cover;
}

.user-chip__avatar--initials {
    display: grid;
    place-items: center;
    background: var(--kc-navy);
    color: var(--kc-yellow);
    font-size: 0.75rem;
    font-weight: 700;
}

.user-chip__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 12rem;
}

/* Contenido principal */
.shell {
    flex: 1;
    width: 100%;
    max-width: var(--shell-max);
    margin: 0 auto;
    padding: clamp(1.5rem, 4vw, 2.5rem) clamp(1rem, 4vw, 2rem) var(--space-7);
}

.page-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-5);
    padding-bottom: var(--space-6);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-6);
}

.page-head__title {
    font-size: clamp(1.625rem, 5vw, 2.125rem);
    font-weight: 600;
    letter-spacing: -0.03em;
}

.page-head__sub {
    margin-top: var(--space-2);
    max-width: 46ch;
    color: var(--text-muted);
    font-size: 0.9375rem;
}

.meta-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-5) var(--space-7);
}

.meta-list__item {
    display: grid;
    gap: var(--space-1);
    min-width: 0;
}

.meta-list dt {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.meta-list dd {
    font-size: 0.9375rem;
    font-weight: 500;
    min-width: 0;
    overflow-wrap: anywhere;
}

/* --------------------------------------------------------------------------
   10. Módulos
   -------------------------------------------------------------------------- */

.grid-modules {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
    gap: var(--space-4);
}

.module {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    transition: border-color var(--dur-base) var(--ease-out);
}

/* Tarjeta informativa: no es interactiva. Al convertirla en módulo real,
   envuélvela en <a> y devuelve cursor:pointer + elevación en hover. */

.module__icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: rgba(14, 58, 107, 0.08);
    color: var(--kc-blue);
    border: 1px solid rgba(14, 58, 107, 0.16);
}

[data-theme="dark"] .module__icon {
    background: rgba(255, 201, 0, 0.1);
    color: var(--kc-yellow);
    border-color: rgba(255, 201, 0, 0.24);
}

.module__body {
    display: grid;
    gap: var(--space-2);
    flex: 1;
}

.module__title {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.module__desc {
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   11. Pie de aplicación
   -------------------------------------------------------------------------- */

.app-foot {
    max-width: var(--shell-max);
    width: 100%;
    margin: 0 auto;
    padding: var(--space-4) clamp(1rem, 4vw, 2rem);
}

/* --------------------------------------------------------------------------
   12. Responsive
   -------------------------------------------------------------------------- */

@media (min-width: 48rem) {
    .page-head {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: end;
    }

    .meta-list {
        justify-content: flex-end;
        text-align: right;
    }

    .meta-list__item {
        justify-items: end;
    }
}

@media (max-width: 40rem) {
    .user-chip__name {
        display: none;
    }

    .topbar__inner {
        gap: var(--space-2);
    }

    .brand__product {
        display: none;
    }

    .auth__foot,
    .app-foot {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-1);
    }
}

@media (max-width: 30rem) {
    .topbar__inner,
    .topbar__actions {
        gap: var(--space-2);
    }

    .topbar__actions .btn--ghost {
        padding-inline: var(--space-3);
        font-size: 0.875rem;
    }

    /* El nombre de marca puede recortarse sin romper la barra */
    .brand__text {
        overflow: hidden;
    }

    .brand__name {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }
}

/* --------------------------------------------------------------------------
   13. Accesibilidad de movimiento
   -------------------------------------------------------------------------- */

@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;
        scroll-behavior: auto !important;
    }
}

/* --------------------------------------------------------------------------
   14. Impresión
   -------------------------------------------------------------------------- */

@media print {
    .topbar,
    .auth__bar,
    .icon-btn,
    .btn,
    .app-foot,
    .auth__foot {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
    }
}
