/* ============================================================================
   ADMIN CHAT WIDGET — Sofia flotante en el panel de admin
   Estilos aislados con prefijo .acw- para no chocar con admin-dashboard.css.
   ============================================================================ */

.acw-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: 99998;
  box-shadow: 0 10px 30px rgba(6, 182, 212, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.acw-launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 36px rgba(6, 182, 212, 0.45); }
.acw-launcher.acw-hidden { display: none; }
.acw-launcher .acw-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #fff;
  display: none;
}
.acw-launcher.acw-has-unread .acw-dot { display: block; }

.acw-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 380px;
  height: 560px;
  min-width: 320px;
  min-height: 360px;
  max-width: 90vw;
  max-height: 90vh;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.06);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
}
.acw-panel.acw-hidden { display: none; }
.acw-panel.acw-minimized { height: 48px !important; min-height: 48px; }
.acw-panel.acw-minimized .acw-body,
.acw-panel.acw-minimized .acw-input-wrap,
.acw-panel.acw-minimized .acw-context-bar,
.acw-panel.acw-minimized .acw-resize { display: none; }

.acw-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  cursor: grab;
  user-select: none;
}
.acw-header.acw-dragging { cursor: grabbing; }
.acw-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}
.acw-title-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}
.acw-title small { color: #94a3b8; font-weight: 400; font-size: 11px; }
.acw-actions { display: flex; gap: 4px; }
.acw-actions button {
  background: transparent;
  border: none;
  color: #94a3b8;
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}
.acw-actions button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.acw-context-bar {
  flex: 0 0 auto;
  padding: 6px 12px;
  background: rgba(59, 130, 246, 0.08);
  border-bottom: 1px solid rgba(59, 130, 246, 0.15);
  font-size: 11px;
  color: #93c5fd;
  display: flex; align-items: center; gap: 6px;
  min-height: 24px;
}
.acw-context-bar.acw-empty { display: none; }
.acw-context-bar i { font-size: 10px; opacity: 0.7; }
.acw-context-bar .acw-ctx-pill {
  background: rgba(59, 130, 246, 0.2);
  padding: 2px 8px;
  border-radius: 10px;
  color: #dbeafe;
}

.acw-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.acw-body::-webkit-scrollbar { width: 6px; }
.acw-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 3px; }

.acw-msg {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 13px;
}
.acw-msg.acw-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.acw-msg.acw-assistant {
  align-self: flex-start;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-bottom-left-radius: 4px;
}
.acw-msg.acw-system {
  align-self: center;
  background: transparent;
  color: #64748b;
  font-size: 11px;
  font-style: italic;
}
.acw-msg-meta {
  font-size: 10px;
  color: #64748b;
  margin-top: 4px;
}
.acw-typing {
  align-self: flex-start;
  padding: 8px 12px;
  background: #1e293b;
  border-radius: 12px;
  display: flex; gap: 4px;
}
.acw-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #64748b;
  animation: acw-bounce 1.2s infinite;
}
.acw-typing span:nth-child(2) { animation-delay: 0.15s; }
.acw-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes acw-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.acw-input-wrap {
  flex: 0 0 auto;
  padding: 10px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: #0b1220;
}
.acw-input {
  flex: 1;
  resize: none;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: #e2e8f0;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.4;
  max-height: 120px;
  outline: none;
}
.acw-input:focus { border-color: #3b82f6; }
.acw-send {
  background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 36px; height: 36px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.acw-send:disabled { opacity: 0.5; cursor: not-allowed; }

.acw-resize {
  position: absolute;
  left: 0;
  top: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.15) 50%);
  border-top-left-radius: 14px;
}

.acw-history-panel {
  position: absolute;
  top: 44px; left: 0; right: 0; bottom: 0;
  background: #0f172a;
  z-index: 2;
  overflow-y: auto;
  padding: 8px;
  display: none;
}
.acw-history-panel.acw-open { display: block; }
.acw-history-item {
  padding: 8px 10px;
  border-radius: 8px;
  background: #1e293b;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 12px;
}
.acw-history-item:hover { background: #334155; }
.acw-history-item .acw-h-title { font-weight: 600; color: #e2e8f0; }
.acw-history-item .acw-h-meta { color: #64748b; font-size: 10px; margin-top: 2px; }
.acw-history-empty { padding: 20px; text-align: center; color: #64748b; font-size: 12px; }

.acw-error {
  align-self: center;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 11px;
}

/* Markdown light formatting inside assistant messages */
.acw-msg.acw-assistant code {
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
  font-family: 'SF Mono', Monaco, monospace;
}
.acw-msg.acw-assistant pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}
.acw-msg.acw-assistant a { color: #60a5fa; text-decoration: underline; }
.acw-msg.acw-assistant strong { color: #fff; }
