/* ============================================================================
   Briora agent chat bubbles + structured sections + rendered markdown.
   Split out of editor.css. Shares the post-box geometry with the .nv-line
   stream (whose colour variants stay in editor.css's chat-column section).
   Everything about rendering a briora agent answer lives here, including the
   markdown code-block syntax colours at the bottom. Tokens: application.css.
   ========================================================================= */
/* Shared post-box geometry for briora agent bubbles and stream lines. */
.briora-agent-bubble,
.nv-line {
  width: fit-content;
  max-width: 60%;
  padding: 6px 10px;
  margin-bottom: 6px;
  border-radius: 10px;
  border: 1px solid rgba(var(--bs-black-rgb), 0.08);
  font-size: 13px;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Right: user-initiated. Left: system / assistant. */
.briora-agent-bubble-user,
.nv-line--cli {
  margin-left: auto;
}

.briora-agent-bubble-assistant,
.briora-agent-bubble-failed,
.nv-line--program,
.nv-line--debug,
.nv-line--error,
.nv-line--warning,
.nv-line--success,
.nv-line--info {
  margin-right: auto;
}

/* Rounded, faintly tinted bubbles; the flattened corner points at the
   speaker (user right, agent left). */
.briora-agent-bubble-user {
  background-color: var(--br-tint-plum);
  color: var(--nv-text);
  border: 0;
  border-bottom-right-radius: 3px;
}
.briora-agent-bubble-assistant {
  background-color: var(--br-tint);
  color: var(--nv-text);
  max-width: 78%;
  border: 0;
  border-bottom-left-radius: 3px;
}
.briora-agent-bubble-failed {
  background-color: var(--nv-error-bg);
  color: var(--nv-error-fg);
  border-color: var(--nv-error-border);
}
.briora-agent-bubble-text {
  white-space: pre-wrap;
}

.briora-agent-streaming {
  white-space: pre-wrap;
}
.briora-agent-streaming:empty {
  display: none;
}

.briora-agent-section {
  margin: 4px 0;
}
.briora-agent-section:first-child {
  margin-top: 0;
}
.briora-agent-section:last-child {
  margin-bottom: 0;
}
.briora-agent-section-text {
  white-space: pre-wrap;
}

.briora-agent-section-recap .briora-agent-section-text {
  border-left: 2px solid var(--br-turquoise);
  padding: 2px 0 2px 8px;
  color: var(--nv-recap-fg);
  font-weight: 600;
}

.briora-agent-section-details .briora-agent-section-text {
  color: var(--nv-detail-fg);
}

/* Rendered markdown (recap/details prose). The container's pre-wrap is for
   plain text; markdown emits real block elements, so reset it and let the
   children own their spacing. Code-block token colours: the
   .syntax-highlighting rules at the bottom of this file. */
.briora-agent-markdown {
  white-space: normal;
}
.briora-agent-markdown > :first-child {
  margin-top: 0;
}
.briora-agent-markdown > :last-child {
  margin-bottom: 0;
}
.briora-agent-markdown p {
  margin: 0 0 8px;
}
.briora-agent-markdown ul,
.briora-agent-markdown ol {
  margin: 0 0 8px;
  padding-left: 20px;
}
.briora-agent-markdown li {
  margin: 2px 0;
}
.briora-agent-markdown h1,
.briora-agent-markdown h2,
.briora-agent-markdown h3,
.briora-agent-markdown h4 {
  margin: 10px 0 6px;
  font-size: 13px;
  font-weight: 600;
}
.briora-agent-markdown a {
  color: var(--nv-accent);
}
/* Code uses a neutral grey (not the green --nv-output-* — that reads as device
   run output); still contrasts against the --nv-panel assistant bubble. */
.briora-agent-markdown code {
  font-family: var(--nv-mono);
  font-size: 12px;
  background-color: var(--nv-bg);
  padding: 1px 4px;
  border-radius: 4px;
}
/* Code blocks sit on paper ground inside the tinted bubble. */
.briora-agent-markdown pre {
  margin: 0 0 8px;
  padding: 6px 10px;
  background-color: var(--nv-bg);
  border: 1px solid var(--nv-border);
  border-radius: 6px;
  overflow-x: auto;
}
.briora-agent-markdown pre code {
  padding: 0;
  background: none;
  border-radius: 0;
  line-height: 1.4;
}
.briora-agent-markdown blockquote {
  margin: 0 0 8px;
  padding-left: 8px;
  border-left: 3px solid var(--nv-border);
  color: var(--nv-muted);
}
.briora-agent-markdown table {
  border-collapse: collapse;
  margin: 0 0 8px;
  font-size: 12px;
  display: block;
  overflow-x: auto;
}
.briora-agent-markdown th,
.briora-agent-markdown td {
  border: 1px solid var(--nv-border);
  padding: 3px 8px;
  text-align: left;
}
.briora-agent-markdown th {
  background-color: var(--nv-border-soft);
  font-weight: 600;
}

.briora-agent-section-label {
  font-size: 11px;
  color: var(--nv-label-fg);
  margin-bottom: 2px;
  font-family: var(--nv-mono);
}

.briora-agent-output {
  margin: 0;
  padding: 6px 10px;
  background-color: var(--nv-bg);
  border: 1px dashed var(--br-faint);
  border-left: 2px solid var(--nv-output-accent);
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.4;
  font-family: var(--nv-mono);
  color: var(--nv-output-fg);
}

.briora-agent-status:empty {
  display: none;
}

.briora-agent-running {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 20px 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--nv-info-fg);
  background-color: var(--nv-info-bg);
  border: 1px solid var(--nv-info-border);
  border-radius: 6px;
}

.briora-agent-running-text {
  flex-grow: 1;
}

.briora-agent-running-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--nv-info-fg);
  animation: briora-agent-pulse 1s ease-in-out infinite;
  flex-shrink: 0;
}

.briora-agent-running-stopping .briora-agent-running-dot {
  background-color: var(--nv-gold);
}

@keyframes briora-agent-pulse {
  0%,
  100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

.briora-agent-stop-form {
  margin: 0;
}
.briora-agent-stop {
  padding: 1px 8px;
  font-size: 11px;
  line-height: 1.4;
}

.briora-agent-notice:empty {
  display: none;
}

.briora-agent-notice-text {
  margin: 0 20px 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--nv-warning-fg);
  background-color: var(--nv-warning-bg);
  border: 1px solid var(--nv-warning-border);
  border-radius: 6px;
}

/* ----------------------------------------------------------------------------
   Syntax highlighting for markdown code blocks.

   commonmarker (comrak) renders fenced code with the syntect highlighter in
   CLASS mode — plugins: { syntax_highlighter: { theme: "" } }, see
   MarkdownHelper. It emits <pre class="syntax-highlighting"> and wraps tokens in
   spans whose classes are TextMate scope names (e.g. "keyword control def
   ruby"). We colour the broad scopes with the same --nv-syntax-* tokens the
   CodeMirror theme uses, so chat code matches the editor. Space-separated scopes
   compound on one element, so `.entity.name.function` requires all three classes
   present. Vocabulary: TextMate/Sublime scope naming conventions. (The <pre> box
   itself — bg/border/padding — is styled by .briora-agent-markdown pre above.)
   -------------------------------------------------------------------------- */
.syntax-highlighting {
  color: var(--nv-syntax-fg);
}

.syntax-highlighting .comment {
  color: var(--nv-syntax-comment);
  font-style: italic;
}

/* control/import keywords (return, if, #include) + modifiers (static, const) */
.syntax-highlighting .keyword,
.syntax-highlighting .storage.modifier {
  color: var(--nv-syntax-keyword);
}

.syntax-highlighting .string {
  color: var(--nv-syntax-string);
}

/* numeric / language / character literals */
.syntax-highlighting .constant {
  color: var(--nv-syntax-type);
}

.syntax-highlighting .entity.name.function {
  color: var(--nv-syntax-def);
}

/* Types get one colour. syntect tags int/struct/typedef and every return/var
   type as `storage.type`; a typedef'd NAME comes through as `entity.name.type`.
   Matches the editor's cm-type. */
.syntax-highlighting .storage.type,
.syntax-highlighting .entity.name.type,
.syntax-highlighting .entity.name.class {
  color: var(--nv-syntax-type);
  font-style: italic;
}

.syntax-highlighting .variable {
  color: var(--nv-syntax-fg);
}

/* ---------------------------------------------------------------- tutorials --
   A printed tutorial step in the output stream. Wider than a chat bubble
   (schematics have to be readable) and left-aligned like the agent's replies. */
.briora-agent-tutorial-step {
  max-width: 85%;
  margin: 0 auto 16px 0;
  padding: 8px 12px;
  border-radius: 10px;
  border-left: 3px solid var(--nv-writer-tutorial);
  background-color: var(--br-tint);
  font-size: 13px;
}

/* The run's first step marks where a kickstart begins: extra room above and
   an accent-colored counter. */
.briora-agent-tutorial-step.is-start {
  margin-top: 24px;
}

/* Line 1: tutorial title (big + bold) with the step counter. */
.briora-agent-tutorial-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  color: var(--nv-text);
  font-size: 15px;
  font-weight: 700;
}

.briora-agent-tutorial-head .bi {
  color: var(--nv-writer-tutorial);
  font-size: 14px;
}

.briora-agent-tutorial-count {
  color: var(--nv-muted);
  font-size: 12px;
  font-weight: 600;
}

.briora-agent-tutorial-step.is-start .briora-agent-tutorial-count {
  color: var(--nv-writer-tutorial);
}

/* Line 2: step label — body size, bold and italic. */
.briora-agent-tutorial-label {
  color: var(--nv-text);
  font-size: 13px;
  font-weight: 700;
  font-style: italic;
  margin: 2px 0 6px;
}

/* Step prose is secondary — soften it against the dark ground. */
[data-bs-theme="dark"] .briora-agent-tutorial-step .briora-agent-markdown {
  color: rgba(236, 236, 241, 0.72);
}

/* ------------------------------------------------------------- hardware --
   The hardware card for a connected board. Same footprint as a printed
   tutorial step (wide, left-aligned); deliberately NOT .nv-line — it must
   stay visible while the CLI stream is hidden. */
.briora-agent-hardware {
  max-width: 85%;
  margin: 0 auto 8px 0;
  padding: 8px 12px;
  border-radius: 10px;
  border-left: 3px solid var(--nv-accent);
  background-color: var(--br-tint);
  font-size: 13px;
}

.briora-agent-hardware-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 6px;
  color: var(--nv-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.briora-agent-hardware-title {
  color: var(--nv-text);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: none;
  font-size: 16px;
}

.briora-agent-hardware-body {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.briora-agent-hardware-image {
  width: 144px;
  height: 144px;
  object-fit: contain;
  border-radius: 6px;
  background: var(--br-paper);
  flex-shrink: 0;
}

.briora-agent-hardware-noimage {
  width: 144px;
  height: 144px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 6px;
  background: var(--br-paper);
  color: var(--nv-muted);
  font-size: 11px;
  flex-shrink: 0;
}

.briora-agent-hardware-noimage .bi {
  font-size: 22px;
}

.briora-agent-hardware-facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 2px 10px;
  margin: 0;
}

.briora-agent-hardware-facts dt {
  color: var(--nv-muted);
  font-weight: 500;
}

.briora-agent-hardware-facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* Interfaces fact row: collapsed to a count, <details> reveals the list. */
.briora-agent-hardware-ifs summary {
  cursor: pointer;
  list-style: none; /* no default disclosure marker */
}

.briora-agent-hardware-ifs summary::-webkit-details-marker {
  display: none;
}

.briora-agent-hardware-ifs-show,
.briora-agent-hardware-ifs-hide {
  color: var(--nv-accent);
}

.briora-agent-hardware-ifs[open] .briora-agent-hardware-ifs-show,
.briora-agent-hardware-ifs:not([open]) .briora-agent-hardware-ifs-hide {
  display: none;
}

.briora-agent-hardware-ifs-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  font-family: var(--bs-font-monospace);
  font-size: 12px;
}

/* Schematics and breadboard photos: never wider than their container. Applies
   to every markdown surface, not just the chat bubble — the admin CRUD renders
   step bodies through the same helper and would otherwise show them fullsize. */
.briora-agent-markdown img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 6px 0;
  border-radius: 6px;
  background: var(--br-paper);
}
