/**
 * Aladdin Chat V2 Frontend Styles — Phase 4 (Frontend parity & UI upgrade)
 *
 * BUG #5 FIX: Unified Gold · Silver · Green design system tokens applied to
 * all Chat V2 components. Previously targeted ".aladdin-chatv2-mount" which
 * did not match the actual widget class ".cv2-widget". Now correctly scoped.
 *
 * @since 5.2.2
 */

/* Ensure design token variables are always available on the widget root,
   providing consistent Gold/Silver/Green brand palette regardless of
   whether the host WordPress theme defines these tokens. */
.cv2-widget,
.aladdin-plugin.cv2-widget {
  /* ── Official Brand Palette ── */
  --cv2-gold:          #C9A84C;
  --cv2-gold-light:    #E8C96A;
  --cv2-gold-dark:     #A8872A;
  --cv2-silver:        #A8B2C1;
  --cv2-silver-light:  #D4DAE3;
  --cv2-silver-dark:   #7A8799;
  --cv2-green:         #2E7D32;
  --cv2-green-light:   #4CAF50;
  --cv2-green-dark:    #1B5E20;

  /* ── Semantic ── */
  --cv2-bg:            #FDFCF7;
  --cv2-surface:       #FFFFFF;
  --cv2-surface-2:     #F8F6EF;
  --cv2-text:          #1A1A0F;
  --cv2-text-muted:    #6B7062;
  --cv2-border:        #E4DFC8;
  --cv2-accent:        var(--cv2-gold);
  --cv2-accent-2:      var(--cv2-green);
  --cv2-danger:        #B91C1C;
  --cv2-warning:       #B45309;

  /* ── Gradients ── */
  --cv2-grad-gold:     linear-gradient(135deg, #B8942A 0%, #C9A84C 35%, #E8C96A 65%, #C9A84C 100%);
  --cv2-grad-green:    linear-gradient(145deg, #1B5E20 0%, #256427 40%, #2E7D32 70%, #337A37 100%);
  --cv2-grad-silver:   linear-gradient(135deg, #8A96A8 0%, #A8B2C1 50%, #C2CBD7 100%);
  --cv2-grad-header:   linear-gradient(145deg, #1A3D1C 0%, #215225 35%, #2E7D32 70%, #1E6B25 100%);
  --cv2-grad-surface:  linear-gradient(160deg, #FDFCF7 0%, #F8F5EC 100%);

  /* ── Shadows ── */
  --cv2-shadow-gold:   0 4px 20px rgba(201,168,76,0.45), 0 2px 8px rgba(201,168,76,0.25);
  --cv2-shadow-green:  0 4px 18px rgba(46,125,50,0.38);
}

/* Header: Dark green gradient with gold bottom border (design system) */
.cv2-widget .cv2-header {
  background: var(--cv2-grad-header);
}

/* User message bubbles: Gold accent */
.cv2-widget .cv2-message--user .cv2-message__bubble {
  background: var(--cv2-grad-gold);
  color: #1A1200;
}

/* Bot message bubbles: Warm white surface */
.cv2-widget .cv2-message--bot .cv2-message__bubble {
  background: #FFFDF8;
  border-color: var(--cv2-border);
}

/* Input bar: Gold focus ring */
.cv2-widget .cv2-input:focus {
  border-color: var(--cv2-gold);
  box-shadow: 0 0 0 3px rgba(201,168,76,0.18);
}

/* Send button: Green with hover glow */
.cv2-widget .cv2-btn-send {
  background: var(--cv2-grad-green);
  box-shadow: var(--cv2-shadow-green);
}
.cv2-widget .cv2-btn-send:hover {
  box-shadow: var(--cv2-shadow-green), 0 6px 20px rgba(46,125,50,0.45);
}

/* Chat bubble toggle: Gold/green gradient */
.cv2-widget .cv2-bubble {
  background: var(--cv2-grad-gold);
  box-shadow: var(--cv2-shadow-gold);
}

/* Typing indicator dots: brand colours */
.cv2-widget .cv2-thinking-dot:nth-child(1) { background: var(--cv2-gold); }
.cv2-widget .cv2-thinking-dot:nth-child(2) { background: var(--cv2-silver); }
.cv2-widget .cv2-thinking-dot:nth-child(3) { background: var(--cv2-green-light); }

/* Legacy mount class — kept for backwards compat with third-party templates */
.aladdin-chatv2-mount {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: #1A1A0F;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.aladdin-chatv2-fallback,
.aladdin-chatv2-noscript {
  display: flex;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
  width: 100%;
  min-height: 84px;
  margin: 0;
  padding: 16px 18px;
  border: 1px solid #e4dfc8;
  border-radius: 14px;
  background: #fffdf8;
  color: #1a1a0f;
  box-shadow: 0 6px 24px rgba(2, 6, 23, 0.10);
}

.aladdin-chatv2-fallback {
  flex-wrap: wrap;
}

.aladdin-chatv2-fallback > span:last-child {
  flex-basis: 100%;
  color: #6b7062;
  font-size: 13px;
}

.aladdin-chatv2-fallback__spinner {
  width: 20px;
  height: 20px;
  border: 3px solid #d4dae3;
  border-top-color: #2e7d32;
  border-radius: 50%;
  animation: aladdin-chatv2-fallback-spin 0.8s linear infinite;
}

.aladdin-chatv2-mount[data-cv2-ready="1"] > .aladdin-chatv2-fallback {
  display: none;
}

@keyframes aladdin-chatv2-fallback-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .aladdin-chatv2-fallback__spinner { animation: none; }
}

/* Container */
.cv2-container {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--cv2-border);
  border-radius: var(--cv2-radius);
  background: var(--cv2-surface);
  overflow: hidden;
  height: 560px;
  max-height: 80vh;
  box-shadow: 0 10px 40px rgba(2, 6, 23, 0.18);
}

/* Header */
.cv2-header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--cv2-primary) 0%, var(--cv2-primary-2) 100%);
  border-bottom: 2px solid rgba(201, 168, 76, 0.75);
  flex-shrink: 0;
}

.cv2-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.cv2-brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(201, 168, 76, 0.65);
  object-fit: cover;
  flex-shrink: 0;
}

.cv2-header-text { min-width: 0; flex: 1 1 auto; }

.cv2-header-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  white-space: normal;
  overflow: hidden;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.cv2-header-subtitle {
  font-size: 11px;
  opacity: 0.88;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cv2-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.cv2-header-overflow {
  position: relative;
  flex: 0 0 auto;
}

.cv2-header-overflow > summary {
  list-style: none;
}

.cv2-header-overflow > summary::-webkit-details-marker {
  display: none;
}

.cv2-header-overflow__toggle {
  min-width: 32px;
  min-height: 32px;
  font-size: 22px;
  line-height: 1;
  letter-spacing: 1px;
}

.cv2-header-overflow__panel {
  position: absolute;
  inset-block-start: calc(100% + 8px);
  inset-inline-end: 0;
  z-index: 70;
  display: grid;
  gap: 6px;
  width: max-content;
  min-width: 190px;
  max-width: min(260px, calc(100vw - 32px));
  padding: 8px;
  border: 1px solid rgba(201, 168, 76, 0.65);
  border-radius: 12px;
  background: #17351b;
  box-shadow: 0 16px 36px rgba(2, 6, 23, 0.28);
}

.cv2-header-overflow:not([open]) .cv2-header-overflow__panel {
  display: none;
}

.cv2-header-overflow__panel .cv2-header-overflow__action {
  width: 100%;
  min-height: 36px;
  height: auto;
  justify-content: flex-start;
  gap: 10px;
  padding: 8px 10px;
  line-height: 1.25;
  text-align: start;
  white-space: normal;
}

.cv2-header-overflow__label {
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
}

.cv2-header-btn {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  cursor: pointer;
  padding: 6px;
  border-radius: 10px;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}

.cv2-header-btn:hover {
  background: rgba(255,255,255,0.18);
  border-color: rgba(201,168,76,0.55);
  transform: translateY(-1px);
}

.cv2-header-btn:focus-visible {
  outline: 2px solid rgba(201,168,76,0.85);
  outline-offset: 2px;
}

.cv2-header-btn svg { width: 16px; height: 16px; stroke: currentColor; }

/* Alert (Error / Warning / Info) */
.cv2-alert {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--cv2-border);
  background: #fff;
}

.cv2-alert.is-show { display: flex; }

.cv2-alert__msg { font-size: 13px; color: var(--cv2-text); }

.cv2-alert--error { background: #fef2f2; border-bottom-color: #fecaca; }
.cv2-alert--error .cv2-alert__msg { color: #991b1b; }

.cv2-alert--warning { background: #fffbeb; border-bottom-color: #fde68a; }
.cv2-alert--warning .cv2-alert__msg { color: #92400e; }

.cv2-alert--info { background: #eff6ff; border-bottom-color: #bfdbfe; }
.cv2-alert--info .cv2-alert__msg { color: #1e3a8a; }

.cv2-alert__actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.cv2-alert__btn {
  background: transparent;
  border: 1px solid currentColor;
  color: inherit;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
  cursor: pointer;
}

.cv2-alert__btn--primary {
  background: var(--cv2-primary);
  border-color: var(--cv2-primary);
  color: #fff;
}

/* Messages */
.cv2-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.cv2-messages::-webkit-scrollbar { width: 6px; }
.cv2-messages::-webkit-scrollbar-thumb { background: rgba(100,116,139,0.35); border-radius: 999px; }

/* Empty state */
.cv2-empty {
  border: 1px dashed rgba(168,178,193,0.65);
  background: linear-gradient(180deg, rgba(201,168,76,0.08), rgba(46,125,50,0.05));
  border-radius: 16px;
  padding: 14px;
}

.cv2-empty__title { font-weight: 700; margin-bottom: 6px; }
.cv2-empty__desc { color: var(--cv2-muted); font-size: 13px; margin-bottom: 10px; }

.cv2-suggestions { display: flex; flex-wrap: wrap; gap: 8px; }

.cv2-chip {
  /* Hard-reset against aggressive theme button rules */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  max-width: 100%;
  background: #fff;
  border: 1px solid var(--cv2-border);
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-family: var(--cv2-font);
  color: var(--cv2-text);
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
  transition: border-color .12s ease, transform .12s ease;
}

.cv2-chip:hover { border-color: rgba(201,168,76,0.7); transform: translateY(-1px); }

/* Message bubbles */
.cv2-msg {
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 16px;
  font-size: 14px;
  word-break: break-word;
  position: relative;
  animation: cv2fi .18s ease;
}

@keyframes cv2fi { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* RTL-MIX-01 — per-block bidi. dir="auto" on the bubble resolves direction from
   the FIRST strong character of the whole message, so an English governance
   label (e.g. "Agricultural advisory") at the top forces the entire Arabic
   reply LTR. `unicode-bidi: plaintext` re-resolves direction per block, and
   `text-align: start` follows each block's own direction. */
.cv2-msg p,
.cv2-msg li,
.cv2-msg h1, .cv2-msg h2, .cv2-msg h3, .cv2-msg h4, .cv2-msg h5, .cv2-msg h6,
.cv2-msg blockquote,
.cv2-msg td, .cv2-msg th {
  unicode-bidi: plaintext;
  text-align: start;
}

.cv2-msg-user {
  align-self: flex-end;
  background: var(--cv2-user);
  border: 1px solid rgba(46,125,50,0.18);
  border-bottom-right-radius: 6px;
}

.cv2-msg-ai {
  align-self: flex-start;
  background: var(--cv2-ai);
  border: 1px solid rgba(168,178,193,0.22);
  border-bottom-left-radius: 6px;
}

.cv2-msg-ai a { color: var(--cv2-primary); text-decoration: underline; }

.cv2-msg-ai pre {
  background: #0b1220;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: 12px;
  overflow-x: auto;
  font-size: 12px;
  margin: 10px 0;
}

.cv2-msg-ai code {
  background: rgba(148,163,184,0.18);
  padding: 1px 4px;
  border-radius: 6px;
  font-size: 12px;
}

.cv2-msg-ai pre code { background: none; padding: 0; }

/* Copy button (always readable) */
.cv2-copy-btn {
  position: absolute;
  top: 8px;
  inset-inline-end: 8px;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--cv2-border);
  border-radius: 10px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s ease;
}

.cv2-msg:hover .cv2-copy-btn { opacity: 1; }

/* Typing indicator */
.cv2-typing {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  align-self: flex-start;
  background: var(--cv2-ai);
  border-radius: 16px;
  border: 1px solid rgba(168,178,193,0.22);
  border-bottom-left-radius: 6px;
}

.cv2-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cv2-muted);
  animation: cv2b 1.4s infinite;
}

.cv2-typing-dot:nth-child(2) { animation-delay: .2s; }
.cv2-typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes cv2b { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* Input */
.cv2-input-area {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--cv2-border);
  background: var(--cv2-bg);
  flex-shrink: 0;
}

.cv2-input-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  width: 100%;
}

.cv2-attachment-strip {
  width: 100%;
  padding: 0 2px;
}
.cv2-attachment-reuse {
  width: 100%;
  display: grid;
  gap: 6px;
  padding: 10px;
  margin-bottom: 8px;
  border: 1px solid rgba(148,163,184,0.45);
  border-radius: 12px;
  background: rgba(248,250,252,0.92);
}
.cv2-attachment-reuse.is-loading {
  border-color: rgba(46,125,50,0.45);
  background: rgba(240,253,244,0.92);
}
.cv2-attachment-reuse.is-empty {
  border-style: dashed;
}
.cv2-attachment-reuse__label {
  display: grid;
  gap: 5px;
  color: var(--cv2-text);
  font-size: 12px;
  font-weight: 600;
}
.cv2-attachment-reuse__select {
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--cv2-border);
  border-radius: 9px;
  background: #fff;
  color: var(--cv2-text);
}
.cv2-attachment-reuse__select:disabled {
  cursor: wait;
  opacity: 0.72;
}
.cv2-attachment-reuse__details {
  color: var(--cv2-muted);
  font-size: 11px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.cv2-attachment-reuse__load-more {
  justify-self: start;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--cv2-border);
  border-radius: 9px;
  background: #fff;
  color: var(--cv2-text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.cv2-attachment-reuse__load-more:hover,
.cv2-attachment-reuse__load-more:focus-visible {
  border-color: var(--cv2-primary);
}
.cv2-attachment-reuse__load-more:disabled {
  cursor: wait;
  opacity: 0.65;
}
.cv2-attachment-strip__row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px dashed rgba(148,163,184,0.45);
  background: rgba(248,250,252,0.85);
  margin-bottom: 6px;
}
.cv2-attachment-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--cv2-border);
  flex-shrink: 0;
}
.cv2-attachment-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}
.cv2-attachment-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--cv2-text);
  word-break: break-word;
}
.cv2-attachment-hint {
  font-size: 11px;
  color: var(--cv2-muted);
  line-height: 1.35;
}
.cv2-attachment-remove,
.cv2-attachment-retry {
  appearance: none;
  border: 1px solid rgba(148,163,184,0.45);
  background: #fff;
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--cv2-text);
  flex-shrink: 0;
}
.cv2-attachment-remove:hover {
  border-color: var(--cv2-warning);
}
.cv2-attachment-retry:hover {
  border-color: var(--cv2-primary);
}

/* Tools (voice / image / mood) */
.cv2-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  overflow-x: auto;
  padding-bottom: 2px;
  width: 100%;
}

.cv2-tools::-webkit-scrollbar { height: 6px; }
.cv2-tools::-webkit-scrollbar-thumb { background: rgba(100,116,139,0.25); border-radius: 999px; }

.cv2-tool-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(148,163,184,0.10);
  border: 1px solid rgba(148,163,184,0.22);
  color: var(--cv2-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0;
  font-family: var(--cv2-font);
}

.cv2-tool-btn svg { width: 18px; height: 18px; stroke: currentColor; display: block; }

.cv2-tool-btn.is-active {
  background: rgba(46,125,50,0.12);
  border-color: rgba(201,168,76,0.55);
}

.cv2-tool-btn--mood { padding: 0 10px; width: auto; }
.cv2-mood-label { font-size: 12px; color: var(--cv2-muted); white-space: nowrap; }

.cv2-input {
  grid-column: 1;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--cv2-border);
  border-radius: 16px;
  padding: 13px 14px;
  font-size: 14px;
  font-family: var(--cv2-font);
  outline: none;
  resize: none;
  min-height: 50px;
  max-height: 140px;
  transition: border-color .12s ease, box-shadow .12s ease;
  color: var(--cv2-text);
  background: #fff;
  overflow-y: auto;
}

.cv2-input::placeholder { color: var(--cv2-muted); opacity: 1; }

.cv2-input:focus { border-color: rgba(201,168,76,0.75); }

.cv2-send-btn {
  grid-column: 2;
  background: var(--cv2-primary);
  color: #fff;
  border: 2px solid rgba(201,168,76,0.55);
  border-radius: 999px;
  width: 48px;
  height: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  padding: 0;
  transition: transform .12s ease, background .12s ease;
}

.cv2-send-btn svg,
.cv2-clear-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  display: block;
}

.cv2-send-btn:hover { transform: translateY(-1px); background: var(--cv2-primary-2); }
.cv2-send-btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.cv2-stop-btn {
  grid-column: 3;
  min-width: 58px;
  height: 42px;
  padding: 0 10px;
  border: 1px solid var(--cv2-danger);
  border-radius: 12px;
  background: transparent;
  color: var(--cv2-danger);
  font-weight: 700;
  cursor: pointer;
}

.cv2-stop-btn[hidden] { display: none !important; }
.cv2-stop-btn:disabled { opacity: .55; cursor: not-allowed; }

.cv2-clear-btn {
  grid-column: auto;
  background: rgba(148,163,184,0.14);
  border: 1px solid rgba(148,163,184,0.25);
  color: var(--cv2-text);
  cursor: pointer;
  border-radius: 12px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.cv2-header-overflow__panel .cv2-clear-btn {
  background: rgba(127,29,29,0.25);
  border-color: rgba(254,202,202,0.32);
  color: #fff;
}

/* SVG hardening — avoid theme rules hiding icons */
.cv2-container svg { display: block; width: 18px; height: 18px; stroke: currentColor; fill: none; }

/* Popup window (bubble) */
.aladdin-chatv2-window .cv2-container {
  position: fixed;
  bottom: 86px;
  right: 18px;
  width: 392px;
  height: 580px;
  z-index: 99990;
}

/* Compact, accessible floating launcher. */
.aladdin-chatv2-window .cv2-toggle-btn {
  position: fixed;
  bottom: 18px;
  right: 18px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(145deg, #285d2d 0%, #173d1b 100%);
  border: 3px solid #c9a84c;
  box-shadow: 0 10px 28px rgba(23, 61, 27, 0.34), 0 2px 8px rgba(2, 6, 23, 0.18);
  cursor: pointer;
  z-index: 99991;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: visible;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.aladdin-chatv2-window .cv2-toggle-btn:hover {
  transform: translateY(-2px);
  border-color: #e8c96a;
  box-shadow: 0 14px 32px rgba(23, 61, 27, 0.4), 0 3px 10px rgba(2, 6, 23, 0.2);
}
.aladdin-chatv2-window .cv2-toggle-btn:active { transform: translateY(0) scale(.97); }
.aladdin-chatv2-window .cv2-toggle-btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(201,168,76,0.75), 0 12px 30px rgba(23,61,27,0.38);
}

.cv2-toggle-mark {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #fff;
  color: #285d2d;
  box-shadow: 0 1px 6px rgba(2,6,23,0.18);
}

.cv2-toggle-logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cv2-toggle-mark--icon svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
}

.cv2-toggle-status {
  position: absolute;
  inset-block-end: 5px;
  inset-inline-end: 4px;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 1px 4px rgba(2,6,23,0.28);
}

/* FIX-4: iconPosition — Bottom Left */
.aladdin-chatv2-window.cv2-pos-bottom_left .cv2-toggle-btn {
  right: auto;
  left: 18px;
}
.aladdin-chatv2-window.cv2-pos-bottom_left .cv2-container {
  right: auto;
  left: 18px;
}

/* FIX-4: iconPosition — Top Right */
.aladdin-chatv2-window.cv2-pos-top_right .cv2-toggle-btn {
  bottom: auto;
  top: 18px;
  right: 18px;
}
.aladdin-chatv2-window.cv2-pos-top_right .cv2-container {
  bottom: auto;
  top: 86px;
  right: 18px;
}

/* FIX-4: iconPosition — Top Left */
.aladdin-chatv2-window.cv2-pos-top_left .cv2-toggle-btn {
  bottom: auto;
  top: 18px;
  right: auto;
  left: 18px;
}
.aladdin-chatv2-window.cv2-pos-top_left .cv2-container {
  bottom: auto;
  top: 86px;
  right: auto;
  left: 18px;
}

/* FIX-4: centerOpen — window centered in viewport */
.aladdin-chatv2-window.cv2-centered .cv2-container {
  bottom: auto;
  right: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 99995;
}

.aladdin-chatv2-window .cv2-container.is-hidden { display: none; }

/* Fullscreen — fixed viewport layout with constrained reading column */
.cv2-container.is-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  max-width: none !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-height: none !important;
  border-radius: 0 !important;
  z-index: 999999 !important;
  box-sizing: border-box;
  isolation: isolate;
  background: var(--cv2-surface, #FFFFFF) !important;
  color: var(--cv2-text, #1A1A0F) !important;
  display: flex !important;
  flex-direction: column !important;
  gap: clamp(8px, 1.75vh, 14px);
  padding-inline: clamp(12px, 2.8vw, 28px);
  padding-top: clamp(12px, 3vh, 28px);
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
}

.cv2-container.is-fullscreen .cv2-header,
.cv2-container.is-fullscreen .cv2-alert,
.cv2-container.is-fullscreen .cv2-debug-panel {
  max-width: min(920px, 100%);
  width: 100%;
  margin-inline: auto;
}

.cv2-container.is-fullscreen .cv2-messages {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  max-width: min(920px, 100%);
  width: 100%;
  margin-inline: auto;
  border-radius: 14px;
  border: 1px solid var(--cv2-border, #E4DFC8);
  background: var(--cv2-surface, #FFFFFF);
  box-sizing: border-box;
}

.cv2-container.is-fullscreen .cv2-input-area {
  flex-shrink: 0;
  max-width: min(920px, 100%);
  width: 100%;
  margin-inline: auto;
  border-radius: 14px;
  border: 1px solid var(--cv2-border, #E4DFC8);
  background: var(--cv2-surface, #FFFFFF);
  box-sizing: border-box;
}

html.cv2-fullscreen-open .aladdin-chatv2-window > .cv2-toggle-btn,
body.cv2-fullscreen-open .aladdin-chatv2-window > .cv2-toggle-btn {
  display: none !important;
}

html.cv2-fullscreen-open,
body.cv2-fullscreen-open {
  overflow: hidden !important;
  overscroll-behavior: none !important;
}

body > .cv2-container.is-fullscreen {
  margin: 0 !important;
  transform: none !important;
}

/* Governed source disclosure rendered from the server provenance envelope. */
.cv2-provenance {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--cv2-border);
  font-size: 12px;
  line-height: 1.5;
}

.cv2-provenance__label {
  margin-bottom: 6px;
  color: var(--cv2-text-muted);
  font-weight: 700;
}

.cv2-provenance__list {
  display: grid;
  gap: 6px;
}

.cv2-provenance__item {
  min-width: 0;
}

.cv2-provenance__link,
.cv2-provenance__text {
  display: block;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.cv2-provenance__link {
  color: var(--cv2-green-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cv2-provenance__link:hover,
.cv2-provenance__link:focus-visible {
  color: var(--cv2-gold-dark);
}

.cv2-citations {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--cv2-border);
  font-size: 12px;
}

.cv2-citations > summary {
  color: var(--cv2-green-dark);
  font-weight: 700;
  cursor: pointer;
}

.cv2-citations__list {
  display: grid;
  gap: 8px;
  margin: 8px 0 0;
  padding-inline-start: 20px;
}

.cv2-citations__list a,
.cv2-citations__list span,
.cv2-citations__list small {
  display: block;
  overflow-wrap: anywhere;
}

.cv2-citations__list small { color: var(--cv2-muted); }

.cv2-conversation-drawer {
  max-height: 220px;
  overflow-y: auto;
  padding: 10px;
  border-bottom: 1px solid var(--cv2-border);
  background: var(--cv2-surface-2);
}

.cv2-conversation-drawer[hidden] { display: none !important; }
.cv2-conversation-list { display: grid; gap: 6px; }

.cv2-conversation-item,
.cv2-history-more {
  width: 100%;
  border: 1px solid var(--cv2-border);
  border-radius: 10px;
  background: var(--cv2-surface);
  color: var(--cv2-text);
  text-align: start;
  cursor: pointer;
}

.cv2-conversation-item {
  display: grid;
  gap: 3px;
  padding: 8px 10px;
}

.cv2-conversation-item__title {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cv2-conversation-item__meta,
.cv2-conversation-empty { color: var(--cv2-muted); font-size: 11px; }

.cv2-history-more {
  margin-top: 8px;
  padding: 7px 10px;
  text-align: center;
}

.cv2-history-more--messages {
  flex: 0 0 auto;
  margin: 0 auto 4px;
  width: auto;
}

.cv2-history-more[hidden] { display: none !important; }

.cv2-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Mobile */
@media (max-width: 480px) {
  .aladdin-chatv2-window .cv2-container {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    max-height: 100%;
  }
  .aladdin-chatv2-window .cv2-toggle-btn {
    bottom: 14px;
    right: 14px;
    width: 60px;
    height: 60px;
  }
  .cv2-header {
    gap: 6px;
    padding: 10px;
  }
  .cv2-header-left { gap: 7px; }
  .cv2-brand-logo { width: 30px; height: 30px; }
  .cv2-header-actions { gap: 4px; }
  .cv2-header-btn { padding: 5px; }
  .cv2-header-subtitle { display: none; }
  .cv2-header-overflow__panel {
    max-width: min(230px, calc(100vw - 24px));
  }
  .cv2-debug-panel {
    max-height: 30vh;
    margin: 8px 8px 0;
  }
  .cv2-debug-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .cv2-msg { animation: none; }
  .cv2-header-btn, .cv2-send-btn, .cv2-toggle-btn, .cv2-chip { transition: none; }
}

/* ──────────────────────────────────────────────────────────────────────────
   Admin-only Debug Panel (frontend)
   - Rendered only when current user is admin.
   - No UI impact for normal users.
────────────────────────────────────────────────────────────────────────── */
.cv2-debug-panel {
  position: static;
  width: auto;
  max-width: none;
  max-height: min(220px, 35vh);
  margin: 10px 12px 0;
  background: rgba(15, 23, 42, 0.94);
  color: rgba(226, 232, 240, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 8px 24px rgba(2,6,23,0.2);
  overflow: auto;
  flex: 0 0 auto;
  box-sizing: border-box;
  display: none;
}
.cv2-debug-panel.is-open { display: block; }

.cv2-debug-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.cv2-debug-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.cv2-debug-actions { display: flex; gap: 6px; }
.cv2-debug-btn {
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(30, 41, 59, 0.9);
  color: rgba(226, 232, 240, 0.96);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.cv2-debug-btn:hover { background: rgba(51, 65, 85, 0.9); }

.cv2-debug-body {
  display: grid;
  gap: 6px;
}
.cv2-debug-row {
  display: grid;
  grid-template-columns: minmax(86px, 110px) minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}
.cv2-debug-k {
  font-size: 11px;
  color: rgba(148, 163, 184, 0.95);
}
.cv2-debug-v {
  font-size: 11px;
  color: rgba(226, 232, 240, 0.96);
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}


/* ── FIX-E1: Per-message user/guest avatar ────────────────────────────────── */
.cv2-msg-avatar {
  display: inline-block;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 6px;
  flex-shrink: 0;
}
.cv2-msg--with-avatar {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

/* ══════════════════════════════════════════════════════════════════════════
   FIX-iconTextDelay: Bubble toggle label (.cv2-icon-label)
   A text label next to the bubble icon, revealed after iconTextDelay seconds.
   Starts invisible (opacity 0, zero width) and animates in when
   .cv2-icon-label--visible is added by engine.js applyPopupSettings().
   ══════════════════════════════════════════════════════════════════════════ */
.cv2-icon-label {
  display: inline-block;
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  opacity: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #fff;
  pointer-events: none;
  /* Transition: expand width then fade in */
  transition: max-width 0.35s ease, opacity 0.3s ease 0.25s, margin-left 0.35s ease;
  margin-left: 0;
  vertical-align: middle;
}

.cv2-icon-label--visible {
  max-width: 160px;  /* wide enough for typical label text */
  opacity: 1;
  margin-left: 8px;
}

/* Ensure the toggle button can grow to accommodate the label */
.aladdin-chatv2-window .cv2-toggle-btn:has(.cv2-icon-label--visible) {
  width: auto;
  padding: 0 16px 0 12px;
  border-radius: 999px;
}
/* Fallback for browsers without :has() support */
.aladdin-chatv2-window .cv2-toggle-btn.cv2-has-label {
  width: auto;
  padding: 0 16px 0 12px;
  border-radius: 999px;
}


/* ══════════════════════════════════════════════════════════════════════════
   FIX-QUOTA-UX: Quota-exceeded alert countdown timer styles
   ══════════════════════════════════════════════════════════════════════════ */
.cv2-alert--quota {
  border-left: 3px solid #f59e0b;
}

.cv2-alert__timer {
  font-size: 12px;
  font-weight: 700;
  color: #f59e0b;
  margin-top: 4px;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

/* Pulsing animation while countdown is active */
@keyframes cv2-quota-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.65; }
}
.cv2-alert--quota .cv2-alert__timer {
  animation: cv2-quota-pulse 1s ease-in-out infinite;
}

/* v55 — capability honesty + theme conflict hardening */
.aladdin-chatv2-mount .cv2-header-actions,
.aladdin-chatv2-mount .cv2-tools,
.aladdin-chatv2-mount .cv2-runtime-caps {
  display: flex;
  visibility: visible;
  align-items: center;
}
.aladdin-chatv2-mount .cv2-header-btn,
.aladdin-chatv2-mount .cv2-tool-btn,
.aladdin-chatv2-mount .cv2-send-btn,
.aladdin-chatv2-mount .cv2-clear-btn {
  display: inline-flex;
  visibility: visible;
}
.aladdin-chatv2-mount .cv2-runtime-caps {
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 8px;
  font-size: 11px;
  color: var(--cv2-muted, #64748b);
}
.aladdin-chatv2-mount .cv2-runtime-cap {
  border: 1px solid var(--cv2-border, #e2e8f0);
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: help;
}
.aladdin-chatv2-mount .cv2-readiness-banner {
  font-size: 12px;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 6px 8px;
  margin-bottom: 6px;
  line-height: 1.38;
  overflow-wrap: anywhere;
}
.aladdin-chatv2-mount .cv2-tool-btn--blocked {
  opacity: 0.45;
  cursor: not-allowed;
}

.aladdin-chatv2-mount .cv2-runtime-cap--off {
  opacity: 0.45;
  border-style: dashed;
}
.aladdin-chatv2-mount .cv2-runtime-cap--blocked {
  color: var(--cv2-danger, #b91c1c);
  border-color: rgba(185,28,28,0.35);
  background: rgba(254,226,226,0.35);
}
.aladdin-chatv2-mount .cv2-runtime-cap--runtime {
  border-color: rgba(46,125,50,0.45);
  color: var(--cv2-green-dark, #1b5e20);
  background: rgba(220,252,231,0.55);
}
.aladdin-chatv2-mount .cv2-runtime-cap--unknown {
  opacity: 0.75;
  border-style: dotted;
}
.aladdin-chatv2-mount .cv2-runtime-cap--muted {
  opacity: 0.8;
  color: #64748b;
  border-color: #cbd5e1;
  background: rgba(241,245,249,0.75);
}

/* Phases v58 (3–5): readable secondary capability chips (WEB/KB/CALC) below compose */
.aladdin-chatv2-mount .cv2-runtime-caps--footer {
  width: 100%;
  justify-content: flex-start;
  margin-top: 4px;
  padding-top: 2px;
  opacity: 0.88;
  gap: 5px;
  font-size: 10px;
}
.aladdin-chatv2-mount .cv2-runtime-caps--footer .cv2-runtime-cap {
  font-weight: 500;
  letter-spacing: 0.06em;
  padding: 1px 6px;
}

/* Narrow widths: compose avoids crowding toolbar */
@media (max-width: 440px) {
  .aladdin-chatv2-mount .cv2-input-compose {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
  }
  .aladdin-chatv2-mount .cv2-input-compose .cv2-input {
    flex: 1 1 100%;
    min-width: 0;
    order: -1;
  }
  .aladdin-chatv2-mount .cv2-input-compose .cv2-send-btn,
  .aladdin-chatv2-mount .cv2-input-compose .cv2-stop-btn {
    flex: 0 0 auto;
  }
  .aladdin-chatv2-mount .cv2-input-compose .cv2-send-btn {
    margin-inline-start: auto;
  }
  .aladdin-chatv2-mount .cv2-tools {
    max-width: 100%;
    padding-bottom: 4px;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   CV2-FULLPAGE-01 — /ai-engine/ full-page chat experience
   Scoped entirely under .cv2-fullpage so nothing leaks into the
   floating widget or other mounts. Green/gold brand identity.
   ═══════════════════════════════════════════════════════════════════ */
.cv2-fullpage {
  max-width: 960px;
  margin: 0 auto;
  padding: 44px 16px 80px;
  box-sizing: border-box;
}

.cv2-fullpage-hero { text-align: center; margin: 0 0 30px; }

.cv2-fullpage-hero h1 {
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 800;
  color: #1d3b1f;
  letter-spacing: -0.5px;
  margin: 0 0 12px;
}

.cv2-fullpage-hero h1 .cv2-fp-accent { color: #C9A84C; }

.cv2-fullpage-hero p {
  color: #5b6b56;
  font-size: 16.5px;
  line-height: 1.7;
  max-width: 660px;
  margin: 0 auto;
}

.cv2-fp-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.cv2-fp-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: #2e5a31;
  background: rgba(140, 198, 63, 0.12);
  border: 1px solid rgba(140, 198, 63, 0.35);
}

.cv2-fp-badge--gold {
  color: #7a6023;
  background: rgba(201, 168, 76, 0.12);
  border-color: rgba(201, 168, 76, 0.4);
}

/* Chat card — taller, elevated, gold-edged */
.cv2-fullpage .cv2-container {
  height: calc(100vh - 330px);
  min-height: 620px;
  max-height: none;
  border-radius: 22px;
  border: 1px solid rgba(201, 168, 76, 0.45);
  box-shadow: 0 24px 70px rgba(29, 59, 31, 0.16), 0 4px 18px rgba(2, 6, 23, 0.08);
}

.cv2-fullpage .cv2-header { padding: 16px 20px; }
.cv2-fullpage .cv2-brand-logo { width: 42px; height: 42px; border-radius: 12px; }
.cv2-fullpage .cv2-header-title { font-size: 17px; }
.cv2-fullpage .cv2-header-subtitle { font-size: 12.5px; }

.cv2-fullpage .cv2-messages { padding: 22px 24px; gap: 14px; }

.cv2-fullpage .cv2-msg {
  max-width: 78%;
  font-size: 15px;
  line-height: 1.75;
  padding: 12px 16px;
  border-radius: 18px;
}

.cv2-fullpage .cv2-msg-user { border-bottom-right-radius: 6px; }
.cv2-fullpage .cv2-msg-ai   { border-bottom-left-radius: 6px; }

.cv2-fullpage .cv2-input-area { padding: 14px 18px; }
.cv2-fullpage .cv2-input { font-size: 15px; }

/* RTL page mirroring (Polylang ar/fa/ur page context) */
[dir="rtl"] .cv2-fullpage .cv2-msg-user { border-bottom-right-radius: 18px; border-bottom-left-radius: 6px; }
[dir="rtl"] .cv2-fullpage .cv2-msg-ai   { border-bottom-left-radius: 18px; border-bottom-right-radius: 6px; }

@media (max-width: 782px) {
  .cv2-fullpage { padding: 24px 10px 48px; }
  .cv2-fullpage .cv2-container { height: calc(100vh - 240px); min-height: 480px; border-radius: 16px; }
  .cv2-fullpage .cv2-msg { max-width: 88%; }
  .cv2-fullpage-hero { margin-bottom: 20px; }
}
