/* ============================================
   CTS AI — Premium Chat Interface
   ============================================ */

.cts-ai__backdrop {
  position: fixed;
  inset: 0;
  z-index: 10050;
  background: rgba(4, 8, 14, 0.55);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease);
}

.cts-ai__backdrop:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
}

.cts-ai__toggle {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 1.1rem 0.65rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border-hover);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-md), 0 0 32px rgba(16, 185, 180, 0.15);
  color: var(--text-primary);
  transition: transform 0.25s var(--ease), box-shadow var(--ease), border-color var(--ease);
}

.cts-ai__toggle:hover {
  transform: translateY(-2px);
  border-color: var(--cts-teal);
  box-shadow: var(--shadow-lg), 0 0 40px rgba(16, 185, 180, 0.25);
}

.cts-ai__toggle.is-open {
  display: none;
}

.cts-ai__toggle--nav {
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  gap: 0.4rem;
  box-shadow: none;
  background: rgba(16, 185, 180, 0.08);
  border: 1px solid rgba(16, 185, 180, 0.22);
}

.cts-ai__toggle--nav:hover {
  transform: none;
  background: rgba(16, 185, 180, 0.14);
  border-color: var(--cts-teal);
  box-shadow: none;
}

.cts-ai__toggle--nav .cts-ai__toggle-icon {
  width: 22px;
  height: 22px;
}

.cts-ai__toggle--nav .cts-ai__toggle-icon img {
  width: 20px;
  height: 20px;
}

.nav__menu > li > .cts-ai__toggle--nav {
  margin-inline-start: 0.15rem;
}

.nav__drawer .cts-ai__toggle--nav {
  width: 100%;
  justify-content: flex-start;
  margin-top: 0.25rem;
}

.cts-ai__toggle-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cts-ai__toggle-icon img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.cts-ai__toggle-label {
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--gradient-text);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.cts-ai__backdrop[hidden] {
  display: none !important;
  opacity: 0;
  pointer-events: none;
}

.cts-ai__panel[hidden] {
  display: none !important;
}

.cts-ai__panel:not([hidden]) {
  display: flex;
  flex-direction: column;
}

.cts-ai__panel {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 10060;
  font-family: var(--font-body);
  width: min(420px, calc(100vw - 1.5rem));
  height: min(640px, calc(100svh - 2rem));
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-hover);
  background: var(--bg-glass);
  backdrop-filter: blur(24px) saturate(1.3);
  box-shadow: var(--shadow-lg), 0 0 60px rgba(16, 185, 180, 0.12);
  overflow: hidden;
  animation: ctsAiIn 0.35s var(--ease);
}

html[dir="rtl"] .cts-ai__panel {
  right: auto;
  left: 1.25rem;
}

@keyframes ctsAiIn {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.cts-ai__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: var(--gradient-brand-soft);
}

.cts-ai__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.cts-ai__avatar {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  position: relative;
  background: transparent;
  border: none;
}

.cts-ai__avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.cts-ai__avatar-pulse {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cts-lime);
  border: 2px solid var(--bg-elevated);
  box-shadow: 0 0 8px var(--cts-lime);
}

.cts-ai__meta h2 {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.cts-ai__status {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.cts-ai__status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cts-lime);
  animation: ctsPulse 2s ease-in-out infinite;
}

@keyframes ctsPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.cts-ai__header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.cts-ai__new,
.cts-ai__close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.cts-ai__new:hover,
.cts-ai__close:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
  background: var(--bg-card);
}

.cts-ai__new:hover {
  color: var(--cts-teal);
  border-color: rgba(16, 185, 180, 0.35);
}

.cts-ai__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scroll-behavior: smooth;
}

.cts-ai__msg {
  display: flex;
  gap: 0.6rem;
  max-width: 92%;
  animation: ctsMsgIn 0.3s var(--ease);
}

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

.cts-ai__msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.cts-ai__msg-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin-top: 4px;
  background: transparent;
}

.cts-ai__msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.cts-ai__msg-body {
  min-width: 0;
}

.cts-ai__msg-bubble {
  padding: 0.75rem 0.95rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  line-height: 1.55;
  word-break: break-word;
}

.cts-ai__msg--bot .cts-ai__msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-top-left-radius: 4px;
}

html[dir="rtl"] .cts-ai__msg--bot .cts-ai__msg-bubble {
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: 4px;
}

.cts-ai__msg--user .cts-ai__msg-bubble {
  background: var(--gradient-brand);
  color: #041018;
  font-weight: 500;
  border-top-right-radius: 4px;
}

html[dir="rtl"] .cts-ai__msg--user .cts-ai__msg-bubble {
  border-top-right-radius: var(--radius-md);
  border-top-left-radius: 4px;
}

.cts-ai__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.cts-ai__action {
  padding: 0.45rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid var(--border-hover);
  background: var(--bg-elevated);
  color: var(--text-primary);
  transition: all var(--transition);
}

.cts-ai__action:hover {
  border-color: var(--cts-teal);
  background: var(--gradient-brand-soft);
}

.cts-ai__typing {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.cts-ai__typing-dots {
  display: flex;
  gap: 4px;
  padding: 0.65rem 0.9rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.cts-ai__typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cts-teal);
  animation: ctsDot 1.2s ease-in-out infinite;
}

.cts-ai__typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.cts-ai__typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ctsDot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.cts-ai__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1rem 0.65rem;
}

.cts-ai__chip {
  padding: 0.4rem 0.7rem;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.cts-ai__chip:hover {
  color: var(--text-primary);
  border-color: var(--cts-cyan);
}

.cts-ai__form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

.cts-ai__input {
  flex: 1;
  padding: 0.75rem 1rem;
  font: inherit;
  font-size: 0.875rem;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition);
}

.cts-ai__input:focus {
  outline: none;
  border-color: var(--cts-teal);
}

.cts-ai__voice,
.cts-ai__send {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.cts-ai__voice {
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--bg-card);
}

.cts-ai__voice.is-listening {
  color: var(--cts-teal);
  border-color: var(--cts-teal);
  animation: ctsPulse 1s ease-in-out infinite;
}

.cts-ai__send {
  background: var(--gradient-brand);
  color: #041018;
  box-shadow: 0 4px 16px rgba(16, 185, 180, 0.25);
}

.cts-ai__send:hover {
  transform: scale(1.05);
}

.cts-ai__send svg,
.cts-ai__voice svg {
  width: 18px;
  height: 18px;
}

body.cts-ai-open {
  overflow: hidden;
}

@media (max-width: 480px) {
  .cts-ai__panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100svh;
    border-radius: 0;
    border: none;
  }

  html[dir="rtl"] .cts-ai__panel {
    left: 0;
  }

  .cts-ai__toggle-label {
    display: none;
  }

  .cts-ai {
    bottom: 1rem;
    right: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cts-ai__panel { animation: none; }
  .cts-ai__msg { animation: none; }
}
