/* ============================================================================
   THE BURGERCODE AI CHAT WIDGET — STYLES.

   The widget is built entirely from the site's own tokens. There is not one
   hard-coded colour in this file: every fill, every border and every piece
   of type comes from a :root variable, so the widget stays in step with the
   rest of the page by construction.

   The panel is a fixed-position card in the bottom-right on desktop, and a
   near-full-screen sheet on a phone. It never covers the site's navigation
   on desktop, and it never traps the visitor: Escape closes it, and the
   close button is always in the same place.

   The animation is deliberately restrained — the site's standing rule is
   that animation must not fight the page. The panel rises and fades in,
   the messages fade up, and that is all. Every one of those is disabled
   under prefers-reduced-motion.
   ========================================================================= */

.bc-chat-root {
  position: fixed;
  right: var(--s-5);
  bottom: var(--s-5);
  z-index: 9000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--s-3);
  font-family: var(--font-body);
  color: var(--text);
  /* The widget must never make the page scroll horizontally. */
  max-width: 100vw;
}

.bc-chat-root *,
.bc-chat-root *::before,
.bc-chat-root *::after {
  box-sizing: border-box;
}

/* ---- The launcher ------------------------------------------------------ */

.bc-chat-launcher {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-strong);
  background: var(--brand);
  color: var(--on-brand);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow:
    0 10px 28px rgba(36, 21, 12, 0.20),
    0 2px 6px rgba(36, 21, 12, 0.12);
  transition:
    transform var(--t-fast) var(--ease-out),
    box-shadow var(--t-fast) var(--ease-out),
    background var(--t-fast) var(--ease-out);
}

.bc-chat-launcher:hover {
  background: var(--ember);
  transform: translateY(-2px);
  box-shadow:
    0 14px 34px rgba(36, 21, 12, 0.24),
    0 3px 8px rgba(36, 21, 12, 0.14);
}

.bc-chat-launcher:active {
  transform: translateY(0);
}

.bc-chat-launcher:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

/* The little unread dot. It disappears once the panel has been opened. */
.bc-chat-launcher-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 11px;
  height: 11px;
  border-radius: var(--r-pill);
  background: var(--patty);
  border: 2px solid var(--bg);
  transition: opacity var(--t-mid) var(--ease-out);
}

.bc-chat-root[data-open="true"] .bc-chat-launcher-dot {
  opacity: 0;
}

/* ---- The panel --------------------------------------------------------- */

.bc-chat-panel {
  width: 400px;
  max-width: calc(100vw - var(--s-6));
  height: min(560px, calc(100vh - 140px));
  max-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow:
    0 28px 64px rgba(36, 21, 12, 0.20),
    0 6px 18px rgba(36, 21, 12, 0.10);
  overflow: hidden;
  opacity: 0;
  transform: translateY(14px) scale(0.985);
  transition:
    opacity var(--t-mid) var(--ease-out),
    transform var(--t-mid) var(--ease-out);
}

.bc-chat-root[data-open="true"] .bc-chat-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.bc-chat-panel[hidden] {
  display: none;
}

/* ---- The header -------------------------------------------------------- */

.bc-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.bc-chat-head-text {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 0;
}

.bc-chat-avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: var(--r-sm);
  background: var(--brand);
  color: var(--on-brand);
  display: grid;
  place-items: center;
}

.bc-chat-head-titles {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.bc-chat-head-titles strong {
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.bc-chat-head-sub {
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bc-chat-head-actions {
  display: flex;
  gap: var(--s-1);
  flex: 0 0 auto;
}

.bc-chat-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition:
    background var(--t-fast) var(--ease-out),
    color var(--t-fast) var(--ease-out);
}

.bc-chat-icon-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.bc-chat-icon-btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---- The message log --------------------------------------------------- */

.bc-chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.bc-chat-log::-webkit-scrollbar {
  width: 8px;
}

.bc-chat-log::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-pill);
}

.bc-chat-msg {
  display: flex;
  animation: bc-chat-rise var(--t-mid) var(--ease-out) both;
}

@keyframes bc-chat-rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bc-chat-msg-user {
  justify-content: flex-end;
}

.bc-chat-bubble {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: var(--r-md);
  font-size: 0.92rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.bc-chat-msg-user .bc-chat-bubble {
  background: var(--brand);
  color: var(--on-brand);
  border-bottom-right-radius: var(--r-sharp);
}

.bc-chat-msg-assistant .bc-chat-bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--r-sharp);
  box-shadow: 0 1px 2px rgba(36, 21, 12, 0.04);
}

/* ---- The rendered markdown --------------------------------------------- */

.bc-chat-p {
  margin: 0 0 var(--s-2);
}

.bc-chat-p:last-child {
  margin-bottom: 0;
}

.bc-chat-heading {
  font-weight: 700;
  font-size: 0.95rem;
}

.bc-chat-list {
  margin: 0 0 var(--s-2);
  padding-left: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.bc-chat-list:last-child {
  margin-bottom: 0;
}

.bc-chat-list li {
  margin: 0;
}

.bc-chat-code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sharp);
  padding: 1px 5px;
}

.bc-chat-link {
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bc-chat-rule {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--s-3) 0;
}

/* ---- The typing indicator ---------------------------------------------- */

.bc-chat-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 15px;
  min-width: 58px;
}

.bc-chat-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--r-pill);
  background: var(--faint);
  animation: bc-chat-pulse 1.15s var(--ease-in-out) infinite;
}

.bc-chat-dot:nth-child(2) { animation-delay: 0.14s; }
.bc-chat-dot:nth-child(3) { animation-delay: 0.28s; }

@keyframes bc-chat-pulse {
  0%, 60%, 100% { opacity: 0.28; transform: translateY(0); }
  30%           { opacity: 1;    transform: translateY(-3px); }
}

/* ---- The suggested questions ------------------------------------------- */

.bc-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
}

.bc-chat-chip {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--r-pill);
  padding: 6px 12px;
  font-size: 0.79rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition:
    background var(--t-fast) var(--ease-out),
    border-color var(--t-fast) var(--ease-out),
    color var(--t-fast) var(--ease-out);
}

.bc-chat-chip:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}

.bc-chat-chip:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---- The composer ------------------------------------------------------ */

.bc-chat-composer {
  display: flex;
  align-items: flex-end;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
}

.bc-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.5;
  padding: 10px 12px;
  max-height: 140px;
  overflow-y: auto;
}

.bc-chat-input::placeholder {
  color: var(--faint);
}

.bc-chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.bc-chat-send {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: var(--r-md);
  border: 1px solid var(--brand);
  background: var(--brand);
  color: var(--on-brand);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition:
    background var(--t-fast) var(--ease-out),
    opacity var(--t-fast) var(--ease-out),
    transform var(--t-fast) var(--ease-out);
}

.bc-chat-send:hover:not(:disabled) {
  background: var(--ember);
  transform: translateY(-1px);
}

.bc-chat-send:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.bc-chat-send:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---- The status line and the privacy note ------------------------------ */

.bc-chat-status {
  padding: 0 var(--s-4) var(--s-3);
  background: var(--surface);
  flex: 0 0 auto;
}

.bc-chat-status-line {
  font-size: 0.78rem;
  color: var(--muted);
  padding-top: var(--s-2);
  display: flex;
  gap: var(--s-2);
  align-items: center;
  flex-wrap: wrap;
}

.bc-chat-status-error {
  color: var(--accent-text);
}

.bc-chat-status-link {
  color: var(--accent-text);
  font-weight: 600;
}

.bc-chat-privacy {
  margin: 0;
  padding-top: var(--s-2);
  font-size: 0.68rem;
  line-height: 1.45;
  color: var(--faint);
}

/* ---- The error bubble -------------------------------------------------- */

.bc-chat-error-msg .bc-chat-bubble {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.bc-chat-error-actions {
  display: flex;
  gap: var(--s-2);
  margin-top: var(--s-3);
  flex-wrap: wrap;
}

.bc-chat-btn {
  display: inline-block;
  border-radius: var(--r-pill);
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  background: var(--brand);
  color: var(--on-brand);
  border: 1px solid var(--brand);
  transition: background var(--t-fast) var(--ease-out);
}

.bc-chat-btn:hover {
  background: var(--ember);
}

.bc-chat-btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}

.bc-chat-btn-ghost:hover {
  background: var(--bg);
  color: var(--text);
}

/* ---- On a phone ------------------------------------------------------- */

@media (max-width: 640px) {
  .bc-chat-root {
    right: var(--s-3);
    bottom: var(--s-3);
    left: var(--s-3);
    align-items: stretch;
  }

  .bc-chat-launcher {
    width: 54px;
    height: 54px;
    align-self: flex-end;
  }

  .bc-chat-panel {
    width: 100%;
    max-width: 100%;
    height: min(74vh, 600px);
    max-height: calc(100dvh - 110px);
    border-radius: var(--r-lg);
  }

  .bc-chat-bubble {
    max-width: 92%;
  }

  /* On a phone the suggested questions scroll sideways in one row rather
     than stacking into five rows and pushing the composer off the screen. */
  .bc-chat-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--s-3);
  }

  .bc-chat-chips::-webkit-scrollbar {
    display: none;
  }

  .bc-chat-chip {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* A smaller privacy note, so it never gets clipped. */
  .bc-chat-privacy {
    font-size: 0.64rem;
  }
}

/* A short landscape phone. The panel must not exceed the viewport. */
@media (max-height: 520px) {
  .bc-chat-panel {
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
  }
}

/* ---- Reduced motion ---------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .bc-chat-panel,
  .bc-chat-launcher,
  .bc-chat-msg,
  .bc-chat-dot,
  .bc-chat-send,
  .bc-chat-chip,
  .bc-chat-icon-btn {
    animation: none !important;
    transition: none !important;
  }

  .bc-chat-panel {
    opacity: 1;
    transform: none;
  }
}

/* ---- Windows High Contrast --------------------------------------------- */

@media (forced-colors: active) {
  .bc-chat-panel,
  .bc-chat-launcher,
  .bc-chat-bubble {
    border: 1px solid CanvasText;
  }
}
