/**
 * Portal AI Q&A drawer — same right-hand chrome as wholesale filter drawers.
 * Work stays on the page; chat is a side panel (Cursor / Copilot shape).
 */

.portal-ai-chat {
  position: fixed;
  inset: 0;
  z-index: 1100;
  pointer-events: none;
}

.portal-ai-chat.is-open {
  pointer-events: auto;
}

.portal-ai-chat__overlay {
  position: absolute;
  inset: 0;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  transition: background 0.2s ease;
}

.portal-ai-chat.is-open .portal-ai-chat__overlay {
  background: var(--app-modal-backdrop, rgba(30, 58, 95, 0.28));
}

.portal-ai-chat__panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 94vw);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  background: var(--nav-dropdown-bg, #fffefb);
  color: var(--color-text, #1e3a5f);
  border-left: 1px solid var(--color-border, #d8d0c2);
  box-shadow: -12px 0 32px rgba(30, 58, 95, 0.12);
  transform: translateX(100%);
  transition: transform 0.22s ease;
}

.portal-ai-chat.is-open .portal-ai-chat__panel {
  transform: translateX(0);
}

.portal-ai-chat__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.125rem 0.75rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  flex: 0 0 auto;
}

.portal-ai-chat__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.25;
  color: var(--color-text, #14283c);
}

.portal-ai-chat__subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  color: var(--color-text-muted, #5e6d7e);
}

.portal-ai-chat__close {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 0.375rem;
  background: transparent;
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.portal-ai-chat__close:hover {
  background: rgba(148, 163, 184, 0.15);
}

.portal-ai-chat__messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.125rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.portal-ai-chat.is-busy .portal-ai-chat__input,
.portal-ai-chat.is-busy [data-ai-chat-send] {
  cursor: wait;
}

.portal-ai-chat__message--thinking .portal-ai-chat__message-body {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--color-text-muted, #5e6d7e);
}

.portal-ai-chat__thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.portal-ai-chat__thinking-dots span {
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 50%;
  background: currentColor;
  animation: portal-ai-chat-think 1s ease-in-out infinite;
}

.portal-ai-chat__thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.portal-ai-chat__thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes portal-ai-chat-think {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-0.15rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .portal-ai-chat__thinking-dots span {
    animation: none;
    opacity: 0.55;
  }
}

.portal-ai-chat__message {
  max-width: 100%;
  font-size: 0.875rem;
  line-height: 1.45;
}

.portal-ai-chat__message-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 0.25rem;
  color: var(--color-text-muted, #5e6d7e);
}

.portal-ai-chat__message--user .portal-ai-chat__message-body {
  white-space: pre-wrap;
}

.portal-ai-chat__message--assistant .portal-ai-chat__message-body {
  white-space: pre-wrap;
}

.portal-ai-chat__footer {
  flex: 0 0 auto;
  padding: 0.75rem 1.125rem 1rem;
  border-top: 1px solid rgba(148, 163, 184, 0.25);
}

.portal-ai-chat__compose {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
}

.portal-ai-chat__input {
  flex: 1;
  min-width: 0;
  min-height: 2.5rem;
  max-height: 8rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--color-border, #e5e2dc);
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  line-height: 1.4;
  resize: vertical;
  background: var(--color-surface, #fff);
  color: var(--color-text, #14283c);
}

.portal-ai-chat__note {
  margin-top: 0.45rem;
  font-size: 0.7rem;
  color: var(--color-text-muted, #5e6d7e);
}

body.theme-dark .portal-ai-chat__panel {
  background: var(--surface-elevated, #1e293b);
  border-color: var(--border-subtle, #334155);
  color: var(--text-primary, #e2e8f0);
}

body.theme-dark .portal-ai-chat__title {
  color: var(--text-primary, #e2e8f0);
}

body.theme-dark .portal-ai-chat__input {
  background: var(--surface, #0f172a);
  border-color: var(--border-subtle, #334155);
  color: var(--text-primary, #e2e8f0);
}
