/**
 * PrimaCode - Rapport-style Fluid Motion & Micro-interactions
 * Inspired by Code & Chill Rapport design system.
 * Zero-framework, GPU-accelerated CSS transitions & spring easing.
 */

:root {
  --motion-ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --motion-ease-snappy: cubic-bezier(0.2, 0.8, 0.2, 1);
  --motion-ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --motion-ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --motion-duration-fast: 0.18s;
  --motion-duration-base: 0.28s;
  --motion-duration-slow: 0.42s;
}

/* ==========================================================================
   1. INK PILL (Traveling Active Indicator for Tabs & Toggles)
   ========================================================================== */

.dash-acum-toggle,
.dash-period-master-toggle,
.dash-leaps-filter-toggle,
.ror-chart-tabs,
.ops-segmented-tabs,
.risk-tabs,
.panel-tabs,
.subpanel-tabs,
.macro-nav-tabs,
.mc-nav-tabs,
.maintenance-tabs,
.segmented-tabs,
.usuarios-filter-tabs {
  position: relative !important;
  isolation: isolate !important;
}

/* La pastilla móvil que viaja entre pestañas */
.motion-ink-pill {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  pointer-events: none;
  border-radius: 6px;
  background: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent-strong, #4f7cff) 45%, transparent);
  box-shadow: 0 4px 14px rgba(59, 91, 219, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transition:
    transform var(--motion-duration-base) var(--motion-ease-snappy),
    width var(--motion-duration-base) var(--motion-ease-snappy),
    height var(--motion-duration-base) var(--motion-ease-snappy),
    opacity var(--motion-duration-fast) ease;
  will-change: transform, width, height;
}

/* Adaptación para Light Mode */
body.light .motion-ink-pill,
html.light .motion-ink-pill {
  background: var(--accent);
  border: 1px solid var(--accent-strong, #172554);
  box-shadow: 0 3px 10px rgba(30, 58, 138, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* En contenedores con ink-pill activa, los botones ceden su fondo estático para que se vea el pill viajando */
.has-ink-pill > button,
.has-ink-pill > a,
.has-ink-pill > .dash-scope-btn,
.has-ink-pill > .ops-tab-btn,
.has-ink-pill > .risk-tab-btn,
.has-ink-pill > .panel-tab,
.has-ink-pill > .subpanel-tab,
.has-ink-pill > .macro-nav-tab,
.has-ink-pill > .mc-nav-tab {
  position: relative;
  z-index: 2;
  transition: color var(--motion-duration-fast) ease, opacity var(--motion-duration-fast) ease;
}

.has-ink-pill > button.active,
.has-ink-pill > a.active,
.has-ink-pill > .dash-scope-btn.active,
.has-ink-pill > .ops-tab-btn.active,
.has-ink-pill > .risk-tab-btn.active,
.has-ink-pill > .panel-tab.active,
.has-ink-pill > .subpanel-tab.active,
.has-ink-pill > .macro-nav-tab.active,
.has-ink-pill > .mc-nav-tab.active {
  background: transparent !important;
  color: #ffffff !important;
  box-shadow: none !important;
  border-color: transparent !important;
}

/* En Panel de control: mostrar la pastilla azul sólida y texto blanco al pasar el cursor */
.panel-tabs > .panel-tab:hover,
.subpanel-tabs > .subpanel-tab:hover {
  background: transparent !important;
  color: #ffffff !important;
}

/* ==========================================================================
   3. STAGGERED ENTRANCE ANIMATIONS (Cascada fluida de entrada)
   ========================================================================== */

@keyframes motionStaggerIn {
  0% {
    opacity: 0;
    transform: translateY(14px) scale(0.985);
  }
  60% {
    opacity: 0.92;
    transform: translateY(-1px) scale(1.002);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.motion-stagger-active {
  animation: motionStaggerIn 0.42s var(--motion-ease-spring) both !important;
}

/* ==========================================================================
   4. TACTILE CLICK FEEDBACK (Micro-háptica visual)
   ========================================================================== */

button:not(:disabled):active,
.btn:active,
.period-filter-pill:active,
.dash-scope-btn:active,
.ops-tab-btn:active,
.risk-tab-btn:active,
.sidebar-link:active,
.dash-info-btn:active {
  transform: scale(0.975);
  transition: transform 0.08s ease;
}

/* Micro-rebote en switches y toggles */
.privacy-toggle-btn:active {
  transform: scale(0.95);
  transition: transform 0.1s ease;
}

/* ==========================================================================
   5. LUMEN SWITCH (Standalone Interactive Luminous Switches)
   Inspired by Code & Chill Lumen Toggle.
   ========================================================================== */

/* Standalone Switch Lumen (para checkbox switches regulares) */
.lumen-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.lumen-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.lumen-switch-track {
  width: 44px;
  height: 24px;
  border-radius: 9999px;
  background: var(--surface2);
  border: 1px solid var(--border-strong);
  position: relative;
  padding: 2px;
  transition: background 0.25s ease, border-color 0.25s ease;
}

.lumen-switch-knob {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), background 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.lumen-toggle input:checked ~ .lumen-switch-track {
  background: var(--accent);
  border-color: var(--accent-strong, #4f7cff);
}

.lumen-toggle input:checked ~ .lumen-switch-track .lumen-switch-knob {
  transform: translateX(20px);
  background: #ffffff;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.7), 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* ==========================================================================
   6. HOP LOADER (12-bead elastic ring spinner inspired by Code & Chill Hop)
   ========================================================================== */

.hop-loader {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  position: relative;
  vertical-align: middle;
}

.hop-loader.hop-loader-sm {
  width: 18px;
  height: 18px;
}

.hop-loader.hop-loader-lg {
  width: 48px;
  height: 48px;
}

.hop-svg {
  width: 100%;
  height: 100%;
  transform-origin: center center;
  animation: hopSpin 4.5s linear infinite;
}

.hop-bead {
  fill: var(--accent-strong, #4f7cff);
  transform-box: fill-box;
  transform-origin: center center;
  animation: hopBeadPulse 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
  animation-delay: calc(var(--i) * 0.1s);
  will-change: transform, opacity;
}

body.light .hop-bead {
  fill: var(--accent, #1e3a8a);
}

@keyframes hopSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes hopBeadPulse {
  0%, 100% {
    transform: scale(0.85);
    opacity: 0.28;
  }
  25% {
    transform: scale(1.48);
    opacity: 1;
    filter: drop-shadow(0 0 5px color-mix(in srgb, var(--accent) 80%, transparent));
  }
  50% {
    transform: scale(1);
    opacity: 0.6;
  }
}

/* Badge flotante de actualización del Dashboard con Hop Loader */
.dash-hop-badge {
  position: absolute;
  top: 10px;
  right: 14px;
  z-index: 12;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 8px;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-strong);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.32);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted-strong);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.22s ease, transform 0.22s var(--motion-ease-spring);
}

.dashboard-loading .dash-hop-badge {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   7. CIRCULAR REVEAL THEME TRANSITION (Efecto Onda de Expansión)
   ========================================================================== */

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

::view-transition-old(root) {
  z-index: 1;
}

::view-transition-new(root) {
  z-index: 9999;
}

/* ==========================================================================
   8. ACCESIBILIDAD Y MOTION REDUCIDO
   ========================================================================== */

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

  .motion-ink-pill {
    display: none !important;
  }
}
