// Side panel rendering one RAG citation's metadata + snippet.
// Sized to sit alongside (≥ 50 rem viewports) or stack on top of
// (< 50 rem) the chatbot panel. ViewEncapsulation.None on the host;
// every class is `chatbot-citation-panel*` namespaced.

.chatbot-citation-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  width: min(22rem, calc(100vw - 2rem));
  max-height: min(28rem, calc(100vh - 4rem));
  display: flex;
  flex-direction: column;
  background-color: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.08),
    0 12px 28px rgba(15, 71, 92, 0.18);
  overflow: hidden;

  &__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background-color: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
  }

  &__title {
    flex: 1 1 auto;
    margin: 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: #1f2937;
  }

  &__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem; // 44 × 44 touch target (ADR-0016)
    border: 0;
    background: transparent;
    color: #1f2937;
    cursor: pointer;
    border-radius: 0.375rem;
    transition: background-color 0.12s ease-out;

    &:hover {
      background-color: rgba(15, 71, 92, 0.08);
    }
    &:focus-visible {
      outline: 2px solid var(--color-brand-primary-500);
      outline-offset: 2px;
    }
  }

  &__meta {
    margin: 0;
    padding: 0.75rem 1rem 0.5rem;
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 0.75rem;
    row-gap: 0.25rem;
    font-size: 0.8rem;

    dt {
      color: #6b7280;
      font-weight: 500;
    }
    dd {
      margin: 0;
      color: #1f2937;
    }
  }

  &__snippet {
    margin: 0;
    padding: 0.5rem 1rem 0.875rem;
    font-size: 0.85rem;
    color: #374151;
    border-left: 3px solid var(--color-brand-primary-300);
  }
}

:host-context(.dark) .chatbot-citation-panel {
  background-color: #0f172a;
  border-color: #1f2937;

  &__header {
    background-color: #0b1220;
    border-bottom-color: #1f2937;
  }
  &__title,
  &__close {
    color: #e5e7eb;
  }
  &__close:hover {
    background-color: rgba(255, 255, 255, 0.08);
  }
  &__meta dt {
    color: #9ca3af;
  }
  &__meta dd,
  &__snippet {
    color: #e5e7eb;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chatbot-citation-panel__close {
    transition: none;
  }
}

// Side-by-side when there's room; stacked on phones.
@media (min-width: 50rem) {
  .chatbot-citation-panel {
    right: calc(1.25rem + 22rem + 0.5rem);
  }
}
