/* =========================================================
   AI Live Chat — Frontend Chat Widget CSS
   ========================================================= */

:root {
  --ailc-primary: var(--ailc-widget-color, #2563eb);
  --ailc-primary-dark: color-mix(in srgb, var(--ailc-primary) 82%, #000);
  --ailc-widget-z: 999999;
  --ailc-widget-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --ailc-msg-radius: 16px;
}

/* Utility */
.ailc-hidden { display: none !important; }


/* ── Widget Launcher Button ── */
#ailc-widget-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--ailc-widget-z);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--ailc-primary);
  box-shadow: 0 4px 20px rgba(0,0,0,0.18), 0 0 0 0 rgba(37,99,235,0.4);
  border: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: ailc-launcher-in 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
#ailc-widget-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0,0,0,0.22), 0 0 0 0 rgba(37,99,235,0.4);
}
#ailc-widget-launcher.bottom-left {
  right: auto;
  left: 24px;
}
@keyframes ailc-launcher-in {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.ailc-launcher-icon {
  width: 26px;
  height: 26px;
  fill: #fff;
  transition: transform 0.25s ease, opacity 0.2s ease;
  position: absolute;
}
.ailc-launcher-icon.ailc-close-icon {
  opacity: 0;
  transform: scale(0.5) rotate(45deg);
}
#ailc-widget-launcher.open .ailc-chat-icon {
  opacity: 0;
  transform: scale(0.5);
}
#ailc-widget-launcher.open .ailc-close-icon {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* ── Unread badge ── */
#ailc-unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 2px solid #fff;
  display: none;
}

/* ── Widget Panel ── */
#ailc-widget-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: var(--ailc-widget-z);
  width: 380px;
  height: 580px;
  max-height: calc(100vh - 120px);
  max-width: calc(100vw - 48px);
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.16), 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95) translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), opacity 0.2s ease;
  font-family: var(--ailc-widget-font);
}
#ailc-widget-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}
#ailc-widget-panel.bottom-left {
  right: auto;
  left: 24px;
}

/* ── Panel Header ── */
.ailc-widget-header {
  background: var(--ailc-primary);
  padding: 18px 20px 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-shrink: 0;
  position: relative;
}
.ailc-widget-header::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 0;
  right: 0;
  height: 12px;
  background: #fff;
  border-radius: 12px 12px 0 0;
}
.ailc-header-agents {
  display: flex;
  margin-bottom: 8px;
}
.ailc-agent-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.7);
  background: rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  margin-left: -8px;
  flex-shrink: 0;
}
.ailc-agent-avatar:first-child { margin-left: 0; }
.ailc-online-dot {
  width: 9px;
  height: 9px;
  background: #4ade80;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
  vertical-align: middle;
}
.ailc-header-title {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 3px;
  line-height: 1.2;
}
.ailc-header-subtitle {
  font-size: 13px;
  color: rgba(255,255,255,0.8);
}
.ailc-widget-close {
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  color: #fff;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.ailc-widget-close:hover { background: rgba(255,255,255,0.25); }

/* ── Pre-chat Form ── */
#ailc-prechat-form {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}
.ailc-prechat-title {
  font-size: 16px;
  font-weight: 700;
  color: #1e2a3a;
  margin: 0;
}
.ailc-prechat-desc {
  font-size: 13px;
  color: #64748b;
  line-height: 1.5;
  margin: -6px 0 0;
}
.ailc-field-label {
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 4px;
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.ailc-field-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 13px;
  color: #1e2a3a;
  background: #f8fafc;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: var(--ailc-widget-font);
}
.ailc-field-input:focus {
  border-color: var(--ailc-primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.ailc-start-btn {
  padding: 12px;
  background: var(--ailc-primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  font-family: var(--ailc-widget-font);
}
.ailc-start-btn:hover { background: var(--ailc-primary-dark); }
.ailc-start-btn:active { transform: scale(0.98); }
.ailc-gdpr-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 11px;
  color: #64748b;
  line-height: 1.4;
}
.ailc-gdpr-row input[type=checkbox] { flex-shrink: 0; margin-top: 2px; }

/* ── Chat Messages Area ── */
#ailc-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
#ailc-chat-messages::-webkit-scrollbar { width: 4px; }
#ailc-chat-messages::-webkit-scrollbar-track { background: transparent; }
#ailc-chat-messages::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 2px; }

.ailc-w-message {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 85%;
  animation: ailc-w-msg-in 0.2s ease;
}
@keyframes ailc-w-msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.ailc-w-message.visitor { align-self: flex-end; flex-direction: row-reverse; }
.ailc-w-message.agent   { align-self: flex-start; }
.ailc-w-message.system  { align-self: center; max-width: 100%; }
.ailc-w-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--ailc-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ailc-w-bubble {
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}
.ailc-w-message.visitor .ailc-w-bubble {
  background: var(--ailc-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ailc-w-message.agent .ailc-w-bubble {
  background: #f1f5f9;
  color: #1e2a3a;
  border-bottom-left-radius: 4px;
}
.ailc-w-message.system .ailc-w-bubble {
  background: transparent;
  color: #94a3b8;
  font-size: 11px;
  text-align: center;
}
.ailc-w-time {
  font-size: 10px;
  color: #94a3b8;
  margin-top: 2px;
  text-align: right;
}
.ailc-w-message.agent .ailc-w-time { text-align: left; }
.ailc-w-file-attach {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.1);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  margin-top: 4px;
}
.ailc-w-message.visitor .ailc-w-file-attach { color: rgba(255,255,255,0.9); }
.ailc-w-message.agent .ailc-w-file-attach { color: #1e2a3a; }

/* ── Typing ── */
.ailc-w-typing {
  display: flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  padding: 4px 0;
}
.ailc-w-typing-dots { display: flex; gap: 3px; background: #f1f5f9; padding: 8px 12px; border-radius: 16px; border-bottom-left-radius: 4px; }
.ailc-w-typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: #94a3b8; animation: ailc-typing 1.2s infinite ease-in-out; }
.ailc-w-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.ailc-w-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ailc-typing { 0%,80%,100% { transform: scale(0.7); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

/* ── Widget Input Bar ── */
.ailc-widget-input-wrap {
  padding: 12px 14px;
  border-top: 1px solid #f1f5f9;
  background: #fff;
  flex-shrink: 0;
}
.ailc-widget-input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 8px 10px;
  transition: border-color 0.15s;
}
.ailc-widget-input-row:focus-within {
  border-color: var(--ailc-primary);
}
.ailc-widget-textarea {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  font-size: 13px;
  color: #1e2a3a;
  font-family: var(--ailc-widget-font);
  min-height: 20px;
  max-height: 96px;
  line-height: 1.5;
}
.ailc-widget-textarea::placeholder { color: #94a3b8; }
.ailc-w-tool {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  color: #94a3b8;
  transition: background 0.15s;
}
.ailc-w-tool:hover { background: #e2e8f0; color: #1e2a3a; }
.ailc-w-send-btn {
  width: 34px;
  height: 34px;
  background: var(--ailc-primary);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.ailc-w-send-btn:hover { background: var(--ailc-primary-dark); }
.ailc-w-send-btn:active { transform: scale(0.9); }
.ailc-w-send-btn svg { width: 15px; height: 15px; fill: #fff; }

/* ── Widget emoji picker ── */
.ailc-w-emoji-picker {
  position: absolute;
  bottom: 56px;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid #f1f5f9;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  z-index: 10;
}
.ailc-w-emoji-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
}
.ailc-w-emoji-btn:hover { background: #f1f5f9; }

/* ── Upload preview ── */
.ailc-upload-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f0f7ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 7px 10px;
  margin-bottom: 6px;
  font-size: 12px;
}
.ailc-upload-name  { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ailc-upload-cancel { border: none; background: transparent; cursor: pointer; color: #94a3b8; font-size: 16px; padding: 0; }

/* ── Powered by ── */
.ailc-widget-footer {
  text-align: center;
  padding: 6px 0 10px;
  font-size: 10px;
  color: #cbd5e1;
}
.ailc-widget-footer a { color: #94a3b8; text-decoration: none; }
.ailc-widget-footer a:hover { color: var(--ailc-primary); }

/* ── Offline mode ── */
.ailc-offline-banner {
  background: #fef3c7;
  border-bottom: 1px solid #fde68a;
  padding: 8px 14px;
  font-size: 12px;
  color: #92400e;
  text-align: center;
  flex-shrink: 0;
}