/* ============================================================
   BUI Microsoft Awards — Ask the Agent
   Design tokens mirrored from the awards site
   (https://website-buiawards-bui-co.pages.dev/)
   ============================================================ */

:root {
  /* Surfaces */
  --bg: #171f28;          /* page background (matches site body) */
  --bg-deep: #12181f;     /* deeper panels */
  --bg-deepest: #0f1419;  /* darkest */
  --surface: #1e2731;     /* cards / agent bubbles */
  --surface-2: #12181f;   /* composer well */

  /* Brand */
  --orange: #d9861c;      /* BUI primary orange */
  --orange-soft: rgba(217, 134, 28, 0.14);
  --orange-line: rgba(217, 134, 28, 0.35);
  --blue: #1e6fa5;        /* secondary accent */
  --green: #3fb950;       /* live status */

  /* Text */
  --text: #e7eaee;
  --text-muted: #c9d3da;
  --text-dim: #8a9ba8;
  --text-faint: #6b7682;

  /* Lines */
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.12);
  --line-3: rgba(255, 255, 255, 0.16);

  /* Type */
  --serif: "Playfair Display", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;

  /* Shape */
  --r-sm: 3px;
  --r-md: 8px;
  --r-lg: 14px;
  --r-pill: 999px;

  --shadow: 0 18px 44px rgba(0, 0, 0, 0.3);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  height: 100%;
  /* Never let the iframe itself scroll — the message log scrolls internally. */
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Scale the fallback font to the web font's x-height so the swap doesn't
     shift layout (CLS). Resolves per-element, so Playfair headings are matched
     too. Ignored where unsupported. */
  font-size-adjust: from-font;
}

::selection {
  background: var(--orange);
  color: var(--bg-deepest);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------- Layout ---------------- */

.chat {
  display: flex;
  flex-direction: column;
  /* Fill the host container exactly. `height: 100%` tracks the iframe's set
     height in every browser; the viewport-unit lines are fallbacks for when
     the page is opened standalone (dvh avoids the mobile URL-bar jump). */
  height: 100vh;
  height: 100dvh;
  height: 100%;
  min-height: 0;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg);
  /* Positioning context for the floating "jump to latest" button. */
  position: relative;
}

/* ---------------- Header ---------------- */

.chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg-deep), var(--bg));
}

.chat__brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.chat__logo {
  width: 52px;
  height: auto;
  display: block;
  flex: none;
}

.chat__titles {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat__eyebrow {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  color: var(--orange);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat__title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 21px;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--text);
  /* Never wrap into the status pill in a narrow embed column. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat__status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: 6px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.chat__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(63, 185, 80, 0.14);
  animation: bui-live 2.4s ease-in-out infinite;
}

.chat__status[data-state="offline"] .chat__dot {
  background: var(--text-faint);
  box-shadow: 0 0 0 4px rgba(107, 118, 130, 0.14);
  animation: none;
}

.chat__status[data-state="busy"] .chat__dot {
  background: var(--orange);
  box-shadow: 0 0 0 4px var(--orange-soft);
}

@keyframes bui-live {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---------------- Conversation ---------------- */

.chat__log {
  flex: 1 1 auto;
  /* min-height:0 lets this flex child shrink below its content and scroll,
     instead of pushing the composer out of the iframe. */
  min-height: 0;
  overflow-y: auto;
  padding: 24px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

.chat__log::-webkit-scrollbar {
  width: 10px;
}
.chat__log::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: var(--r-pill);
  border: 3px solid var(--bg);
}

.msg {
  display: flex;
  gap: 12px;
  max-width: 100%;
  animation: bui-up 0.35s ease both;
}

@keyframes bui-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.msg__avatar {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--orange);
  background: var(--orange-soft);
  border: 1px solid var(--orange-line);
}

.msg__bubble {
  padding: 12px 16px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text-muted);
  max-width: min(80%, 560px);
  overflow-wrap: anywhere;
}

/* User messages — right aligned, orange-tinted */
.msg--user {
  flex-direction: row-reverse;
}

.msg--user .msg__avatar {
  color: var(--text-dim);
  background: var(--surface);
  border-color: var(--line-2);
}

.msg--user .msg__bubble {
  background: linear-gradient(180deg, rgba(217, 134, 28, 0.16), rgba(217, 134, 28, 0.08));
  border-color: var(--orange-line);
  color: var(--text);
}

/* Markdown content inside agent bubbles */
.msg__bubble { text-wrap: pretty; } /* avoid orphaned words in answers (progressive) */
.msg__bubble p { margin: 0 0 0.6em; }
.msg__bubble p:last-child { margin-bottom: 0; }
.msg__bubble ul,
.msg__bubble ol { margin: 0.2em 0 0.6em; padding-left: 1.3em; }
.msg__bubble li { margin: 0.2em 0; }
.msg__bubble strong { color: var(--text); font-weight: 600; }
.msg__bubble a { color: var(--orange); text-underline-offset: 2px; }
.msg__bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
  background: var(--bg-deepest);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 1px 5px;
}
.msg__bubble pre {
  background: var(--bg-deepest);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0.4em 0 0.6em;
}
.msg__bubble pre code { background: none; border: 0; padding: 0; }

/* Typing indicator */
.msg--typing .msg__bubble {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 16px;
}
.msg--typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: bui-pulse 1.2s ease-in-out infinite;
}
.msg--typing span:nth-child(2) { animation-delay: 0.18s; }
.msg--typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes bui-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.7); }
}

/* Error bubble */
.msg--error .msg__bubble {
  border-color: rgba(217, 70, 70, 0.4);
  background: rgba(217, 70, 70, 0.08);
  color: #f0c9c9;
}

/* ---------------- Suggested prompts ---------------- */

.chat__suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 20px 4px;
}

.chat__suggest.is-hidden { display: none; }

.chip {
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-pill);
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.chip:hover {
  color: var(--text);
  border-color: var(--orange-line);
  background: var(--orange-soft);
}

/* ---------------- Composer ---------------- */

.chat__composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 8px 16px 6px;
  padding: 8px 8px 8px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  transition: border-color 0.15s;
}

.chat__composer:focus-within {
  border-color: var(--orange-line);
}

.chat__input {
  flex: 1 1 auto;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  max-height: 140px;
  padding: 8px 0;
  /* Auto-grow vertically with content where supported (no Firefox yet);
     app.js runs its JS auto-grow only when this is unsupported. Width stays
     flex-controlled so there's no horizontal jitter. */
  field-sizing: content;
  min-block-size: 1lh;
  max-block-size: 140px;
}

.chat__input::placeholder { color: var(--text-faint); }

.chat__send {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-md);
  background: var(--orange);
  color: var(--bg-deepest);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.05s, filter 0.15s;
}

.chat__send:hover:not(:disabled) { filter: brightness(1.08); }
.chat__send:active:not(:disabled) { transform: scale(0.94); }
.chat__send:disabled {
  background: var(--surface);
  color: var(--text-faint);
  cursor: not-allowed;
}

.chat__footnote {
  text-align: center;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--text-dim); /* meets WCAG AA contrast on the dark surface */
  padding: 2px 20px 12px;
}

/* Floating "jump to latest" — shown only when the user has scrolled up. */
.chat__jump {
  position: absolute;
  right: 18px;
  bottom: 92px;
  z-index: 2;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--orange-line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--orange);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: opacity 0.15s, transform 0.15s;
}
.chat__jump[hidden] { display: none; }
.chat__jump:hover { filter: brightness(1.1); }
.chat__jump:active { transform: scale(0.92); }

@media (max-width: 480px) {
  .chat__header { padding: 12px 16px; }
  .chat__log { padding: 18px 14px 6px; }
  .chat__suggest { padding: 6px 14px 2px; }
  .chat__composer { margin: 6px 12px; }
  .chat__title { font-size: 19px; }
  .msg__bubble { max-width: 88%; }
}

/* Very narrow embed columns: drop the status pill and shrink the logo so the
   title always has room. */
@media (max-width: 430px) {
  .chat__logo { width: 40px; }
  .chat__status { display: none; }
  .chat__title { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; scroll-behavior: auto !important; }
}
