/** ============================================
   AI Assistant Widget Styles
   Floating site guide drawer
   ============================================ */

.ai-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 500;
  display: inline-flex;
  width: 56px;
  height: 56px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(125, 211, 252, 0.34);
  border-radius: 999px;
  background:
    radial-gradient(circle at 34% 18%, rgba(45, 212, 191, 0.36), transparent 32%),
    linear-gradient(135deg, #1d4ed8 0%, #4f46e5 54%, #0f766e 100%);
  color: #fff;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.34);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.ai-fab:hover,
.ai-fab:focus-visible {
  border-color: rgba(103, 232, 249, 0.72);
  box-shadow: 0 24px 56px rgba(14, 116, 144, 0.32);
  outline: none;
  transform: translateY(-2px);
}

.ai-fab:active {
  transform: translateY(0) scale(0.97);
}

.ai-drawer {
  position: fixed;
  right: 24px;
  bottom: 92px;
  z-index: 501;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(440px, calc(100vw - 48px));
  height: min(680px, calc(100dvh - 122px));
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 8px;
  background:
    radial-gradient(circle at 100% 0%, rgba(34, 211, 238, 0.16), transparent 35%),
    linear-gradient(160deg, rgba(24, 24, 27, 0.98), rgba(3, 7, 18, 0.98));
  box-shadow: 0 28px 72px rgba(0, 0, 0, 0.42);
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px) scale(0.97);
  transition: opacity 200ms ease, transform 200ms ease;
}

.ai-drawer.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.ai-drawer-header {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.ai-title-block {
  display: grid;
  min-width: 0;
  gap: 0.28rem;
}

.ai-shell-status {
  width: fit-content;
  color: #67e8f9;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.ai-drawer-header h3 {
  margin: 0;
  color: var(--color-text, #fafafa);
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.2;
}

.ai-drawer-header p {
  max-width: 24rem;
  margin: 0;
  color: var(--color-text-muted, #a1a1aa);
  font-size: 0.82rem;
  line-height: 1.5;
}

.ai-header-actions {
  display: flex;
  flex-shrink: 0;
  gap: 0.4rem;
  align-items: center;
}

.ai-clear,
.ai-close {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.58);
  color: var(--color-text-secondary, #d4d4d8);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.ai-clear {
  padding: 0 0.6rem;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
}

.ai-close {
  width: 34px;
  padding: 0;
}

.ai-clear:hover,
.ai-close:hover,
.ai-clear:focus-visible,
.ai-close:focus-visible {
  border-color: rgba(34, 211, 238, 0.55);
  background: rgba(8, 145, 178, 0.18);
  color: var(--color-text, #fafafa);
  outline: none;
}

.ai-messages {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  padding: 1rem;
  scroll-behavior: smooth;
}

.ai-message {
  display: grid;
  max-width: 94%;
  gap: 0.45rem;
}

.ai-message-bot {
  grid-template-columns: 28px minmax(0, 1fr);
  align-self: flex-start;
}

.ai-message-user {
  grid-template-columns: minmax(0, 1fr) 34px;
  align-self: flex-end;
}

.ai-message-user .ai-message-avatar {
  order: 2;
}

.ai-message-body {
  display: grid;
  min-width: 0;
  gap: 0.42rem;
}

.ai-message-avatar {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  align-self: end;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.7);
  color: #67e8f9;
  font-size: 0.68rem;
  font-weight: 800;
}

.ai-message-user .ai-message-avatar {
  width: 34px;
  color: #fff;
  background: rgba(79, 70, 229, 0.72);
}

.ai-message-content {
  min-width: 0;
  padding: 0.78rem 0.9rem;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.62;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.ai-message-user .ai-message-content {
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
}

.ai-message-bot .ai-message-content {
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.6);
  color: var(--color-text, #fafafa);
}

.ai-message-source {
  width: fit-content;
  color: var(--color-text-muted, #a1a1aa);
  font-size: 0.68rem;
  font-weight: 700;
}

.ai-message-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem;
}

.ai-message-link {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 0.32rem 0.58rem;
  border: 1px solid rgba(34, 211, 238, 0.28);
  border-radius: 8px;
  background: rgba(8, 145, 178, 0.1);
  color: #67e8f9;
  font-size: 0.72rem;
  font-weight: 750;
  text-decoration: none;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.ai-message-link:hover,
.ai-message-link:focus-visible {
  border-color: rgba(34, 211, 238, 0.68);
  background: rgba(8, 145, 178, 0.22);
  color: #cffafe;
  outline: none;
}

.ai-typing-indicator {
  display: inline-flex;
  width: fit-content;
  gap: 5px;
  align-items: center;
  padding: 0.78rem 0.9rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.6);
}

.ai-typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #67e8f9;
  animation: ai-typing-bounce 1.2s infinite ease-in-out both;
}

.ai-typing-indicator span:nth-child(1) { animation-delay: -0.24s; }
.ai-typing-indicator span:nth-child(2) { animation-delay: -0.12s; }

@keyframes ai-typing-bounce {
  0%, 80%, 100% { transform: scale(0.65); opacity: 0.45; }
  40% { transform: scale(1); opacity: 1; }
}

.ai-suggested-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  padding: 0 1rem 1rem;
}

.ai-suggested-chip {
  min-height: 40px;
  padding: 0.55rem 0.68rem;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 8px;
  background: rgba(3, 7, 18, 0.36);
  color: var(--color-text-secondary, #d4d4d8);
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: left;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}

.ai-suggested-chip:hover,
.ai-suggested-chip:focus-visible {
  border-color: rgba(34, 211, 238, 0.62);
  background: rgba(8, 145, 178, 0.14);
  color: var(--color-text, #fafafa);
  outline: none;
  transform: translateY(-1px);
}

.ai-input-area {
  display: grid;
  gap: 0.5rem;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(3, 7, 18, 0.38);
}

.ai-input-meta,
.ai-input-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.ai-input-meta {
  min-height: 18px;
  justify-content: space-between;
  color: var(--color-text-muted, #a1a1aa);
  font-size: 0.7rem;
  font-weight: 700;
}

.ai-service-state {
  display: inline-flex;
  gap: 0.38rem;
  align-items: center;
}

.ai-service-state::before {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #22d3ee;
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.5);
  content: '';
}

.ai-service-state[data-state="thinking"]::before {
  background: #fbbf24;
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.46);
}

.ai-service-state[data-state="online"]::before {
  background: #34d399;
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.5);
}

.ai-char-count {
  font-variant-numeric: tabular-nums;
}

.ai-input {
  width: 100%;
  min-height: 48px;
  max-height: 112px;
  padding: 0.7rem 0.78rem;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 8px;
  background: rgba(3, 7, 18, 0.68);
  color: var(--color-text, #fafafa);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  resize: vertical;
}

.ai-input:disabled {
  cursor: wait;
  opacity: 0.72;
}

.ai-input:focus {
  border-color: rgba(34, 211, 238, 0.82);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.14);
  outline: none;
}

.ai-send {
  flex: 0 0 42px;
  display: inline-flex;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
  transition: background 160ms ease, opacity 160ms ease, transform 160ms ease;
}

.ai-send:hover:not(:disabled),
.ai-send:focus-visible:not(:disabled) {
  background: #0891b2;
  outline: none;
  transform: translateY(-1px);
}

.ai-send:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

@media (max-width: 640px) {
  .ai-drawer {
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .ai-drawer-header {
    padding: calc(0.9rem + env(safe-area-inset-top)) 0.9rem 0.85rem;
  }

  .ai-header-actions {
    align-items: flex-start;
  }

  .ai-suggested-list {
    grid-template-columns: 1fr;
  }

  .ai-input-area {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }

  .ai-fab {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: 52px;
    height: 52px;
  }

  body.comments-in-view .ai-fab,
  body.rewards-in-view .ai-fab {
    opacity: 0;
    pointer-events: none;
    transform: translateY(16px) scale(0.92);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-fab,
  .ai-drawer,
  .ai-clear,
  .ai-close,
  .ai-suggested-chip,
  .ai-send {
    transition: none;
  }

  .ai-typing-indicator span {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

[data-theme="light"] .ai-drawer {
  background:
    radial-gradient(circle at 100% 0%, rgba(14, 165, 233, 0.13), transparent 35%),
    rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 62px rgba(15, 23, 42, 0.18);
}

[data-theme="light"] .ai-message-bot .ai-message-content,
[data-theme="light"] .ai-typing-indicator,
[data-theme="light"] .ai-suggested-chip,
[data-theme="light"] .ai-input,
[data-theme="light"] .ai-clear,
[data-theme="light"] .ai-close {
  background: rgba(248, 250, 252, 0.92);
}

[data-theme="light"] .ai-message-link {
  background: rgba(14, 116, 144, 0.08);
  color: #0e7490;
}
