:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  color: #263c59;
  background: #f7f9fc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 20rem;
}

.skip-link {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 3;
  padding: 0.65rem 0.9rem;
  color: #ffffff;
  background: #172033;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header,
.page-shell {
  width: min(100% - 2rem, 50.75rem);
  margin-inline: auto;
}

.site-header {
  padding-block: 0.75rem;
  background: #f7f9fc;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--site-header-height, 12rem) - 1rem);
  min-height: 0;
  overflow-y: auto;
}
.chat-shell > * { flex-shrink: 0; }

.site-header h1 { margin-bottom: 0; font-size: 1.5rem; }
.panel.chat-shell { padding-block: 1.25rem; margin-bottom: 1rem; }

.site-header h1,
.panel h2,
.result h3 {
  margin-top: 0;
}

.dev-banner {
  margin: 0.5rem 0 0;
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: 0.75rem;
  color: #536782;
  background: #edf2f8;
  font-size: 0.8rem;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: #4a5872;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel {
  margin-bottom: 1.5rem;
  padding: clamp(1rem, 3vw, 2rem);
  border: 1px solid #e5eaf1;
  border-radius: 1.25rem;
  background: #ffffff;
  box-shadow: 0 0.25rem 1.5rem rgb(23 32 51 / 3%);
}

.chat-shell__header,
.chat-composer__actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.chat-shell__header h2 {
  margin-bottom: 0;
}

.provider-badge {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid #174ea6;
  border-radius: 999px;
  color: #174ea6;
  background: #edf4ff;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
}

.state-label {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border: 1px solid #62718a;
  border-radius: 999px;
  color: #34435b;
  background: #edf0f5;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.state-label[data-state="ready"],
.state-label[data-state="active"],
.state-label[data-state="completed"] {
  border-color: #38825a;
  color: #205d3a;
  background: #edf9f1;
}

.state-label[data-state="busy"],
.state-label[data-state="running"],
.state-label[data-state="waiting_for_approval"] {
  border-color: #9a6300;
  color: #684300;
  background: #fff5d6;
}

.state-label[data-state="failed"],
.state-label[data-state="unavailable"],
.state-label[data-state="session_expired"],
.state-label[data-state="outcome_unknown"] {
  border-color: #a72b3a;
  color: #7d1421;
  background: #fff0f1;
}

.state-label[data-state="reconnecting"] {
  border-color: #7a5b96;
  color: #533576;
  background: #f6f0ff;
}

.provider-chooser {
  margin-top: 1.25rem;
  padding: 1rem;
  border: 1px solid #c7d0df;
  border-radius: 0.5rem;
  background: #f8fafc;
}

.provider-chooser fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.provider-chooser legend {
  margin-bottom: 0.65rem;
  font-weight: 700;
}

.provider-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.provider-choices label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid #8b98ac;
  border-radius: 0.4rem;
  font-weight: 600;
  cursor: pointer;
}

.provider-choices input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: #174ea6;
}

.provider-choices label:has(:checked) {
  border-color: #174ea6;
  background: #edf4ff;
}

.provider-choices input:focus-visible {
  outline: 3px solid #ffbf47;
  outline-offset: 3px;
}

.conversation-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem 1rem;
  margin: 0.75rem 0 0;
  color: #536782;
  font-size: 0.75rem;
}
.conversation-meta div {
  display: block;
  min-width: 0;
  padding: 0;
  border: 0;
}
.conversation-meta dt { margin-bottom: 0.2rem; font-weight: 600; }
.conversation-meta dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }

.chat-transcript {
  /* Contain hidden message labels within the transcript scroll area. */
  position: relative;
  display: flow-root;
  flex: 1 1 0;
  margin: 0.75rem 0;
  padding: 1.5rem 0 0;
  list-style: none;
  min-height: 0;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 1.5rem);
  mask-image: linear-gradient(to bottom, transparent, #000 1.5rem);
  overflow-y: auto;
}

.chat-transcript,
.chat-composer textarea {
  scrollbar-width: thin;
  scrollbar-color: #c6d2e2 transparent;
}
.chat-message { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.chat-message--user {
  width: fit-content;
  max-width: 85%;
  margin: 1.5rem 0 1.5rem auto;
  padding: 0.8rem 1.1rem;
  border: 0;
  border-radius: 1.25rem;
  background: #f0f2f5;
}
/* Item identity is retained for replay; only Markdown supplies agent spacing. */
.chat-message--assistant {
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}
.chat-message--provider,
.chat-message--error {
  width: fit-content;
  margin: 1rem auto 1rem 0;
  padding: 0.75rem 1rem;
  border: 0;
  border-radius: 0.75rem;
  color: #465b78;
  background: #eaf2ff;
  font-size: 0.8rem;
}
.chat-message--error { color: #7d1421; background: #fff0f1; }
.chat-message--error .chat-message__label { color: #9c3444; }
.chat-error__json { margin: 0.65rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 0.75rem/1.6 ui-monospace, monospace; }
.chat-message__label {
  margin: 0 0 0.4rem;
  color: #476c9e;
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.sr-only,
.chat-message--user > .chat-message__label,
.chat-message--assistant > .chat-message__label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.chat-message__body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; line-height: 1.75; }
.chat-message__body:has(> *) { white-space: normal; }
.chat-message__body p { margin-block: 0 1rem; }
.chat-message--user .chat-message__body > :first-child { margin-top: 0; }
.chat-message--user .chat-message__body > :last-child { margin-bottom: 0; }
.chat-message__body pre {
  max-width: 100%;
  padding: 1rem;
  border-radius: 0.75rem;
  background: #f1f5fa;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.85em;
}
.chat-message__body a { color: #215ec3; overflow-wrap: anywhere; }
.chat-message__body blockquote { margin-inline: 0; padding-left: 1rem; border-left: 3px solid #b4cae8; color: #536782; }
.chat-message__body table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.chat-message__body th, .chat-message__body td { padding: 0.5rem; border-bottom: 1px solid #dfe7f1; text-align: left; }
.chat-composer {
  position: relative;
  margin-top: 1rem;
  padding: 0.5rem;
  border-radius: 1.5rem;
  background: #f0f3f7;
  box-shadow: 0 0 0 6px #fff;
}
.chat-composer:focus-within { box-shadow: 0 0 0 2px #c7d9f5, 0 0 0 6px #fff; }
.chat-composer textarea {
  display: block;
  width: 100%;
  min-height: 0;
  overflow-y: hidden;
  padding: 0.5rem 0.85rem;
  border: 0;
  border-radius: 1rem;
  outline: none;
  color: inherit;
  background: transparent;
  font: inherit;
  line-height: 1.6;
  resize: none;
}
.chat-composer textarea::placeholder { color: #7184a0; }
.chat-composer__actions { display: flex; align-items: center; justify-content: flex-end; min-height: 2.5rem; }
button.composer-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 2.25rem;
  width: 2.25rem;
  min-height: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #2863bd;
}
.composer-icon svg { width: 1.25rem; height: 1.25rem; }
button.composer-icon:disabled { background: #91a2bb; opacity: 1; cursor: default; }
.chat-recovery, .approval-request__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }
.chat-recovery:has(button:not([hidden])) { margin-top: 1rem; }

button {
  min-height: 2.75rem;
  padding: 0.65rem 1rem;
  border: 2px solid #174ea6;
  border-radius: 0.4rem;
  color: #ffffff;
  background: #174ea6;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #103d83;
  border-color: #103d83;
}

button.button-secondary {
  border-color: #53627a;
  color: #26354d;
  background: #eef2f7;
}

button.button-secondary:hover:not(:disabled) {
  border-color: #34435b;
  background: #dfe6ef;
}

button:focus-visible,
.skip-link:focus-visible {
  outline: 3px solid #ffbf47;
  outline-offset: 3px;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.status,
.result {
  margin-top: 1.25rem;
  padding: 1rem;
  border-radius: 0.4rem;
}

.status {
  border: 0;
  color: #536782;
  background: #f5f8fc;
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
}

.status[data-state="session_expired"],
.status[data-state="failed"],
.status[data-state="unavailable"],
.status[data-state="outcome_unknown"] {
  border: 1px solid #a72b3a;
  background: #fff0f1;
}

.status[data-state="reconnecting"],
.status[data-state="waiting_for_approval"] {
  border: 1px solid #7a5b96;
  background: #f6f0ff;
}

.cancellation-status {
  margin-block: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid #8ba7ce;
  border-radius: 0.4rem;
  background: #edf4ff;
}

.approval-requests {
  display: grid;
  gap: 0.85rem;
  margin-top: 1rem;
}

.approval-request {
  padding: 1rem;
  border: 1px solid #9a6300;
  border-radius: 0.5rem;
  background: #fffaf0;
}

.approval-request h3 {
  margin-top: 0;
}

.approval-request__actions {
  margin-top: 1rem;
}

.approval-request__result {
  margin: 0;
  font-weight: 700;
}

.result--success {
  border: 1px solid #38825a;
  background: #edf9f1;
}

.result--error {
  border: 1px solid #a72b3a;
  background: #fff0f1;
}

.result h3,
.result p {
  margin-bottom: 0;
}

dl,
dl div {
  display: grid;
  gap: 0.35rem;
}

dl {
  margin-bottom: 0;
}

dl div {
  grid-template-columns: minmax(7rem, 1fr) 3fr;
  padding-block: 0.55rem;
  border-top: 1px solid rgb(23 32 51 / 15%);
}

dt {
  font-weight: 700;
}

dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

[hidden] {
  display: none !important;
}

@media (max-width: 32rem) {
  .approval-request__actions {
    align-items: stretch;
    flex-direction: column;
  }

  .provider-badge {
    align-self: flex-start;
  }

  .conversation-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .conversation-meta div { display: block; }

  dl div {
    grid-template-columns: 1fr;
  }

  button:not(.composer-icon) {
    width: 100%;
  }
  .chat-message--user { max-width: 90%; }
}

@media (prefers-reduced-motion: no-preference) {
  button,
  .skip-link {
    transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
  }
}
