/* Door Soft chat window, terminal look. UI only until the RAG phase.
   Uses the colour and font tokens from site.css, so light and dark themes come for free.
   Fallback values below are the light terminal palette, used only if site.css is missing.
   Load after site.css:  <link rel="stylesheet" href="/assets/chat-widget.css"> */

.ds-chat {
  --c-surface: var(--surface, #fbf8f1);
  --c-bg: var(--bg, #f4ede0);
  --c-tint: var(--tint, #ece4d4);
  --c-line: var(--line, #ddd5c6);
  --c-line-2: var(--line-2, #c3baa9);
  --c-fg: var(--fg, #1f1c14);
  --c-fg-2: var(--fg-2, #3a352b);
  --c-muted: var(--muted, #665f52);
  --c-accent: var(--accent, #b5442a);
  --c-accent-strong: var(--accent-strong, #933520);
  --c-accent-tint: var(--accent-tint, #f1dccd);
  --c-on-accent: var(--on-accent, #fff);
  --c-mint: var(--mint, #3f6a39);
  --c-mint-tint: var(--mint-tint, #e1e6d2);
  --c-amber-tint: var(--amber-tint, #f3e2c2);
  --c-ink: var(--ink, #1f1c14);
  --c-ink-fg: var(--ink-fg, #e6dfd0);
  --c-ink-line: var(--ink-line, #3e392e);
  --c-shadow: var(--shadow-lift, 0 1px 0 rgba(31, 28, 20, .06), 0 18px 40px rgba(31, 28, 20, .10));
  position: fixed;
  right: max(20px, env(safe-area-inset-right, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  display: grid;
  justify-items: end;
  gap: 12px;
  --c-mono: var(--display, ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace);
  font-family: var(--sans, ui-sans-serif, system-ui, sans-serif);
}
/* Martian Mono's wide space breaks Bangla, so Bangla text uses the sans stack. */
.ds-chat:lang(bn) { --c-mono: var(--sans, ui-sans-serif, system-ui, sans-serif); }

/* Launcher — same size on every page (en/bn). Sans + fixed metrics; do not use mono
   (Martian Mono is wider, so Bangla pages looked smaller when --c-mono switched to sans). */
.ds-chat__launcher {
  display: inline-flex; align-items: center; gap: 10px;
  box-sizing: border-box; min-height: 44px;
  padding: 12px 18px; border-radius: 999px;
  background: var(--c-ink); color: #fff; border: 1px solid var(--c-ink-line);
  font: 600 0.94rem/1.2 var(--sans, ui-sans-serif, system-ui, sans-serif);
  letter-spacing: 0; cursor: pointer; box-shadow: var(--c-shadow);
}
.ds-chat__launcher[aria-expanded="true"] { background: var(--c-surface); color: var(--c-fg); border-color: var(--c-line-2); }
.ds-chat__dot {
  position: relative;
  width: 10px; height: 10px; flex: 0 0 auto;
  border-radius: 50%;
  background: var(--c-mint);
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--c-mint) 55%, transparent),
    0 0 0 5px color-mix(in srgb, var(--c-mint) 22%, transparent);
}
.ds-chat__dot::after {
  content: "";
  position: absolute; inset: -6px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--c-mint) 45%, transparent);
  animation: ds-dot-ring 1.8s ease-out infinite;
  pointer-events: none;
}
@keyframes ds-dot-ring {
  0% { transform: scale(0.72); opacity: 0.9; }
  70% { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}
.ds-chat__label-long, .ds-chat__label-short { font: inherit; letter-spacing: inherit; }
.ds-chat__label-short { display: none; }

/* Panel */
.ds-chat__panel {
  width: min(380px, calc(100vw - 40px));
  max-height: min(640px, calc(100dvh - 120px));
  display: flex; flex-direction: column;
  background: var(--c-surface); color: var(--c-fg);
  border: 1px solid var(--c-line); border-radius: 12px;
  box-shadow: var(--c-shadow); overflow: hidden;
}
.ds-chat__panel[hidden] { display: none; }

.ds-chat__top { display: flex; align-items: flex-start; gap: 12px; padding: 16px 14px 14px 18px; background: var(--c-ink); color: var(--c-ink-fg); }
.ds-chat__top > div { flex: 1 1 auto; min-width: 0; }
.ds-chat__top h2 { margin: 0; font: 600 0.95rem/1.3 var(--c-mono); letter-spacing: -0.02em; color: #fff; }
.ds-chat__top p { margin: 4px 0 0; font-size: 0.82rem; line-height: 1.4; }
.ds-chat__status { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; font: 500 0.7rem var(--c-mono); letter-spacing: -0.02em; color: #fff; background: rgba(255, 255, 255, .08); border: 1px solid var(--c-ink-line); border-radius: 4px; padding: 3px 8px; }
.ds-chat__status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c-mint); }
.ds-chat__status[data-state="soon"]::before { background: var(--amber, #e8b45c); }
.ds-chat__close { flex: 0 0 auto; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--c-ink-fg); cursor: pointer; }
.ds-chat__close:hover { border-color: var(--c-ink-line); color: #fff; }

.ds-chat__log { flex: 1 1 auto; min-height: 150px; overflow-y: auto; overscroll-behavior: contain; padding: 16px; display: flex; flex-direction: column; gap: 10px; }

/* Messages */
.ds-msg { max-width: 88%; margin: 0; padding: 10px 13px; border-radius: 10px; font-size: 0.92rem; line-height: 1.5; overflow-wrap: anywhere; }
.ds-msg--ai { align-self: flex-start; background: var(--c-tint); border-bottom-left-radius: 4px; }
.ds-msg--user { align-self: flex-end; background: var(--c-accent); color: var(--c-on-accent); border-bottom-right-radius: 4px; }
.ds-msg--note { align-self: stretch; max-width: none; background: var(--c-amber-tint); color: var(--c-fg); }
.ds-msg p { margin: 0; }
.ds-msg p + p { margin-top: 6px; }
.ds-msg__sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--c-line); }
.ds-msg__sources span { width: 100%; font: 400 0.7rem var(--c-mono); letter-spacing: -0.02em; color: var(--c-muted); }
.ds-msg__sources a { font-size: 0.8rem; font-weight: 600; color: var(--c-accent); text-decoration: none; background: var(--c-surface); border: 1px solid var(--c-line); border-radius: 6px; padding: 2px 8px; }
.ds-msg__sources a:hover { border-color: var(--c-accent); }
.ds-msg__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ds-msg__actions a, .ds-msg__actions button { display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px; border-radius: 8px; font: 600 0.84rem var(--sans, inherit); text-decoration: none; cursor: pointer; border: 1px solid var(--c-line-2); background: var(--c-surface); color: var(--c-fg); }
.ds-msg__actions .is-primary { background: var(--c-accent); border-color: var(--c-accent); color: var(--c-on-accent); }

/* Typing indicator */
.ds-typing { align-self: flex-start; display: inline-flex; gap: 4px; padding: 12px 14px; background: var(--c-tint); border-radius: 10px; border-bottom-left-radius: 4px; }
.ds-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--c-muted); animation: ds-blink 1.2s infinite both; }
.ds-typing i:nth-child(2) { animation-delay: .2s; }
.ds-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes ds-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* Suggested questions — no scrollbar; fade + chevrons hint when more than ~2 chips. */
.ds-chat__chips-wrap {
  position: relative;
  flex: 0 0 auto;
  margin: 0 0 4px;
}
.ds-chat__chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 0 16px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scroll-snap-type: x proximity;
  direction: ltr;
  scrollbar-width: none;
  cursor: grab;
}
.ds-chat__chips.is-dragging { cursor: grabbing; scroll-behavior: auto; user-select: none; }
.ds-chat__chips::-webkit-scrollbar { display: none; height: 0; }
.ds-chat__chips-wrap[data-can-left="true"]::before,
.ds-chat__chips-wrap[data-can-right="true"]::after {
  content: "";
  position: absolute; top: 0; bottom: 12px; width: 28px;
  pointer-events: none; z-index: 1;
}
.ds-chat__chips-wrap[data-can-left="true"]::before {
  left: 0;
  background: linear-gradient(to right, var(--c-surface) 35%, transparent);
}
.ds-chat__chips-wrap[data-can-right="true"]::after {
  right: 0;
  background: linear-gradient(to left, var(--c-surface) 35%, transparent);
}
.ds-chat__chips-nav {
  position: absolute; top: 50%; z-index: 2;
  transform: translateY(calc(-50% - 6px));
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 999px;
  border: 1px solid var(--c-line-2);
  background: var(--c-surface);
  color: var(--c-accent);
  box-shadow: var(--c-shadow);
  cursor: pointer;
}
.ds-chat__chips-nav[hidden] { display: none; }
.ds-chat__chips-nav--prev { left: 6px; }
.ds-chat__chips-nav--next { right: 6px; }
.ds-chat__chips-nav:hover { border-color: var(--c-accent); background: var(--c-accent-tint); }
.ds-chat__chips button {
  flex: 0 0 auto;
  white-space: nowrap;
  scroll-snap-align: start;
  font: 500 0.82rem var(--sans, inherit);
  color: var(--c-accent);
  background: var(--c-accent-tint);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}
.ds-chat__chips button:hover { border-color: var(--c-accent); }

/* Hand-off to a person (shown by the RAG phase) */
.ds-chat__lead { flex: 0 0 auto; display: grid; gap: 8px; margin: 0 16px 12px; padding: 12px; border: 1px solid var(--c-line); border-radius: 10px; background: var(--c-bg); }
.ds-chat__lead[hidden] { display: none; }
.ds-chat__lead p { margin: 0; font-size: 0.86rem; color: var(--c-fg-2); }
.ds-chat__lead input { width: 100%; min-width: 0; font: 400 0.95rem var(--sans, inherit); color: var(--c-fg); background: var(--c-surface); border: 1px solid var(--c-line-2); border-radius: 8px; padding: 9px 11px; }
.ds-chat__lead button { justify-self: start; min-height: 38px; padding: 0 14px; border-radius: 8px; border: 0; background: var(--c-accent); color: var(--c-on-accent); font: 600 0.88rem var(--sans, inherit); cursor: pointer; }

/* Input */
.ds-chat__input { flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--c-line); }
.ds-chat__input textarea { flex: 1 1 auto; min-width: 0; resize: none; max-height: 120px; font: 400 0.95rem/1.4 var(--sans, inherit); color: var(--c-fg); background: var(--c-surface); border: 1px solid var(--c-line-2); border-radius: 8px; padding: 9px 11px; }
.ds-chat__input textarea:focus, .ds-chat__lead input:focus { outline: 2px solid var(--c-accent); outline-offset: 1px; border-color: var(--c-accent); }
.ds-chat__send { flex: 0 0 auto; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 8px; border: 0; background: var(--c-accent); color: var(--c-on-accent); cursor: pointer; }
.ds-chat__send:disabled { opacity: .45; cursor: default; }
.ds-chat__foot { flex: 0 0 auto; margin: 0; padding: 8px 16px 12px; font: 400 0.7rem/1.45 var(--c-mono); letter-spacing: -0.02em; color: var(--c-muted); }
.ds-chat__foot a { color: inherit; }

.ds-chat .vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Mirror site.css .consent-open .helpdesk — cookie bar must not cover the launcher. */
.consent-open .ds-chat { display: none; }

/* Open mobile nav (site.css z-index 35) must not sit under the chat (z-index 50). */
@media (max-width: 1100px) {
  :has(.nav.open) .ds-chat { display: none; }
}

/* Phone: the panel becomes a sheet above the bottom bar */
@media (max-width: 600px) {
  .ds-chat { right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  .ds-chat__label-long { display: none; }
  .ds-chat__label-short { display: inline; }
  .ds-chat.is-open { left: 0; right: 0; bottom: 0; gap: 0; }
  .ds-chat.is-open .ds-chat__launcher { display: none; }
  .ds-chat.is-open .ds-chat__panel { width: 100%; max-height: 100dvh; border-radius: 12px 12px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  /* Full-height sheet: hide the fixed mobile CTA while chat is open. */
  :has(.ds-chat.is-open) .mobile-cta { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .ds-typing i { animation: none; opacity: .6; }
  .ds-chat__dot::after { animation: none; opacity: 0.55; transform: scale(1); }
}
