/* Atlas AI — Chat Widget */
:root {
  --aai-accent: #2563eb;
  --aai-accent-dark: #1d4ed8;
  --aai-header-bg: var(--aai-accent);
  --aai-bg: #ffffff;
  --aai-surface: #f8fafc;
  --aai-border: #e2e8f0;
  --aai-text: #1e293b;
  --aai-text-muted: #64748b;
  --aai-user-bg: var(--aai-accent);
  --aai-user-text: #ffffff;
  --aai-bot-bg: #f1f5f9;
  --aai-bot-text: #1e293b;
  --aai-radius: 16px;
  --aai-widget-width: 380px;
  --aai-widget-height: 560px;
  --aai-widget-top-offset: 20px;
  --aai-z: 999999;
}

/* Launcher button */
.aai-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--aai-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
  transition: transform 0.2s, background 0.2s;
  z-index: var(--aai-z);
}
.aai-launcher:hover { background: var(--aai-accent-dark); transform: scale(1.05); }
.aai-launcher svg { width: 24px; height: 24px; fill: #fff; transition: opacity 0.2s; }
.aai-launcher .aai-icon-close { display: none; }
.aai-launcher.aai-open .aai-icon-chat  { display: none; }
.aai-launcher.aai-open .aai-icon-close { display: block; }

/* Launcher avatar: shown when widget is closed and avatar_url is configured */
.aai-launcher-avatar {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  display: none;
}
.aai-launcher-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.aai-launcher.aai-has-avatar .aai-icon-chat { display: none; }
.aai-launcher.aai-has-avatar .aai-launcher-avatar { display: block; }
.aai-launcher.aai-open .aai-launcher-avatar { display: none; }

/* Badge */
.aai-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
  font-size: 10px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

/* Widget panel */
.aai-widget {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: var(--aai-widget-width);
  height: var(--aai-widget-height);
  max-height: calc(100vh - 92px - var(--aai-widget-top-offset));
  background: var(--aai-bg);
  border-radius: var(--aai-radius);
  border: 1px solid var(--aai-border);
  box-shadow: 0 8px 40px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--aai-z);
  transform: scale(0.92) translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(.34,1.56,.64,1), opacity 0.18s;
  transform-origin: bottom right;
}
.aai-widget.aai-visible {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Header */
.aai-header {
  padding: 16px 18px;
  background: var(--aai-header-bg);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.aai-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  overflow: hidden;
  flex-shrink: 0;
}
.aai-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.aai-header-info { flex: 1; min-width: 0; }
.aai-header-name  { font-size: 15px; font-weight: 600; }
.aai-header-status { font-size: 12px; opacity: 0.85; display: flex; align-items: center; gap: 5px; }
.aai-status-dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; }
.aai-header-close {
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,0.8); padding: 4px;
  border-radius: 6px; display: flex; align-items: center; justify-content: center;
}
.aai-header-close:hover { background: rgba(255,255,255,0.15); color: #fff; }
.aai-header-close svg { width: 18px; height: 18px; }

/* Reset / new conversation button in header */
.aai-header-reset {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.8);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.aai-header-reset:hover { background: rgba(255,255,255,0.15); color: #fff; }
.aai-header-reset svg { width: 16px; height: 16px; }

/* Messages */
.aai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.aai-messages::-webkit-scrollbar { width: 4px; }
.aai-messages::-webkit-scrollbar-track { background: transparent; }
.aai-messages::-webkit-scrollbar-thumb { background: var(--aai-border); border-radius: 2px; }

/* Message bubbles */
.aai-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 88%;
}
.aai-msg--bot  { align-self: flex-start; }
.aai-msg--user { align-self: flex-end; flex-direction: row-reverse; }

.aai-msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--aai-accent);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #fff;
  font-weight: 600;
  overflow: hidden;
}
.aai-msg__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.aai-msg--user .aai-msg__avatar { display: none; }

.aai-msg__bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  max-width: 100%;
  word-break: break-word;
  white-space: pre-wrap;
}
.aai-msg--bot  .aai-msg__bubble { background: var(--aai-bot-bg);  color: var(--aai-bot-text);  border-bottom-left-radius: 4px; }
.aai-msg--user .aai-msg__bubble { background: var(--aai-user-bg); color: var(--aai-user-text); border-bottom-right-radius: 4px; }
.aai-msg__bubble a { color: inherit; text-decoration: underline; }
.aai-msg__bubble a:hover { opacity: 0.8; }

.aai-msg__time {
  font-size: 10px;
  color: var(--aai-text-muted);
  margin-top: 2px;
  padding: 0 4px;
}

/* Typing indicator */
.aai-typing .aai-msg__bubble {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.aai-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--aai-text-muted);
  animation: aai-bounce 1.2s infinite;
}
.aai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.aai-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes aai-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Input area */
.aai-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--aai-border);
  background: var(--aai-bg);
  flex-shrink: 0;
}
.aai-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--aai-surface);
  border: 1px solid var(--aai-border);
  border-radius: 24px;
  padding: 6px 6px 6px 14px;
  transition: border-color 0.15s;
}
.aai-input-row:focus-within { border-color: var(--aai-accent); }

.aai-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 14px;
  line-height: 1.5;
  color: var(--aai-text);
  max-height: 100px;
  outline: none;
  font-family: inherit;
  padding: 4px 0;
}
.aai-input::placeholder { color: var(--aai-text-muted); }

.aai-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--aai-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.aai-send-btn:hover   { background: var(--aai-accent-dark); }
.aai-send-btn:active  { transform: scale(0.92); }
.aai-send-btn:disabled { background: var(--aai-border); cursor: not-allowed; }
.aai-send-btn svg { width: 16px; height: 16px; fill: #fff; }

.aai-footer-brand {
  text-align: center;
  font-size: 11px;
  color: var(--aai-text-muted);
  margin-top: 8px;
}
.aai-footer-brand a { color: inherit; text-decoration: none; }
.aai-footer-brand a:hover { text-decoration: underline; }

/* Error state */
.aai-msg--error .aai-msg__bubble {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

/* Position variants */
.aai-pos-bottom-left  .aai-launcher,
.aai-pos-bottom-left  .aai-widget { right: auto; left: 24px; }
.aai-pos-bottom-left  .aai-widget { transform-origin: bottom left; }

/* Mobile */
@media (max-width: 480px) {
  .aai-widget {
    width: 100%;
    height: 100%;
    bottom: 0;
    right: 0;
    border-radius: 0;
    transform: translateY(100%);
  }
  .aai-widget.aai-visible { transform: translateY(0); }
  .aai-launcher { bottom: 16px; right: 16px; }
}

/* -------------------------------------------------------------------------
   Quick reply suggestion chips
   ------------------------------------------------------------------------- */
.aai-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 4px;
}

.aai-qr-chip {
  background: transparent;
  border: 1px solid var(--aai-accent);
  color: var(--aai-accent);
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.aai-qr-chip:hover {
  background: var(--aai-accent);
  color: #fff;
}

/* -------------------------------------------------------------------------
   Escalation button (header)
   ------------------------------------------------------------------------- */
.aai-escalate-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: 4px;
  transition: background 0.15s;
  white-space: nowrap;
}

.aai-escalate-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.aai-escalate-label {
  font-size: 11px;
}

/* -------------------------------------------------------------------------
   CSAT rating UI
   ------------------------------------------------------------------------- */
.aai-csat {
  text-align: center;
  padding: 16px 12px;
  background: var(--aai-surface);
  border-radius: 12px;
  border: 1px solid var(--aai-border);
  margin: 8px 4px 4px;
}

.aai-csat__prompt {
  font-size: 14px;
  font-weight: 500;
  margin: 0 0 12px;
  color: var(--aai-text);
}

.aai-csat__options {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 10px;
}

.aai-csat__btn {
  background: none;
  border: 2px solid transparent;
  border-radius: 50%;
  font-size: 30px;
  cursor: pointer;
  padding: 4px;
  transition: border-color 0.15s, transform 0.1s;
  line-height: 1;
}

.aai-csat__btn:hover {
  border-color: var(--aai-accent);
  transform: scale(1.2);
}

.aai-csat__skip {
  background: none;
  border: none;
  color: var(--aai-text-muted);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

/* -------------------------------------------------------------------------
   KB / Help articles panel
   ------------------------------------------------------------------------- */

/* Header book icon button */
.aai-kb-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.8);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.aai-kb-btn:hover,
.aai-kb-btn--active {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}
.aai-kb-btn svg { width: 18px; height: 18px; }

/* Panel — fills remaining widget height, hidden by default */
.aai-kb-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  background: var(--aai-bg);
}
.aai-kb-panel.aai-kb-visible {
  display: flex;
}

/* Panel header row */
.aai-kb-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--aai-border);
  flex-shrink: 0;
}

.aai-kb-panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--aai-text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Back button */
.aai-kb-back {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--aai-accent);
  font-size: 13px;
  font-weight: 500;
  padding: 4px 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  transition: background 0.15s;
  white-space: nowrap;
}
.aai-kb-back:hover { background: var(--aai-surface); }
.aai-kb-back svg { width: 14px; height: 14px; }

/* Search input */
.aai-kb-search-wrap {
  padding: 10px 14px;
  border-bottom: 1px solid var(--aai-border);
  flex-shrink: 0;
}

.aai-kb-search {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  border: 1px solid var(--aai-border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--aai-text);
  background: var(--aai-surface);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}
.aai-kb-search:focus { border-color: var(--aai-accent); }
.aai-kb-search::placeholder { color: var(--aai-text-muted); }

/* Scrollable article list */
.aai-kb-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}
.aai-kb-list::-webkit-scrollbar { width: 4px; }
.aai-kb-list::-webkit-scrollbar-track { background: transparent; }
.aai-kb-list::-webkit-scrollbar-thumb { background: var(--aai-border); border-radius: 2px; }

/* Individual article row */
.aai-kb-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--aai-border);
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.12s;
}
.aai-kb-item:last-child { border-bottom: none; }
.aai-kb-item:hover { background: var(--aai-surface); }

.aai-kb-item__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--aai-text);
  margin-bottom: 4px;
  line-height: 1.4;
}

.aai-kb-item__excerpt {
  font-size: 12px;
  color: var(--aai-text-muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Status/empty/error messages */
.aai-kb-status {
  padding: 24px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--aai-text-muted);
}
.aai-kb-status--error { color: #b91c1c; }

/* Single article view */
.aai-kb-article {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.aai-kb-article::-webkit-scrollbar { width: 4px; }
.aai-kb-article::-webkit-scrollbar-track { background: transparent; }
.aai-kb-article::-webkit-scrollbar-thumb { background: var(--aai-border); border-radius: 2px; }

.aai-kb-article__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--aai-text);
  line-height: 1.35;
}

.aai-kb-article__content {
  font-size: 13px;
  color: var(--aai-text);
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.aai-kb-article__content a { color: var(--aai-accent); text-decoration: underline; }
.aai-kb-article__content a:hover { opacity: 0.8; }

/* Image attachment (Fin Vision) */
.aai-attach-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--aai-text-muted);
  border-radius: 6px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
  order: -1;
}
.aai-attach-btn:hover { color: var(--aai-accent); background: rgba(37,99,235,.06); }
.aai-attach-btn svg   { width: 18px; height: 18px; }

.aai-image-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 12px 0;
  background: var(--aai-surface);
}
.aai-image-preview-item {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}
.aai-image-preview-item img {
  max-height: 64px;
  max-width: 80px;
  border-radius: 6px;
  border: 1px solid var(--aai-border);
  object-fit: cover;
  display: block;
}
.aai-image-preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ef4444;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}

/* Image thumbnails inside chat message bubbles */
.aai-msg__images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.aai-msg__image {
  max-height: 160px;
  max-width: 200px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,.08);
  object-fit: cover;
  display: block;
  cursor: pointer;
}
.aai-msg--user .aai-msg__image {
  border-color: rgba(255,255,255,.25);
}
