/**
 * conversive_widget.css
 * ─────────────────────
 * Styles for the Conversive Floating Communication Widget (V33).
 *
 * Design: dark glassmorphism FAB + expandable panel.
 * Theme can be switched to "light" via data-widget-theme="light" on the root element.
 */

/* ── Root variables ─────────────────────────────────────────────────────── */
:root {
  --cw-accent:        #7c3aed;          /* Conversive purple */
  --cw-accent-hover:  #6d28d9;
  --cw-bg-dark:       rgba(15, 15, 25, 0.92);
  --cw-bg-light:      rgba(255, 255, 255, 0.96);
  --cw-text-dark:     #f1f5f9;
  --cw-text-light:    #1e293b;
  --cw-border-dark:   rgba(255,255,255,0.10);
  --cw-border-light:  rgba(0,0,0,0.10);
  --cw-radius:        16px;
  --cw-fab-size:      56px;
  --cw-panel-w:       360px;
  --cw-panel-h:       520px;
  --cw-z:             99999;
  --cw-shadow:        0 8px 40px rgba(0,0,0,0.35), 0 2px 8px rgba(0,0,0,0.2);
  --cw-transition:    0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Wrapper (injected into host page) ─────────────────────────────────── */
#conversive-widget-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--cw-z);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#conversive-widget-root[data-position="bottom-left"] {
  right: unset;
  left: 24px;
  align-items: flex-start;
}

/* ── FAB button ─────────────────────────────────────────────────────────── */
.cw-fab {
  width:  var(--cw-fab-size);
  height: var(--cw-fab-size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cw-accent), #9f5cf7);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(124,58,237,0.45), var(--cw-shadow);
  transition: transform var(--cw-transition), box-shadow var(--cw-transition);
  outline: none;
  position: relative;
}

.cw-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(124,58,237,0.60), var(--cw-shadow);
}

.cw-fab:active {
  transform: scale(0.96);
}

.cw-fab svg {
  width: 24px;
  height: 24px;
  fill: #fff;
  transition: opacity var(--cw-transition), transform var(--cw-transition);
}

/* Unread badge */
.cw-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  animation: cw-pulse 2s infinite;
}

@keyframes cw-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.45); }
  50%       { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

/* ── Panel ─────────────────────────────────────────────────────────────── */
.cw-panel {
  width: var(--cw-panel-w);
  height: var(--cw-panel-h);
  border-radius: var(--cw-radius);
  background: var(--cw-bg-dark);
  border: 1px solid var(--cw-border-dark);
  box-shadow: var(--cw-shadow);
  backdrop-filter: blur(20px) saturate(1.6);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity var(--cw-transition), transform var(--cw-transition);
}

#conversive-widget-root[data-position="bottom-left"] .cw-panel {
  transform-origin: bottom left;
}

/* Hidden state */
.cw-panel[hidden],
.cw-panel.cw-hidden {
  display: none !important;
}

.cw-panel.cw-entering {
  animation: cw-expand 0.22s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.cw-panel.cw-leaving {
  animation: cw-collapse 0.18s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes cw-expand {
  from { opacity: 0; transform: scale(0.85) translateY(12px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

@keyframes cw-collapse {
  from { opacity: 1; transform: scale(1)    translateY(0); }
  to   { opacity: 0; transform: scale(0.85) translateY(12px); }
}

/* ── Panel header ─────────────────────────────────────────────────────── */
.cw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  background: linear-gradient(135deg, rgba(124,58,237,0.18), rgba(159,92,247,0.12));
  border-bottom: 1px solid var(--cw-border-dark);
  flex-shrink: 0;
}

.cw-header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cw-header-brand span {
  font-size: 13px;
  font-weight: 600;
  color: #a78bfa;
  letter-spacing: 0.02em;
}

.cw-header-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--cw-text-dark);
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}

.cw-header-lead-name {
  font-size: 13.5px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.cw-header-lead-phone {
  font-size: 10.5px;
  font-weight: 400;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.cw-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  color: rgba(255,255,255,0.5);
  transition: color var(--cw-transition), background var(--cw-transition);
  line-height: 1;
}

.cw-close-btn:hover {
  color: #fff;
  background: rgba(255,255,255,0.08);
}

/* ── Tab bar ───────────────────────────────────────────────────────────── */
.cw-tabs {
  display: flex;
  padding: 0 16px;
  border-bottom: 1px solid var(--cw-border-dark);
  flex-shrink: 0;
}

.cw-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.45);
  cursor: pointer;
  transition: color var(--cw-transition), border-color var(--cw-transition);
  margin-bottom: -1px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cw-tab.cw-active {
  color: #c4b5fd;
  border-bottom-color: #7c3aed;
}

.cw-tab:hover:not(.cw-active) {
  color: rgba(255,255,255,0.75);
}

/* ── Tab panes ─────────────────────────────────────────────────────────── */
.cw-pane {
  display: none;
  flex: 1;
  overflow: hidden;
  flex-direction: column;
}

.cw-pane.cw-active {
  display: flex;
}

/* Live call state inside the Call tab */
.cw-call-live {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex: 1;
  padding: 24px 16px;
}
.cw-call-live-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.cw-call-live-name {
  font-size: 15px;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
}
.cw-call-live-phone {
  font-size: 12px;
  color: rgba(255,255,255,0.45);
}
.cw-call-live-timer {
  font-size: 24px;
  font-weight: 700;
  color: #a78bfa;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  margin-top: 6px;
}
.cw-call-live-controls {
  display: flex;
  gap: 12px;
}


.cw-msg-history {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cw-msg-history::-webkit-scrollbar { width: 4px; }
.cw-msg-history::-webkit-scrollbar-track { background: transparent; }
.cw-msg-history::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.cw-bubble {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.45;
  word-break: break-word;
}

.cw-bubble.cw-outbound {
  align-self: flex-end;
  background: linear-gradient(135deg, #7c3aed, #9f5cf7);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.cw-bubble.cw-inbound {
  align-self: flex-start;
  background: rgba(255,255,255,0.09);
  color: var(--cw-text-dark);
  border-bottom-left-radius: 4px;
}

.cw-bubble-time {
  font-size: 10.5px;
  opacity: 0.55;
  margin-top: 3px;
  text-align: right;
}

.cw-msg-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: rgba(255,255,255,0.3);
  font-size: 13px;
}

/* Compose bar */
.cw-compose {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--cw-border-dark);
  background: rgba(255,255,255,0.03);
  flex-shrink: 0;
}

.cw-compose-input {
  flex: 1;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--cw-text-dark);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 80px;
  transition: border-color var(--cw-transition);
}

.cw-compose-input:focus {
  border-color: rgba(124,58,237,0.6);
}

.cw-compose-input::placeholder {
  color: rgba(255,255,255,0.25);
}

.cw-send-btn {
  background: linear-gradient(135deg, var(--cw-accent), #9f5cf7);
  border: none;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform var(--cw-transition), box-shadow var(--cw-transition);
}

.cw-send-btn:hover { transform: scale(1.08); box-shadow: 0 4px 14px rgba(124,58,237,0.5); }
.cw-send-btn:active { transform: scale(0.94); }
.cw-send-btn svg { width: 18px; height: 18px; fill: #fff; }
.cw-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Status toast ─────────────────────────────────────────────────────── */
.cw-toast {
  position: absolute;
  bottom: 80px;
  right: 0;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 500;
  background: rgba(15,15,25,0.95);
  color: #c4b5fd;
  border: 1px solid rgba(124,58,237,0.35);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: cw-toast-in 0.2s ease;
  pointer-events: none;
  white-space: nowrap;
}

.cw-toast.cw-toast-error { color: #fca5a5; border-color: rgba(239,68,68,0.35); }
.cw-toast.cw-toast-success { color: #86efac; border-color: rgba(34,197,94,0.35); }

@keyframes cw-toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Light theme override ─────────────────────────────────────────────── */
#conversive-widget-root[data-widget-theme="light"] .cw-panel {
  background: var(--cw-bg-light);
  border-color: var(--cw-border-light);
}

#conversive-widget-root[data-widget-theme="light"] .cw-header-title,
#conversive-widget-root[data-widget-theme="light"] .cw-tab,
#conversive-widget-root[data-widget-theme="light"] .cw-bubble.cw-inbound {
  color: var(--cw-text-light);
}

#conversive-widget-root[data-widget-theme="light"] .cw-compose-input {
  background: rgba(0,0,0,0.05);
  border-color: rgba(0,0,0,0.12);
  color: var(--cw-text-light);
}

#conversive-widget-root[data-widget-theme="light"] .cw-compose-input::placeholder {
  color: rgba(0,0,0,0.35);
}

/* .cw-powered-by removed — footer deprecated */

/* ── V34: Channel selector ─────────────────────────────── */
.cw-channel-bar {
  display: flex;
  gap: 6px;
  padding: 8px 12px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
[data-widget-theme="light"] .cw-channel-bar {
  border-bottom-color: rgba(0,0,0,0.08);
}
.cw-channel-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.15);
  background: transparent;
  color: rgba(255,255,255,0.55);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.cw-channel-btn svg { width: 14px; height: 14px; fill: currentColor; flex-shrink: 0; }
.cw-channel-btn:hover { border-color: rgba(255,255,255,0.3); color: rgba(255,255,255,0.85); }
.cw-channel-btn.cw-active {
  background: rgba(124,58,237,0.25);
  border-color: #7c3aed;
  color: #c4b5fd;
}
[data-widget-theme="light"] .cw-channel-btn {
  border-color: rgba(0,0,0,0.15);
  color: rgba(0,0,0,0.5);
}
[data-widget-theme="light"] .cw-channel-btn.cw-active {
  background: rgba(124,58,237,0.1);
  border-color: #7c3aed;
  color: #7c3aed;
}

/* ── Session banner ──────────────────────────────────────── */
.cw-session-banner {
  margin: 8px 12px 0;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cw-session-banner.cw-hidden { display: none; }
.cw-banner-info  { background: rgba(99,102,241,0.15); color: #a5b4fc; }
.cw-banner-warn  { background: rgba(245,158,11,0.15); color: #fcd34d; }
.cw-banner-error { background: rgba(239,68,68,0.15);  color: #fca5a5; }
[data-widget-theme="light"] .cw-banner-info  { background: rgba(99,102,241,0.08); color: #4f46e5; }
[data-widget-theme="light"] .cw-banner-warn  { background: rgba(245,158,11,0.1);  color: #b45309; }
[data-widget-theme="light"] .cw-banner-error { background: rgba(239,68,68,0.08);  color: #dc2626; }

/* ── Template picker ─────────────────────────────────────── */
.cw-tpl-wrap {
  padding: 10px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.cw-tpl-wrap.cw-hidden { display: none; }
.cw-tpl-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
}
[data-widget-theme="light"] .cw-tpl-label { color: rgba(0,0,0,0.4); }
.cw-tpl-select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: #f3f4f6;
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.cw-tpl-select:focus { border-color: #7c3aed; }
[data-widget-theme="light"] .cw-tpl-select {
  border-color: rgba(0,0,0,0.15);
  background: #fff;
  color: #111827;
}
.cw-tpl-preview {
  padding: 10px;
  border-radius: 8px;
  background: rgba(124,58,237,0.1);
  border: 1px solid rgba(124,58,237,0.25);
  font-size: 12px;
  line-height: 1.5;
  color: rgba(255,255,255,0.75);
  white-space: pre-wrap;
  max-height: 120px;
  overflow-y: auto;
}
.cw-tpl-preview.cw-hidden { display: none; }
[data-widget-theme="light"] .cw-tpl-preview {
  background: rgba(124,58,237,0.05);
  color: #374151;
}

/* ── Spinner animation ───────────────────────────────────── */
@keyframes cw-rotate { to { transform: rotate(360deg); } }
.cw-spin { animation: cw-rotate 0.8s linear infinite; width: 14px; height: 14px; }
