:root {
  --agent-chat-width: 270px;
}

#agent-chat-panel {
  --agent-chat-bg: #26262c;
  --agent-chat-surface: #32323a;
  --agent-chat-text: #f3f3f6;
  --agent-chat-muted: #adadb5;
  --agent-chat-border: #484852;
  --agent-chat-accent: #6eb5ff;
  --agent-chat-accent-hover: #9ccfff;
  --agent-chat-pill-bg: #3c3c46;
  --agent-chat-user-bg: #484852;
  --agent-chat-unprompted-bg: #3a3a48;
  --agent-chat-send-bg: #636370;
  --agent-chat-send-hover: #757580;

  position: fixed;
  top: 0;
  left: 0;
  z-index: 1040;
  height: 100vh;
  width: var(--agent-chat-width);
  background: var(--agent-chat-bg);
  color: var(--agent-chat-text);
  border-right: 1px solid var(--agent-chat-border);
  display: none;
  flex-direction: row;
  overflow: hidden;
}

#agent-chat-panel.agent-chat-panel--open,
html.agent-chat-open #agent-chat-panel {
  display: flex;
}

/* Floating button shown only when the panel is closed */
#agent-chat-fab {
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 1039;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--agent-chat-fab-bg, #2f6df6);
  color: #fff;
  cursor: pointer;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

#agent-chat-fab sup {
  font-size: 0.6em;
  vertical-align: super;
}

#agent-chat-fab:hover {
  background: var(--agent-chat-fab-hover, #1f5be0);
}

body.agent-chat-open #agent-chat-fab,
html.agent-chat-open #agent-chat-fab {
  display: none;
}

.agent-chat-inner {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--agent-chat-bg);
}

/* Drag-to-resize handle on the right edge */
.agent-chat-resize {
  flex-shrink: 0;
  width: 6px;
  cursor: col-resize;
  background: transparent;
}

.agent-chat-resize:hover,
body.agent-chat-resizing .agent-chat-resize {
  background: var(--agent-chat-border);
}

/* Blocks iframe pointer capture while resizing the chat column (see #rupert-resize-shield). */
#agent-chat-resize-shield {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1035;
  background: transparent;
  cursor: col-resize;
}

body.agent-chat-resizing #agent-chat-resize-shield {
  display: block;
}

body.agent-chat-resizing {
  cursor: col-resize;
  user-select: none;
}

.agent-chat-titlebar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  padding: 10px 12px;
  border-bottom: 1px solid var(--agent-chat-border);
  background: var(--agent-chat-surface);
  color: var(--agent-chat-text);
  font-weight: 600;
  flex-shrink: 0;
}

.agent-chat-bubbles {
  color: var(--agent-chat-accent);
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.agent-chat-title {
  font-size: 15px;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.agent-chat-titlebar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.agent-chat-titlebar-btn {
  border: none;
  background: transparent;
  color: var(--agent-chat-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  line-height: 1;
}

.agent-chat-titlebar-btn:hover {
  color: var(--agent-chat-text);
}

#agent-chat-clear:hover {
  color: #f08080;
}

.agent-chat-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.agent-chat-lock {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(38, 38, 44, 0.92);
  backdrop-filter: blur(2px);
}

.agent-chat-lock-text {
  color: var(--agent-chat-text);
  font-size: 14px;
  line-height: 1.4;
  max-width: 220px;
}

.agent-chat-lock-btn {
  border: 1px solid var(--agent-chat-border);
  background: var(--agent-chat-send-bg);
  color: var(--agent-chat-text);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
}

.agent-chat-lock-btn:hover {
  background: var(--agent-chat-send-hover);
}

#agent-chat-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 12px 0;
  padding-bottom: 80px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--agent-chat-text);
  background: var(--agent-chat-bg);
}

#agent-chat-prompt {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
}

.agent-chat-prompt-shell {
  background: var(--agent-chat-surface);
  border-top: 1px solid var(--agent-chat-border);
  border-radius: 16px 16px 0 0;
  padding: 8px 10px 0;
}

.agent-chat-form {
  width: 100%;
  margin: 0;
}

.agent-chat-prompt-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--agent-chat-pill-bg);
  border-radius: 26px;
  padding: 6px 6px 6px 12px;
}

.prompt-parent-div {
  flex: 1;
  min-width: 0;
  max-height: 150px;
  overflow: auto;
  margin-bottom: 2px;
}

.agent-prompt-input {
  display: block;
  width: 100%;
  min-height: 24px;
  border: 0;
  background: transparent;
  color: var(--agent-chat-text);
  padding: 4px 0;
  font-size: 14px;
  line-height: 1.45;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
}

.agent-prompt-input.placeholder {
  color: var(--agent-chat-muted);
}

.prompt-message-button {
  position: relative;
  bottom: auto;
  right: auto;
  flex-shrink: 0;
  border: 0;
  background-color: var(--agent-chat-send-bg);
  border-radius: 16px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #eee;
}

.prompt-message-button:hover {
  background-color: var(--agent-chat-send-hover);
}

.prompt-message-button:focus {
  outline: none;
}

.prompt-message-button:hover .send-chat-arrow {
  color: #fff;
}

.prompt-bottom-text {
  padding: 6px 8px 10px;
  font-size: 11px;
  color: var(--agent-chat-muted);
  text-align: center;
}

.agent-chat-previous {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--agent-chat-muted);
  cursor: pointer;
  padding: 12px 0 8px;
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  text-align: left;
}

.agent-chat-previous:hover {
  color: var(--agent-chat-text);
}

.user-prompt-outer {
  display: flex;
  flex-flow: column wrap;
  align-content: flex-end;
}

.user-prompt {
  color: var(--agent-chat-text);
  padding: 5px 10px;
  border-radius: 10px;
  background-color: var(--agent-chat-user-bg);
  margin: 20px 0;
  width: 80%;
  white-space: pre-wrap;
  word-break: break-word;
}

.agent-msg.assistant {
  margin-bottom: 8px;
}

.agent-msg.assistant .agent-answer {
  white-space: normal;
  color: var(--agent-chat-text);
}

.agent-msg.assistant.unprompted .agent-answer,
.agent-msg.system .agent-system-body {
  background-color: var(--agent-chat-unprompted-bg);
  padding: 8px 12px;
  border-radius: 10px;
  border-left: 3px solid var(--agent-chat-accent);
  white-space: normal;
  color: var(--agent-chat-text);
}

.agent-msg.system {
  margin-bottom: 8px;
}

.agent-msg-divider {
  width: 60%;
  height: 1px;
  margin: 12px auto;
  background-color: var(--agent-chat-muted);
  opacity: 0.35;
}

/* Divider between progressive (partial-answer) segments within one assistant
   message. Subtler than the between-message divider. */
.agent-answer-divider {
  width: 40%;
  height: 1px;
  margin: 10px auto;
  background-color: var(--agent-chat-muted);
  opacity: 0.2;
}

/* Inline compiled figure (generate_figure tool / stored figure markers). */
.agent-figure {
  margin: 10px auto;
  max-width: 320px;
  text-align: center;
}

.agent-figure .agent-figure-svg {
  display: inline-block;
  background-color: #ffffff;
  border: 1px solid #d8d8d8;
  border-radius: 8px;
  padding: 6px;
  line-height: 0;
}

.agent-figure .agent-figure-svg svg {
  max-width: 100%;
  height: auto;
}

.agent-figure-caption {
  margin-top: 4px;
  font-size: 11px;
  font-style: italic;
  color: var(--agent-chat-muted);
}

.agent-figure-loading {
  min-height: 40px;
}

/* Self-contained task sub-chat that sits inside the main chat list. */
.agent-subchat {
  margin: 16px 0;
  border: 1px solid var(--agent-chat-accent);
  border-radius: 12px;
  background-color: var(--agent-chat-unprompted-bg);
  overflow: hidden;
}

.agent-subchat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.agent-subchat-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--agent-chat-text);
  line-height: 1.3;
}

.agent-subchat-close {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--agent-chat-muted);
  cursor: pointer;
  border-radius: 6px;
}

.agent-subchat-close:hover {
  color: var(--agent-chat-text);
  background-color: rgba(255, 255, 255, 0.08);
}

.agent-subchat-messages {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
}

.agent-subchat-messages .agent-msg.system .agent-system-body {
  background-color: transparent;
  border-left: none;
  padding: 4px 0;
}

.agent-subchat-messages .user-prompt-outer.agent-subchat-user .user-prompt {
  margin: 8px 0;
}

.agent-subchat-note {
  padding: 0 12px 10px;
  font-size: 12px;
  color: var(--agent-chat-muted);
}

.agent-subchat-footer {
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.agent-subchat-footer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.agent-subchat-footer-hint {
  font-size: 11px;
  color: var(--agent-chat-muted);
  text-align: right;
  width: 100%;
}

.agent-review-loading .agent-system-body {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--agent-chat-muted);
}

.agent-review-loading-text {
  font-style: italic;
}

.agent-review-loading .agent-typing-indicator span {
  background: var(--agent-chat-muted);
}

.agent-subchat-end {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--agent-chat-text);
}

.agent-subchat-end:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.agent-subchat-next,
.agent-subchat-continue {
  border: none;
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background-color: var(--agent-chat-accent);
  color: #fff;
}

.agent-subchat-next:hover,
.agent-subchat-continue:hover {
  filter: brightness(1.08);
}

@keyframes agent-chat-stream-cursor-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

.agent-stream-cursor {
  display: inline-block;
  margin: 4px 0 2px;
  min-height: 1em;
  line-height: 1.4;
}

.agent-stream-cursor-bar {
  display: inline-block;
  color: var(--agent-chat-text, #111);
  font-weight: 400;
  animation: agent-chat-stream-cursor-blink 1s step-end infinite;
}

.agent-typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-height: 1em;
}

.agent-typing-indicator span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--agent-chat-muted);
  animation: agent-chat-typing-wave 1.2s ease-in-out infinite;
}

.agent-typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.agent-typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes agent-chat-typing-wave {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }

  30% {
    transform: translateY(-2px);
    opacity: 1;
  }
}

.user-system-attachment {
  margin-top: 6px;
}

.user-prompt-outer:has(.user-system-attachment) .user-prompt {
  margin-bottom: 2px;
}

.user-prompt-outer:has(.user-system-attachment) .user-system-attachment {
  margin-top: 0;
  margin-bottom: 18px;
}

.user-system-attachment-stub {
  display: block;
  padding: 0;
  border: none;
  background: none;
  color: var(--agent-chat-muted);
  font-style: italic;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
}

.user-system-attachment-stub:hover {
  color: var(--agent-chat-accent-hover);
}

.user-system-attachment-detail {
  margin-top: 6px;
  padding: 8px 10px;
  border-left: 2px solid rgba(110, 181, 255, 0.35);
  font-size: 12px;
  color: var(--agent-chat-muted);
  white-space: pre-wrap;
}

.user-system-attachment-heading {
  font-style: italic;
  margin-bottom: 6px;
}

.user-system-attachment-block + .user-system-attachment-block,
.user-system-attachment-detail hr {
  margin-top: 8px;
}

.user-system-attachment-detail hr {
  border: none;
  border-top: 1px solid var(--agent-chat-border);
}

.agent-prompt-input.agent-chat-input-blocked,
#agent-prompt-textarea.agent-chat-input-blocked {
  opacity: 0.55;
  cursor: not-allowed;
}

.prompt-message-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.agent-msg.error,
.chat-error {
  color: var(--agent-chat-muted);
  font-style: italic;
  margin: 10px 0;
}

.agent-thinking {
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--agent-chat-muted);
}

.agent-thinking summary {
  cursor: pointer;
  user-select: none;
  opacity: 0.85;
}

.agent-thinking-body {
  margin-top: 6px;
  padding: 8px;
  border-left: 2px solid rgba(110, 181, 255, 0.35);
  white-space: pre-wrap;
  opacity: 0.8;
}

.agent-answer h1,
.agent-answer h2,
.agent-answer h3,
.agent-answer h4 {
  margin: 0.6em 0 0.35em;
  font-size: 1em;
  font-weight: 700;
  color: var(--agent-chat-text);
}

.agent-answer p {
  margin: 0 0 0.65em;
}

.agent-answer ul,
.agent-answer ol {
  margin: 0 0 0.65em 1.2em;
  padding: 0;
}

.agent-answer li {
  padding-bottom: 6px;
}

.agent-answer code {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.92em;
}

.agent-answer pre {
  background: rgba(255, 255, 255, 0.06);
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0 0 0.65em;
}

.agent-answer pre code {
  background: none;
  padding: 0;
}

.agent-answer .katex {
  color: inherit;
}

.chat-caret,
.chat-caret2 {
  color: var(--agent-chat-muted);
  margin-left: 10px;
  animation-name: agent-chat-blink;
  animation-duration: 0.5s;
  animation-timing-function: ease-in;
  animation-iteration-count: infinite;
}

.new-chat-caret {
  margin-bottom: 8px;
}

@keyframes agent-chat-blink {
  0% { color: #777; }
  50% { color: #ccc; }
  100% { color: #777; }
}

body.agent-chat-open,
html.agent-chat-open body {
  margin-left: var(--agent-chat-width);
}

/* Small portrait screens: panel overlays/covers the page instead of pushing it */
@media (max-width: 600px) and (orientation: portrait) {
  #agent-chat-panel {
    width: 100vw;
  }

  body.agent-chat-open,
  html.agent-chat-open body {
    margin-left: 0;
  }

  .agent-chat-resize {
    display: none;
  }

  #agent-chat-fab {
    left: 12px;
    bottom: 16px;
    width: 46px;
    height: 46px;
    font-size: 18px;
  }
}

/* Tool-activity breadcrumbs: faint, display-only status lines shown while the
   agentic loop runs tools. Collapsed once the final answer starts streaming. */
.agent-tool-status {
  margin: 2px 0 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  transition: opacity 0.2s ease, max-height 0.2s ease;
  max-height: 240px;
}

.agent-tool-status.collapsed {
  max-height: 0;
  opacity: 0;
  margin: 0;
}

.agent-tool-status-line {
  font-size: 12px;
  line-height: 1.3;
  color: var(--agent-chat-muted);
  font-style: italic;
}

.agent-tool-status-line::before {
  content: "\2022";
  margin-right: 6px;
  opacity: 0.6;
}

.agent-tool-status-line.agent-wb-drawing {
  display: flex;
  align-items: center;
  gap: 8px;
  font-style: normal;
}

.agent-tool-status-line.agent-wb-drawing::before {
  content: none;
}

.agent-wb-drawing-text {
  font-style: italic;
}

.agent-wb-wave {
  flex-shrink: 0;
  color: var(--agent-chat-muted);
  opacity: 0.85;
}

.agent-wb-wave path {
  stroke-dasharray: 12 10;
  animation: agent-wb-wave-dash 1.1s linear infinite;
}

@keyframes agent-wb-wave-dash {
  from {
    stroke-dashoffset: 44;
  }
  to {
    stroke-dashoffset: 0;
  }
}

.wb-drawing-wait {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 12px;
  line-height: 1.3;
  color: var(--agent-chat-muted);
  font-style: italic;
}

.wb-prompt-shell.wb-drawing-locked #wb-prompt-textarea {
  opacity: 0.55;
  cursor: wait;
}

/* Whiteboard popup (test-review coach snapshot) */
#wb-container {
  --agent-chat-bg: #26262c;
  --agent-chat-surface: #32323a;
  --agent-chat-text: #f3f3f6;
  --agent-chat-muted: #adadb5;
  --agent-chat-border: #484852;
  --agent-chat-pill-bg: #3c3c46;
  --agent-chat-send-bg: #636370;
  --agent-chat-send-hover: #757580;
  position: absolute;
  display: none;
  top: 48px;
  left: 80px;
  width: min(720px, calc(100vw - 40px));
  height: min(560px, calc(100vh - 60px));
  padding-bottom: 0;
  background: #fff;
  -webkit-box-shadow: -1px 4px 18px -6px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: -1px 4px 18px -6px rgba(0, 0, 0, 0.75);
  box-shadow: -1px 4px 18px -6px rgba(0, 0, 0, 0.75);
  overflow: hidden;
}

#wb-container-header {
  padding: 10px 12px;
  cursor: move;
  opacity: 0.9;
  background-color: #2196f3;
  color: #fff;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  box-sizing: border-box;
}

#wb-container-header .window-button {
  margin-left: auto;
  color: #fff;
  opacity: 0.95;
  text-shadow: none;
  float: none;
}

#wb-iframe {
  display: block;
  width: 100%;
  height: calc(100% - 42px - 58px);
  border: 0;
  background: #fff;
}

#wb-prompt {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
}

.wb-prompt-shell {
  background: var(--agent-chat-surface);
  border-top: 1px solid var(--agent-chat-border);
  padding: 8px 10px 10px;
}

#wb-prompt .agent-chat-prompt-row {
  background: var(--agent-chat-pill-bg);
}

#wb-prompt .agent-prompt-input {
  color: var(--agent-chat-text);
}

#wb-prompt .agent-prompt-input.placeholder {
  color: var(--agent-chat-muted);
}

#wb-prompt .prompt-message-button {
  position: relative;
  bottom: auto;
  right: auto;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--agent-chat-send-bg);
  color: #eee;
}

#wb-prompt .prompt-message-button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.agent-subchat-wb {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--agent-chat-muted);
  cursor: pointer;
  border-radius: 6px;
  margin-left: auto;
}

.agent-subchat-wb:hover {
  color: var(--agent-chat-text);
  background-color: rgba(255, 255, 255, 0.08);
}

.agent-subchat-user .agent-subchat-wb-thumb {
  display: block;
  max-width: 100%;
  max-height: 160px;
  width: auto;
  height: auto;
  border-radius: 8px;
  margin: 0 0 8px;
  background: #fff;
  object-fit: contain;
}

@media only screen and (max-width: 750px) {
  #wb-container {
    width: 90%;
    height: 70vh;
    left: 5%;
    top: 40px;
  }
}

