/* ============================================================
 * AI Assist — Chatbot widget v2.0
 *
 * Intercom-inspired visual language. Light default + dark via
 * [data-theme="dark"] attribute on the host element.
 *
 * Class prefix kept as .ai-asst-wgt- for JS compatibility.
 *
 * @package AiAssist
 */

/* ============== DESIGN TOKENS — LIGHT ============== */
:host, #aiassist-widget {
  --aiassist-primary:        #0057FF;
  --aiassist-primary-dark:   #0044CC;
  --aiassist-primary-light:  #E6EEFF;

  --aiassist-bg:             #FFFFFF;
  --aiassist-bg-elev:        #FFFFFF;
  --aiassist-bg-subtle:      #F6F8FB;
  --aiassist-bg-hover:       #EEF1F6;
  --aiassist-bg-bot-bubble:  #F1F3F7;
  --aiassist-bg-user-bubble: var(--aiassist-primary);

  --aiassist-header-bg:      linear-gradient(135deg, #0057FF 0%, #6B7CFF 100%);
  --aiassist-header-text:    #FFFFFF;
  --aiassist-header-sub:     rgba(255,255,255,0.78);

  --aiassist-text:           #0A0E1A;
  --aiassist-text-secondary: #4A5468;
  --aiassist-text-muted:     #7E8AA0;
  --aiassist-text-on-user:   #FFFFFF;
  --aiassist-text-on-bot:    #0A0E1A;

  --aiassist-border:         #E5E8EE;
  --aiassist-border-strong:  #D5DAE2;

  --aiassist-shadow-launcher: 0 4px 14px rgba(10, 14, 26, 0.18), 0 1px 3px rgba(10, 14, 26, 0.08);
  --aiassist-shadow-panel:    0 20px 50px rgba(10, 14, 26, 0.18), 0 8px 16px rgba(10, 14, 26, 0.08);
  --aiassist-shadow-bubble:   0 6px 20px rgba(10, 14, 26, 0.14), 0 2px 6px rgba(10, 14, 26, 0.06);
  --aiassist-shadow-chip:     0 3px 10px rgba(10, 14, 26, 0.12);

  --aiassist-radius-bubble:   18px;
  --aiassist-radius-panel:    16px;
  --aiassist-radius-card:     12px;
  --aiassist-radius-input:    24px;
  --aiassist-radius-chip:     20px;

  --aiassist-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --aiassist-ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============== DESIGN TOKENS — DARK ============== */
:host([data-theme="dark"]),
#aiassist-widget[data-theme="dark"] {
  --aiassist-bg:             #1A1D26;
  --aiassist-bg-elev:        #232734;
  --aiassist-bg-subtle:      #1F232E;
  --aiassist-bg-hover:       #2A2F3C;
  --aiassist-bg-bot-bubble:  #2A2F3C;

  --aiassist-text:           #F2F4F8;
  --aiassist-text-secondary: #B5BDCC;
  --aiassist-text-muted:     #8189A0;
  --aiassist-text-on-bot:    #F2F4F8;

  --aiassist-border:         #2E3340;
  --aiassist-border-strong:  #3B4151;

  --aiassist-shadow-launcher: 0 4px 14px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.2);
  --aiassist-shadow-panel:    0 20px 50px rgba(0, 0, 0, 0.5), 0 8px 16px rgba(0, 0, 0, 0.25);
  --aiassist-shadow-bubble:   0 6px 20px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* ============== RESET ============== */
:host *,
:host *::before,
:host *::after,
#aiassist-widget *,
#aiassist-widget *::before,
#aiassist-widget *::after {
  box-sizing: border-box;
}

/* The browser's user-agent stylesheet sets [hidden] { display: none }, but
 * many of our component rules below set display:flex/grid/block which take
 * precedence due to specificity. Force [hidden] to actually hide everywhere
 * inside the widget root so HTML's hidden attribute behaves predictably.
 * Without this, the emoji tray, prechat form, actions bar, email form, and
 * launcher badge would all be visible on load even though the JS sets them
 * hidden by default. */
:host [hidden],
#aiassist-widget [hidden] {
  display: none !important;
}

/* ============== LAUNCHER ============== */
.ai-asst-wgt-launcher {
  position: fixed;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--aiassist-primary);
  color: #FFFFFF;
  cursor: pointer;
  z-index: 99998;
  box-shadow: var(--aiassist-shadow-launcher);
  transition: transform 0.2s var(--aiassist-ease), box-shadow 0.2s var(--aiassist-ease), background 0.2s var(--aiassist-ease);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--aiassist-font);
  padding: 0;
}
.ai-asst-wgt-launcher.ai-asst-wgt-right { right: 24px; }
.ai-asst-wgt-launcher.ai-asst-wgt-left  { left:  24px; }
.ai-asst-wgt-launcher:hover {
  transform: scale(1.06);
  background: var(--aiassist-primary-dark);
  box-shadow: 0 6px 20px rgba(10, 14, 26, 0.24), 0 2px 6px rgba(10, 14, 26, 0.12);
}
.ai-asst-wgt-launcher:active { transform: scale(0.98); }
.ai-asst-wgt-launcher svg { width: 26px; height: 26px; fill: currentColor; transition: opacity 0.2s var(--aiassist-ease); }

.ai-asst-wgt-launcher .ai-asst-wgt-icon-close { display: none; }
.ai-asst-wgt-launcher.is-open .ai-asst-wgt-icon-chat { display: none; }
.ai-asst-wgt-launcher.is-open .ai-asst-wgt-icon-close { display: block; }

.ai-asst-wgt-launcher-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #FF3B30;
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--aiassist-font);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--aiassist-bg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.18);
}

.ai-asst-wgt-launcher-alert { animation: ai-asst-wgt-pulse 1.8s ease-in-out infinite; }
@keyframes ai-asst-wgt-pulse {
  0%, 100% { box-shadow: var(--aiassist-shadow-launcher), 0 0 0 0 rgba(0, 87, 255, 0.35); }
  50%      { box-shadow: var(--aiassist-shadow-launcher), 0 0 0 10px rgba(0, 87, 255, 0); }
}

/* ============== PANEL ============== */
.ai-asst-wgt-panel {
  position: fixed;
  bottom: 96px;
  width: 380px;
  height: 620px;
  max-height: calc(100vh - 120px);
  background: var(--aiassist-bg);
  border-radius: var(--aiassist-radius-panel);
  box-shadow: var(--aiassist-shadow-panel);
  z-index: 99999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--aiassist-font);
  color: var(--aiassist-text);
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  transition: transform 0.28s var(--aiassist-ease), opacity 0.22s var(--aiassist-ease);
}
.ai-asst-wgt-panel.ai-asst-wgt-right { right: 24px; transform-origin: bottom right; }
.ai-asst-wgt-panel.ai-asst-wgt-left  { left:  24px; transform-origin: bottom left;  }
.ai-asst-wgt-panel.ai-asst-wgt-open {
  display: flex;
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* ============== HEADER ============== */
.ai-asst-wgt-header {
  padding: 18px 16px 16px;
  background: var(--aiassist-header-bg);
  color: var(--aiassist-header-text);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.ai-asst-wgt-header::after {
  content: '';
  position: absolute;
  top: -40%;
  right: -10%;
  width: 60%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.10) 0%, transparent 60%);
  pointer-events: none;
}
.ai-asst-wgt-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  background: rgba(255,255,255,0.20);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-weight: 700;
  font-size: 16px;
  position: relative;
  z-index: 1;
  overflow: hidden;
}
.ai-asst-wgt-header-avatar img {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
}
.ai-asst-wgt-header-text { flex: 1; min-width: 0; position: relative; z-index: 1; }
.ai-asst-wgt-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--aiassist-header-text);
}
.ai-asst-wgt-sub {
  font-size: 12px;
  color: var(--aiassist-header-sub);
  line-height: 1.4;
  margin-top: 2px;
}

.ai-asst-wgt-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
  z-index: 1;
}
.ai-asst-wgt-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--aiassist-header-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s var(--aiassist-ease);
  padding: 0;
  font-family: inherit;
}
.ai-asst-wgt-header-btn:hover { background: rgba(255,255,255,0.16); }
.ai-asst-wgt-header-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-asst-wgt-header-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* ============== 3-DOT MENU ============== */
.ai-asst-wgt-menu {
  position: absolute;
  top: 60px;
  right: 12px;
  background: var(--aiassist-bg-elev);
  border: 1px solid var(--aiassist-border);
  border-radius: var(--aiassist-radius-card);
  box-shadow: var(--aiassist-shadow-bubble);
  z-index: 10;
  min-width: 210px;
  padding: 6px;
  display: none;
  animation: ai-asst-wgt-menu-in 0.16s var(--aiassist-ease);
}
.ai-asst-wgt-menu.is-open { display: block; }
@keyframes ai-asst-wgt-menu-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ai-asst-wgt-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--aiassist-text);
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.ai-asst-wgt-menu-item:hover { background: var(--aiassist-bg-hover); }
.ai-asst-wgt-menu-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.ai-asst-wgt-menu-item svg { width: 16px; height: 16px; fill: currentColor; opacity: 0.7; }
.ai-asst-wgt-menu-item.is-danger { color: #DC2626; }
.ai-asst-wgt-menu-item.is-danger svg { fill: #DC2626; opacity: 1; }
.ai-asst-wgt-menu-divider { height: 1px; background: var(--aiassist-border); margin: 4px 0; }

/* ============== MESSAGES ============== */
.ai-asst-wgt-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--aiassist-bg);
  scroll-behavior: smooth;
}
.ai-asst-wgt-messages::-webkit-scrollbar { width: 6px; }
.ai-asst-wgt-messages::-webkit-scrollbar-track { background: transparent; }
.ai-asst-wgt-messages::-webkit-scrollbar-thumb { background: var(--aiassist-border-strong); border-radius: 3px; }
.ai-asst-wgt-messages::-webkit-scrollbar-thumb:hover { background: var(--aiassist-text-muted); }

.ai-asst-wgt-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: ai-asst-wgt-msg-in 0.3s var(--aiassist-ease);
}
@keyframes ai-asst-wgt-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-asst-wgt-msg-bubble {
  padding: 11px 16px;
  border-radius: var(--aiassist-radius-bubble);
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.ai-asst-wgt-msg-user {
  align-self: flex-end;
  align-items: flex-end;
}
.ai-asst-wgt-msg-user .ai-asst-wgt-msg-bubble {
  background: var(--aiassist-bg-user-bubble);
  color: var(--aiassist-text-on-user);
  border-bottom-right-radius: 6px;
}

.ai-asst-wgt-msg-bot,
.ai-asst-wgt-msg-admin {
  align-self: flex-start;
  align-items: flex-start;
  position: relative;
  padding-left: 40px;
}
.ai-asst-wgt-msg-bot .ai-asst-wgt-msg-bubble,
.ai-asst-wgt-msg-admin .ai-asst-wgt-msg-bubble {
  background: var(--aiassist-bg-bot-bubble);
  color: var(--aiassist-text-on-bot);
  border-bottom-left-radius: 6px;
}

.ai-asst-wgt-msg-avatar {
  position: absolute;
  left: 0;
  top: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--aiassist-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--aiassist-primary);
  font-weight: 700;
  font-size: 13px;
  border: 2px solid var(--aiassist-bg);
}

.ai-asst-wgt-msg-meta {
  font-size: 11px;
  color: var(--aiassist-text-muted);
  margin-top: 4px;
  padding-left: 4px;
  line-height: 1.3;
}
.ai-asst-wgt-msg-meta strong { color: var(--aiassist-text-secondary); font-weight: 600; }

.ai-asst-wgt-msg-system {
  align-self: center;
  text-align: center;
  max-width: 100%;
  font-size: 12px;
  color: var(--aiassist-text-muted);
  font-style: italic;
  padding: 6px 12px;
}
.ai-asst-wgt-msg-system .ai-asst-wgt-msg-bubble { background: transparent; padding: 0; border-radius: 0; }

.ai-asst-wgt-msg-error { align-self: center; max-width: 100%; }
.ai-asst-wgt-msg-error .ai-asst-wgt-msg-bubble {
  background: #FEE2E2;
  color: #991B1B;
  border: 1px solid #FECACA;
  font-size: 13px;
  text-align: center;
}

.ai-asst-wgt-typing {
  align-self: flex-start;
  padding: 12px 18px;
  background: var(--aiassist-bg-bot-bubble);
  border-radius: var(--aiassist-radius-bubble);
  border-bottom-left-radius: 6px;
  display: flex;
  gap: 4px;
  margin-left: 40px;
}
.ai-asst-wgt-typing span,
.ai-asst-wgt-hydrating span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--aiassist-text-muted);
  animation: ai-asst-wgt-blink 1.4s infinite ease-in-out;
}
.ai-asst-wgt-typing span:nth-child(2),
.ai-asst-wgt-hydrating span:nth-child(2) { animation-delay: 0.2s; }
.ai-asst-wgt-typing span:nth-child(3),
.ai-asst-wgt-hydrating span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-asst-wgt-blink {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30%           { opacity: 1;   transform: scale(1);   }
}
.ai-asst-wgt-hydrating {
  display: flex; gap: 4px; padding: 18px; justify-content: center;
}

/* ============== KB / OFFER / FEEDBACK ============== */
.ai-asst-wgt-kb {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--aiassist-bg-subtle);
  border-radius: var(--aiassist-radius-card);
  font-size: 12px;
  border: 1px solid var(--aiassist-border);
}
.ai-asst-wgt-kb small {
  color: var(--aiassist-text-muted);
  font-size: 10px;
  display: block;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.ai-asst-wgt-kb a {
  display: block;
  color: var(--aiassist-primary);
  text-decoration: none;
  padding: 4px 0;
  font-size: 13px;
}
.ai-asst-wgt-kb a:hover { text-decoration: underline; }

.ai-asst-wgt-offer { margin-top: 10px; }
.ai-asst-wgt-offer-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  background: var(--aiassist-primary);
  color: #FFFFFF;
  border: none;
  border-radius: var(--aiassist-radius-chip);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s var(--aiassist-ease), transform 0.1s var(--aiassist-ease);
}
.ai-asst-wgt-offer-btn:hover { background: var(--aiassist-primary-dark); }
.ai-asst-wgt-offer-btn:active { transform: scale(0.98); }
.ai-asst-wgt-offer-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* v2.2.23: "play reply aloud" button (replaces the old star rating). */
.ai-asst-wgt-tts {
  display: flex;
  margin-top: 6px;
}
.ai-asst-wgt-tts-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 1px solid var(--aiassist-border-strong);
  color: var(--aiassist-text-muted);
  border-radius: 100px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 11px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.ai-asst-wgt-tts-btn:hover {
  color: var(--aiassist-primary);
  border-color: var(--aiassist-primary);
}
.ai-asst-wgt-tts-btn.ai-asst-wgt-tts-on {
  background: var(--aiassist-primary);
  border-color: var(--aiassist-primary);
  color: #fff;
}
.ai-asst-wgt-tts-btn svg { flex-shrink: 0; }

/* ============== ATTACHMENTS ============== */
.ai-asst-wgt-attach { margin-top: 4px; }
.ai-asst-wgt-attach-img {
  display: block; max-width: 100%; max-height: 280px;
  border-radius: var(--aiassist-radius-card); cursor: pointer;
}
.ai-asst-wgt-attach-file {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--aiassist-border);
  border-radius: var(--aiassist-radius-card);
  font-size: 12px; text-decoration: none; color: var(--aiassist-text);
  max-width: 100%;
}
.ai-asst-wgt-msg-user .ai-asst-wgt-attach-file {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.32);
  color: #FFFFFF;
}
.ai-asst-wgt-attach-name {
  font-weight: 500; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ai-asst-wgt-attach-size { opacity: 0.7; font-size: 11px; }

.ai-asst-wgt-attach-staging:empty { display: none; }
.ai-asst-wgt-attach-staging {
  padding: 8px 16px;
  border-top: 1px solid var(--aiassist-border);
  background: var(--aiassist-bg-subtle);
}
.ai-asst-wgt-stage-item { font-size: 12px; color: var(--aiassist-text-secondary); }
.ai-asst-wgt-stage-name { margin-bottom: 4px; }
.ai-asst-wgt-stage-bar { height: 4px; background: var(--aiassist-border); border-radius: 2px; overflow: hidden; }
.ai-asst-wgt-stage-fill { height: 100%; background: var(--aiassist-primary); transition: width 0.2s ease; }

/* ============== COMPOSER ============== */
.ai-asst-wgt-footer {
  border-top: 1px solid var(--aiassist-border);
  padding: 12px 16px 14px;
  background: var(--aiassist-bg);
  flex-shrink: 0;
}
.ai-asst-wgt-input-wrap { display: flex; align-items: flex-end; gap: 8px; }
.ai-asst-wgt-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  font-family: inherit;
  color: var(--aiassist-text);
  resize: none;
  padding: 6px 0;
  max-height: 100px;
  line-height: 1.5;
}
.ai-asst-wgt-input::placeholder { color: var(--aiassist-text-muted); }
.ai-asst-wgt-input:disabled { opacity: 0.6; cursor: not-allowed; }

.ai-asst-wgt-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--aiassist-primary);
  color: #FFFFFF;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  padding: 0;
}
.ai-asst-wgt-send:hover:not(:disabled) { background: var(--aiassist-primary-dark); }
.ai-asst-wgt-send:active:not(:disabled) { transform: scale(0.95); }
.ai-asst-wgt-send:disabled { background: var(--aiassist-border-strong); cursor: not-allowed; }
.ai-asst-wgt-send svg { width: 16px; height: 16px; fill: currentColor; transform: translateX(1px); }

.ai-asst-wgt-tools {
  display: flex; align-items: center; gap: 4px; margin-top: 6px;
}
.ai-asst-wgt-icon-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: transparent; border: none;
  color: var(--aiassist-text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.15s, color 0.15s;
  padding: 0; font-family: inherit;
}
.ai-asst-wgt-icon-btn:hover {
  background: var(--aiassist-bg-hover);
  color: var(--aiassist-text-secondary);
}
.ai-asst-wgt-icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ai-asst-wgt-icon-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* ============== EMOJI TRAY ============== */
.ai-asst-wgt-emoji-tray {
  position: absolute;
  bottom: 70px;
  left: 14px;
  right: 14px;
  background: var(--aiassist-bg-elev);
  border: 1px solid var(--aiassist-border);
  border-radius: var(--aiassist-radius-card);
  box-shadow: var(--aiassist-shadow-bubble);
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 180px;
  overflow-y: auto;
  z-index: 5;
}
.ai-asst-wgt-emoji {
  background: transparent; border: none; cursor: pointer;
  font-size: 20px; padding: 4px; border-radius: 6px;
  transition: background 0.1s; line-height: 1;
}
.ai-asst-wgt-emoji:hover { background: var(--aiassist-bg-hover); }

/* ============== VOICE RECORDER + AUDIO PLAYER (v2.1) ============== */
.ai-asst-wgt-voice-recorder {
  border-top: 1px solid var(--aiassist-border);
  background: var(--aiassist-bg-subtle);
  padding: 10px 14px;
  flex-shrink: 0;
}
.ai-asst-wgt-voice-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--aiassist-font);
}
.ai-asst-wgt-voice-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #E53935;
  animation: ai-asst-wgt-rec-pulse 1.4s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes ai-asst-wgt-rec-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}
.ai-asst-wgt-voice-elapsed {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--aiassist-text);
  font-weight: 600;
}
.ai-asst-wgt-voice-hint {
  font-size: 12px;
  color: var(--aiassist-text-muted);
  flex: 1;
  min-width: 0;
}
/* v2.2.22: transient voice notice (denied mic, no device, etc.).
   A soft amber strip — informative, not an alarm. Replaces the old
   behaviour of dumping red error bubbles into the chat transcript. */
.ai-asst-wgt-voice-notice {
  padding: 2px 0;
}
.ai-asst-wgt-voice-notice .ai-asst-wgt-voice-hint {
  color: #8a6d00;
  line-height: 1.45;
}

/* Audio attachment player */
.ai-asst-wgt-attach-audio {
  width: 100%;
  max-width: 260px;
  height: 36px;
  border-radius: 24px;
  outline: none;
}
/* v2.2.22: voice-note row — small label above the player so a voice
   note reads clearly as audio even alongside its transcript text. */
.ai-asst-wgt-attach-voice {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}
.ai-asst-wgt-attach-voice-label {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.65;
  display: flex;
  align-items: center;
}

/* GIF tray (placeholder — populated by GIF picker in next turn) */
.ai-asst-wgt-gif-tray {
  position: absolute;
  bottom: 70px;
  left: 14px;
  right: 14px;
  background: var(--aiassist-bg-elev);
  border: 1px solid var(--aiassist-border);
  border-radius: var(--aiassist-radius-card);
  box-shadow: var(--aiassist-shadow-bubble);
  padding: 10px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 5;
}
.ai-asst-wgt-gif-search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--aiassist-border-strong);
  border-radius: 20px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  margin-bottom: 8px;
  color: var(--aiassist-text);
  background: var(--aiassist-bg);
}
.ai-asst-wgt-gif-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.ai-asst-wgt-gif-item {
  width: 100%;
  border: none;
  background: var(--aiassist-bg-subtle);
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 16/9;
}
.ai-asst-wgt-gif-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ai-asst-wgt-gif-item:hover { transform: scale(1.02); }

/* ============== POWERED-BY FOOTER ============== */
.ai-asst-wgt-disclaimer {
  text-align: center;
  padding: 8px 12px 10px;
  font-size: 10px;
  color: var(--aiassist-text-muted);
  background: var(--aiassist-bg);
  border-top: 1px solid var(--aiassist-border);
  flex-shrink: 0;
}
.ai-asst-wgt-disclaimer a { color: var(--aiassist-text-secondary); text-decoration: none; }
.ai-asst-wgt-disclaimer strong { color: var(--aiassist-text-secondary); font-weight: 600; }

/* ============== TRANSCRIPT ACTIONS ============== */
.ai-asst-wgt-actions-bar {
  display: flex; gap: 8px; padding: 10px 16px;
  background: var(--aiassist-bg-subtle);
  border-top: 1px solid var(--aiassist-border);
  flex-shrink: 0;
}
.ai-asst-wgt-mini-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; font-size: 12px;
  border-radius: 8px;
  border: 1px solid var(--aiassist-border-strong);
  background: var(--aiassist-bg);
  color: var(--aiassist-text-secondary);
  cursor: pointer; font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.ai-asst-wgt-mini-btn:hover {
  background: var(--aiassist-bg-hover);
  border-color: var(--aiassist-text-muted);
}
.ai-asst-wgt-mini-btn-primary {
  background: var(--aiassist-primary);
  border-color: var(--aiassist-primary);
  color: #FFFFFF;
}
.ai-asst-wgt-mini-btn-primary:hover {
  background: var(--aiassist-primary-dark);
  border-color: var(--aiassist-primary-dark);
}

.ai-asst-wgt-email-form {
  display: flex; gap: 6px; padding: 10px 16px;
  background: var(--aiassist-bg-subtle);
  border-top: 1px solid var(--aiassist-border);
  flex-shrink: 0;
}
.ai-asst-wgt-email-input {
  flex: 1; padding: 8px 12px; font-size: 13px;
  border: 1px solid var(--aiassist-border-strong);
  border-radius: 8px; font-family: inherit; outline: none;
  color: var(--aiassist-text); background: var(--aiassist-bg);
}
.ai-asst-wgt-email-input:focus { border-color: var(--aiassist-primary); }

/* ============== PRECHAT FORM ============== */
.ai-asst-wgt-prechat:empty { display: none; }
.ai-asst-wgt-prechat {
  padding: 18px 16px;
  background: var(--aiassist-bg);
  flex: 1; overflow-y: auto;
}
.ai-asst-wgt-prechat-card {
  background: var(--aiassist-bg-subtle);
  border: 1px solid var(--aiassist-border);
  border-radius: var(--aiassist-radius-card);
  padding: 16px;
}
.ai-asst-wgt-prechat-intro {
  font-size: 13px; color: var(--aiassist-text-secondary);
  margin-bottom: 14px; line-height: 1.5;
}
.ai-asst-wgt-prechat-fields { display: flex; flex-direction: column; gap: 12px; }
.ai-asst-wgt-prechat-field { display: flex; flex-direction: column; gap: 4px; }
.ai-asst-wgt-prechat-field span {
  font-size: 12px; font-weight: 500;
  color: var(--aiassist-text-secondary);
}
.ai-asst-wgt-prechat-field input {
  padding: 9px 12px; font-size: 13px;
  border: 1px solid var(--aiassist-border-strong);
  border-radius: 8px; outline: none; font-family: inherit;
  color: var(--aiassist-text); background: var(--aiassist-bg);
}
.ai-asst-wgt-prechat-field input:focus { border-color: var(--aiassist-primary); }
.ai-asst-wgt-prechat-submit {
  margin-top: 4px; padding: 10px 16px;
  background: var(--aiassist-primary); color: #FFFFFF;
  border: none; border-radius: var(--aiassist-radius-input);
  font-size: 14px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: background 0.15s;
}
.ai-asst-wgt-prechat-submit:hover { background: var(--aiassist-primary-dark); }
.ai-asst-wgt-prechat-error {
  margin-top: 10px; padding: 8px 12px;
  background: #FEE2E2; color: #991B1B;
  border-radius: 8px; font-size: 12px;
}

/* ============== ATTENTION BUBBLE (rich) ============== */
.ai-asst-wgt-bubble {
  position: fixed;
  bottom: 92px;
  max-width: 280px;
  background: var(--aiassist-bg-elev);
  color: var(--aiassist-text);
  font-family: var(--aiassist-font);
  padding: 14px 36px 14px 14px;
  border-radius: var(--aiassist-radius-card);
  box-shadow: var(--aiassist-shadow-bubble);
  cursor: pointer;
  z-index: 99997;
  display: flex;
  gap: 10px;
  animation: ai-asst-wgt-bubble-in 0.4s var(--aiassist-ease);
}
.ai-asst-wgt-bubble.ai-asst-wgt-right { right: 24px; }
.ai-asst-wgt-bubble.ai-asst-wgt-left  { left:  24px; }
.ai-asst-wgt-bubble-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: var(--aiassist-primary-light); color: var(--aiassist-primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; overflow: hidden;
}
.ai-asst-wgt-bubble-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ai-asst-wgt-bubble-body { flex: 1; min-width: 0; }
.ai-asst-wgt-bubble-title {
  font-size: 13px; font-weight: 600; margin-bottom: 2px;
  color: var(--aiassist-text);
}
.ai-asst-wgt-bubble-text {
  font-size: 13px; line-height: 1.4;
  color: var(--aiassist-text-secondary);
  white-space: normal; word-wrap: break-word;
}
.ai-asst-wgt-bubble-meta {
  font-size: 11px; color: var(--aiassist-text-muted); margin-top: 4px;
}
.ai-asst-wgt-bubble-close {
  position: absolute; top: 4px; right: 6px;
  width: 22px; height: 22px;
  background: transparent; border: 0; font-size: 16px; line-height: 1;
  color: var(--aiassist-text-muted); cursor: pointer; border-radius: 4px;
  padding: 0; font-family: inherit;
}
.ai-asst-wgt-bubble-close:hover {
  background: var(--aiassist-bg-hover); color: var(--aiassist-text);
}
@keyframes ai-asst-wgt-bubble-in {
  from { opacity: 0; transform: translateY(8px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============== QUICK-REPLY CHIPS (KB-derived) ============== */
.ai-asst-wgt-quickreplies {
  position: fixed;
  z-index: 99996;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 280px;
  pointer-events: none;
}
.ai-asst-wgt-quickreplies.ai-asst-wgt-right {
  right: 24px;
  align-items: flex-end;
}
.ai-asst-wgt-quickreplies.ai-asst-wgt-left {
  left: 24px;
  align-items: flex-start;
}
.ai-asst-wgt-chip {
  pointer-events: auto;
  background: var(--aiassist-bg-elev);
  color: var(--aiassist-text);
  border: 1px solid var(--aiassist-border);
  padding: 9px 14px;
  border-radius: var(--aiassist-radius-chip);
  font-size: 12.5px;
  font-family: var(--aiassist-font);
  cursor: pointer;
  box-shadow: var(--aiassist-shadow-chip);
  transition: transform 0.15s var(--aiassist-ease), background 0.15s var(--aiassist-ease);
  animation: ai-asst-wgt-chip-in 0.35s var(--aiassist-ease) both;
  text-align: left;
  line-height: 1.3;
  max-width: 100%;
}
.ai-asst-wgt-chip:nth-child(1) { animation-delay: 0s; }
.ai-asst-wgt-chip:nth-child(2) { animation-delay: 0.08s; }
.ai-asst-wgt-chip:nth-child(3) { animation-delay: 0.16s; }
.ai-asst-wgt-chip:nth-child(4) { animation-delay: 0.24s; }
.ai-asst-wgt-chip:hover {
  transform: translateY(-1px);
  background: var(--aiassist-bg-hover);
}
@keyframes ai-asst-wgt-chip-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============== MOBILE ============== */
@media (max-width: 480px) {
  .ai-asst-wgt-panel {
    width: calc(100vw - 16px);
    right: 8px !important;
    left: 8px !important;
    bottom: 76px;
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
  }
  .ai-asst-wgt-launcher.ai-asst-wgt-right { right: 16px; }
  .ai-asst-wgt-launcher.ai-asst-wgt-left  { left:  16px; }
  .ai-asst-wgt-bubble { display: none; }
  .ai-asst-wgt-quickreplies { display: none; }
  .ai-asst-wgt-msg { max-width: 90%; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-asst-wgt-panel,
  .ai-asst-wgt-msg,
  .ai-asst-wgt-chip,
  .ai-asst-wgt-bubble,
  .ai-asst-wgt-launcher,
  .ai-asst-wgt-typing span,
  .ai-asst-wgt-hydrating span,
  .ai-asst-wgt-launcher-alert {
    animation: none !important;
    transition: none !important;
  }
}
