/* Markdown in replies, code with its colours, what tool cards show, and the diff view.
   Linked after styles.css: everything here uses that file's tokens; the only tokens added are the
   code colours below, one set per theme (each reads at 4.5:1 or better on --bg and --sunken). */

html[data-theme="dark"] {
  --hl-comment: #8b919b;
  --hl-keyword: #c891e6;
  --hl-string: #9bcb86;
  --hl-number: #dba56e;
  --hl-function: #6fb3f2;
  --hl-property: #ea8a90;
  --hl-meta: #e5c07b;
}

html[data-theme="light"] {
  --hl-comment: #6a717b;
  --hl-keyword: #8b2aa8;
  --hl-string: #1b6b34;
  --hl-number: #8a5300;
  --hl-function: #0b55b8;
  --hl-property: #b0302a;
  --hl-meta: #7a5a00;
}

.hl-c { color: var(--hl-comment); }
.hl-k { color: var(--hl-keyword); }
.hl-s { color: var(--hl-string); }
.hl-n, .hl-l { color: var(--hl-number); }
.hl-f { color: var(--hl-function); }
.hl-p, .hl-t { color: var(--hl-property); }
.hl-m { color: var(--hl-meta); }
.hl-a { color: var(--success); }
.hl-d { color: var(--danger); }

/* --- A reply ----------------------------------------------------------------------------------- */

.msg.md-text { white-space: normal; }
.md-text > :first-child { margin-top: 0; }
.md-text > :last-child { margin-bottom: 0; }
.md-text p { margin: 0 0 8px; }
.md-text h1, .md-text h2, .md-text h3, .md-text h4, .md-text h5, .md-text h6 { margin: 14px 0 6px; font-weight: 600; }
.md-text h1 { font-size: 19px; line-height: 26px; }
.md-text h2 { font-size: 17px; line-height: 24px; }
.md-text h3 { font-size: 15px; line-height: 22px; }
.md-text h4, .md-text h5, .md-text h6 { font-size: 14px; line-height: 22px; }
.md-text h5, .md-text h6 { color: var(--text-2); }
.md-text strong { font-weight: 600; }
.md-text del { color: var(--text-3); }
.md-text a { text-decoration: underline; text-decoration-color: var(--text-4); text-underline-offset: 3px; }
.md-text a:hover { text-decoration-color: currentColor; }
.md-text code { padding: 1px 5px; border-radius: 5px; background: var(--fill); font-family: var(--mono); font-size: .9em; white-space: pre-wrap; }
.md-text hr { height: 1px; margin: 12px 0; border: 0; background: var(--border-2); }
.md-text blockquote { margin: 0 0 8px; padding-left: 12px; border-left: 3px solid var(--border-2); color: var(--text-2); }
.md-text blockquote > :last-child { margin-bottom: 0; }
.md-raw { white-space: pre-wrap; }

.md-text ul, .md-text ol { margin: 0 0 8px; padding-left: 22px; }
.md-text li { margin: 2px 0; }
.md-text li > p { margin: 0 0 6px; }
.md-text li > ul, .md-text li > ol { margin: 2px 0 0; }
.md-text li > :last-child { margin-bottom: 0; }
/* A task: its box stands where the bullet would. */
.md-text li.md-task { list-style: none; }
.md-task input[type="checkbox"] { width: 13px; height: 13px; margin: 0 6px 0 -19px; vertical-align: -2px; accent-color: var(--blue); }

/* A table wider than the bubble scrolls in its own box. Cells break between words only, so a
   wide table stays readable instead of being squeezed into one letter per line. */
.md-table { margin: 0 0 8px; overflow-x: auto; overflow-wrap: normal; scrollbar-width: thin; }
.md-table table { border-collapse: collapse; font-size: 13px; line-height: 19px; }
.md-table th, .md-table td { padding: 4px 10px; border: 1px solid var(--border-2); text-align: left; vertical-align: top; }
.md-table th { background: var(--fill); font-weight: 600; white-space: nowrap; }
.md-table .md-center { text-align: center; }
.md-table .md-right { text-align: right; }

/* While a reply is being written, the mark sits at the end of its last line of text. When the
   reply ends in a box instead (code, a table), it sits under the box. */
.msg.md-text[data-streaming="true"] .md-tail::after { content: ""; display: inline-block; width: 6px; height: 14px; margin-left: 3px; vertical-align: -2px; border-radius: 1px; background: var(--text-3); animation: pulse 1s ease-in-out infinite; }
.msg.md-text.md-tailed[data-streaming="true"]::after { content: none; }
.msg.md-text[data-streaming="true"]:not(.md-tailed):not(:empty)::after { display: block; margin: 6px 0 0; }

/* --- Code --------------------------------------------------------------------------------------- */

/* A label and Copy over the code. A long line scrolls inside the block and never widens what holds it. */
.md-code { margin: 0 0 8px; border: 1px solid var(--border-3); border-radius: 10px; background: var(--bg); overflow: hidden; }
.md-code-head { display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 4px 0 10px; border-bottom: 1px solid var(--divider); font: 11px/16px var(--font); color: var(--text-3); }
.md-code-lang { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.md-copy { flex: none; height: 22px; padding: 0 8px; border-radius: 6px; font: 11px/16px var(--font); color: var(--text-3); }
.md-copy:hover { background: var(--fill); color: var(--text); }
.md-code pre { margin: 0; padding: 8px 10px; overflow-x: auto; scrollbar-width: thin; font: 12px/18px var(--mono); color: var(--text); white-space: pre; overflow-wrap: normal; word-break: normal; tab-size: 4; }
.md-code pre code { padding: 0; border-radius: 0; background: none; font: inherit; white-space: inherit; }

/* --- Tool cards: what a tool was given and what it answered ------------------------------------- */

.tool-body > * + * { margin-top: 6px; }
.tool-body .md-code, .tool-body .dv, .approval-input .md-code, .approval-input .dv { margin-bottom: 0; }
.tool-note { font: 12px/18px var(--font); color: var(--text-2); overflow-wrap: anywhere; }
.tool-note[data-tone="bad"] { color: var(--danger); }
.tool-path { display: flex; align-items: baseline; gap: 8px; min-width: 0; font: 12px/18px var(--mono); color: var(--text-2); }
.tool-path-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-range { flex: none; font-family: var(--font); color: var(--text-4); }
.tool-more { display: inline-flex; align-items: center; height: 22px; margin-top: 4px; padding: 0 8px; border-radius: 6px; font: 11px/16px var(--font); color: var(--text-3); }
.tool-more:hover { background: var(--fill); color: var(--text); }
.tool-body .dv, .approval-input .dv { max-height: 260px; border: 1px solid var(--border-3); border-radius: 10px; background: var(--bg); }
.approval-input { padding: 0 12px 8px; font: 12px/18px var(--font); color: var(--text-3); }
.approval-input > summary { cursor: pointer; }
.approval-input > * + * { margin-top: 6px; }

/* --- Diff --------------------------------------------------------------------------------------- */

/* Rows are the .pl lines of styles.css, with the same tints for added and removed lines, but kept
   on one line each: the view scrolls sideways, and a tint runs the full width of the longest
   line. Line numbers and signs are drawn from attributes, so a selection copies the code alone. */
.dv { max-height: 420px; overflow: auto; scrollbar-width: thin; font: 12px/18px var(--mono); color: var(--text); }
.dv-body { width: max-content; min-width: 100%; padding: 6px 0; }
.dv .pl { display: block; min-height: 18px; padding: 0 12px 0 0; white-space: pre; overflow-wrap: normal; word-break: normal; tab-size: 4; }
.dv .pl.add { background: color-mix(in srgb, var(--success) 14%, transparent); }
.dv .pl.del { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.dv .pl.hunk, .dv .pl.meta, .dv .pl.note { padding-left: 12px; color: var(--text-4); }
.dv .pl.hunk:not(:first-child) { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--divider); }
.dv-no, .dv-sign { display: inline-block; height: 18px; vertical-align: top; color: var(--text-4); user-select: none; -webkit-user-select: none; }
.dv-no { width: calc(var(--dv-digits, 3) * 1ch + 12px); padding-right: 4px; text-align: right; }
.dv-no::before { content: attr(data-n); }
.dv-sign { width: 20px; text-align: center; }
.dv-sign::before { content: attr(data-sign); }
.pl.add .dv-sign { color: var(--success); }
.pl.del .dv-sign { color: var(--danger); }

@media (max-width: 767px) {
  .md-code-head { height: 40px; }
  .md-copy, .tool-more { height: 32px; min-width: 44px; padding: 0 12px; font-size: 12px; }
}
