/**
 * 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-btn,
.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-btn.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;
}

/* ==========================================================================
   2. BENTO CARDS & SPOTLIGHT HOVER EFFECT (Aplicado a TODAS las cards)
   ========================================================================== */

.card,
.panel-card,
.metric-card,
.period-hero,
.period-side,
.period-stat,
.dash-acum-card,
.dash-rolls-card,
.dash-acum-stat,
.chart-card,
.table-card,
.ror-hero-card,
.ror-stat-card,
.gestion-account-card,
.gestion-own-summary,
.caja-card,
.caja-summary-card,
.asset-reserve-card,
.ml-index-card,
.ml-item-card,
.ml-eco-event-card,
.ml-yield-tile,
.gex-card,
.gex-level-card,
.darkpool-panel,
.heatmap-panel,
.flow-hist-stat-card,
.whale-kpi-card,
.chart-kpi-card,
.chart-viewport-card,
.chart-positions-card,
.chart-gex-macro-card,
.chart-market-kpi-card,
.risk-card,
.risk-stat,
.risk-main-card,
.risk-import-card,
.risk-lab-dashboard-card,
.terminal-kpi-card,
.terminal-chart-card,
.terminal-table-card,
.terminal-filters-card,
.terminal-flow-history-card,
.ops-card,
.ops-form-card,
.ops-table-card,
.ops-history-card,
.ops-recon-card,
.ops-recon-success-card,
.ops-mini-stat,
.config-card,
.config-subcard,
.account-card,
.billing-card,
.billing-kpi-card,
.system-status-card,
.saas-alerts-card,
.saas-detail-card,
.mc-cuenta-id-card,
.summary-card,
.bento-card {
  position: relative;
  transition:
    transform var(--motion-duration-base) var(--motion-ease-spring),
    box-shadow var(--motion-duration-base) var(--motion-ease-spring),
    border-color var(--motion-duration-fast) ease;
  will-change: transform, box-shadow;
}

/* Hover suave con elevación premium y resplandor perimetral fino */
.card:hover,
.panel-card:hover,
.metric-card:hover,
.period-hero:hover,
.period-side:hover,
.period-stat:hover,
.dash-acum-card:hover,
.dash-rolls-card:hover,
.dash-acum-stat:hover,
.chart-card:hover,
.table-card:hover,
.ror-hero-card:hover,
.ror-stat-card:hover,
.gestion-account-card:hover,
.gestion-own-summary:hover,
.caja-card:hover,
.caja-summary-card:hover,
.asset-reserve-card:hover,
.ml-index-card:hover,
.ml-item-card:hover,
.ml-eco-event-card:hover,
.ml-yield-tile:hover,
.gex-card:hover,
.gex-level-card:hover,
.flow-hist-stat-card:hover,
.whale-kpi-card:hover,
.chart-kpi-card:hover,
.chart-viewport-card:hover,
.chart-positions-card:hover,
.chart-gex-macro-card:hover,
.chart-market-kpi-card:hover,
.risk-card:hover,
.risk-stat:hover,
.risk-main-card:hover,
.risk-import-card:hover,
.risk-lab-dashboard-card:hover,
.terminal-kpi-card:hover,
.terminal-chart-card:hover,
.terminal-table-card:hover,
.terminal-filters-card:hover,
.terminal-flow-history-card:hover,
.ops-card:hover,
.ops-form-card:hover,
.ops-table-card:hover,
.ops-history-card:hover,
.ops-recon-card:hover,
.ops-recon-success-card:hover,
.ops-mini-stat:hover,
.config-card:hover,
.config-subcard:hover,
.account-card:hover,
.billing-card:hover,
.billing-kpi-card:hover,
.system-status-card:hover,
.saas-alerts-card:hover,
.saas-detail-card:hover,
.mc-cuenta-id-card:hover,
.summary-card:hover,
.bento-card:hover {
  transform: translateY(-2.5px);
  border-color: color-mix(in srgb, var(--accent) 38%, var(--border-strong));
  box-shadow: 0 14px 30px -8px rgba(0, 0, 0, 0.44), 0 0 0 1px color-mix(in srgb, var(--accent) 26%, transparent);
}

body.light .card:hover,
body.light .panel-card:hover,
body.light .metric-card:hover,
body.light .period-hero:hover,
body.light .period-side:hover,
body.light .period-stat:hover,
body.light .dash-acum-card:hover,
body.light .dash-rolls-card:hover,
body.light .dash-acum-stat:hover,
body.light .chart-card:hover,
body.light .table-card:hover,
body.light .ror-hero-card:hover,
body.light .ror-stat-card:hover,
body.light .gestion-account-card:hover,
body.light .gestion-own-summary:hover,
body.light .caja-card:hover,
body.light .caja-summary-card:hover,
body.light .asset-reserve-card:hover,
body.light .ml-index-card:hover,
body.light .ml-item-card:hover,
body.light .ml-eco-event-card:hover,
body.light .ml-yield-tile:hover,
body.light .gex-card:hover,
body.light .gex-level-card:hover,
body.light .flow-hist-stat-card:hover,
body.light .whale-kpi-card:hover,
body.light .chart-kpi-card:hover,
body.light .chart-viewport-card:hover,
body.light .chart-positions-card:hover,
body.light .chart-gex-macro-card:hover,
body.light .chart-market-kpi-card:hover,
body.light .risk-card:hover,
body.light .risk-stat:hover,
body.light .risk-main-card:hover,
body.light .risk-import-card:hover,
body.light .risk-lab-dashboard-card:hover,
body.light .terminal-kpi-card:hover,
body.light .terminal-chart-card:hover,
body.light .terminal-table-card:hover,
body.light .terminal-filters-card:hover,
body.light .terminal-flow-history-card:hover,
body.light .ops-card:hover,
body.light .ops-form-card:hover,
body.light .ops-table-card:hover,
body.light .ops-history-card:hover,
body.light .ops-recon-card:hover,
body.light .ops-recon-success-card:hover,
body.light .ops-mini-stat:hover,
body.light .config-card:hover,
body.light .config-subcard:hover,
body.light .account-card:hover,
body.light .billing-card:hover,
body.light .billing-kpi-card:hover,
body.light .system-status-card:hover,
body.light .saas-alerts-card:hover,
body.light .saas-detail-card:hover,
body.light .mc-cuenta-id-card:hover,
body.light .summary-card:hover,
body.light .bento-card:hover {
  box-shadow: 0 12px 26px -6px rgba(15, 23, 42, 0.12), 0 0 0 1px color-mix(in srgb, var(--accent) 30%, var(--border));
}

/* Spotlight radial que sigue al cursor en tarjetas con interacción */
.motion-spotlight {
  overflow: hidden;
}

.motion-spotlight::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  background: radial-gradient(380px circle at var(--mouse-x, -999px) var(--mouse-y, -999px), color-mix(in srgb, var(--accent) 15%, transparent), transparent 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 1;
}

.motion-spotlight:hover::before {
  opacity: 1;
}

/* ==========================================================================
   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;
  }
}
