/* ==========================================================================
   The chat screen: tokens and components.

   This file used to hold only the --chat-* mapping while the component rules
   lived in style/app.css — the stylesheet every public page loads. Half of
   those rules still hardcoded light colours (white bubbles in the dark panel)
   and the rest described markup the chat no longer emits: a fixed 583px
   transcript, a mobile layout built on position:fixed, <img> icons. They are
   gone from app.css; everything the chat paints is here, and this file loads
   only where $loadAI is set.

   Two rules keep it honest, and tests/chat-shell.php checks both:

     1. Colours come from --chat-* only. No literal colour anywhere in this
        file — the mapping blocks point at --site-* or --harmony-*, which
        already flip on [data-theme], so light, dark and developer come free.

          :root              → --site-*    (guest and embedded chat)
          .harmony-workspace → --harmony-* (signed-in chat inside the frame)

     2. Both blocks define the same set of --chat-* names. A name defined on
        one side only resolves to nothing on the other, which renders as an
        invisible element rather than a wrong colour.

   Markup contract: _chat.php's displayMessage() and js/chat.js's
   buildMessage() emit the same message structure. Change one, change both.
   ========================================================================== */

:root {
  --chat-canvas: var(--site-surface-2);
  --chat-surface: var(--site-card-bg);
  --chat-surface-2: var(--site-surface);
  --chat-surface-active: var(--site-accent-subtle);
  --chat-fg: var(--site-fg);
  --chat-fg-muted: var(--site-fg-muted);
  --chat-border: var(--site-border);
  --chat-border-soft: var(--site-border-muted);
  --chat-accent: var(--site-accent);
  --chat-accent-fg: var(--site-on-accent);
  --chat-accent-soft: var(--site-accent-subtle);
  --chat-accent-strong: var(--site-accent-active);
  --chat-highlight-bg: var(--site-accent);
  --chat-highlight-fg: var(--site-on-accent);
  --chat-vip-bg: var(--site-accent-muted);
  --chat-shadow: var(--site-shadow);
  --chat-scroll-thumb: var(--site-fg-subtle);
  --chat-scroll-thumb-hover: var(--site-fg-muted);
  --chat-scroll-track: var(--site-surface);
  --chat-scroll-track-hover: var(--site-border);
  --chat-radius: var(--site-radius);
  --chat-radius-sm: var(--site-radius-sm);
  --chat-font: var(--site-body-font);
  --chat-heading-font: var(--site-heading-font);
  --chat-accent-text: var(--site-accent-fg);
  --chat-bubble-ai: var(--site-card-bg);
  --chat-bubble-user: var(--site-accent-subtle);
  --chat-bubble-fg: var(--site-fg);
  --chat-composer-bg: var(--site-card-bg);
  --chat-danger: var(--bs-danger);
  --chat-danger-fg: var(--bs-white);
  --chat-online: var(--bs-success);
  --chat-overlay: var(--site-fg);
  --chat-overlay-fg: var(--site-canvas);
  --chat-code-bg: var(--site-surface-2);
}

/* Inside the panel the chat is one more workspace surface, so it takes the
   workspace palette rather than the public site's. */
.harmony-workspace {
  --chat-canvas: var(--harmony-bg);
  --chat-surface: var(--harmony-surface);
  --chat-surface-2: var(--harmony-surface-soft);
  /* not --harmony-sidebar-hover: that is the dark rail's colour in every theme */
  --chat-surface-active: var(--harmony-neutral-subtle);
  --chat-fg: var(--harmony-text);
  --chat-fg-muted: var(--harmony-muted);
  --chat-border: var(--harmony-border);
  --chat-border-soft: var(--harmony-border);
  --chat-accent: var(--harmony-accent);
  --chat-accent-fg: var(--harmony-surface);
  --chat-accent-soft: var(--harmony-neutral-subtle);
  --chat-accent-strong: var(--harmony-accent);
  --chat-highlight-bg: var(--harmony-accent);
  --chat-highlight-fg: var(--harmony-surface);
  --chat-vip-bg: var(--harmony-warning-subtle);
  --chat-shadow: var(--harmony-shadow);
  --chat-scroll-thumb: var(--harmony-muted);
  --chat-scroll-thumb-hover: var(--harmony-text);
  --chat-scroll-track: var(--harmony-surface-soft);
  --chat-scroll-track-hover: var(--harmony-border);
  --chat-radius: var(--harmony-radius);
  --chat-radius-sm: var(--harmony-radius-sm);
  --chat-font: var(--harmony-body-font);
  --chat-heading-font: var(--harmony-heading-font);
  --chat-accent-text: var(--harmony-accent);
  --chat-bubble-ai: var(--harmony-surface);
  --chat-bubble-user: var(--harmony-neutral-subtle);
  --chat-bubble-fg: var(--harmony-text);
  --chat-composer-bg: var(--harmony-surface);
  --chat-danger: var(--harmony-danger);
  --chat-danger-fg: var(--harmony-surface);
  --chat-online: var(--harmony-success);
  --chat-overlay: var(--harmony-text);
  --chat-overlay-fg: var(--harmony-surface);
  --chat-code-bg: var(--harmony-surface-soft);
}

/* ── Frame ────────────────────────────────────────────────────────────────
   The screen is one column: header, transcript, composer. Only the
   transcript scrolls — the composer is never position:fixed, so the
   on-screen keyboard and the footer can't slide over it. */

.harmony-workspace .harmony-main.is-chat {
  max-width: none;
  padding: 0;
  overflow: hidden;
  height: calc(100vh - 92px);
  height: calc(100dvh - 92px);
}
.harmony-workspace .harmony-main.is-chat > section {
  height: 100%;
}
@media (max-width: 767px) {
  .harmony-workspace .harmony-main.is-chat {
    height: calc(100vh - 76px);
    height: calc(100dvh - 76px);
  }
}

.chat-shell {
  color: var(--chat-fg);
  font-family: var(--chat-font);
}
.chat-shell .chat-container {
  height: 100%;
}
.chat-shell.is-public {
  padding: 12px 0 24px;
}
.chat-shell.is-public .chat-layout {
  height: calc(100vh - 150px);
  height: calc(100dvh - 150px);
  min-height: 460px;
}
.chat-shell.embed-chat,
.chat-shell.embed-chat .chat-layout {
  height: 100vh;
  height: 100dvh;
  padding: 0;
}
.chat-shell.chat-full-width {
  padding: 0;
}
.chat-shell.chat-full-width .chat-layout,
.chat-shell.embed-chat .chat-layout {
  border-radius: 0;
  border-width: 0;
}

.chat-layout {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  height: 100%;
  overflow: hidden;
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
}
.chat-shell.is-workspace .chat-layout {
  border-width: 0;
  border-radius: 0;
}
.chat-shell.is-side-open .chat-layout {
  grid-template-columns: 290px minmax(0, 1fr);
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* ── Header ───────────────────────────────────────────────────────────── */

.ai-chat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--chat-border);
  background: var(--chat-surface);
}
.wrapper-ai-chat-top {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.ai-chat-top-image {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--chat-accent-soft);
}
.ai-chat-top-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ai-chat-top-info {
  min-width: 0;
}
.ai-chat-top-name h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--chat-fg);
  font-family: var(--chat-heading-font);
  font-size: 1.05rem;
  font-weight: 700;
}
.ai-chat-top-job {
  overflow: hidden;
  color: var(--chat-fg-muted);
  font-size: .875rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.online-bullet {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--chat-online);
}
.ai-chat-top-name .card-vip {
  position: static;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--chat-vip-bg);
}
.ai-chat-top-name .card-vip img {
  width: 12px;
  height: 12px;
}
.ai-chat-top-name .card-vip span {
  color: var(--chat-fg);
  font-size: .72rem;
  font-weight: 600;
}
.ai-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.badge-categories {
  padding: 1px 8px;
  border: 1px solid var(--chat-border);
  border-radius: 999px;
  color: var(--chat-fg-muted);
  font-size: .72rem;
  text-decoration: none;
}
a.badge-categories:hover {
  border-color: var(--chat-accent);
  color: var(--chat-accent-text);
}

.icons-options {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
}
.chat-action-buttons {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius-sm);
  background: var(--chat-surface);
  color: var(--chat-fg-muted);
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.chat-action-buttons i {
  font-size: 1rem;
}
.chat-action-buttons:hover,
.chat-action-buttons:focus-visible,
.chat-action-buttons.is-active {
  border-color: var(--chat-accent);
  background: var(--chat-accent-soft);
  color: var(--chat-fg);
}
.chat-action-buttons[hidden] {
  display: none;
}
.dropdown-item-chat {
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  box-shadow: var(--chat-shadow);
}
.dropdown-item-chat .dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  color: var(--chat-fg);
}
.dropdown-item-chat .dropdown-item:hover,
.dropdown-item-chat .dropdown-item:focus {
  background: var(--chat-surface-2);
  color: var(--chat-fg);
}

/* ── Transcript ───────────────────────────────────────────────────────── */

.chat-frame {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--chat-canvas);
}
#overflow-chat {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 24px 20px 12px;
  scrollbar-color: var(--chat-scroll-thumb) transparent;
  scrollbar-width: thin;
}
#overflow-chat:focus-visible {
  outline: 2px solid var(--chat-accent);
  outline-offset: -2px;
}
#overflow-chat::-webkit-scrollbar {
  width: 8px;
}
#overflow-chat::-webkit-scrollbar-thumb {
  border-radius: 8px;
  background-color: var(--chat-scroll-thumb);
}
#overflow-chat::-webkit-scrollbar-thumb:hover {
  background-color: var(--chat-scroll-thumb-hover);
}
#overflow-chat::-webkit-scrollbar-track {
  background-color: transparent;
}

.conversation-thread {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 880px;
  margin: 0 auto 18px;
}
.thread-user {
  justify-content: flex-end;
}
.user-image {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  margin-top: 2px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--chat-accent-soft);
}
.user-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-container {
  position: relative;
  min-width: 0;
  max-width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius-sm);
  background: var(--chat-bubble-ai);
  color: var(--chat-bubble-fg);
}
.thread-ai .message-container {
  flex: 1 1 auto;
  border-inline-start: 3px solid var(--chat-accent);
}
.thread-user .message-container {
  max-width: min(80%, 640px);
  border-color: transparent;
  background: var(--chat-bubble-user);
}

.wrapper-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.user-name h5 {
  margin: 0;
  color: var(--chat-accent-text);
  font-family: var(--chat-heading-font);
  font-size: .82rem;
  font-weight: 700;
}
.thread-user .user-name h5 {
  color: var(--chat-fg-muted);
}
.chat-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: .55;
  transition: opacity .15s ease;
}
.conversation-thread:hover .chat-actions,
.conversation-thread:focus-within .chat-actions {
  opacity: 1;
}
@media (hover: none) {
  .chat-actions {
    opacity: 1;
  }
}
.copy-text,
.chat-audio {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--chat-fg-muted);
  cursor: pointer;
}
.copy-text:hover,
.copy-text:focus-visible,
.chat-audio:hover {
  background: var(--chat-surface-2);
  color: var(--chat-fg);
}
.copy-text.is-copied {
  color: var(--chat-accent-text);
}
.chat-audio img {
  height: 18px;
}

.message-text {
  position: relative;
  min-width: 0;
}
.chat-response {
  overflow-wrap: anywhere;
  line-height: 1.65;
  white-space: pre-wrap;
}
.chat-response.chat-markdown,
.chat-response.no-white-space {
  white-space: normal;
}
.date-chat {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  color: var(--chat-fg-muted);
  font-size: .72rem;
}
.date-chat:has(time:empty) {
  display: none;
}

/* ── Markdown ─────────────────────────────────────────────────────────── */

.chat-markdown > :first-child {
  margin-top: 0;
}
.chat-markdown > :last-child {
  margin-bottom: 0;
}
.chat-markdown p,
.chat-markdown ul,
.chat-markdown ol,
.chat-markdown blockquote,
.chat-markdown pre,
.chat-markdown .chat-table {
  margin: 0 0 .75em;
}
.chat-markdown h1,
.chat-markdown h2,
.chat-markdown h3,
.chat-markdown h4,
.chat-markdown h5,
.chat-markdown h6 {
  margin: 1.1em 0 .45em;
  color: var(--chat-fg);
  font-family: var(--chat-heading-font);
  font-weight: 700;
  line-height: 1.3;
}
.chat-markdown h1 { font-size: 1.3em; }
.chat-markdown h2 { font-size: 1.18em; }
.chat-markdown h3 { font-size: 1.06em; }
.chat-markdown h4,
.chat-markdown h5,
.chat-markdown h6 { font-size: 1em; }
.chat-markdown ul,
.chat-markdown ol {
  padding-inline-start: 1.4em;
}
.chat-markdown li + li {
  margin-top: .2em;
}
.chat-markdown a {
  color: var(--chat-accent-text);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-markdown blockquote {
  padding: .1em 0 .1em 1em;
  border-inline-start: 3px solid var(--chat-border);
  color: var(--chat-fg-muted);
}
.chat-markdown hr {
  margin: 1em 0;
  border: 0;
  border-top: 1px solid var(--chat-border);
  opacity: 1;
}
.chat-markdown code {
  padding: .1em .35em;
  border-radius: 6px;
  background: var(--chat-code-bg);
  color: var(--chat-fg);
  font-size: .9em;
}
.chat-response pre {
  position: relative;
  overflow-x: auto;
  padding: 14px 16px;
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius-sm);
  background: var(--chat-code-bg);
  white-space: pre;
}
.chat-response pre code,
.chat-response pre code.hljs {
  display: block;
  padding: 0;
  background: transparent;
  font-size: .86em;
  line-height: 1.55;
}
.chat-response .copy-code {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  background: var(--chat-surface);
  color: var(--chat-fg-muted);
  font-family: var(--chat-font);
  font-size: .75rem;
  opacity: 0;
  transition: opacity .15s ease;
}
.chat-response pre:hover .copy-code,
.chat-response .copy-code:focus-visible,
.chat-response .copy-code.is-copied {
  opacity: 1;
}
@media (hover: none) {
  .chat-response .copy-code {
    opacity: 1;
  }
}
html[dir="rtl"] .chat-response .copy-code {
  right: auto;
  left: 8px;
}
.chat-table {
  overflow-x: auto;
}
.chat-markdown table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92em;
}
.chat-markdown th,
.chat-markdown td {
  padding: 6px 10px;
  border: 1px solid var(--chat-border);
  text-align: start;
  vertical-align: top;
}
.chat-markdown th {
  background: var(--chat-surface-2);
  font-weight: 700;
}

.chat-response-highlight {
  border-radius: 3px;
  background: var(--chat-highlight-bg);
  color: var(--chat-highlight-fg);
}

/* ── Live answer ──────────────────────────────────────────────────────── */

.cursor {
  display: inline-block;
  width: .45em;
  height: 1.1em;
  margin-inline-start: .15em;
  vertical-align: text-bottom;
  background-color: var(--chat-fg);
  animation: chat-blink 1s steps(2, start) infinite;
}
.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}
.chat-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chat-fg-muted);
  animation: chat-bounce 1.2s ease-in-out infinite;
}
.chat-typing i:nth-child(3) { animation-delay: .15s; }
.chat-typing i:nth-child(4) { animation-delay: .3s; }

@keyframes chat-blink {
  to { visibility: hidden; }
}
@keyframes chat-bounce {
  0%, 80%, 100% { opacity: .3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
  .cursor,
  .chat-typing i {
    animation: none;
  }
}
.harmony-reduced-motion .cursor,
.harmony-reduced-motion .chat-typing i {
  animation: none;
}

/* ── Images ───────────────────────────────────────────────────────────── */

.thumbnail-vision-img {
  display: block;
  max-width: 220px;
  max-height: 220px;
  margin-bottom: 10px;
  border-radius: var(--chat-radius-sm);
  object-fit: cover;
}
.wrapper-image-ia {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.image-ia img {
  width: 100%;
  border-radius: var(--chat-radius-sm);
}
.ia-image-prompt-label {
  color: var(--chat-fg);
}

/* ── Composer ─────────────────────────────────────────────────────────── */

.message-area-bottom {
  position: relative;
  flex: 0 0 auto;
  padding: 10px 20px 14px;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-composer-bg);
}
.message-area-bottom > * {
  max-width: 880px;
  margin-inline: auto;
}
#audioVisualizer {
  position: absolute;
  right: 0;
  bottom: 100%;
  left: 0;
  width: 100%;
  max-width: none;
  height: 48px;
  pointer-events: none;
}

.chat-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.chat-starters[hidden] {
  display: none;
}
.chat-starter {
  max-width: 100%;
  overflow: hidden;
  padding: 6px 12px;
  border: 1px solid var(--chat-border);
  border-radius: 999px;
  background: var(--chat-surface);
  color: var(--chat-fg);
  font-size: .85rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}
.chat-starter:hover,
.chat-starter:focus-visible {
  border-color: var(--chat-accent);
  background: var(--chat-accent-soft);
}

.col-options-input {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.col-options-input[hidden] {
  display: none;
}
.form-f-chat label {
  display: block;
  margin-bottom: 3px;
  color: var(--chat-fg-muted);
  font-size: .75rem;
  font-weight: 600;
}
.form-f-chat .form-select {
  border-color: var(--chat-border);
  background-color: var(--chat-surface);
  color: var(--chat-fg);
  font-size: .9rem;
}

.chat-input {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 10px 8px 14px;
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius-sm);
  background: var(--chat-surface);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.chat-input:focus-within {
  border-color: var(--chat-accent);
  box-shadow: 0 0 0 3px var(--chat-accent-soft);
}
.chat-input textarea {
  width: 100%;
  min-height: 26px;
  max-height: 220px;
  padding: 2px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--chat-fg);
  font-family: var(--chat-font);
  font-size: 1rem;
  line-height: 1.5;
}
/* site.css outlines every focused textarea; here the composer box's own
   :focus-within ring is the indicator, so a second ring inside it is noise. */
.chat-input textarea:focus,
.chat-input textarea:focus-visible {
  outline: 0;
  box-shadow: none;
}
.chat-input textarea::placeholder {
  color: var(--chat-fg-muted);
}
.chat-input textarea:disabled {
  background: transparent;
  opacity: .6;
}
.chat-tools {
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-tool {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--chat-fg-muted);
  cursor: pointer;
}
.chat-tool:hover,
.chat-tool:focus-visible,
.chat-tool.is-active {
  background: var(--chat-surface-2);
  color: var(--chat-fg);
}
.chat-tool i {
  font-size: 1.05rem;
}
#microphone-button .mic-live {
  display: none;
}
#microphone-button.is-recording {
  background: var(--chat-danger);
  color: var(--chat-danger-fg);
}
#microphone-button.is-recording .mic-idle {
  display: none;
}
#microphone-button.is-recording .mic-live {
  display: inline;
}
.chat-counter {
  margin-inline-start: auto;
  color: var(--chat-fg-muted);
  font-size: .72rem;
  font-variant-numeric: tabular-nums;
}
.btn-send-chat,
.btn-cancel-chat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  font-family: var(--chat-heading-font);
  font-size: .88rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-send-chat {
  background: var(--chat-accent);
  color: var(--chat-accent-fg);
}
.btn-send-chat:hover,
.btn-send-chat:focus-visible {
  background: var(--chat-accent-strong);
  color: var(--chat-accent-fg);
}
.btn-send-chat:disabled {
  opacity: .55;
  cursor: default;
}
.btn-cancel-chat {
  background: var(--chat-danger);
  color: var(--chat-danger-fg);
}
.btn-cancel-chat:hover,
.btn-cancel-chat:focus-visible {
  filter: brightness(1.1);
  color: var(--chat-danger-fg);
}
.chat-hint {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  color: var(--chat-fg-muted);
  font-size: .72rem;
}
@media (pointer: coarse) {
  .chat-hint-keys {
    visibility: hidden;
  }
}

.image-upload-wrapper {
  position: relative;
  display: inline-flex;
}
.image-upload-wrapper .spinner-vision {
  position: absolute;
  inset: 5px;
  width: 24px;
  height: 24px;
  color: var(--chat-accent);
  opacity: 0;
  pointer-events: none;
}
.image-preview-container {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  padding: 4px;
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius-sm);
  background: var(--chat-surface);
  box-shadow: var(--chat-shadow);
}
.image-preview-container .image-preview {
  display: block;
  max-width: 120px;
  max-height: 120px;
  border-radius: 8px;
}
.image-preview-container .remove-icon {
  position: absolute;
  top: -8px;
  right: -8px;
  color: var(--chat-danger);
  font-size: 1.1rem;
}

.chat-alert-mobile .alert {
  border-radius: var(--chat-radius-sm);
}

/* ── Side column ──────────────────────────────────────────────────────── */

.chat-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-inline-end: 1px solid var(--chat-border);
  background: var(--chat-surface);
}
.chat-side[hidden] {
  display: none;
}
.chat-side-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-side-section + .chat-side-section {
  border-top: 1px solid var(--chat-border);
}
.chat-side-conversations {
  flex: 1 1 auto;
}
.ai-contacts-top,
.chat-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px 10px;
}
.ai-contacts-top {
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
}
.ai-contacts-top strong,
.chat-side-head strong {
  color: var(--chat-fg);
  font-family: var(--chat-heading-font);
  font-size: .9rem;
}
.ai-contacts-top span {
  color: var(--chat-fg-muted);
  font-size: .8rem;
}
.ai-contacts-scroll,
.chat-side-list {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0 8px 10px;
  overflow-y: auto;
  list-style: none;
  scrollbar-width: thin;
}
.ai-contacts-item,
.chat-side-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--chat-fg);
  text-align: start;
  text-decoration: none;
}
.ai-contacts-item:hover,
.chat-side-item:hover,
.chat-side-item:focus-visible {
  background: var(--chat-surface-2);
  color: var(--chat-fg);
}
.ai-contacts-item-active,
.ai-contacts-item-active:hover,
.chat-side-item.is-current,
.chat-side-item.is-current:hover {
  background: var(--chat-surface-active);
}
.ai-contacts-image {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  overflow: hidden;
  border-radius: 50%;
}
.ai-contacts-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ai-contacts-info,
.chat-side-item-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.ai-contacts-name,
.chat-side-item-title {
  overflow: hidden;
  font-size: .86rem;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.ai-contacts-job,
.chat-side-item-meta {
  overflow: hidden;
  color: var(--chat-fg-muted);
  font-size: .75rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.ai-contacts-item .card-vip {
  position: absolute;
  top: 4px;
  left: 6px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  background: var(--chat-vip-bg);
}
.ai-contacts-item .card-vip img {
  width: 10px;
  height: 10px;
}
.ai-contacts-item .card-vip span {
  display: none;
}
.chat-side-empty {
  padding: 4px 18px 14px;
  color: var(--chat-fg-muted);
  font-size: .8rem;
}
.chat-side-new {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--chat-border);
  border-radius: 9px;
  background: var(--chat-surface);
  color: var(--chat-fg);
  font-size: .8rem;
  font-weight: 600;
  text-decoration: none;
}
.chat-side-new:hover,
.chat-side-new:focus-visible {
  border-color: var(--chat-accent);
  color: var(--chat-accent-text);
}
.chat-shell.is-busy .chat-side-item,
.chat-shell.is-busy .chat-side-new {
  opacity: .55;
  pointer-events: none;
}

.chat-shell.is-switching #overflow-chat {
  opacity: .5;
  transition: opacity .15s ease;
}

/* ── Plan gate ────────────────────────────────────────────────────────── */

.wrapper-vip-message {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 40px 20px;
  background: var(--chat-canvas);
  text-align: center;
}
.wrapper-vip-message h3 {
  margin-bottom: 24px;
  color: var(--chat-fg);
  font-family: var(--chat-heading-font);
  font-size: 1.25rem;
  font-weight: 700;
}
.wrapper-vip-package-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-bottom: 20px;
}
.wrapper-vip-credit-pack {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius-sm);
  background: var(--chat-surface);
  text-align: start;
}
.wrapper-vip-credit-image {
  width: 46px;
  height: 46px;
  overflow: hidden;
  border-radius: 12px;
  background: var(--chat-accent-soft);
}
.wrapper-vip-credit-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.wrapper-vip-credit-pack h4 {
  margin: 0;
  color: var(--chat-fg);
  font-size: .95rem;
  font-weight: 700;
}
.wrapper-vip-credit-pack h5 {
  margin: 0;
  color: var(--chat-fg-muted);
  font-size: .85rem;
}

/* ── Modals opened from the chat ──────────────────────────────────────── */

.wrapper-suggestion-group {
  max-height: 60vh;
  overflow-y: auto;
}
.wrapper-suggestion-group p {
  margin: 0 1em 0 0;
}

/* ── The About panel ──────────────────────────────────────────────────────
   One paragraph became the assistant's card, so it needs a shape: capability
   chips, then a definition list of facts. */
.assistant-about-description {
  margin-bottom: 1rem;
  white-space: pre-line;
  color: var(--chat-fg);
}
.assistant-about-caps {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}
.assistant-about-caps li {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .2rem .6rem;
  border: 1px solid var(--chat-border);
  border-radius: 999px;
  background: var(--chat-accent-soft);
  color: var(--chat-fg);
  font-size: .8rem;
}
.assistant-about-facts {
  display: grid;
  gap: .1rem;
  margin: 0;
}
.assistant-about-facts > div {
  display: grid;
  grid-template-columns: minmax(0, 11rem) minmax(0, 1fr);
  gap: .75rem;
  padding: .5rem 0;
  border-top: 1px solid var(--chat-border-soft);
}
.assistant-about-facts > div:first-child {
  border-top: 0;
}
.assistant-about-facts dt {
  display: flex;
  align-items: center;
  gap: .45rem;
  margin: 0;
  color: var(--chat-fg-muted);
  font-weight: 500;
}
.assistant-about-facts dt i {
  color: var(--chat-accent);
}
.assistant-about-facts dd {
  margin: 0;
  color: var(--chat-fg);
}

/* ── Narrow screens ───────────────────────────────────────────────────── */

@media (max-width: 991px) {
  .chat-shell.is-side-open .chat-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  /* The side column becomes a drawer over the conversation instead of
     squeezing it. */
  .chat-side {
    position: absolute;
    z-index: 20;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(300px, 86%);
    box-shadow: var(--chat-shadow);
  }
  html[dir="rtl"] .chat-side {
    right: 0;
    left: auto;
  }
}

@media (max-width: 767px) {
  .chat-shell.is-public {
    padding: 0;
  }
  .chat-shell.is-public .chat-container {
    padding: 0;
  }
  .chat-shell.is-public .chat-layout {
    height: calc(100vh - 70px);
    height: calc(100dvh - 70px);
    min-height: 0;
    border-width: 0;
    border-radius: 0;
  }
  .assistant-about-facts > div {
    grid-template-columns: minmax(0, 1fr);
    gap: .1rem;
  }
  .ai-chat-top {
    padding: 10px 12px;
  }
  .ai-chat-top-image {
    width: 38px;
    height: 38px;
  }
  .ai-categories,
  .chat-btn-suggestions,
  .chat-btn-about {
    display: none;
  }
  #overflow-chat {
    padding: 16px 12px 8px;
  }
  .conversation-thread {
    gap: 8px;
  }
  .user-image {
    width: 28px;
    height: 28px;
  }
  .thread-user .message-container {
    max-width: 88%;
  }
  .message-area-bottom {
    padding: 8px 10px 10px;
  }
  .btn-send-chat span,
  .btn-cancel-chat span {
    display: none;
  }
  .chat-hint {
    display: none;
  }
}
