@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&family=IBM+Plex+Mono:wght@400;500&display=swap");

/* ==========================================================================
   Granite Document Chat — Carbon "Research Demos" shell
   Ported from the shared Granite demo template (Granite Guardian): cool-gray
   app card, white canvas frames, pill composer, dark floating info panel.
   Light only, like the template. Every colour, radius and duration below
   comes from the token block.
   ========================================================================== */

:root {
  color-scheme: light;

  /* --- Carbon / IBM tokens (verbatim from the template) --- */
  --white: #ffffff;
  --black: #000000;
  --cool-gray-10: #f2f4f8;
  --cool-gray-20: #dde1e6;
  --cool-gray-30: #c1c7cd;
  --cool-gray-50: #878d96;
  --cool-gray-60: #697077;
  --cool-gray-80: #343a3f;
  --cool-gray-100: #121619;

  --text-primary: #161616;
  --text-secondary: #525252;
  --text-helper: #6f6f6f;
  --text-placeholder: #a8a8a8;
  --text-on-color: #ffffff;
  --text-on-color-disabled: #8d8d8d;
  --content-regular: #252525;
  --icon-primary: #161616;
  --icon-secondary: #525252;

  --blue-10: #edf5ff;
  --blue-20: #d0e2ff;
  --blue-60: #0f62fe;
  --blue-70: #0353e9;
  --red-60: #da1e28;
  --red-10: #fff1f1;
  --green-60: #198038;

  --tag-color-orange: #8a3800;
  --tag-background-orange: #ffd9be;
  --tag-border-orange: #ff832b;

  --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Semantic aliases the rules below use. */
  --accent: var(--blue-60);
  --danger: var(--red-60);
  --line: var(--cool-gray-20);

  --r-sm: 6px;
  --r: 12px;
  --r-lg: 20px;

  /* app.js reads --dur and --ease for its two JS-driven animations. */
  --dur-fast: 120ms;
  --dur: 220ms;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition-property: opacity, background-color, border-color, color !important;
    transition-duration: 1ms !important;
    transform: none !important;
  }
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

* {
  box-sizing: border-box;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--cool-gray-30); border-radius: 100px; }
::-webkit-scrollbar-thumb:hover { background: var(--cool-gray-50); }
* { scrollbar-width: thin; scrollbar-color: var(--cool-gray-30) transparent; }

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--cool-gray-10);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 20px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--blue-20);
}

:where(button, input, textarea, select) {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

:where(a) {
  color: var(--accent);
  text-underline-offset: 2px;
}

:where(:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   App shell: card, header
   -------------------------------------------------------------------------- */

.app {
  height: 100dvh;
  min-height: 520px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-card {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--cool-gray-10);
  /* clip, not hidden: the closed info panel waits just past the right edge, and
     a hidden-overflow box can still be scrolled to it by a focus change. */
  overflow: clip;
}

.app-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 20px;
  height: 44px;
  padding: 0 8px 0 16px;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1 0 0;
  min-width: 0;
}

.app-header__logo {
  width: 31px;
  height: auto;
  flex-shrink: 0;
  color: var(--text-primary);
}

.app-header__divider {
  width: 1px;
  height: 24px;
  flex-shrink: 0;
  background: var(--cool-gray-30);
}

.app-header__title {
  margin: 0;
  font-size: 16px;
  line-height: 20px;
  color: var(--content-regular);
  white-space: nowrap;
}

.app-header__title strong {
  font-weight: 700;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* Model chips: Carbon read-only tags, quiet until their model is working. */
.chips {
  display: flex;
  gap: 6px;
  min-width: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid var(--cool-gray-20);
  background: var(--white);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease),
    background-color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease);
}

/* Model in flight: the one chip allowed to be loud. */
.chip.live {
  color: var(--blue-70);
  background: var(--blue-10);
  border-color: var(--blue-20);
}

/* A sleeping scale-to-zero endpoint. Amber rather than red: cold is normal,
   not broken -- the demo works, the first answer is just slow. */
.chip.waking {
  color: color-mix(in srgb, var(--warn, #b45309) 90%, var(--text));
  background: color-mix(in srgb, var(--warn, #b45309) 12%, transparent);
  border-color: color-mix(in srgb, var(--warn, #b45309) 35%, transparent);
}

.chip.waking::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: chip-pulse 1.4s ease-in-out infinite;
}

/* Honours prefers-reduced-motion: the colour alone carries the state. */
@media (prefers-reduced-motion: reduce) {
  .chip.waking::before {
    animation: none;
  }
}

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

.chip.live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.6s var(--ease) infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.28;
  }
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 14px;
  border: 1px solid var(--cool-gray-30);
  border-radius: 20px;
  background: var(--white);
  color: var(--icon-secondary);
  font-size: 14px;
  line-height: 16px;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease), transform 100ms var(--ease);
}

.btn-pill:hover,
.btn-pill[aria-pressed="true"] {
  color: var(--icon-primary);
}

.btn-pill__icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

@media (hover: hover) and (pointer: fine) {
  .btn-pill:active {
    transform: scale(0.97);
  }
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--icon-secondary);
  transition: color var(--dur-fast) var(--ease),
    background-color var(--dur-fast) var(--ease);
}

.icon-btn:hover {
  background: var(--cool-gray-10);
  color: var(--icon-primary);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Carbon tertiary-ish: the document card's Open, failure retries. */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--cool-gray-30);
  border-radius: 20px;
  background: var(--white);
  color: var(--text-primary);
  font-size: 14px;
  transition: background-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    transform 100ms var(--ease);
}

.btn-secondary:hover {
  background: var(--cool-gray-100);
  border-color: var(--cool-gray-100);
  color: var(--white);
}

.btn-secondary:active {
  transform: scale(0.97);
}

.text-btn {
  padding: 2px 6px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--text-helper);
  font-size: 12px;
  line-height: 16px;
  transition: background-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}

.text-btn:hover {
  background: var(--cool-gray-10);
  color: var(--text-primary);
}

/* Tooltips — dark pill shown below the trigger on hover/focus. */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--text-primary);
  color: var(--text-on-color);
  font-size: 12px;
  line-height: 12px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-fast) ease;
  z-index: 30;
}

/* A control at a panel's right edge grows its tooltip leftward. */
[data-tooltip].tt-end::after {
  left: auto;
  right: 0;
  transform: none;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   Workspace: Document (left) | Chat (right)
   -------------------------------------------------------------------------- */

.workspace {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  overflow: hidden;
}

.ws-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 8px 8px;
  overflow: hidden;
}

.ws-col--right {
  padding-left: 0;
}

.canvas-frame {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--white);
  border: 1px solid var(--cool-gray-20);
  border-radius: var(--r);
  overflow: hidden;
}

.canvas-toolbar {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  padding: 12px 16px;
  background: var(--white);
}

.canvas-toolbar__lead {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.canvas-toolbar__title {
  flex: none;
  font-weight: 500;
  font-size: 16px;
  line-height: 20px;
}

.chat-toolbar__actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* --------------------------------------------------------------------------
   Document panel
   -------------------------------------------------------------------------- */

.drawer-title {
  min-width: 0;
  color: var(--text-helper);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* View controls do nothing until there is a document to view. */
.drawer:not(.has-doc) .chat-toolbar__actions {
  opacity: 0.4;
  pointer-events: none;
}

/* Carbon content switcher, small. */
.seg {
  display: flex;
  margin-right: 6px;
  border: 1px solid var(--cool-gray-30);
  border-radius: 8px;
  overflow: hidden;
}

.seg-btn {
  height: 28px;
  padding: 0 12px;
  border: 0;
  border-left: 1px solid var(--cool-gray-30);
  background: var(--white);
  color: var(--text-secondary);
  font-size: 13px;
  transition: background-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}

.seg-btn:first-child {
  border-left: 0;
}

.seg-btn:hover {
  background: var(--cool-gray-10);
  color: var(--text-primary);
}

.seg-btn.on,
.seg-btn[aria-selected="true"] {
  background: var(--cool-gray-100);
  color: var(--white);
}

.seg-btn:focus-visible {
  outline-offset: -2px;
}

.doc-empty {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 16px 16px;
  overflow: auto;
}

.drop-card {
  flex: 1 1 0;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  border: 1px dashed var(--cool-gray-30);
  border-radius: var(--r);
  background: var(--cool-gray-10);
  color: var(--text-primary);
  text-align: center;
  transition: background-color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease);
}

.drop-card:hover {
  background: var(--blue-10);
  border-color: var(--accent);
}

.drop-card svg {
  width: 24px;
  height: 24px;
  margin-bottom: 6px;
  color: var(--icon-secondary);
}

.drop-card__primary {
  font-size: 14px;
  font-weight: 500;
}

.drop-card__secondary,
.doc-empty__hint {
  color: var(--text-helper);
  font-size: 13px;
}

.doc-empty__hint {
  margin: 0;
}

.drawer-body {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 24px 48px;
  font-size: 14px;
  line-height: 22px;
}

.drawer-body:focus-visible {
  outline-offset: -2px;
}

/* --------------------------------------------------------------------------
   Rendered markdown (document panel)
   -------------------------------------------------------------------------- */

.drawer-body > :first-child,
.drawer-body > .doc-chunk:first-child > :first-child {
  margin-top: 0;
}

.drawer-body :where(p, ul, ol, blockquote, h1, h2, h3, h4, h5, h6) {
  max-width: 72ch;
}

/* A figure's crop, placed by app.js above the vision model's description. */
.drawer-body .doc-figure {
  max-width: 72ch;
  margin: 16px 0 8px;
}

.drawer-body .doc-figure img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--cool-gray-20);
  border-radius: 4px;
  background: var(--white);
}

.drawer-body h1 {
  margin: 0 0 12px;
  font-weight: 400;
  font-size: 24px;
  line-height: 32px;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.drawer-body h2 {
  margin: 32px 0 8px;
  font-size: 16px;
  font-weight: 600;
  line-height: 22px;
}

.drawer-body h3 {
  margin: 24px 0 8px;
  font-size: 14px;
  font-weight: 600;
}

.drawer-body h4,
.drawer-body h5,
.drawer-body h6 {
  margin: 20px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.drawer-body p {
  margin: 0 0 12px;
  text-wrap: pretty;
}

.drawer-body em {
  color: var(--text-secondary);
}

.drawer-body ul,
.drawer-body ol {
  margin: 0 0 12px;
  padding-left: 1.4em;
}

.drawer-body li {
  margin-bottom: 4px;
}

.drawer-body blockquote {
  margin: 0 0 12px;
  padding-left: 14px;
  border-left: 2px solid var(--cool-gray-20);
  color: var(--text-secondary);
}

.drawer-body hr {
  height: 1px;
  margin: 28px 0;
  border: 0;
  background: var(--cool-gray-20);
}

.drawer-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--r-sm);
}

.drawer-body code,
.msg.assistant code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--cool-gray-10);
}

.drawer-body pre,
.msg.assistant pre {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--cool-gray-10);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 18px;
  overflow-x: auto;
}

.drawer-body pre code,
.msg.assistant pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

/* Raw tab: one long monospace document, full width. */
.drawer-body pre.raw {
  margin: 0;
  padding: 0;
  border-radius: 0;
  background: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-primary);
}

/* Tables: the wrapper scrolls, the table does not squash. */
.table-wrap {
  max-width: 100%;
  margin: 0 0 16px;
  overflow-x: auto;
  border: 1px solid var(--cool-gray-20);
  border-radius: 8px;
}

.drawer-body table,
.msg.assistant table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 13px;
  line-height: 18px;
}

.drawer-body > table,
.msg.assistant > table {
  display: block;
  max-width: 100%;
  margin-bottom: 16px;
  overflow-x: auto;
}

.drawer-body th,
.msg.assistant th {
  padding: 8px 12px;
  background: var(--cool-gray-10);
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

.drawer-body td,
.msg.assistant td {
  padding: 8px 12px;
  border-top: 1px solid var(--cool-gray-20);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Chat panel
   -------------------------------------------------------------------------- */

.chat-body {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 0 16px 16px;
}

.chat-messages {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 8px 4px 16px 0;
}

.thread:empty {
  padding: 0;
}

/* Welcome — icon box, title, description, then the suggestion. */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin: auto 0;
  padding: 24px 16px 24px 12px;
  max-width: 560px;
}

.chat-welcome__icon-box {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  border: 1px solid var(--cool-gray-20);
  border-radius: var(--r-sm);
  background: var(--white);
  animation: welcome-in 320ms var(--ease) 40ms both;
}

.chat-welcome__icon {
  width: 16px;
  height: 16px;
}

.chat-welcome__title {
  margin: 0 0 8px;
  font-size: 24px;
  line-height: 32px;
  font-weight: 400;
  letter-spacing: -0.01em;
  animation: welcome-in 360ms var(--ease) 160ms both;
}

.chat-welcome__description {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 20px;
  text-wrap: pretty;
  animation: welcome-in 400ms var(--ease) 280ms both;
}

@keyframes welcome-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  margin: 20px 0 0 -12px;
  animation: welcome-in 400ms var(--ease) 380ms both;
}

.chat-suggestion {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  text-align: left;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  transition: background-color var(--dur-fast) var(--ease),
    transform 100ms var(--ease);
}

.chat-suggestion__primary {
  flex: none;
  color: var(--text-primary);
}

.chat-suggestion__secondary {
  color: var(--text-helper);
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-suggestion:hover {
  background: var(--cool-gray-10);
}

.chat-suggestion:active {
  transform: scale(0.98);
  background: var(--cool-gray-20);
}

.chat-suggestion:disabled {
  opacity: 0.5;
  cursor: progress;
}

/* --------------------------------------------------------------------------
   Messages
   -------------------------------------------------------------------------- */

.msg {
  animation: rise var(--dur) var(--ease) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.msg.user {
  align-self: flex-end;
  max-width: 80%;
  min-width: 60px;
  padding: 12px 16px;
  background: var(--cool-gray-10);
  border-radius: 20px 20px 0 20px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* An attachment turn is markup, not typed text. */
.msg.user:has(.attach-chip) {
  white-space: normal;
}

.msg.user p {
  margin: 0;
  white-space: pre-wrap;
}

.msg.user .attach-chip + p {
  margin-top: 8px;
}

/* No bubble: a grounded answer can run six paragraphs and must read as prose. */
.msg.assistant {
  max-width: 68ch;
  padding-left: 12px;
  font-size: 14px;
  line-height: 22px;
  overflow-wrap: anywhere;
}

.msg.assistant > :first-child {
  margin-top: 0;
}

.msg.assistant > :last-child {
  margin-bottom: 0;
}

.msg.assistant p {
  margin: 0 0 12px;
}

.msg.assistant ul,
.msg.assistant ol {
  margin: 0 0 12px;
  padding-left: 1.35em;
}

.msg.assistant li {
  margin-bottom: 4px;
}

.msg.assistant strong {
  font-weight: 600;
}

.msg.assistant h1,
.msg.assistant h2,
.msg.assistant h3 {
  margin: 18px 0 6px;
  font-size: 15px;
  font-weight: 600;
}

/* Attachment chip: badge, name, page count. */
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  font-size: 13px;
  overflow-wrap: anywhere;
  white-space: normal;
}

.attach-badge {
  flex: none;
  display: grid;
  place-items: center;
  height: 20px;
  min-width: 32px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--tag-background-orange);
  border: 1px solid var(--tag-border-orange);
  color: var(--tag-color-orange);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.attach-name {
  font-weight: 500;
}

.attach-meta {
  color: var(--text-helper);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Tool-call trace — an accordion in the template's evaluation vocabulary.
   -------------------------------------------------------------------------- */

.trace {
  margin-left: 12px;
  border: 1px solid var(--cool-gray-20);
  border-radius: var(--r);
  background: var(--white);
  overflow: hidden;
  animation: rise var(--dur) var(--ease) both;
}

.trace-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  background: none;
  font-size: 14px;
  line-height: 20px;
  color: var(--text-secondary);
  text-align: left;
}

/* The card clips overflow, so the ring goes inside. */
.trace-head:focus-visible {
  outline-offset: -2px;
}

/* Carbon chevron--down, rotated open. */
.trace-head::before {
  content: "";
  flex: none;
  width: 16px;
  height: 16px;
  background: var(--icon-secondary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M16 22 6 12 7.4 10.6 16 19.2 24.6 10.6 26 12z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M16 22 6 12 7.4 10.6 16 19.2 24.6 10.6 26 12z'/%3E%3C/svg%3E") center / contain no-repeat;
  transform: rotate(-90deg);
  transition: transform var(--dur) var(--ease);
}

.trace:not(.collapsed) .trace-head::before {
  transform: rotate(0deg);
}

.trace-name {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trace-summary {
  display: none;
  color: var(--text-helper);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trace.collapsed .trace-summary {
  display: inline;
}

.trace-time {
  margin-left: auto;
  flex: none;
  color: var(--text-helper);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.trace.collapsed .trace-body {
  display: none;
}

.trace-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 14px 14px 38px;
}

.trace-kv {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 18px;
  color: var(--text-helper);
  overflow-wrap: anywhere;
}

.trace-kv b {
  color: var(--text-primary);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.trace-body .text-btn {
  align-self: flex-start;
  margin-left: -6px;
}

.trace-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--cool-gray-20);
  overflow: hidden;
}

.trace-bar > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: var(--accent);
  transition: width var(--dur) var(--ease);
}

/* Running: the template's "Evaluating" text shimmer on the tool name. */
.trace.running .trace-name {
  color: transparent;
  background-image: linear-gradient(110deg,
      var(--text-secondary) 0%, var(--text-secondary) 35%,
      var(--text-primary) 50%,
      var(--text-secondary) 65%, var(--text-secondary) 100%);
  background-size: 200% 100%;
  background-position: 100% 50%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: text-shimmer 2s linear infinite;
}

@keyframes text-shimmer {
  to {
    background-position: 0% 50%;
  }
}

.trace.failed {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--cool-gray-20));
  background: var(--red-10);
}

.trace.failed .trace-head::before {
  background: var(--danger);
}

.trace.failed .trace-name,
.trace.failed .trace-summary {
  color: var(--danger);
}

.trace.failed .trace-bar > i {
  background: var(--danger);
}

/* --------------------------------------------------------------------------
   Document card
   -------------------------------------------------------------------------- */

.doccard {
  margin-left: 12px;
  border: 1px solid var(--cool-gray-20);
  border-radius: var(--r);
  background: var(--white);
  overflow: hidden;
  animation: rise var(--dur) var(--ease) both;
}

.doccard-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 14px 16px 0;
}

.doccard-title {
  font-size: 16px;
  font-weight: 500;
  line-height: 22px;
  overflow-wrap: anywhere;
}

.doccard-ext {
  margin-left: auto;
  flex: none;
  color: var(--text-helper);
  font-family: var(--font-mono);
  font-size: 12px;
}

.doccard-preview {
  margin: 0;
  padding: 8px 16px 0;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 20px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.doccard-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px 14px;
}

.doccard-meta {
  color: var(--text-helper);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.doccard-foot .btn-secondary {
  margin-left: auto;
}

/* --------------------------------------------------------------------------
   Composer — the template's pill input bar
   -------------------------------------------------------------------------- */

.chat-input-bar {
  flex-shrink: 0;
  margin: 0;
}

/* A sleeping scale-to-zero endpoint. Amber rather than red: cold is normal,
   not broken -- the demo works, the first answer is just slow. The negative
   margin pulls it toward the composer it describes, inside .chat-body's gap. */
.endpoint-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin: 0 0 -8px;
  padding: 0 12px;
  color: color-mix(in srgb, var(--warn, #b45309) 90%, var(--text));
  font-size: 12px;
  line-height: 16px;
}

.endpoint-status::before {
  content: "";
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: chip-pulse 1.4s ease-in-out infinite;
}

/* Honours prefers-reduced-motion: the colour alone carries the state. */
@media (prefers-reduced-motion: reduce) {
  .endpoint-status::before {
    animation: none;
  }
}

.chat-input-bar__inner {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 45px;
  padding: 6px 6px 6px 8px;
  background: var(--white);
  border: 1px solid var(--cool-gray-20);
  border-radius: 100px;
  transition: border-color 160ms var(--ease), border-radius 200ms var(--ease);
}

.chat-input-bar__inner:focus-within {
  border-color: var(--cool-gray-50);
}

/* More than one line, or a pending attachment: the pill relaxes to a card. */
.chat-input-bar.is-multiline .chat-input-bar__inner,
.chat-input-bar__inner:has(#pending-attachment) {
  align-items: flex-end;
  flex-wrap: wrap;
  border-radius: 16px;
}

.chat-input {
  flex: 1 1 0;
  min-width: 0;
  max-height: 120px;
  padding: 6px 0;
  border: 0;
  background: transparent;
  font-size: 14px;
  line-height: 20px;
  color: var(--text-primary);
  outline: none;
  resize: none;
  field-sizing: content;
}

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

/* The field, not the bare textarea, carries focus — the row reads as one control. */
.chat-input:focus,
.chat-input:focus-visible {
  outline: none;
}

/* Focus darkens the pill's border to cool-gray-100 rather than ringing it: the
   template's input never wears a ring, and the change is still unmistakable. */
.chat-input-bar__inner:has(.chat-input:focus-visible) {
  border-color: var(--cool-gray-100);
}

.chat-input-bar__inner .icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.chat-send-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--cool-gray-100);
  color: var(--white);
  transition: background-color var(--dur-fast) var(--ease),
    transform 100ms var(--ease);
}

.chat-send-btn:hover {
  background: var(--blue-60);
}

.chat-send-btn:active {
  transform: scale(0.95);
}

.chat-send-btn:disabled {
  background: var(--cool-gray-30);
  cursor: not-allowed;
}

.chat-send-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* Pending attachment: a full-width row on top of the relaxed card. */
#pending-attachment {
  order: -1;
  flex: 1 0 100%;
  min-width: 0;
  gap: 8px;
  padding: 2px 4px 4px;
}

#pending-attachment > .attach-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#pending-attachment > .text-btn {
  flex: none;
  margin-left: auto;
}

/* --------------------------------------------------------------------------
   Info panel — dark, floating, over a frosted card
   -------------------------------------------------------------------------- */

.app-card::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 15;
  background: rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  backdrop-filter: blur(12px) saturate(1.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}

.app-card.is-dimmed::after {
  opacity: 1;
  pointer-events: auto;
}

.info-panel {
  position: absolute;
  z-index: 20;
  top: 8px;
  right: 8px;
  bottom: 8px;
  width: calc(60% - 8px);
  display: flex;
  border-radius: 8px;
  background: var(--black);
  color: var(--text-on-color);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  transform: translateX(24px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease),
    visibility 0s linear var(--dur);
}

.info-panel.is-open {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease),
    visibility 0s;
}

.info-panel__graphic {
  position: relative;
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px 0 12px 12px;
  border-radius: var(--r);
  background: var(--blue-60);
  overflow: hidden;
}

.info-panel__graphic::after {
  content: "";
  position: absolute;
  inset: -30% 0;
  pointer-events: none;
  transform: translateX(-150%) skewX(-20deg);
  background: linear-gradient(90deg, transparent 5%, rgba(69, 137, 255, 0.65) 50%, transparent 95%);
  animation: shimmer 3s infinite;
}

@keyframes shimmer {
  to {
    transform: translateX(150%) skewX(-20deg);
  }
}

.info-panel__glyph {
  width: 96px;
  height: 96px;
  color: var(--white);
}

.info-panel__main {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.info-panel__handle {
  display: none;
  width: 36px;
  height: 4px;
  margin: 12px auto 4px;
  border-radius: 2px;
  background: var(--cool-gray-60);
  flex-shrink: 0;
}

.info-panel__header {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 24px;
}

.info-panel__header::after {
  content: "";
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 0;
  height: 1px;
  background: var(--cool-gray-80);
}

.info-panel__title {
  margin: 0;
  font-weight: 400;
  font-size: 20px;
  line-height: 28px;
}

.info-panel__subtitle {
  margin: 4px 0 0;
  font-size: 16px;
  line-height: 24px;
  color: var(--text-on-color-disabled);
}

.info-panel__links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.info-panel__link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--cool-gray-100);
  color: var(--text-on-color);
  font-size: 14px;
  line-height: 18px;
  text-decoration: none;
  transition: border-color var(--dur-fast) var(--ease);
}

.info-panel__link:hover {
  border-color: var(--cool-gray-80);
}

.info-panel__link:focus-visible {
  outline-color: var(--white);
  outline-offset: 2px;
}

.info-panel__link-arrow,
.info-panel__link-logo {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.info-panel__actions {
  flex-shrink: 0;
}

.info-panel__icon-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--cool-gray-80);
  border-radius: 50%;
  background: transparent;
  color: var(--text-on-color);
}

.info-panel__icon-btn:hover {
  background: var(--cool-gray-80);
}

.info-panel__icon-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

.info-panel__body {
  flex: 1 0 0;
  min-height: 0;
  padding: 20px;
  overflow: auto;
  font-size: 14px;
  line-height: 20px;
  letter-spacing: 0.16px;
}

.info-panel__body > * {
  max-width: 504px;
}

.info-panel__body p {
  margin: 0 0 20px;
}

.info-panel__body p.info-panel__list-title {
  margin: 0 0 4px;
}

.info-panel__body ul {
  margin: 0;
  padding-left: 21px;
}

.info-panel__body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.info-panel__footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
  padding: 20px 20px 16px;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 12px;
  background: var(--tag-background-orange);
  border: 1px solid var(--tag-border-orange);
  color: var(--tag-color-orange);
  font-size: 14px;
  line-height: 18px;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Drop overlay
   -------------------------------------------------------------------------- */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  /* Never intercept the drag it is reporting. */
  pointer-events: none;
  display: grid;
  place-items: center;
  background: rgba(242, 244, 248, 0.85);
  color: var(--blue-60);
  font-size: 16px;
  font-weight: 500;
  animation: fade var(--dur-fast) var(--ease) both;
}

.drop-overlay::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 2px dashed var(--blue-60);
  border-radius: var(--r);
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   Responsive — Carbon breakpoints (lg 1056, md 672)
   -------------------------------------------------------------------------- */

@media (max-width: 1056px) {
  /* Stacked: chat leads; the document panel takes the top 40% once it has
     something to show, and stays a slim invitation until then. */
  .workspace {
    display: flex;
    flex-direction: column;
  }

  .ws-col--left {
    order: 0;
    flex: 0 0 auto;
    max-height: 40%;
  }

  /* Until then the frame sizes to its content -- a 1fr frame in an
     auto-height column has nothing to fill and collapses to zero. */
  .ws-col--left .canvas-frame {
    flex: 0 1 auto;
  }

  .ws-col--left:has(.drawer.has-doc) {
    flex: 0 0 40%;
  }

  .ws-col--left:has(.drawer.has-doc) .canvas-frame {
    flex: 1 1 0;
  }

  .doc-empty {
    flex: none;
  }

  .ws-col--right {
    flex: 1 1 0;
    padding-left: 8px;
  }

  .drop-card {
    flex: none;
    min-height: 0;
    flex-direction: row;
    padding: 14px;
  }

  .drop-card svg {
    margin: 0 4px 0 0;
  }

  .doc-empty__hint,
  .drop-card__secondary {
    display: none;
  }

  .msg.user {
    max-width: 88%;
  }

  /* Info panel → bottom sheet */
  .info-panel {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 60dvh;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }

  .info-panel.is-open {
    transform: none;
  }

  .info-panel__graphic {
    display: none;
  }

  .info-panel__handle {
    display: block;
  }

  .info-panel__header {
    padding: 8px 16px 16px;
  }

  .info-panel__header::after {
    left: 16px;
    right: 16px;
  }

  .info-panel__body {
    padding: 14px 16px;
  }

  .info-panel__footer {
    padding: 12px 16px 14px;
  }
}

@media (max-width: 672px) {
  [data-tooltip]::after {
    display: none;
  }

  .app-header {
    padding: 0 6px 0 12px;
    gap: 10px;
  }

  .app-header__brand {
    gap: 10px;
  }

  .app-header__title {
    font-size: 14px;
  }

  /* The chips are status, not navigation; on a phone the Info pill matters more. */
  .chips {
    display: none;
  }

  .btn-pill__label {
    display: none;
  }

  .btn-pill--icon {
    width: 28px;
    padding: 0;
  }

  .ws-col {
    padding: 0 4px 4px;
  }

  .ws-col--right {
    padding-left: 4px;
  }

  .canvas-toolbar {
    min-height: 52px;
    padding: 10px 12px;
  }

  .drawer-title {
    display: none;
  }

  .chat-body {
    padding: 0 12px 12px;
  }

  .doc-empty {
    padding: 0 12px 12px;
  }

  .drawer-body {
    padding: 4px 16px 32px;
  }

  .chat-welcome {
    padding: 16px 4px;
  }

  .chat-suggestions {
    margin-left: -8px;
  }
}
