/**
 * ERP DPS Live Chat Widget — Estilos
 * Usa CSS custom properties (--erpdps-color, --erpdps-pos) inyectadas desde PHP.
 */

/* ── Reset & base ─────────────────────────────────────────────────────────── */
#erpdps-livechat-root {
  --erpdps-color: #6366f1;
  --erpdps-pos: right;
  --erpdps-z: 99999;
  --erpdps-radius: 20px;
  --erpdps-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --erpdps-shadow: 0 16px 60px rgba(0,0,0,0.18), 0 2px 14px rgba(0,0,0,0.10);
}

/* ── Toggle button ───────────────────────────────────────────────────────── */
.erpdps-toggle {
  position: fixed;
  bottom: 24px;
  z-index: var(--erpdps-z);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--erpdps-color) 0%, color-mix(in oklab, var(--erpdps-color), #7c3aed 38%) 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 24px color-mix(in oklab, var(--erpdps-color), transparent 45%), 0 2px 8px rgba(0,0,0,0.14);
  transition: transform 0.22s cubic-bezier(.34,1.36,.64,1), box-shadow 0.2s;
  color: #fff;
  overflow: visible;
  animation: erpdps-pop-in 0.65s cubic-bezier(.34,1.56,.64,1) 0.3s both;
}
.erpdps-toggle::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2.5px solid var(--erpdps-color);
  opacity: 0;
  animation: erpdps-ring 3s ease-out 2s infinite;
  pointer-events: none;
}
.erpdps-toggle:hover {
  transform: scale(1.10);
  box-shadow: 0 10px 34px color-mix(in oklab, var(--erpdps-color), transparent 30%), 0 2px 10px rgba(0,0,0,0.16);
}
.erpdps-toggle:active { transform: scale(0.95); }
.erpdps-toggle.erpdps--right { right: 24px; }
.erpdps-toggle.erpdps--left  { left: 24px; }

/* Toggle icon swap */
.erpdps-toggle .erpdps-icon-open  { display: flex; align-items: center; justify-content: center; }
.erpdps-toggle .erpdps-icon-open svg { width: 26px; height: 26px; filter: drop-shadow(0 1px 3px rgba(0,0,0,0.20)); }
.erpdps-toggle .erpdps-icon-close { display: none; width: 22px; height: 22px; }
.erpdps-toggle[aria-expanded="true"] .erpdps-icon-open  { display: none; }
.erpdps-toggle[aria-expanded="true"] .erpdps-icon-close { display: block; }

/* Online badge */
.erpdps-toggle-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #4ade80;
  border: 2.5px solid #fff;
  animation: erpdps-badge-pulse 2.4s ease-out 1s infinite;
  pointer-events: none;
}
.erpdps-toggle[aria-expanded="true"] .erpdps-toggle-badge { display: none; }

@keyframes erpdps-pop-in {
  0%   { opacity: 0; transform: scale(0.3) translateY(18px); }
  100% { opacity: 1; transform: scale(1)   translateY(0); }
}
@keyframes erpdps-ring {
  0%   { transform: scale(1);   opacity: 0.6; }
  100% { transform: scale(1.7); opacity: 0; }
}
@keyframes erpdps-badge-pulse {
  0%,100% { box-shadow: 0 0 0 0   rgba(74,222,128,0.55); }
  50%     { box-shadow: 0 0 0 5px rgba(74,222,128,0); }
}

/* ── Chat panel ──────────────────────────────────────────────────────────── */
.erpdps-panel {
  position: fixed;
  bottom: 92px;
  z-index: var(--erpdps-z);
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 500px;
  max-height: calc(100dvh - 120px);
  border-radius: var(--erpdps-radius);
  background: #fff;
  box-shadow: var(--erpdps-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--erpdps-font);
  font-size: 14px;
  line-height: 1.5;
  transition: opacity 0.22s ease, transform 0.28s cubic-bezier(.34,1.2,.64,1);
  will-change: transform, opacity;
}
.erpdps-panel.erpdps--right { right: 24px; }
.erpdps-panel.erpdps--left  { left: 24px; }

/* Closed state */
.erpdps-panel--closed {
  opacity: 0;
  pointer-events: none;
  transform: translateY(28px) scale(0.96);
}

/* ── Panel header ────────────────────────────────────────────────────────── */
.erpdps-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--erpdps-color) 0%, color-mix(in oklab, var(--erpdps-color), #000 20%) 100%);
  color: #fff;
  border-radius: var(--erpdps-radius) var(--erpdps-radius) 0 0;
  flex-shrink: 0;
}

.erpdps-header-name {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
}
.erpdps-header-status {
  margin: 2px 0 0;
  font-size: 11px;
  opacity: 0.88;
  display: flex;
  align-items: center;
  gap: 5px;
}
.erpdps-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 2px rgba(74,222,128,0.3);
  animation: erpdps-pulse 2s infinite;
}
@keyframes erpdps-pulse {
  0%,100% { box-shadow: 0 0 0 2px rgba(74,222,128,0.3); }
  50%      { box-shadow: 0 0 0 4px rgba(74,222,128,0.15); }
}

/* ── Avatar ──────────────────────────────────────────────────────────────── */
.erpdps-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
}
.erpdps-header-avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
}
.erpdps-avatar-img,
.erpdps-header-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.erpdps-avatar-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}
.erpdps-header-avatar .erpdps-avatar-initials {
  font-size: 15px;
}

/* ── Messages body ───────────────────────────────────────────────────────── */
.erpdps-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  background: #f8f9fb;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
.erpdps-body::-webkit-scrollbar { width: 4px; }
.erpdps-body::-webkit-scrollbar-track { background: transparent; }
.erpdps-body::-webkit-scrollbar-thumb { background: #dde1e8; border-radius: 4px; }

/* Message rows */
.erpdps-row { display: flex; align-items: flex-end; gap: 8px; }
.erpdps-row--user { flex-direction: row-reverse; }
.erpdps-row--bot  { flex-direction: row; }

/* Bubbles */
.erpdps-bubble {
  max-width: 78%;
  padding: 9px 14px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
}
.erpdps-bubble--user {
  background: var(--erpdps-color);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 12px rgba(99,102,241,0.20);
}
.erpdps-bubble--bot {
  background: #fff;
  color: #1a1b2e;
  border: 1px solid #e8eaf0;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.erpdps-bubble--agent {
  background: #f0fdf4;
  color: #14532d;
  border: 1px solid #86efac;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(34,197,94,0.10);
}
.erpdps-agent-label {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  color: #16a34a;
  margin-bottom: 2px;
  letter-spacing: 0.02em;
}
.erpdps-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 78%;
}
.erpdps-avatar--agent { opacity: 0.9; }

.erpdps-time {
  display: block;
  font-size: 10px;
  opacity: 0.55;
  margin-top: 4px;
  text-align: right;
}
.erpdps-bubble--bot .erpdps-time { text-align: left; }

/* Typing dots */
.erpdps-typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 12px 16px;
}
.erpdps-typing span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c4c9d8;
  animation: erpdps-bounce 1.1s infinite;
}
.erpdps-typing span:nth-child(2) { animation-delay: 0.18s; }
.erpdps-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes erpdps-bounce {
  0%,80%,100% { transform: translateY(0); }
  40%         { transform: translateY(-6px); }
}

/* ── Footer / Input ──────────────────────────────────────────────────────── */
.erpdps-footer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 10px;
  background: #fff;
  border-top: 1px solid #ebebf0;
  flex-shrink: 0;
}
.erpdps-input {
  flex: 1;
  resize: none;
  border: 1px solid #e2e4eb;
  border-radius: 14px;
  padding: 9px 13px;
  font-size: 13.5px;
  font-family: var(--erpdps-font);
  line-height: 1.45;
  color: #1a1b2e;
  background: #f3f4f8;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
  max-height: 120px;
  overflow-y: auto;
}
.erpdps-input:focus {
  border-color: var(--erpdps-color);
  background: #fff;
}
.erpdps-input::placeholder { color: #9ca3af; }

.erpdps-send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--erpdps-color);
  border: none;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, opacity 0.15s;
}
.erpdps-send:hover  { opacity: 0.88; }
.erpdps-send:active { transform: scale(0.90); }
.erpdps-send svg    { width: 17px; height: 17px; }

/* ── Branding footer ─────────────────────────────────────────────────────── */
.erpdps-branding {
  margin: 0;
  text-align: center;
  font-size: 10px;
  color: #b0b7c4;
  padding: 4px 0 8px;
  background: #fff;
  flex-shrink: 0;
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .erpdps-panel {
    bottom: 0;
    right: 0 !important;
    left: 0 !important;
    width: 100%;
    max-width: 100%;
    height: 85dvh;
    border-radius: 20px 20px 0 0;
  }
  .erpdps-toggle.erpdps--right { right: 16px; bottom: 16px; }
  .erpdps-toggle.erpdps--left  { left: 16px;  bottom: 16px; }
}
