/* ============================================================================
   FacilBot — Design System (theme.css)
   Sistema de tokens, modo oscuro, glassmorphism, skeletons, toasts y micro-
   interacciones. Compartido por el dashboard (index.html) y la landing
   (landing.html). Stack sin build: Tailwind CDN + Alpine.js + anime.js.
   ========================================================================== */

/* ----------------------------------------------------------------------------
   1. Tokens base (modo claro)
   Reutiliza las variables --brand-* ya definidas inline en cada HTML.
---------------------------------------------------------------------------- */
:root {
  /* Superficies y texto (modo claro) */
  --surface:        #ffffff;
  --surface-2:      #f9fafb; /* gray-50  */
  --surface-3:      #f3f4f6; /* gray-100 */
  --surface-muted:  #f3f4f6;
  --border-soft:    #e5e7eb; /* gray-200 */
  --border-strong:  #d1d5db; /* gray-300 */
  --text-strong:    #111827; /* gray-900 */
  --text:           #1f2937; /* gray-800 */
  --text-muted:     #6b7280; /* gray-500 */
  --text-faint:     #9ca3af; /* gray-400 */
  --app-bg:         #f4f6fb;

  /* Marca / acentos */
  --brand-accent:   #f59e0b;
  --brand-gradient: linear-gradient(135deg, var(--brand-500) 0%, var(--brand-700) 100%);
  --brand-gradient-soft: linear-gradient(135deg, var(--brand-50) 0%, #ffffff 60%);
  --sidebar-gradient: linear-gradient(180deg, var(--brand-900) 0%, #16263f 100%);

  /* Elevación (sombras multicapa suaves) */
  --shadow-sm:  0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md:  0 2px 6px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.07);
  --shadow-lg:  0 8px 32px rgba(15, 23, 42, 0.10), 0 2px 8px rgba(15, 23, 42, 0.05);
  --shadow-brand: 0 8px 28px rgba(37, 99, 235, 0.28);

  /* Glassmorphism */
  --glass-bg:     rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.55);
  --glass-blur:   blur(14px) saturate(140%);

  /* Skeleton shimmer */
  --skeleton-base:  #e9edf3;
  --skeleton-shine: #f4f7fb;

  /* Easings y radios */
  --ease-out-soft: cubic-bezier(0.22, 1, 0.36, 1);
  --radius-card: 16px;
}

/* ----------------------------------------------------------------------------
   2. Modo oscuro — overrides de tokens
---------------------------------------------------------------------------- */
html.dark {
  --surface:        #1e293b; /* slate-800 */
  --surface-2:      #0f172a; /* slate-900 */
  --surface-3:      #334155; /* slate-700 */
  --surface-muted:  #273449;
  --border-soft:    #334155;
  --border-strong:  #475569;
  --text-strong:    #f1f5f9;
  --text:           #e2e8f0;
  --text-muted:     #94a3b8;
  --text-faint:     #64748b;
  --app-bg:         #0b1220;

  --brand-gradient-soft: linear-gradient(135deg, #1e293b 0%, #16233b 60%);
  --sidebar-gradient: linear-gradient(180deg, #0f1c33 0%, #0a1424 100%);

  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md:  0 2px 8px rgba(0, 0, 0, 0.45);
  --shadow-lg:  0 12px 40px rgba(0, 0, 0, 0.55);

  --glass-bg:     rgba(20, 30, 48, 0.66);
  --glass-border: rgba(148, 163, 184, 0.18);

  --skeleton-base:  #243044;
  --skeleton-shine: #30405a;

  color-scheme: dark;
}

/* ----------------------------------------------------------------------------
   3. Retrofit de utilidades Tailwind para modo oscuro
   Evita reescribir cientos de elementos: remapea las clases utilitarias más
   usadas a los tokens de superficie cuando html.dark está activo.
---------------------------------------------------------------------------- */
html.dark body,
html.dark .bg-gray-50  { background-color: var(--app-bg) !important; }
html.dark .bg-white    { background-color: var(--surface) !important; }
html.dark .bg-gray-100 { background-color: var(--surface-3) !important; }
html.dark .bg-gray-200 { background-color: var(--surface-muted) !important; }

html.dark .text-gray-900,
html.dark .text-gray-800 { color: var(--text-strong) !important; }
html.dark .text-gray-700,
html.dark .text-gray-600 { color: var(--text) !important; }
html.dark .text-gray-500 { color: var(--text-muted) !important; }
html.dark .text-gray-400 { color: var(--text-faint) !important; }

html.dark .border,
html.dark .border-gray-200,
html.dark .border-gray-100 { border-color: var(--border-soft) !important; }
html.dark .border-gray-300 { border-color: var(--border-strong) !important; }
html.dark .border-b,
html.dark .border-t,
html.dark .border-r,
html.dark .border-l { border-color: var(--border-soft) !important; }
html.dark .divide-y > * { border-color: var(--border-soft) !important; }

/* Inputs y selects en dark */
html.dark input,
html.dark select,
html.dark textarea {
  background-color: var(--surface-2) !important;
  border-color: var(--border-strong) !important;
  color: var(--text) !important;
}
html.dark input::placeholder,
html.dark textarea::placeholder { color: var(--text-faint) !important; }

/* Hovers genéricos de filas/botones claros */
html.dark .hover\:bg-gray-50:hover  { background-color: var(--surface-muted) !important; }
html.dark .hover\:bg-gray-100:hover { background-color: var(--surface-3) !important; }
html.dark .hover\:bg-gray-200:hover { background-color: var(--surface-3) !important; }

/* Burbujas de chat en dark (las claras se ven mal sobre fondo oscuro) */
html.dark .chat-bubble-client { background: #1f3d2e !important; color: #d9f3e1; }
html.dark .chat-bubble-bot    { background: var(--surface-3) !important; color: var(--text); }
html.dark .chat-bubble-agent  { background: #25304f !important; color: #dbe3ff; }

/* ----------------------------------------------------------------------------
   4. Componentes y utilidades nuevas
---------------------------------------------------------------------------- */

/* App background con un toque de profundidad */
body.app-shell {
  background:
    radial-gradient(1200px 600px at 100% -10%, color-mix(in srgb, var(--brand-500) 8%, transparent), transparent 60%),
    var(--app-bg);
}

/* Glass surface (sidebar, topbar, cards destacadas) */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
}

/* Gradiente de marca */
.bg-brand-gradient { background: var(--brand-gradient); }
.text-brand-gradient {
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.sidebar-surface { background: var(--sidebar-gradient); }

/* Elevación de tarjetas + hover lift */
.card-elevated {
  box-shadow: var(--shadow-sm);
  transition: box-shadow .35s var(--ease-out-soft), transform .35s var(--ease-out-soft);
}
.card-hover:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

/* Botón con micro-interacción */
.btn-press { transition: transform .12s ease, box-shadow .2s ease, background-color .2s ease; }
.btn-press:active { transform: scale(.97); }
.btn-lift { transition: transform .2s var(--ease-out-soft), box-shadow .2s var(--ease-out-soft); }
.btn-lift:hover { transform: translateY(-1px); box-shadow: var(--shadow-brand); }

/* Realce del item activo del sidebar */
.nav-active {
  position: relative;
  background: rgba(255, 255, 255, 0.10);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.nav-active::before {
  content: "";
  position: absolute;
  left: 0; top: 18%; bottom: 18%;
  width: 3px; border-radius: 0 4px 4px 0;
  background: var(--brand-accent);
}

/* ----------------------------------------------------------------------------
   5. Skeleton loaders
---------------------------------------------------------------------------- */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--skeleton-base);
  border-radius: 8px;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--skeleton-shine), transparent);
  animation: skeleton-shimmer 1.4s infinite;
}
@keyframes skeleton-shimmer { 100% { transform: translateX(100%); } }

/* ----------------------------------------------------------------------------
   6. Toasts
---------------------------------------------------------------------------- */
.toast-stack {
  position: fixed;
  top: 1rem; right: 1rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  width: min(360px, calc(100vw - 2rem));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  padding: .8rem .95rem;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-soft);
  border-left: 4px solid var(--brand-500);
  font-size: .85rem;
}
.toast--success { border-left-color: #10b981; }
.toast--error   { border-left-color: #ef4444; }
.toast--warning { border-left-color: #f59e0b; }
.toast--info    { border-left-color: var(--brand-500); }
.toast__icon { flex-shrink: 0; width: 1.1rem; height: 1.1rem; margin-top: 1px; }
.toast--success .toast__icon { color: #10b981; }
.toast--error   .toast__icon { color: #ef4444; }
.toast--warning .toast__icon { color: #f59e0b; }
.toast--info    .toast__icon { color: var(--brand-500); }

/* ----------------------------------------------------------------------------
   7. Animaciones de entrada (usadas por ui-kit.js / Alpine x-transition)
---------------------------------------------------------------------------- */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.anim-fade-up { animation: fade-up .5s var(--ease-out-soft) both; }

/* Scroll reveal (landing) — estado inicial; ui-kit.js añade .is-visible */
.reveal { opacity: 0; transform: translateY(24px); transition: opacity .7s var(--ease-out-soft), transform .7s var(--ease-out-soft); }
.reveal.is-visible { opacity: 1; transform: translateY(0); }

/* ----------------------------------------------------------------------------
   8. Accesibilidad: respetar reduced-motion (neutraliza anime.js y reveals)
---------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .reveal { opacity: 1 !important; transform: none !important; }
}
