/* ===================================================================
   AAI Chatbot Widget — Concierge Theme
   Light mode: warm cream  •  Dark mode: deep navy
   Auto-switches via prefers-color-scheme.
   =================================================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

/* ── Design tokens (light) ───────────────────────────────────────── */
.aai-chatbot-root {
  --aai-bg:             #f8efe4;
  --aai-bg-header:      #eedecf;
  --aai-bubble-bot:     #ffffff;
  --aai-bubble-user:    #dfc99e;
  --aai-text:           #241510;
  --aai-text-muted:     #6e5440;
  --aai-accent:         #a87020;
  --aai-accent-dark:    #865614;
  --aai-accent-text:    #ffffff;
  --aai-border:         rgba(120, 80, 30, 0.32);
  --aai-shadow:         0 20px 60px rgba(80, 40, 0, 0.22), 0 4px 16px rgba(80, 40, 0, 0.10);
  --aai-bubble-shadow:  0 2px 10px rgba(80, 40, 0, 0.10);
  --aai-input-bg:       #ffffff;
  --aai-input-border:   rgba(120, 80, 30, 0.42);
  --aai-sys-bg:         rgba(0, 0, 0, 0.07);
  --aai-sys-text:       #5c4030;

  /* layout */
  position: fixed;
  bottom: 24px;
  z-index: 999999;
  font-family: 'DM Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Design tokens (dark) — OS preference ────────────────────────── */
@media (prefers-color-scheme: dark) {
  .aai-chatbot-root:not(.aai-light) {
    --aai-bg:             #0f1219;
    --aai-bg-header:      #0d1017;
    --aai-bubble-bot:     #1c2133;
    --aai-bubble-user:    #252a3d;
    --aai-text:           #e8dcc8;
    --aai-text-muted:     #8a8a9a;
    --aai-accent:         #c9a84c;
    --aai-accent-dark:    #a88630;
    --aai-accent-text:    #0f1219;
    --aai-border:         rgba(200, 160, 70, 0.16);
    --aai-shadow:         0 20px 60px rgba(0, 0, 0, 0.60), 0 4px 16px rgba(0, 0, 0, 0.30);
    --aai-bubble-shadow:  0 2px 10px rgba(0, 0, 0, 0.32);
    --aai-input-bg:       rgba(255, 255, 255, 0.07);
    --aai-input-border:   rgba(200, 160, 70, 0.25);
    --aai-sys-bg:         rgba(255, 255, 255, 0.06);
    --aai-sys-text:       #9a8a7a;
  }
}

/* ── Design tokens (dark) — manual toggle override ───────────────── */
.aai-chatbot-root.aai-dark {
  --aai-bg:             #0f1219;
  --aai-bg-header:      #0d1017;
  --aai-bubble-bot:     #1c2133;
  --aai-bubble-user:    #252a3d;
  --aai-text:           #e8dcc8;
  --aai-text-muted:     #8a8a9a;
  --aai-accent:         #c9a84c;
  --aai-accent-dark:    #a88630;
  --aai-accent-text:    #0f1219;
  --aai-border:         rgba(200, 160, 70, 0.16);
  --aai-shadow:         0 20px 60px rgba(0, 0, 0, 0.60), 0 4px 16px rgba(0, 0, 0, 0.30);
  --aai-bubble-shadow:  0 2px 10px rgba(0, 0, 0, 0.32);
  --aai-input-bg:       rgba(255, 255, 255, 0.07);
  --aai-input-border:   rgba(200, 160, 70, 0.25);
  --aai-sys-bg:         rgba(255, 255, 255, 0.06);
  --aai-sys-text:       #9a8a7a;
}

/* ── Design tokens (light) — manual toggle override ─────────────── */
.aai-chatbot-root.aai-light {
  --aai-bg:             #f8efe4;
  --aai-bg-header:      #eedecf;
  --aai-bubble-bot:     #ffffff;
  --aai-bubble-user:    #dfc99e;
  --aai-text:           #241510;
  --aai-text-muted:     #6e5440;
  --aai-accent:         #a87020;
  --aai-accent-dark:    #865614;
  --aai-accent-text:    #ffffff;
  --aai-border:         rgba(120, 80, 30, 0.32);
  --aai-shadow:         0 20px 60px rgba(80, 40, 0, 0.22), 0 4px 16px rgba(80, 40, 0, 0.10);
  --aai-bubble-shadow:  0 2px 10px rgba(80, 40, 0, 0.10);
  --aai-input-bg:       #ffffff;
  --aai-input-border:   rgba(120, 80, 30, 0.42);
  --aai-sys-bg:         rgba(0, 0, 0, 0.07);
  --aai-sys-text:       #5c4030;
}

/* ── Positioning helpers ─────────────────────────────────────────── */
.aai-chatbot-right { right: 24px; align-items: flex-end; }
.aai-chatbot-left  { left:  24px; align-items: flex-start; }

/* ── Launch bubble ───────────────────────────────────────────────── */
.aai-chatbot-bubble {
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--aai-accent);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.24);
  transition: transform 0.18s, box-shadow 0.18s;
}

.aai-chatbot-bubble:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.30);
}

.aai-chatbot-icon {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* ── Panel ───────────────────────────────────────────────────────── */
.aai-chatbot-panel {
  display: none;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 100px);
  background: var(--aai-bg);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--aai-shadow);
  border: 1px solid var(--aai-border);
  transform-origin: bottom right;
}

/* ── Panel open / close animations ──────────────────────────────── */
@keyframes aai-panel-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes aai-panel-out {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
}

.aai-chatbot-open .aai-chatbot-panel {
  display: flex;
  animation: aai-panel-in 0.30s cubic-bezier(0.34, 1.18, 0.64, 1) both;
}

.aai-chatbot-panel.aai-panel-closing {
  display: flex !important;
  animation: aai-panel-out 0.18s cubic-bezier(0.4, 0, 1, 1) both;
}

/* ── Header ──────────────────────────────────────────────────────── */
.aai-chatbot-header {
  padding: 13px 12px 13px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--aai-bg-header);
  border-bottom: 1px solid var(--aai-border);
  color: var(--aai-text);
  font-weight: 600;
  flex-shrink: 0;
}

/* Left side: avatar + title */
.aai-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.aai-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--aai-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.aai-header-avatar svg {
  width: 22px;
  height: 22px;
}

.aai-header-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--aai-text);
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Right side: action buttons */
.aai-chatbot-header-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

/* Theme toggle (sun / moon) */
.aai-theme-toggle {
  border: none;
  background: transparent;
  color: var(--aai-text-muted);
  cursor: pointer;
  padding: 5px 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}

.aai-theme-toggle:hover {
  color: var(--aai-accent);
  background: var(--aai-sys-bg);
}

/* Minimise ✕ */
.aai-chatbot-close {
  border: none;
  background: transparent;
  color: var(--aai-text-muted);
  font-size: 15px;
  cursor: pointer;
  line-height: 1;
  padding: 5px 6px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}

.aai-chatbot-close:hover {
  color: var(--aai-text);
  background: var(--aai-sys-bg);
}

/* "Close conversation" — ghost pill */
.aai-chatbot-hdr-btn {
  border: 1px solid var(--aai-border);
  background: transparent;
  color: var(--aai-text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 999px;
  line-height: 1.5;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.aai-chatbot-hdr-btn:hover:not(:disabled) {
  background: var(--aai-sys-bg);
  border-color: var(--aai-accent);
  color: var(--aai-text);
}

.aai-chatbot-hdr-btn:disabled {
  opacity: 0.40;
  cursor: not-allowed;
}

/* "End Session" — amber/gold filled pill */
.aai-chatbot-hdr-btn-danger {
  background: var(--aai-accent);
  border-color: var(--aai-accent);
  color: var(--aai-accent-text);
  display: flex;
  align-items: center;
  gap: 5px;
}

.aai-chatbot-hdr-btn-danger:hover:not(:disabled) {
  background: var(--aai-accent-dark);
  border-color: var(--aai-accent-dark);
  color: #ffffff;
}

.aai-hdr-btn-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* ── Reopen banner ───────────────────────────────────────────────── */
.aai-reopen-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(196, 154, 60, 0.10);
  border-top: 1px solid var(--aai-border);
  border-bottom: 1px solid var(--aai-border);
  flex-shrink: 0;
}

.aai-reopen-banner-text {
  flex: 1;
  font-size: 12px;
  color: var(--aai-text-muted);
  line-height: 1.35;
}

.aai-reopen-btn {
  flex-shrink: 0;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: var(--aai-accent);
  color: var(--aai-accent-text);
  white-space: nowrap;
  transition: background 0.15s, opacity 0.15s;
}

.aai-reopen-btn:hover:not(:disabled) { background: var(--aai-accent-dark); }
.aai-reopen-btn:disabled { opacity: 0.65; cursor: not-allowed; }

/* ── Session-expired banner ──────────────────────────────────────── */
.aai-expired-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(200, 60, 60, 0.08);
  border-top: 1px solid rgba(200, 60, 60, 0.22);
  border-bottom: 1px solid rgba(200, 60, 60, 0.22);
  flex-shrink: 0;
}

.aai-expired-icon { font-size: 14px; flex-shrink: 0; line-height: 1; }

.aai-expired-text {
  flex: 1;
  font-size: 12px;
  color: var(--aai-text-muted);
  line-height: 1.35;
}

.aai-restart-btn {
  flex-shrink: 0;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: #dc2626;
  color: #ffffff;
  white-space: nowrap;
  transition: background 0.15s, opacity 0.15s;
}

.aai-restart-btn:hover:not(:disabled) { background: #b91c1c; }
.aai-restart-btn:disabled { opacity: 0.65; cursor: not-allowed; }

/* ── Messages area ───────────────────────────────────────────────── */
.aai-chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 8px;
  background: var(--aai-bg);
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
}

.aai-chatbot-messages::-webkit-scrollbar { width: 4px; }
.aai-chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(120, 80, 20, 0.18);
  border-radius: 4px;
}

/* ── Message bubbles ─────────────────────────────────────────────── */
.aai-chatbot-message {
  max-width: 82%;
  margin: 0 0 10px;
  padding: 10px 14px;
  border-radius: 18px;
  line-height: 1.50;
  font-size: 14px;
  white-space: pre-wrap;
  color: var(--aai-text);
  position: relative;
}

.aai-chatbot-message-assistant {
  align-self: flex-start;
  background: var(--aai-bubble-bot);
  border-bottom-left-radius: 4px;
  box-shadow: var(--aai-bubble-shadow);
}

.aai-chatbot-message-visitor {
  align-self: flex-end;
  background: var(--aai-bubble-user);
  border-bottom-right-radius: 4px;
  box-shadow: var(--aai-bubble-shadow);
}

/* Agent badge — shown beneath human-agent bubbles */
.aai-agent-badge {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--aai-accent);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-top: 5px;
  padding-left: 1px;
}

/* ── System / notification messages ─────────────────────────────── */
.aai-chatbot-message-system {
  align-self: center;
  max-width: 90%;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
  background: var(--aai-sys-bg);
  color: var(--aai-sys-text);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  border-radius: 20px;
  padding: 5px 13px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.aai-sys-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  opacity: 0.75;
}

/* info — agent joined, request sent */
.aai-chatbot-message-system.aai-sys-info {
  background: rgba(80, 100, 200, 0.12);
  color: #3a4a9a;
}

@media (prefers-color-scheme: dark) {
  .aai-chatbot-root:not(.aai-light) .aai-chatbot-message-system.aai-sys-info {
    background: rgba(100, 120, 220, 0.14);
    color: #8898d8;
  }
}
.aai-chatbot-root.aai-dark .aai-chatbot-message-system.aai-sys-info {
  background: rgba(100, 120, 220, 0.14);
  color: #8898d8;
}

/* success — reopened, returned to AI */
.aai-chatbot-message-system.aai-sys-success {
  background: rgba(30, 140, 70, 0.12);
  color: #1a6030;
}

@media (prefers-color-scheme: dark) {
  .aai-chatbot-root:not(.aai-light) .aai-chatbot-message-system.aai-sys-success {
    background: rgba(40, 160, 80, 0.14);
    color: #60c880;
  }
}
.aai-chatbot-root.aai-dark .aai-chatbot-message-system.aai-sys-success {
  background: rgba(40, 160, 80, 0.14);
  color: #60c880;
}

/* warning — closed, ended, expired */
.aai-chatbot-message-system.aai-sys-warning {
  background: rgba(160, 110, 20, 0.13);
  color: #6a3e08;
}

@media (prefers-color-scheme: dark) {
  .aai-chatbot-root:not(.aai-light) .aai-chatbot-message-system.aai-sys-warning {
    background: rgba(196, 154, 60, 0.14);
    color: #c09040;
  }
}
.aai-chatbot-root.aai-dark .aai-chatbot-message-system.aai-sys-warning {
  background: rgba(196, 154, 60, 0.14);
  color: #c09040;
}

/* error — unable to reach, something went wrong */
.aai-chatbot-message-system.aai-sys-error {
  background: rgba(180, 40, 40, 0.12);
  color: #7a1010;
}

@media (prefers-color-scheme: dark) {
  .aai-chatbot-root:not(.aai-light) .aai-chatbot-message-system.aai-sys-error {
    background: rgba(200, 50, 50, 0.14);
    color: #e07070;
  }
}
.aai-chatbot-root.aai-dark .aai-chatbot-message-system.aai-sys-error {
  background: rgba(200, 50, 50, 0.14);
  color: #e07070;
}

/* ── Agent bar ("Talk to an Agent") ─────────────────────────────── */
.aai-agent-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  background: transparent;
  border-top: 1px solid var(--aai-border);
  flex-shrink: 0;
}

/* icon + label hidden — person icon is rendered via ::before on button */
.aai-agent-bar-icon,
.aai-agent-bar-label {
  display: none;
}

.aai-agent-btn {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  background: var(--aai-accent);
  color: var(--aai-accent-text);
  white-space: nowrap;
  transition: background 0.18s, opacity 0.18s, transform 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  letter-spacing: 0.1px;
  font-family: inherit;
}

.aai-agent-btn::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='12' cy='7' r='4'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

@media (prefers-color-scheme: dark) {
  .aai-chatbot-root:not(.aai-light) .aai-agent-btn::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230f1219' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='12' cy='7' r='4'/%3E%3C/svg%3E");
  }
}
.aai-chatbot-root.aai-dark .aai-agent-btn::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230f1219' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='12' cy='7' r='4'/%3E%3C/svg%3E");
}

.aai-agent-btn:hover:not(:disabled) {
  background: var(--aai-accent-dark);
  transform: translateY(-1px);
}

.aai-agent-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.aai-agent-btn-done {
  background: #16a34a !important;
  opacity: 1 !important;
}

.aai-agent-btn-done::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") !important;
}

/* ── Composer ────────────────────────────────────────────────────── */
.aai-chatbot-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 14px;
  background: var(--aai-bg);
  border-top: 1px solid var(--aai-border);
  flex-shrink: 0;
}

.aai-chatbot-composer input {
  flex: 1;
  border: 1px solid var(--aai-input-border);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 14px;
  background: var(--aai-input-bg);
  color: var(--aai-text);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
  min-width: 0;
}

.aai-chatbot-composer input::placeholder {
  color: var(--aai-text-muted);
  opacity: 1;
}

.aai-chatbot-composer input:focus {
  border-color: var(--aai-accent);
}

.aai-chatbot-composer button {
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  background: var(--aai-accent);
  color: var(--aai-accent-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.12s;
  padding: 0;
}

.aai-chatbot-composer button:hover:not(:disabled) {
  background: var(--aai-accent-dark);
  transform: translateY(-1px);
}

.aai-chatbot-composer button:disabled,
.aai-chatbot-composer input:disabled {
  opacity: 0.50;
  cursor: not-allowed;
}

.aai-chatbot-composer button:disabled {
  transform: none;
}

/* ── Escalation inline prompt ────────────────────────────────────── */
.aai-chatbot-escalation {
  display: flex;
  gap: 8px;
  margin: 6px 0 10px;
  flex-wrap: wrap;
}

.aai-btn {
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
  background: var(--aai-accent);
  color: var(--aai-accent-text);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: background 0.15s;
}

.aai-btn:hover { background: var(--aai-accent-dark); }

.aai-btn-muted {
  background: var(--aai-sys-bg);
  color: var(--aai-text-muted);
  border: 1px solid var(--aai-border);
}

.aai-btn-muted:hover {
  background: var(--aai-input-border);
  color: var(--aai-text);
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .aai-chatbot-root,
  .aai-chatbot-left,
  .aai-chatbot-right {
    right: 14px;
    left: auto;
    bottom: max(14px, env(safe-area-inset-bottom));
    align-items: flex-end;
  }

  .aai-chatbot-panel {
    width: min(360px, calc(100vw - 16px));
    max-height: calc(100vh - 90px);
  }
}
