/* HTMX loading indicator */
.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }

/* Suppress per-row spinners during background conv-list poll.
   Only #search-spinner (sibling of conv-list) should show during polls. */
#conv-list.htmx-request .htmx-indicator { opacity: 0 !important; transition: none !important; }

/* Chat scrollbar */
.chat-scroll::-webkit-scrollbar { width: 6px; }
.chat-scroll::-webkit-scrollbar-track { background: #ffffff; }
.chat-scroll::-webkit-scrollbar-thumb { background: #C8A951; border-radius: 3px; }

/* Active nav link */
.nav-active { background-color: rgba(200, 169, 81, 0.15); border-left: 3px solid #C8A951; }

/* Mobile sidebar */
[x-cloak] { display: none !important; }

/* ========================================
   ANIMATIONS
   ======================================== */

/* Page content fade-in */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.animate-fadeIn {
  animation: fadeIn 0.4s ease-out both;
}

/* Slide up (for modals, message bubbles) */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-slideUp {
  animation: slideUp 0.3s ease-out both;
}

/* Message bubble entrance — only NEW messages (htmx-added), not existing ones on Idiomorph morph */
@keyframes msgEnter {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.msg-bubble.htmx-added {
  animation: msgEnter 0.25s ease-out both;
}

/* Login card entrance */
@keyframes cardEnter {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-cardEnter {
  animation: cardEnter 0.5s ease-out both;
  animation-delay: 0.1s;
}

/* Staggered fade for dashboard cards */
.stagger-1 { animation-delay: 0.05s; }
.stagger-2 { animation-delay: 0.10s; }
.stagger-3 { animation-delay: 0.15s; }
.stagger-4 { animation-delay: 0.20s; }
.stagger-5 { animation-delay: 0.25s; }

/* ========================================
   TRANSITION UTILITIES
   ======================================== */

/* Hover lift for cards */
.card-hover {
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.card-hover:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

/* Smooth table row hover */
.row-hover {
  transition: background-color 0.15s ease;
}

/* ========================================
   SIDEBAR MOBILE SLIDE
   ======================================== */

@media (max-width: 767px) {
  #sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease-in-out;
  }
  #sidebar.sidebar-open {
    transform: translateX(0);
  }
}

/* Sidebar overlay fade */
#sidebar-overlay {
  opacity: 0;
  transition: opacity 0.25s ease-in-out;
  pointer-events: none;
}
#sidebar-overlay.overlay-visible {
  opacity: 1;
  pointer-events: auto;
}

/* ========================================
   FUNNEL & STAT BARS
   ======================================== */

/* Dashboard funnel bar */
.funnel-bar {
  height: 32px;
  border-radius: 4px;
  transition: width 0.6s ease-out;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  min-width: 32px;
}

/* Stats horizontal bar */
.stat-bar {
  height: 8px;
  border-radius: 4px;
  transition: width 0.5s ease-out;
  min-width: 4px;
}

/* ========================================
   TIMELINE
   ======================================== */

/* Events timeline dot */
.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid;
  background: white;
  flex-shrink: 0;
  margin-top: 4px;
}
.timeline-line {
  width: 2px;
  background: #E5E7EB;
  flex-shrink: 0;
}

/* ========================================
   TABLE SCROLL INDICATOR (mobile)
   ======================================== */

/* Gradient shadow on right edge hints at horizontal overflow */
.table-scroll-container {
  position: relative;
}
.table-scroll-container::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 24px;
  pointer-events: none;
  background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.06));
  border-radius: 0 0.5rem 0.5rem 0;
  opacity: 1;
  transition: opacity 0.2s ease;
}
@media (min-width: 768px) {
  .table-scroll-container::after {
    display: none;
  }
}

/* ========================================
   RESPONSIVE OVERRIDES
   ======================================== */

@media (max-width: 767px) {
  main.main-content {
    padding: 1rem;
  }
}

/* Number formatting helper */
.num-format {
  font-variant-numeric: tabular-nums;
}

/* ========================================
   HTMX SWAP TRANSITIONS
   ======================================== */

/* Smooth HTMX content swap — exclude morph containers */
.htmx-settling {
  opacity: 0;
}
.htmx-added {
  opacity: 1;
  transition: opacity 0.3s ease-in;
}

/* Override: disable settling/added transitions inside morph-swapped containers.
   Idiomorph patches the DOM in-place, so the fade-out/fade-in is disruptive.
   Must also cover the containers themselves (#conv-list.htmx-settling), not
   only their children, because HTMX adds htmx-settling to the swap target too. */
#conv-list.htmx-settling,
#conv-list .htmx-settling,
#conv-list.htmx-added,
#conv-list .htmx-added,
#message-list.htmx-settling,
#message-list .htmx-settling,
#message-list.htmx-added,
#message-list .htmx-added {
  opacity: 1 !important;
  transition: none !important;
}

/* ========================================
   CONVERSATION THREAD — PREMIUM CHAT VIEW
   ======================================== */

/* ------------------------------------------
   1. CHAT BACKGROUND — subtle paper texture
   ------------------------------------------ */
#conv-thread {
  overflow-y: overlay; /* overlay scrollbar: no layout width impact, header covers full width */
  transition: opacity 0.22s ease;
  background-color: #f8f6f0;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 28px,
      rgba(200, 169, 81, 0.04) 28px,
      rgba(200, 169, 81, 0.04) 29px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 28px,
      rgba(200, 169, 81, 0.04) 28px,
      rgba(200, 169, 81, 0.04) 29px
    );
  background-size: 29px 29px;
}

/* ------------------------------------------
   5. DELIVERY STATUS INDICATORS
   ------------------------------------------ */

/* Base icon styling shared across all states */
.status-check,
.status-delivered,
.status-read,
.status-failed {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  font-size: 0.65rem;
  line-height: 1;
  vertical-align: middle;
  margin-left: 4px;
}

/* Single check — sent, not yet delivered */
.status-check::before {
  content: "✓";
  color: #9ca3af;
}

/* Double check — delivered to device */
.status-delivered::before {
  content: "✓✓";
  color: #9ca3af;
  letter-spacing: -2px;
}

/* Double check — read (gold) */
.status-read::before {
  content: "✓✓";
  color: #C8A951;
  letter-spacing: -2px;
}

/* Failed — red X */
.status-failed::before {
  content: "✕";
  color: #ef4444;
  font-weight: 700;
}

/* ------------------------------------------
   6. INTENT BADGE — tiny classification pill
   ------------------------------------------ */
.intent-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: rgba(200, 169, 81, 0.10);
  color: #92742a;
  border: 1px solid rgba(200, 169, 81, 0.25);
  white-space: nowrap;
  user-select: none;
  vertical-align: middle;
}

/* Per-intent color overrides */
.intent-badge[data-intent="busqueda"]       { background: rgba(200, 169, 81, 0.10); color: #92742a; border-color: rgba(200, 169, 81, 0.25); }
.intent-badge[data-intent="lead"]           { background: rgba(34, 197, 94, 0.10);  color: #166534; border-color: rgba(34, 197, 94, 0.25); }
.intent-badge[data-intent="saludo"]         { background: rgba(99, 102, 241, 0.10); color: #3730a3; border-color: rgba(99, 102, 241, 0.25); }
.intent-badge[data-intent="opt_out"]        { background: rgba(239, 68, 68, 0.10);  color: #991b1b; border-color: rgba(239, 68, 68, 0.25); }
.intent-badge[data-intent="conversacion"]   { background: rgba(156, 163, 175, 0.15); color: #374151; border-color: rgba(156, 163, 175, 0.30); }
.intent-badge[data-intent="detalle"]        { background: rgba(59, 130, 246, 0.10); color: #1e40af; border-color: rgba(59, 130, 246, 0.25); }
.intent-badge[data-intent="paginacion"]     { background: rgba(245, 158, 11, 0.10); color: #92400e; border-color: rgba(245, 158, 11, 0.25); }

/* ------------------------------------------
   7. PHOTO — click-to-open-in-new-tab
   ------------------------------------------ */
.chat-photo-link {
  display: inline-block;
  cursor: zoom-in;
  border-radius: 8px;
  overflow: hidden;
  transition: opacity 0.2s ease, box-shadow 0.2s ease;
}
.chat-photo-link:hover {
  opacity: 0.88;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
}
.chat-photo-link img {
  display: block;
  max-width: 220px;
  max-height: 200px;
  object-fit: cover;
  border-radius: 8px;
  background: #e5e7eb;
}

/* ========================================
   HTMX LOADING SPINNER
   ======================================== */

.htmx-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #e5e7eb;
  border-top: 2px solid #C8A951;
  border-radius: 50%;
  animation: htmxSpin 0.6s linear infinite;
  vertical-align: middle;
}
.htmx-spinner.htmx-spinner-sm {
  width: 14px;
  height: 14px;
}

@keyframes htmxSpin {
  to { transform: rotate(360deg); }
}

/* ========================================
   GLOBAL ERROR TOAST
   ======================================== */

.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  max-width: 360px;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  line-height: 1.4;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: toastIn 0.3s ease-out both;
}
.toast-error {
  background: #dc2626;
}
.toast-warning {
  background: #d97706;
}
.toast-success {
  background: #16a34a;
}

.toast.toast-out {
  animation: toastOut 0.25s ease-in both;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}

