/* ===================================================================
   WEBTOKEN AGENT - PANEL DE ATENCIÓN Y MONITOREO
   Diseñado para LiteSpeed / PHP / Vanilla JS
   Paleta Oficial Webtoken Glassmorphism
   =================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --wt-magenta: #D4145A;
  --wt-purple: #662D91;
  --wt-indigo: #3B2D91;
  --wt-blue-bright: #1579FF;
  --wt-emerald: #10B981;
  --wt-amber: #F59E0B;
  --wt-whatsapp: #25D366;

  --bg-body: #090814;
  --bg-sidebar: #0E0D1F;
  --bg-surface: #14132B;
  --bg-surface-elevated: #1B1938;
  --bg-card: rgba(24, 22, 49, 0.7);
  --bg-card-hover: rgba(33, 30, 66, 0.85);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.14);
  --border-glow: rgba(212, 20, 90, 0.4);

  --text-primary: #F8FAFC;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --text-light: #FFFFFF;

  --font-main: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --grad-brand: linear-gradient(135deg, #D4145A 0%, #662D91 50%, #3B2D91 100%);
  --grad-agent: linear-gradient(135deg, rgba(212, 20, 90, 0.15) 0%, rgba(102, 45, 145, 0.25) 100%);
  --grad-client: #1B1938;
  --grad-operator: linear-gradient(135deg, rgba(21, 121, 255, 0.2) 0%, rgba(16, 185, 129, 0.2) 100%);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header Principal */
.agent-header {
  height: 64px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 10;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-badge {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--grad-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #fff;
  font-size: 1.1rem;
  box-shadow: 0 0 15px rgba(212, 20, 90, 0.5);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-title span {
  color: var(--wt-magenta);
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.header-status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  color: var(--wt-emerald);
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--wt-emerald);
  box-shadow: 0 0 8px var(--wt-emerald);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.9); }
  100% { opacity: 1; transform: scale(1); }
}

/* Contenedor Principal (App Grid) */
.app-container {
  display: flex;
  flex: 1;
  height: calc(100vh - 64px);
  position: relative;
}

/* Panel Izquierdo: Lista de Conversaciones */
.conversations-sidebar {
  width: 380px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
}

.sidebar-controls {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

.search-input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--wt-magenta);
}

/* Filtros por Canal */
.channel-filters {
  display: flex;
  gap: 6px;
}

.filter-btn {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.filter-btn.active, .filter-btn:hover {
  background: var(--bg-surface-elevated);
  color: var(--text-light);
  border-color: var(--wt-magenta);
}

.filter-count {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
}

/* Lista de Chats */
.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-card {
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.chat-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-medium);
  transform: translateY(-1px);
}

.chat-card.active {
  background: var(--bg-surface-elevated);
  border-color: var(--wt-magenta);
  box-shadow: 0 0 15px rgba(212, 20, 90, 0.15);
}

.chat-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.contact-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 8px;
}

.channel-tag {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tag-whatsapp {
  background: rgba(37, 211, 102, 0.15);
  color: var(--wt-whatsapp);
  border: 1px solid rgba(37, 211, 102, 0.3);
}

.tag-web {
  background: rgba(21, 121, 255, 0.15);
  color: var(--wt-blue-bright);
  border: 1px solid rgba(21, 121, 255, 0.3);
}

.chat-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-card-body {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.last-message-snippet {
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.badge-unread {
  background: var(--wt-magenta);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.status-badge {
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 6px;
  display: inline-block;
}

.status-bot {
  background: rgba(102, 45, 145, 0.2);
  color: #c084fc;
  border: 1px solid rgba(102, 45, 145, 0.4);
}

.status-human {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

/* Panel Derecho: Área Principal de Conversación */
.chat-main-area {
  flex: 1;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  position: relative;
}

.empty-chat-state {
  margin: auto;
  text-align: center;
  max-width: 420px;
  padding: 40px;
}

.empty-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 20px;
  color: var(--text-muted);
}

/* Barra Superior de la Conversación */
.chat-topbar {
  height: 64px;
  padding: 0 24px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-contact-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.contact-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--wt-blue-bright);
}

.contact-details h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-light);
}

.contact-details p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bot-toggle-btn {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.btn-bot-pause {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.4);
}

.btn-bot-pause:hover {
  background: rgba(245, 158, 11, 0.3);
}

.btn-bot-resume {
  background: rgba(16, 185, 129, 0.15);
  color: var(--wt-emerald);
  border-color: rgba(16, 185, 129, 0.4);
}

.btn-bot-resume:hover {
  background: rgba(16, 185, 129, 0.3);
}

/* Área de Mensajes (Timeline) */
.messages-timeline {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  animation: fadeIn 0.2s ease-in;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-wrapper.from-client {
  align-self: flex-start;
}

.message-wrapper.from-agent, .message-wrapper.from-operator {
  align-self: flex-end;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-wrapper.from-client .message-bubble {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: 2px;
}

.message-wrapper.from-agent .message-bubble {
  background: var(--grad-agent);
  border: 1px solid rgba(212, 20, 90, 0.35);
  color: #ffffff;
  border-bottom-right-radius: 2px;
  box-shadow: 0 4px 15px rgba(212, 20, 90, 0.1);
}

.message-wrapper.from-operator .message-bubble {
  background: var(--grad-operator);
  border: 1px solid rgba(21, 121, 255, 0.4);
  color: #ffffff;
  border-bottom-right-radius: 2px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.message-wrapper.from-agent .message-meta,
.message-wrapper.from-operator .message-meta {
  justify-content: flex-end;
}

.sender-tag {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.65rem;
}

.sender-tag.toki {
  color: var(--wt-magenta);
}

.sender-tag.humano {
  color: var(--wt-blue-bright);
}

/* Barra Inferior de Envío (Composer) */
.chat-composer {
  padding: 16px 24px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.composer-input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  resize: none;
  outline: none;
  line-height: 1.4;
}

.composer-input:focus {
  border-color: var(--wt-blue-bright);
}

.btn-send {
  height: 44px;
  padding: 0 20px;
  background: var(--wt-blue-bright);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-send:hover {
  background: #0060df;
  box-shadow: 0 0 15px rgba(21, 121, 255, 0.4);
}

/* Responsive */
@media (max-width: 860px) {
  .conversations-sidebar {
    width: 100%;
    position: absolute;
    height: 100%;
    z-index: 5;
  }

  .conversations-sidebar.hidden-mobile {
    display: none;
  }

  .chat-main-area.hidden-mobile {
    display: none;
  }
}
