/* JARVIS V4 — estilos base */
:root { color-scheme: dark; }
* { scrollbar-width: thin; scrollbar-color: #2a3447 transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2a3447; border-radius: 4px; }

.card { background: #121826; border: 1px solid #1e2637; border-radius: 0.75rem; }
.btn { display: inline-flex; align-items: center; gap: .5rem; padding: .5rem 1rem; border-radius: .5rem; font-weight: 600; font-size: .875rem; transition: all .15s; cursor: pointer; border: 1px solid transparent; }
.btn-primary { background: #6366f1; color: white; }
.btn-primary:hover { background: #4f46e5; }
.btn-secondary { background: #1e2637; color: #e2e8f0; border-color: #2a3447; }
.btn-secondary:hover { background: #2a3447; }
.btn-danger { background: rgba(239,68,68,.15); color: #f87171; border-color: rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-sm { padding: .25rem .625rem; font-size: .75rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.input, .select, .textarea {
  width: 100%; background: #0b0e14; border: 1px solid #2a3447; border-radius: .5rem;
  padding: .5rem .75rem; color: #e2e8f0; font-size: .875rem; outline: none; transition: border-color .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: #6366f1; }
.label { display: block; font-size: .75rem; font-weight: 600; color: #94a3b8; margin-bottom: .375rem; text-transform: uppercase; letter-spacing: .03em; }

.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .125rem .5rem; border-radius: 9999px; font-size: .6875rem; font-weight: 600; }
.badge-green { background: rgba(34,197,94,.15); color: #4ade80; }
.badge-yellow { background: rgba(234,179,8,.15); color: #facc15; }
.badge-red { background: rgba(239,68,68,.15); color: #f87171; }
.badge-blue { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge-purple { background: rgba(139,92,246,.15); color: #a78bfa; }
.badge-gray { background: rgba(148,163,184,.15); color: #94a3b8; }

.nav-item { display: flex; align-items: center; gap: .75rem; padding: .5rem .75rem; border-radius: .5rem; font-size: .8125rem; font-weight: 500; color: #94a3b8; cursor: pointer; transition: all .12s; }
.nav-item:hover { background: #1a2234; color: #e2e8f0; }
.nav-item.active { background: rgba(99,102,241,.15); color: #a5b4fc; }
.nav-item i { width: 1.125rem; text-align: center; }

.table-j { width: 100%; font-size: .8125rem; }
.table-j th { text-align: left; padding: .5rem .75rem; color: #64748b; font-weight: 600; font-size: .6875rem; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid #1e2637; }
.table-j td { padding: .625rem .75rem; border-bottom: 1px solid #161d2d; }
.table-j tr:hover td { background: rgba(30,38,55,.4); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); backdrop-filter: blur(2px); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-box { background: #121826; border: 1px solid #2a3447; border-radius: 1rem; max-width: 42rem; width: 100%; max-height: 88vh; overflow-y: auto; }

.toast-wrap { position: fixed; bottom: 1.25rem; right: 1.25rem; z-index: 100; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: #1a2234; border: 1px solid #2a3447; border-radius: .625rem; padding: .75rem 1rem; font-size: .8125rem; min-width: 260px; max-width: 380px; box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: slideIn .2s ease; }
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.kpi { background: #121826; border: 1px solid #1e2637; border-radius: .75rem; padding: 1rem; }
.kpi .val { font-size: 1.5rem; font-weight: 800; }
.kpi .lbl { font-size: .6875rem; color: #64748b; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }

.spinner { width: 2rem; height: 2rem; border: 3px solid #6366f1; border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 3rem 1rem; color: #64748b; }
.empty-state i { font-size: 2.25rem; margin-bottom: .75rem; opacity: .5; }

.tab { padding: .5rem 1rem; font-size: .8125rem; font-weight: 600; color: #64748b; border-bottom: 2px solid transparent; cursor: pointer; }
.tab.active { color: #a5b4fc; border-bottom-color: #6366f1; }

pre.code { background: #0b0e14; border: 1px solid #1e2637; border-radius: .5rem; padding: .75rem; font-size: .75rem; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }

/* ============================================================
   JARVIS V4 — Capa de vanguardia: intro cinematográfico,
   accesibilidad, micro-interacciones y rendimiento
   ============================================================ */

/* ---- Tokens ---- */
:root {
  --j-bg: #0b0e14; --j-panel: #121826; --j-border: #1e2637; --j-border-hi: #2a3447;
  --j-accent: #6366f1; --j-accent2: #8b5cf6; --j-accent3: #22d3ee;
  --j-text: #e2e8f0; --j-muted: #94a3b8;
  --j-ease: cubic-bezier(.16,1,.3,1);
  --j-glow: 0 0 0 1px rgba(99,102,241,.35), 0 8px 32px -8px rgba(99,102,241,.45);
}

/* ---- Accesibilidad: foco visible siempre ---- */
:focus-visible {
  outline: 2px solid var(--j-accent3);
  outline-offset: 2px;
  border-radius: 4px;
}
.btn:focus-visible, .nav-item:focus-visible, .tab:focus-visible { outline-offset: 3px; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline-offset: 0; }

/* Salto al contenido para lectores de pantalla / teclado */
.skip-link {
  position: fixed; top: -100px; left: 1rem; z-index: 200;
  background: var(--j-accent); color: #fff; padding: .625rem 1rem;
  border-radius: .5rem; font-weight: 700; font-size: .8125rem;
  transition: top .2s var(--j-ease);
}
.skip-link:focus { top: 1rem; }

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

/* Área táctil mínima accesible en botones pequeños */
.btn-sm { min-height: 30px; }
.nav-item { min-height: 36px; }

/* ============================================================
   INTRO CINEMATOGRÁFICO
   ============================================================ */
#jarvis-intro {
  position: fixed; inset: 0; z-index: 9999;
  background: radial-gradient(ellipse 120% 90% at 50% 55%, #10162a 0%, #080b12 45%, #05070c 100%);
  display: grid; place-items: center; overflow: hidden;
  contain: strict;
}
#jarvis-intro[hidden] { display: none; }

/* Rejilla en perspectiva que se aleja */
.intro-grid {
  /* Suelo que se aleja: anclado abajo y girado sobre su borde inferior, de modo
     que ocupe el tercio inferior en lugar de comprimirse fuera del viewport. */
  /* La altura completa es intencionada: al girar 71° sobre el borde inferior,
     se proyecta comprimida en el tercio inferior con el horizonte arriba. */
  position: absolute; left: -60%; right: -60%; bottom: 0; height: 100%;
  background-image:
    linear-gradient(to right, rgba(129,140,248,.28) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(129,140,248,.28) 1px, transparent 1px);
  background-size: 56px 56px;
  transform: perspective(560px) rotateX(71deg) translateZ(0);
  transform-origin: 50% 100%;
  /* Se difumina hacia el horizonte en lugar de cortarse en seco. */
  -webkit-mask-image: linear-gradient(to top, #000 8%, rgba(0,0,0,.35) 48%, transparent 72%);
  mask-image: linear-gradient(to top, #000 8%, rgba(0,0,0,.35) 48%, transparent 72%);
  animation: gridDrift 3.4s linear infinite, gridFade 3.2s var(--j-ease) forwards;
  will-change: background-position, opacity;
}
@keyframes gridDrift { to { background-position: 0 56px, 0 56px; } }
@keyframes gridFade { 0%{opacity:0} 18%{opacity:1} 78%{opacity:.55} 100%{opacity:0} }

/* Halo de energía respirando */
.intro-halo {
  position: absolute; width: 46rem; height: 46rem; border-radius: 50%;
  background: radial-gradient(circle, rgba(99,102,241,.22) 0%, rgba(139,92,246,.12) 38%, transparent 66%);
  filter: blur(28px);
  animation: haloPulse 3.2s var(--j-ease) forwards;
  will-change: transform, opacity;
}
@keyframes haloPulse {
  0% { transform: scale(.35); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  74% { transform: scale(1.1); opacity: .85; }
  100% { transform: scale(2.6); opacity: 0; }
}

/* Escenario central */
.intro-stage { position: relative; text-align: center; z-index: 2; }

/* Reactor: anillos que se ensamblan */
.intro-core { position: relative; width: 8.5rem; height: 8.5rem; margin: 0 auto 2rem; }
.intro-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid transparent;
  animation: ringIn 1.15s var(--j-ease) backwards, ringSpin linear infinite;
  will-change: transform, opacity;
}
.intro-ring:nth-child(1) { border-top-color: var(--j-accent);  border-right-color: rgba(99,102,241,.28); animation-delay: .05s, .05s; animation-duration: 1.15s, 3.2s; }
.intro-ring:nth-child(2) { inset: .85rem; border-bottom-color: var(--j-accent2); border-left-color: rgba(139,92,246,.28); animation-delay: .2s, .2s; animation-duration: 1.15s, 2.4s; animation-direction: normal, reverse; }
.intro-ring:nth-child(3) { inset: 1.7rem; border-top-color: var(--j-accent3); border-left-color: rgba(34,211,238,.28); animation-delay: .35s, .35s; animation-duration: 1.15s, 1.8s; }
@keyframes ringIn {
  from { transform: scale(.2) rotate(-160deg); opacity: 0; filter: blur(6px); }
  to   { transform: scale(1) rotate(0); opacity: 1; filter: blur(0); }
}
@keyframes ringSpin { to { transform: rotate(360deg); } }

/* Núcleo del reactor */
.intro-atom {
  position: absolute; inset: 2.55rem; border-radius: 50%;
  background: linear-gradient(135deg, var(--j-accent), var(--j-accent2));
  display: grid; place-items: center;
  color: #fff; font-size: 1.5rem;
  box-shadow: 0 0 44px rgba(99,102,241,.75), inset 0 0 18px rgba(255,255,255,.22);
  animation: atomIgnite 1s var(--j-ease) .5s backwards, atomBeat 1.9s ease-in-out 1.5s infinite;
  will-change: transform, box-shadow;
}
@keyframes atomIgnite {
  0%   { transform: scale(0) rotate(-180deg); opacity: 0; }
  60%  { transform: scale(1.28) rotate(8deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes atomBeat {
  0%,100% { box-shadow: 0 0 44px rgba(99,102,241,.75), inset 0 0 18px rgba(255,255,255,.22); }
  50%     { box-shadow: 0 0 68px rgba(139,92,246,.95), inset 0 0 24px rgba(255,255,255,.32); }
}

/* Onda expansiva del arranque */
.intro-shock {
  position: absolute; inset: 2.55rem; border-radius: 50%;
  border: 2px solid rgba(99,102,241,.6);
  /* `both` es obligatorio: con solo `backwards` el anillo recupera su estado
     sin animar al terminar y se queda fijo sobre el reactor. */
  animation: shock 1.5s var(--j-ease) .85s both;
  will-change: transform, opacity;
}
.intro-shock:nth-of-type(2) { animation-delay: 1.15s; }
@keyframes shock {
  from { transform: scale(1); opacity: .85; }
  to   { transform: scale(4.2); opacity: 0; }
}

/* Wordmark: letras que caen en su sitio */
.intro-word {
  display: flex; justify-content: center; align-items: baseline;
  gap: .06em; margin-bottom: .75rem;
}
.intro-word span {
  display: inline-block;
  font-size: clamp(2.25rem, 8vw, 4rem); font-weight: 800; letter-spacing: -.02em;
  background: linear-gradient(180deg, #fff 0%, #c7d2fe 55%, #818cf8 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: letterDrop .78s var(--j-ease) backwards;
  will-change: transform, opacity;
}
@keyframes letterDrop {
  from { transform: translateY(-1.4em) rotateX(-90deg) scale(.7); opacity: 0; filter: blur(8px); }
  to   { transform: none; opacity: 1; filter: blur(0); }
}
/* El distintivo de versión: separado del wordmark y en menor jerarquía,
   para que no se lea "JARVISV4". */
.intro-v4 {
  margin-left: .42em;
  font-size: clamp(1.2rem, 4.2vw, 2rem) !important;
  font-weight: 700 !important;
  letter-spacing: .02em !important;
  align-self: center;
  background: linear-gradient(180deg, #a5b4fc 0%, var(--j-accent2) 100%) !important;
  -webkit-background-clip: text !important; background-clip: text !important;
}

/* Línea de escaneo que barre el wordmark */
.intro-scan {
  position: absolute; left: 50%; top: 50%; width: 26rem; max-width: 90vw; height: 2px;
  transform: translate(-50%,-50%);
  background: linear-gradient(90deg, transparent, var(--j-accent3), transparent);
  /* `both`: sin el estado final la línea cian se queda cruzando el wordmark. */
  animation: scanSweep 1.5s var(--j-ease) 1s both;
  will-change: transform, opacity;
}
@keyframes scanSweep {
  0%   { transform: translate(-50%,-50%) scaleX(0); opacity: 0; }
  35%  { transform: translate(-50%,-50%) scaleX(1); opacity: 1; }
  100% { transform: translate(-50%,-50%) scaleX(1) translateY(4rem); opacity: 0; }
}

/* Subtítulo y secuencia de arranque */
.intro-sub {
  font-size: clamp(.7rem,2.4vw,.8125rem); color: var(--j-muted);
  text-transform: uppercase; letter-spacing: .34em; font-weight: 600;
  animation: fadeUp .9s var(--j-ease) 1.15s backwards;
}
.intro-boot {
  margin-top: 1.85rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .6875rem; color: #64748b; min-height: 1.1rem; letter-spacing: .04em;
  animation: fadeUp .7s var(--j-ease) 1.5s backwards;
}
.intro-boot b { color: #4ade80; font-weight: 600; }
@keyframes fadeUp { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Barra de progreso del arranque */
.intro-bar {
  margin: 1.15rem auto 0; width: 15rem; max-width: 70vw; height: 2px;
  background: var(--j-border); border-radius: 2px; overflow: hidden;
  animation: fadeUp .7s var(--j-ease) 1.5s backwards;
}
.intro-bar i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--j-accent), var(--j-accent3));
  animation: barFill 1.75s var(--j-ease) 1.55s forwards;
}
@keyframes barFill { to { width: 100%; } }

/* Partículas ascendentes */
.intro-dust { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.intro-dust i {
  position: absolute; bottom: -8px; width: 2px; height: 2px; border-radius: 50%;
  background: var(--j-accent); opacity: 0;
  animation: dustRise linear infinite;
  will-change: transform, opacity;
}
@keyframes dustRise {
  0%   { transform: translateY(0) scale(1); opacity: 0; }
  12%  { opacity: .8; }
  100% { transform: translateY(-100vh) scale(.3); opacity: 0; }
}

/* Salida del intro */
#jarvis-intro.intro-exit {
  animation: introExit .85s var(--j-ease) forwards;
  pointer-events: none;
}
@keyframes introExit {
  to { opacity: 0; transform: scale(1.08); filter: blur(12px); }
}
.intro-skip {
  position: absolute; bottom: 1.5rem; right: 1.5rem;
  font-size: .6875rem; color: #475569; background: transparent;
  border: 1px solid var(--j-border-hi); border-radius: 9999px;
  padding: .375rem .875rem; cursor: pointer; transition: all .2s var(--j-ease);
  animation: fadeUp .6s var(--j-ease) 2s backwards;
}
.intro-skip:hover { color: var(--j-text); border-color: var(--j-accent); }

/* ============================================================
   ENTRADA DEL SHELL Y MICRO-INTERACCIONES
   ============================================================ */
.app-enter { animation: appEnter .7s var(--j-ease) both; }
@keyframes appEnter { from { opacity: 0; transform: translateY(12px) scale(.99); } to { opacity: 1; transform: none; } }

.page-enter { animation: pageEnter .38s var(--j-ease) both; }
@keyframes pageEnter { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Tarjetas con elevación y borde reactivo */
.card { transition: border-color .22s var(--j-ease), transform .22s var(--j-ease), box-shadow .22s var(--j-ease); }
.card:hover { border-color: var(--j-border-hi); }
article.card:hover { transform: translateY(-2px); box-shadow: 0 12px 32px -12px rgba(0,0,0,.6); }

.kpi { position: relative; overflow: hidden; transition: border-color .22s var(--j-ease), transform .22s var(--j-ease); }
.kpi::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 2px;
  background: linear-gradient(90deg, var(--j-accent), var(--j-accent2), var(--j-accent3));
  transform: scaleX(0); transform-origin: left; transition: transform .4s var(--j-ease);
}
.kpi:hover { transform: translateY(-2px); border-color: var(--j-border-hi); }
.kpi:hover::before { transform: scaleX(1); }

/* Botones con brillo de barrido */
.btn { position: relative; overflow: hidden; }
.btn-primary::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,.28) 50%, transparent 65%);
  transform: translateX(-120%); transition: transform .55s var(--j-ease);
}
.btn-primary:hover::after { transform: translateX(120%); }
.btn:active { transform: scale(.97); }
.btn-primary { box-shadow: 0 4px 14px -4px rgba(99,102,241,.6); }
.btn-primary:hover { box-shadow: 0 6px 20px -4px rgba(99,102,241,.8); }

/* Navegación con indicador deslizante */
.nav-item { position: relative; }
.nav-item::before {
  content: ''; position: absolute; left: 0; top: 50%; width: 3px; height: 0;
  background: linear-gradient(180deg, var(--j-accent), var(--j-accent3));
  border-radius: 0 3px 3px 0; transform: translateY(-50%);
  transition: height .28s var(--j-ease);
}
.nav-item.active::before { height: 65%; }
.nav-item i { transition: transform .22s var(--j-ease); }
.nav-item:hover i { transform: scale(1.15); }

/* Tabs con subrayado animado */
.tab { position: relative; border-bottom-color: transparent !important; transition: color .2s var(--j-ease); }
.tab::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -2px; height: 2px;
  background: var(--j-accent); transform: scaleX(0); transition: transform .28s var(--j-ease);
}
.tab.active::after { transform: scaleX(1); }
.tab:hover { color: var(--j-text); }

/* Filas de tabla e inputs */
.table-j tbody tr { transition: background .15s var(--j-ease); }
.input, .select, .textarea { transition: border-color .18s var(--j-ease), box-shadow .18s var(--j-ease); }
.input:focus, .select:focus, .textarea:focus { box-shadow: 0 0 0 3px rgba(99,102,241,.14); }

/* Badges */
.badge { transition: transform .15s var(--j-ease); }
.badge:hover { transform: translateY(-1px); }

/* Modales con entrada elástica */
.modal-overlay { animation: ovIn .22s var(--j-ease) both; backdrop-filter: blur(6px); }
@keyframes ovIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box { animation: boxIn .38s var(--j-ease) both; box-shadow: 0 24px 64px -16px rgba(0,0,0,.8); }
@keyframes boxIn { from { opacity: 0; transform: translateY(18px) scale(.96); } to { opacity: 1; transform: none; } }

/* Toasts con barra de vida */
.toast { position: relative; overflow: hidden; }
.toast::after {
  content: ''; position: absolute; left: 0; bottom: 0; height: 2px; width: 100%;
  background: rgba(99,102,241,.55); transform-origin: left;
  animation: toastLife 5s linear forwards;
}
@keyframes toastLife { to { transform: scaleX(0); } }

/* Empty states con icono flotante */
.empty-state i { animation: floaty 3.4s ease-in-out infinite; }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

/* Skeleton para carga percibida */
.skeleton {
  background: linear-gradient(90deg, #151c2b 25%, #1d2536 50%, #151c2b 75%);
  background-size: 200% 100%; border-radius: .5rem;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Barra de progreso de navegación (top loader) */
#nav-progress {
  position: fixed; top: 0; left: 0; height: 2px; z-index: 150; width: 0;
  background: linear-gradient(90deg, var(--j-accent), var(--j-accent3));
  box-shadow: 0 0 8px var(--j-accent);
  transition: width .3s var(--j-ease), opacity .3s var(--j-ease);
}

/* Truncado multilínea */
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---- Responsive: sidebar colapsable en móvil ---- */
@media (max-width: 1023px) {
  #sidebar {
    transform: translateX(-100%);
    transition: transform .3s var(--j-ease);
    box-shadow: 0 0 40px rgba(0,0,0,.6);
  }
  #sidebar.open { transform: none; }
  #app main { margin-left: 0 !important; }
  #sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 39; backdrop-filter: blur(2px); }
}
@media (min-width: 1024px) { #mobile-topbar, #sidebar-backdrop { display: none !important; } }

/* ---- Impresión ---- */
@media print {
  #sidebar, #mobile-topbar, .toast-wrap, .modal-overlay, #jarvis-intro, #nav-progress { display: none !important; }
  #app main { margin: 0 !important; }
  body { background: #fff !important; color: #000 !important; }
  .card { border-color: #ccc !important; background: #fff !important; }
}

/* ---- Respeto por preferencias del usuario ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
  .intro-grid, .intro-halo, .intro-dust { display: none !important; }
}
@media (prefers-contrast: more) {
  .card, .kpi { border-color: #4a5568 !important; }
  .text-jmuted, .label { color: #cbd5e1 !important; }
}
