/* ==========================================================================
   Mexicana — Polish layer
   Capa de CSS encima de MudBlazor para micro-interacciones, animaciones,
   espaciado y profundidad. No reemplaza componentes; los enriquece.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Variables custom para reutilizar en componentes
   -------------------------------------------------------------------------- */
:root {
    --mex-easing: cubic-bezier(0.4, 0, 0.2, 1);
    --mex-duration-fast: 150ms;
    --mex-duration-base: 250ms;
    --mex-duration-slow: 400ms;
    --mex-shadow-hover: 0 8px 24px -8px rgba(46, 125, 50, 0.25), 0 4px 12px -4px rgba(0, 0, 0, 0.08);
    --mex-shadow-card: 0 2px 8px -2px rgba(0, 0, 0, 0.06), 0 4px 16px -4px rgba(0, 0, 0, 0.04);
    --mex-glow-primary: 0 0 0 4px rgba(46, 125, 50, 0.12);
}

.mud-theme-dark, [data-mud-theme="dark"] {
    --mex-shadow-hover: 0 8px 24px -8px rgba(102, 187, 106, 0.35), 0 4px 12px -4px rgba(0, 0, 0, 0.6);
    --mex-shadow-card: 0 2px 8px -2px rgba(0, 0, 0, 0.4), 0 4px 16px -4px rgba(0, 0, 0, 0.3);
    --mex-glow-primary: 0 0 0 4px rgba(102, 187, 106, 0.2);
}

/* --------------------------------------------------------------------------
   2. Scroll suave y mejores barras
   -------------------------------------------------------------------------- */
html { scroll-behavior: smooth; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: content-box;
    transition: background var(--mex-duration-base) var(--mex-easing);
}
::-webkit-scrollbar-thumb:hover { background: rgba(46, 125, 50, 0.5); background-clip: content-box; }

.mud-theme-dark ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); background-clip: content-box; }

/* --------------------------------------------------------------------------
   3. Cards con hover lift suave
   -------------------------------------------------------------------------- */
.mud-paper {
    transition:
        transform var(--mex-duration-base) var(--mex-easing),
        box-shadow var(--mex-duration-base) var(--mex-easing),
        border-color var(--mex-duration-base) var(--mex-easing) !important;
}

.mud-paper.mud-elevation-2:hover,
.mud-paper.mud-elevation-3:hover,
.mud-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--mex-shadow-hover) !important;
}

/* No aplicar lift al banner del Dashboard (Elevation=0) ni al menú */
.mud-drawer .mud-paper { box-shadow: none !important; transform: none !important; }
.mud-appbar.mud-paper:hover { transform: none !important; }

/* --------------------------------------------------------------------------
   4. Botones: scale al click, sombra primaria
   -------------------------------------------------------------------------- */
.mud-button-root {
    transition:
        transform var(--mex-duration-fast) var(--mex-easing),
        box-shadow var(--mex-duration-fast) var(--mex-easing),
        background-color var(--mex-duration-fast) var(--mex-easing) !important;
    will-change: transform;
}

.mud-button-root:hover { transform: translateY(-1px); }
.mud-button-root:active { transform: translateY(0) scale(0.98); transition-duration: 50ms !important; }

.mud-button-filled.mud-button-filled-primary {
    box-shadow: 0 2px 4px -1px rgba(46, 125, 50, 0.3), 0 1px 2px rgba(0, 0, 0, 0.1) !important;
}
.mud-button-filled.mud-button-filled-primary:hover {
    box-shadow: 0 6px 14px -4px rgba(46, 125, 50, 0.5), 0 2px 4px rgba(0, 0, 0, 0.15) !important;
}

/* --------------------------------------------------------------------------
   5. Inputs y selects: focus ring suave
   -------------------------------------------------------------------------- */
.mud-input-outlined-border, .mud-input-control-input-container {
    transition: border-color var(--mex-duration-base) var(--mex-easing) !important;
}

.mud-input-outlined:focus-within .mud-input-outlined-border {
    box-shadow: var(--mex-glow-primary);
}

/* --------------------------------------------------------------------------
   6. Tablas con hover suave y zebra muy sutil
   -------------------------------------------------------------------------- */
.mud-table-row {
    transition: background-color var(--mex-duration-fast) var(--mex-easing);
}
.mud-table-root .mud-table-body tr.mud-table-row:hover {
    background-color: rgba(46, 125, 50, 0.06) !important;
}

/* --------------------------------------------------------------------------
   7. Chips: animación pulse para "Crítica" / "VENCIDO" / "Bajo stock"
   -------------------------------------------------------------------------- */
@keyframes mex-pulse-error {
    0%, 100% { box-shadow: 0 0 0 0 rgba(211, 47, 47, 0.6); }
    50%      { box-shadow: 0 0 0 6px rgba(211, 47, 47, 0); }
}
@keyframes mex-pulse-warn {
    0%, 100% { box-shadow: 0 0 0 0 rgba(249, 168, 37, 0.6); }
    50%      { box-shadow: 0 0 0 6px rgba(249, 168, 37, 0); }
}

.mex-chip-pulse-error { animation: mex-pulse-error 2.2s var(--mex-easing) infinite; }
.mex-chip-pulse-warn  { animation: mex-pulse-warn 2.2s var(--mex-easing) infinite; }

/* --------------------------------------------------------------------------
   8. Drawer y menú: items con transición suave
   -------------------------------------------------------------------------- */
.mud-nav-link, .mud-nav-group .mud-nav-link {
    transition:
        background-color var(--mex-duration-fast) var(--mex-easing),
        color var(--mex-duration-fast) var(--mex-easing),
        padding var(--mex-duration-fast) var(--mex-easing) !important;
}
.mud-nav-link:hover {
    background-color: rgba(46, 125, 50, 0.08) !important;
    padding-left: calc(var(--mud-default-borderradius, 8px) + 4px);
}
.mud-nav-link.active {
    background: linear-gradient(90deg, rgba(46, 125, 50, 0.12), rgba(46, 125, 50, 0.04)) !important;
    border-left: 3px solid #2E7D32 !important;
    color: #2E7D32 !important;
    font-weight: 600 !important;
}

/* --------------------------------------------------------------------------
   9. Dialogs: backdrop con blur (vendrá en Etapa F)
   -------------------------------------------------------------------------- */
.mud-overlay-dialog {
    backdrop-filter: blur(4px) saturate(120%);
    -webkit-backdrop-filter: blur(4px) saturate(120%);
    background-color: rgba(0, 0, 0, 0.35) !important;
}

.mud-dialog {
    box-shadow:
        0 24px 48px -12px rgba(0, 0, 0, 0.25),
        0 8px 24px -6px rgba(0, 0, 0, 0.15) !important;
}

/* --------------------------------------------------------------------------
   10. Page enter animation
   -------------------------------------------------------------------------- */
@keyframes mex-fade-up {
    0%   { opacity: 0; transform: translateY(8px); }
    100% { opacity: 1; transform: translateY(0); }
}

.mud-main-content > .mud-container > * {
    animation: mex-fade-up var(--mex-duration-slow) var(--mex-easing) both;
}

/* --------------------------------------------------------------------------
   11. KpiCard premium: lift + glow al hover
   -------------------------------------------------------------------------- */
.mex-kpi-card {
    cursor: default;
    overflow: hidden;
    position: relative;
}
.mex-kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, transparent 0%, rgba(255,255,255,0.04) 50%, transparent 100%);
    transform: translateX(-100%);
    transition: transform var(--mex-duration-slow) var(--mex-easing);
    pointer-events: none;
}
.mex-kpi-card:hover::before { transform: translateX(100%); }

/* --------------------------------------------------------------------------
   12. Skeleton shimmer
   -------------------------------------------------------------------------- */
@keyframes mex-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.mex-skeleton {
    background: linear-gradient(
        90deg,
        rgba(0,0,0,0.06) 25%,
        rgba(0,0,0,0.12) 50%,
        rgba(0,0,0,0.06) 75%
    );
    background-size: 200% 100%;
    animation: mex-shimmer 1.4s linear infinite;
    border-radius: 6px;
}

.mud-theme-dark .mex-skeleton {
    background: linear-gradient(
        90deg,
        rgba(255,255,255,0.04) 25%,
        rgba(255,255,255,0.10) 50%,
        rgba(255,255,255,0.04) 75%
    );
    background-size: 200% 100%;
}

/* --------------------------------------------------------------------------
   13. Login con glassmorphism
   -------------------------------------------------------------------------- */
.mex-login-card {
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    background-color: rgba(255, 255, 255, 0.92) !important;
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow:
        0 20px 60px -12px rgba(0, 0, 0, 0.4),
        0 8px 24px -6px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.mud-theme-dark .mex-login-card {
    background-color: rgba(30, 30, 30, 0.85) !important;
    border-color: rgba(255, 255, 255, 0.1);
}

/* --------------------------------------------------------------------------
   14. Stepper visual de OT
   -------------------------------------------------------------------------- */
.mex-stepper {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 12px 0;
}
.mex-stepper-step {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}
.mex-stepper-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--mud-palette-background-grey, #E0E0E0);
    color: rgba(0, 0, 0, 0.4);
    font-weight: 700;
    font-size: 0.95rem;
    transition: all var(--mex-duration-base) var(--mex-easing);
    border: 2px solid transparent;
    z-index: 1;
}
.mex-stepper-step.done .mex-stepper-circle {
    background: #2E7D32;
    color: #fff;
}
.mex-stepper-step.active .mex-stepper-circle {
    background: #fff;
    border-color: #2E7D32;
    color: #2E7D32;
    box-shadow: 0 0 0 4px rgba(46, 125, 50, 0.18);
    animation: mex-pulse-active 2s var(--mex-easing) infinite;
}
.mex-stepper-step.cancelled .mex-stepper-circle {
    background: #D32F2F;
    color: #fff;
}
.mex-stepper-step + .mex-stepper-step::before {
    content: '';
    position: absolute;
    top: 18px;
    left: -50%;
    right: 50%;
    height: 3px;
    background: var(--mud-palette-background-grey, #E0E0E0);
    z-index: 0;
}
.mex-stepper-step.done + .mex-stepper-step::before,
.mex-stepper-step + .mex-stepper-step.done::before,
.mex-stepper-step + .mex-stepper-step.active::before {
    background: linear-gradient(90deg, #2E7D32, #66BB6A);
}
.mex-stepper-label {
    margin-top: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--mud-palette-text-secondary, #616161);
    text-align: center;
    line-height: 1.2;
}
.mex-stepper-step.active .mex-stepper-label,
.mex-stepper-step.done .mex-stepper-label {
    color: var(--mud-palette-text-primary, #212121);
}

@keyframes mex-pulse-active {
    0%, 100% { box-shadow: 0 0 0 4px rgba(46, 125, 50, 0.18); }
    50%      { box-shadow: 0 0 0 8px rgba(46, 125, 50, 0.08); }
}

/* --------------------------------------------------------------------------
   15. Hero del Dashboard con patrón sutil de fondo
   -------------------------------------------------------------------------- */
.mex-hero {
    position: relative;
    overflow: hidden;
}
.mex-hero::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 80% 20%, rgba(255,255,255,0.06) 0%, transparent 50%),
        radial-gradient(circle at 20% 80%, rgba(255,255,255,0.04) 0%, transparent 50%);
    pointer-events: none;
}
.mex-hero > * { position: relative; z-index: 1; }

/* --------------------------------------------------------------------------
   16. Tabla con header sticky cuando hay mucho scroll vertical
   -------------------------------------------------------------------------- */
.mex-sticky-header .mud-table-head { position: sticky; top: 0; z-index: 2; }

/* --------------------------------------------------------------------------
   17. Footer del MainLayout, más sutil
   -------------------------------------------------------------------------- */
.mud-main-content .mud-paper.mud-elevation-0:last-child:hover {
    transform: none;
    box-shadow: none !important;
}

/* --------------------------------------------------------------------------
   18a. Tipografía y rhythm refinados
   -------------------------------------------------------------------------- */

/* Inter en todo el sistema con feature settings premium */
html, body {
    font-family: 'Inter', 'Helvetica Neue', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    font-feature-settings: 'cv01', 'cv03', 'cv11', 'ss01';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Headings con tracking ligeramente apretado para look más editorial */
.mud-typography-h1, .mud-typography-h2, .mud-typography-h3 {
    letter-spacing: -0.02em;
    font-weight: 800 !important;
}
.mud-typography-h4, .mud-typography-h5 {
    letter-spacing: -0.015em;
    font-weight: 700 !important;
}
.mud-typography-h6 {
    letter-spacing: -0.01em;
    font-weight: 700 !important;
}

/* Overline con más presencia: distinguido del cuerpo */
.mud-typography-overline {
    font-weight: 700 !important;
    letter-spacing: 0.12em !important;
    font-size: 0.72rem !important;
    opacity: 0.85;
}

/* Caption con peso 500 para mejor legibilidad */
.mud-typography-caption {
    font-weight: 500;
    letter-spacing: 0.01em;
}

/* Body con line-height más generoso */
.mud-typography-body1, .mud-typography-body2 {
    line-height: 1.6;
}

/* Page titles: mayor respiración inferior */
.mud-main-content > .mud-container > * + * { margin-top: 8px; }

/* Spacing rhythm: cards con bordes redondeados consistentes */
.mud-paper:not(.mud-appbar):not(.mud-drawer) {
    border-radius: 12px !important;
}
.mud-card { border-radius: 16px !important; }

/* --------------------------------------------------------------------------
   18. Reduce motion: respeta prefers-reduced-motion
   -------------------------------------------------------------------------- */
@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;
    }
}
