:root {
  --bg: #fff;
  --ink: #050505;
  --muted: #6b6b6b;
  --line: #d8d8d8;
  --soft: #f4f4f4;
  --softer: #fafafa;
  --focus: #111;
  --error: #9b1c1c;
  --success: #17623b;
  --max: 880px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
textarea {
  font: inherit;
}

a {
  color: var(--ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

.app-shell {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  padding: 28px clamp(16px, 4vw, 48px);
  gap: 30px;
}

.topbar {
  width: min(var(--max), 100%);
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
  border-bottom: 1px solid var(--ink);
  padding-bottom: 22px;
}

.wordmark {
  display: grid;
  gap: 0;
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
  font-size: clamp(34px, 6vw, 72px);
  line-height: 0.86;
  letter-spacing: 0;
}

.topbar-copy {
  text-align: right;
  max-width: 300px;
  padding-top: 4px;
}

.agent-name {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.agent-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.resource-links {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 7px;
}

.resource-link {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--ink);
  background: #fff;
  color: var(--ink);
  padding: 7px 9px;
  text-decoration: none;
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.resource-button {
  cursor: pointer;
}

.resource-link:hover,
.resource-link:focus-visible,
.resource-button[aria-expanded="true"] {
  background: var(--ink);
  color: #fff;
}

.btp-icon {
  width: 13px;
  height: 13px;
  display: inline-block;
  border: 2px solid currentColor;
  border-left-width: 5px;
}

.brief-panel {
  width: min(var(--max), 100%);
  height: auto;
  min-height: 0;
  flex: 0 0 auto;
  margin: -16px auto 0;
  border: 1px solid var(--ink);
  border-top: 0;
  padding: 12px 14px 14px;
}

.brief-panel-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.brief-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.brief-links a {
  border-bottom: 1px solid var(--ink);
  padding-bottom: 2px;
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
}

.chat-frame {
  width: min(var(--max), 100%);
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-rows: 1fr auto;
  border: 1px solid var(--ink);
  background: var(--bg);
}

.messages {
  min-height: 360px;
  max-height: calc(100svh - 280px);
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

.message {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 18px;
  padding: 20px 0;
  border-top: 1px solid var(--line);
}

.message:first-child {
  border-top: 0;
  padding-top: 0;
}

.message-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  overflow-wrap: anywhere;
}

.message.user .message-body {
  font-weight: 650;
}

.message.assistant .message-body {
  background: var(--softer);
  border-left: 3px solid var(--ink);
  padding: 16px 18px;
}

.message.assistant.is-transient .message-body {
  position: relative;
  animation: btp-rule 1.1s ease-in-out infinite;
}

.message.assistant.is-transient .message-body::after {
  content: "";
  position: absolute;
  left: -3px;
  top: 0;
  width: 3px;
  height: 100%;
  background: var(--ink);
  animation: btp-scan 1.6s ease-in-out infinite;
}

.message.error .message-body {
  color: var(--error);
  background: #fff7f7;
  border-left-color: var(--error);
}

.message-body {
  min-width: 0;
  font-size: 16px;
  line-height: 1.55;
}

.message-body > :first-child {
  margin-top: 0;
}

.message-body > :last-child {
  margin-bottom: 0;
}

.message-body h1,
.message-body h2,
.message-body h3 {
  margin: 22px 0 10px;
  line-height: 1.05;
  letter-spacing: 0;
}

.message-body h1 {
  font-size: 28px;
}

.message-body h2 {
  font-size: 22px;
}

.message-body h3 {
  font-size: 18px;
}

.message-body ul,
.message-body ol {
  margin: 10px 0 14px;
  padding-left: 1.4em;
}

.message-body li {
  margin: 4px 0;
}

.message-body .rule {
  height: 1px;
  background: var(--line);
  margin: 18px 0;
}

.copy-block {
  margin: 14px 0;
  border: 1px solid var(--ink);
  background: #fff;
}

.copy-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--ink);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.copy-block pre {
  margin: 0;
  padding: 14px;
  white-space: pre-wrap;
  overflow-x: auto;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.45;
}

.copy-button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 800;
}

.composer {
  border-top: 1px solid var(--ink);
  background: var(--soft);
}

.composer textarea {
  width: 100%;
  display: block;
  resize: vertical;
  min-height: 104px;
  max-height: 240px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 18px 20px;
  outline: none;
  font-size: 16px;
  line-height: 1.45;
}

.composer textarea:focus {
  box-shadow: inset 0 0 0 2px var(--focus);
}

.composer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.status.busy {
  color: var(--ink);
}

.status.busy::after {
  content: "";
  width: 18px;
  height: 1px;
  display: inline-block;
  margin-left: 8px;
  vertical-align: middle;
  background: var(--ink);
  animation: btp-work 0.9s steps(2, end) infinite;
}

.status.ok {
  color: var(--success);
}

.status.error {
  color: var(--error);
}

#send-button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  min-width: 116px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#send-button:disabled {
  cursor: wait;
  opacity: 0.45;
}

.chat-frame.is-busy .message.assistant.is-transient .message-body {
  animation: btp-rule 1.1s ease-in-out infinite;
}

@keyframes btp-work {
  0%,
  100% {
    transform: scaleX(0.35);
    transform-origin: left;
  }
  50% {
    transform: scaleX(1);
    transform-origin: left;
  }
}

@keyframes btp-rule {
  0%,
  100% {
    box-shadow: inset 0 0 0 0 var(--ink);
  }
  50% {
    box-shadow: inset 3px 0 0 0 var(--ink);
  }
}

@keyframes btp-scan {
  0%,
  100% {
    opacity: 0.35;
    transform: scaleY(0.35);
    transform-origin: top;
  }
  50% {
    opacity: 1;
    transform: scaleY(1);
    transform-origin: top;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status.busy::after,
  .chat-frame.is-busy .message.assistant.is-transient .message-body,
  .message.assistant.is-transient .message-body::after {
    animation: none;
  }
}

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

@media (max-width: 720px) {
  .app-shell {
    padding: 18px 12px;
    gap: 18px;
  }

  .topbar {
    display: grid;
    gap: 16px;
  }

  .topbar-copy {
    max-width: none;
    text-align: left;
  }

  .resource-links {
    justify-content: flex-start;
  }

  .brief-panel {
    margin-top: -6px;
  }

  .chat-frame {
    min-height: calc(100svh - 210px);
  }

  .messages {
    max-height: calc(100svh - 330px);
    padding: 18px 14px;
  }

  .message {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 16px 0;
  }

  .message.assistant .message-body {
    padding: 14px;
  }
}
