/**
 * DrupalX AI Chat — centered, fluid width, compact composer.
 */

@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;600&family=Plus+Jakarta+Sans:wght@500;600;700&display=swap");

:root {
  --dx-ai-bg: #f5f5f7;
  --dx-ai-surface: #ffffff;
  --dx-ai-ink: #1d1d1f;
  --dx-ai-muted: #6e6e73;
  --dx-ai-line: rgba(0, 0, 0, 0.08);
  --dx-ai-accent: #0071e3;
  --dx-ai-accent-soft: rgba(0, 113, 227, 0.12);
  --dx-ai-user: #0071e3;
  --dx-ai-display: "Plus Jakarta Sans", "Noto Sans SC", sans-serif;
  --dx-ai-body: "Noto Sans SC", "Plus Jakarta Sans", sans-serif;
  --dx-ai-ease: cubic-bezier(0.22, 1, 0.36, 1);
  /* Fluid centered column */
  --dx-ai-col: clamp(320px, 92vw, 1080px);
}

/* —— Shell fills viewport —— */
.dx-shell--chat {
  height: 100dvh;
  max-height: 100dvh;
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: var(--dx-ai-bg);
  color: var(--dx-ai-ink);
  font-family: var(--dx-ai-body);
}

.dx-shell--chat .dx-chat-top {
  flex: 0 0 auto;
  width: 100%;
  z-index: 20;
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  background: rgba(245, 245, 247, 0.9);
  border-bottom: 1px solid var(--dx-ai-line);
}

.dx-shell--chat .dx-chat-top__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: var(--dx-ai-col);
  max-width: 100%;
  margin: 0 auto;
  padding: 0.65rem 0;
  box-sizing: border-box;
}

@media (max-width: 640px) {
  .dx-shell--chat .dx-chat-top__inner {
    width: calc(100% - 1.5rem);
    padding: 0.55rem 0;
  }
}

.dx-shell--chat .dx-chat-brand {
  font-family: var(--dx-ai-display);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.04em;
  color: var(--dx-ai-ink);
  text-decoration: none;
}

.dx-shell--chat .dx-chat-brand span {
  color: var(--dx-ai-accent);
}

.dx-shell--chat .dx-chat-top__meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--dx-ai-muted);
}

.dx-shell--chat .dx-chat-top__label {
  font-weight: 500;
  color: var(--dx-ai-ink);
}

.dx-shell--chat .dx-chat-top__meta a {
  color: var(--dx-ai-muted);
  text-decoration: none;
}

.dx-shell--chat .dx-chat-top__meta a:hover {
  color: var(--dx-ai-accent);
}

/* CRITICAL: column flex + stretch so content is full-width then self-centers */
.dx-shell--chat .dx-chat-main {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  overflow: hidden;
}

.dx-shell--chat .dx-chat-main > * {
  width: 100% !important;
  max-width: none !important;
  flex: 1 1 auto;
  min-height: 0;
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
}

.dx-shell--chat .dx-chat-flash {
  flex: 0 0 auto !important;
  width: var(--dx-ai-col) !important;
  max-width: calc(100% - 1.5rem) !important;
  margin: 0 auto !important;
  padding: 0.35rem 0 0 !important;
}

body.path-ai-chat {
  overflow: hidden;
  margin: 0;
}

/* Strip Drupal content chrome — keep full width chain */
.path-ai-chat .dx-content,
.dx-shell--chat .region-content,
.dx-shell--chat .block-system-main-block,
.dx-shell--chat .block,
.dx-shell--chat .block-system,
.dx-shell--chat .block-system > div {
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  border: 0 !important;
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  flex: 1 1 auto !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
}

.path-ai-chat .dx-content > h1,
.path-ai-chat .block-page-title-block,
.path-ai-chat .page-title {
  display: none !important;
}

/* —— Centered page column —— */
.dx-ai-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  margin: 0;
  padding: 0.5rem 0 0.45rem;
  box-sizing: border-box;
}

.dx-ai-page__banner,
.dx-ai-page__stage,
.dx-ai-page__hint {
  width: var(--dx-ai-col);
  max-width: calc(100% - 1.5rem);
  box-sizing: border-box;
}

.dx-ai-page__banner {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 0.4rem;
  padding: 0;
}

.dx-ai-page__title {
  margin: 0;
  font-family: var(--dx-ai-display);
  font-size: clamp(1.1rem, 2vw, 1.4rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.2;
  text-align: left;
}

.dx-ai-page__lead {
  margin: 0.12rem 0 0;
  color: var(--dx-ai-muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.dx-ai-page__usage {
  margin: 0;
  flex: 0 0 auto;
  font-size: 0.78rem;
  color: var(--dx-ai-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dx-ai-page__stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 0;
  margin: 0;
}

.dx-ai-page__widget {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
}

.dx-ai-page__hint {
  flex: 0 0 auto;
  margin: 0.3rem 0 0;
  font-size: 0.72rem;
  color: var(--dx-ai-muted);
  text-align: center;
  line-height: 1.3;
}

.dx-ai-page__hint a {
  color: var(--dx-ai-muted);
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

/* —— Chat panel —— */
.dx-ai-chat {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: var(--dx-ai-surface);
  border: 1px solid var(--dx-ai-line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.04);
}

.dx-ai-chat__messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: auto;
  padding: 0.85rem clamp(0.75rem, 2vw, 1.25rem);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: #f7f7f9;
}

.dx-ai-chat__row {
  display: flex;
  width: min(720px, 100%);
}

.dx-ai-chat__row--user {
  align-self: flex-end;
  justify-content: flex-end;
}

.dx-ai-chat__row--assistant {
  align-self: flex-start;
  justify-content: flex-start;
}

.dx-ai-chat__message {
  margin: 0;
  max-width: 100%;
  padding: 0.6rem 0.85rem;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--dx-ai-ink);
}

.dx-ai-chat__message--user {
  background: var(--dx-ai-user);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.dx-ai-chat__message--assistant {
  background: #fff;
  border: 1px solid var(--dx-ai-line);
  border-bottom-left-radius: 5px;
}

.dx-ai-chat__message--pending {
  opacity: 0.7;
  min-width: 2rem;
}

.dx-ai-chat__message--pending::after {
  content: "";
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  margin-left: 0.2rem;
  border-radius: 50%;
  background: var(--dx-ai-muted);
  animation: dx-ai-pulse 1s ease-in-out infinite;
  vertical-align: middle;
}

/* Compact bottom composer */
.dx-ai-chat__form {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.5rem 0.65rem 0.55rem;
  background: #fff;
  border-top: 1px solid var(--dx-ai-line);
}

.dx-ai-chat__composer {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.4rem;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0.15rem 0.2rem 0.15rem 0.8rem;
  background: var(--dx-ai-bg);
  border: 1px solid var(--dx-ai-line);
  border-radius: 999px;
  box-sizing: border-box;
  transition: border-color 0.15s var(--dx-ai-ease), box-shadow 0.15s var(--dx-ai-ease);
}

.dx-ai-chat__composer:focus-within {
  border-color: rgba(0, 113, 227, 0.45);
  box-shadow: 0 0 0 3px var(--dx-ai-accent-soft);
  background: #fff;
}

.dx-ai-chat__input {
  flex: 1 1 auto;
  min-width: 0;
  height: 2rem;
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  font-size: 0.94rem;
  color: var(--dx-ai-ink);
  outline: none;
}

.dx-ai-chat__input::placeholder {
  color: #a1a1a6;
}

.dx-ai-chat__submit {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3.25rem;
  height: 2rem;
  padding: 0 0.9rem;
  margin: 0;
  border: 0;
  border-radius: 999px;
  background: var(--dx-ai-accent);
  color: #fff;
  font-family: var(--dx-ai-display);
  font-weight: 600;
  font-size: 0.86rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.dx-ai-chat__submit:hover {
  background: #0077ed;
}

.dx-ai-chat__submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dx-ai-chat__submit-icon {
  display: none;
  font-size: 1rem;
  line-height: 1;
}

@media (max-width: 640px) {
  :root {
    --dx-ai-col: calc(100vw - 1.25rem);
  }

  .dx-ai-page__lead {
    display: none;
  }

  .dx-ai-chat {
    border-radius: 12px;
  }

  .dx-ai-chat__submit-label {
    display: none;
  }

  .dx-ai-chat__submit-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .dx-ai-chat__submit {
    min-width: 2rem;
    width: 2rem;
    padding: 0;
  }

  .dx-ai-chat__row {
    width: min(100%, 92vw);
  }
}

@media (min-width: 1400px) {
  :root {
    --dx-ai-col: clamp(960px, 72vw, 1200px);
  }
}

/* Embeds elsewhere */
.block:not(.block-system-main-block) .dx-ai-chat,
.dx-feature .dx-ai-chat {
  max-width: 560px;
  height: 420px;
}

@keyframes dx-ai-pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dx-ai-chat__message--pending::after {
    animation: none !important;
  }
}
