/* ============================================================
   jcd-output.css  ·  default stylesheet for jcd::ai model output
   ------------------------------------------------------------
   Wrap every model reply in a single scope:

       <div class="jcd-output"> … </div>

   When prefer_html = true  → the model emits semantic HTML inside
   that wrapper (no inline styles — these rules do the work).
   When prefer_html = false → the host renders the model's Markdown
   to HTML inside the same wrapper, so the markup maps 1:1.

   Add the modifier class  .jcd-output.light  for the light theme.
   ============================================================ */

.jcd-output {
  --bg:        #0d0d0e;
  --surface:   #131316;
  --surface-2: #161619;
  --code-bg:   #0f0f11;
  --border:    #232327;
  --heading:   #f0efed;
  --text:      #e6e6e4;
  --text-dim:  #a0a09e;
  --text-mute: #6c6c6a;
  --accent:    #993333;
  --accent-fg: #e0a0a0;
  --accent-tint: rgba(153, 51, 51, 0.16);
  --ok:   #22c55e;
  --warn: #d8a23a;
  --err:  #d96a6a;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, sans-serif;

  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  max-width: 820px;          /* keep replies readable — never full-bleed */
  container-type: inline-size; /* make the reply a query container (responsive to ITS width, not the screen) */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.jcd-output.light {
  --bg:        #fbfbfa;
  --surface:   #ffffff;
  --surface-2: #f5f5f4;
  --code-bg:   #f6f6f5;
  --border:    #e6e6e3;
  --heading:   #16140f;
  --text:      #1c1c1a;
  --text-dim:  #57564f;
  --text-mute: #8a8a85;
  --accent-fg: #8a2f2f;
  --accent-tint: rgba(153, 51, 51, 0.10);
}

/* Kill browser-default block margins at ZERO specificity weight (:where) so the
   adjacency rhythm rules below ALWAYS own vertical spacing. Without this, a
   per-element reset like `blockquote { margin: 0 }` (specificity 0,1,1) would
   out-rank `h2 + *` (also 0,1,1, but earlier in the file) and silently collapse
   the gap to zero — which is exactly why cards sat flush under their heading. */
.jcd-output :where(p, ul, ol, blockquote, figure) { margin: 0; }

/* ---- vertical rhythm ------------------------------------- */
.jcd-output > * + *        { margin-top: 14px; }
.jcd-output > h1,
.jcd-output > h2,
.jcd-output > h3           { margin-top: 30px; }
.jcd-output > :first-child { margin-top: 0; }
/* breathing room between a section subject and the content it labels — a bit
   more than the default rhythm so the subject reads as a header for what follows
   (card, table, list or text), but not so much that it floats away from it */
.jcd-output h1 + *,
.jcd-output h2 + *,
.jcd-output h3 + *,
.jcd-output h4 + *         { margin-top: 20px; }
/* CARD BREATHING ROOM — callout notes (blockquote) and code blocks (pre) are
   panels, not text, so the default 14px rhythm crowds them. Give them more space
   BOTH before and after, so a text block never butts straight up against a card
   (and vice-versa). Same idea as the table spacing. Headings are excluded on both
   sides because they already carry their own generous margins. */
.jcd-output :not(h1):not(h2):not(h3):not(h4) + blockquote,
.jcd-output :not(h1):not(h2):not(h3):not(h4) + pre,
.jcd-output blockquote + :not(h1):not(h2):not(h3):not(h4),
.jcd-output pre + :not(h1):not(h2):not(h3):not(h4) { margin-top: 24px; }

/* ---- headings -------------------------------------------- */
.jcd-output h1,
.jcd-output h2,
.jcd-output h3,
.jcd-output h4 {
  color: var(--heading);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin-bottom: 0;
}
.jcd-output h1 { font-size: 22px; }
.jcd-output h2 {
  font-size: 17px;
}
.jcd-output h3 { font-size: 14.5px; color: var(--text); }
.jcd-output h4 { font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }

/* ---- text ------------------------------------------------ */
.jcd-output p           { color: var(--text-dim); }
.jcd-output strong      { color: var(--text); font-weight: 600; }
.jcd-output em          { font-style: italic; }
.jcd-output a {
  color: var(--accent-fg);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-tint);
  transition: border-color 0.15s;
}
.jcd-output a:hover     { border-bottom-color: var(--accent); }
.jcd-output small       { font-size: 12px; color: var(--text-mute); }

/* ---- lists ----------------------------------------------- */
.jcd-output ul,
.jcd-output ol {
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.jcd-output li { position: relative; padding-left: 22px; color: var(--text-dim); line-height: 1.55; }
.jcd-output ul > li::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 9px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.jcd-output ol { counter-reset: jcd-i; }
.jcd-output ol > li { counter-increment: jcd-i; }
.jcd-output ol > li::before {
  content: counter(jcd-i);
  position: absolute;
  left: 0;
  top: 1px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

/* ---- code ------------------------------------------------ */
.jcd-output code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--text);
}
.jcd-output pre {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  color: var(--text-dim);
}
.jcd-output pre code { background: none; border: none; padding: 0; font-size: inherit; color: inherit; }
.jcd-output kbd {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--text);
}

/* ---- tables ---------------------------------------------- */
/* Columns size to their content — an ID column is exactly as wide as its
   IDs, never a fixed share. A table narrower than the reply stretches to
   full width; a wider one keeps its natural width and scrolls inside its
   wrapper. */
.jcd-output table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: 13px; table-layout: auto; }
.jcd-output th, .jcd-output td { max-width: 40ch; }
/* the table's own left-right scroll when it is wider than the reply */
.jcd-output .tblwrap { overflow-x: auto; scrollbar-width: thin; }
.jcd-output .tblwrap::-webkit-scrollbar { height: 6px; }
.jcd-output .tblwrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
/* extra breathing room after a table when the next thing ISN'T a new section heading
   (a heading already brings its own space) — keeps the last row off the following text */
.jcd-output .tblwrap + :not(h1):not(h2):not(h3):not(h4) { margin-top: 28px; }
/* a chip (<code>) leading the first column: pull it left by its own padding + border
   so its TEXT lines up with the header text (and plain-text cells), not 7px right of it */
.jcd-output td:first-child > code:first-child { margin-left: -7px; }
/* Header cells — matches a proper <thead> th AND a header row the model emits as
   <th> inside <tbody> (first row), so both render identically. */
.jcd-output thead th,
.jcd-output tbody tr:first-child th {
  text-align: left;
  vertical-align: top;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-mute);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.jcd-output tbody td {
  padding: 9px 12px;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.jcd-output tbody tr:last-child td { border-bottom: none; }
/* SHARED COLUMN INSET — header cells and body cells MUST use the exact same
   horizontal padding, so every column's subject sits directly above its content.
   Applies to EVERY th/td (not just thead th) because the model often emits the
   header row as <th> inside <tbody> with no <thead> — without this those header
   cells fall back to browser defaults (no padding) and sit flush-left while the
   data rows indent. Locked here as one source of truth. */
.jcd-output th,
.jcd-output td { padding-left: 12px; padding-right: 12px; }
/* numeric columns — add class="num" on th + td. Numbers are LEFT-aligned like
   every other column (kept in the mono face so figures stay legible/aligned
   digit-wise); we deliberately do NOT right-align, so a number column lines up
   under its subject exactly like the text columns. */
.jcd-output th.num,
.jcd-output td.num { font-family: var(--mono); white-space: nowrap; }
/* never trust per-cell alignment the Markdown renderer injects (align="center",
   inline text-align, :---: syntax). EVERYTHING stays left — text and numbers —
   so each column sits directly under its subject. */
.jcd-output th,
.jcd-output td        { text-align: left !important; }

/* ---- blockquote / note ----------------------------------- */
.jcd-output blockquote {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 13px 16px;
  color: var(--text-dim);
}
.jcd-output blockquote > :first-child { margin-top: 0; }

/* ---- rule / image ---------------------------------------- */
.jcd-output hr { border: none; border-top: 1px solid var(--border); margin: 22px 0; }
.jcd-output img { max-width: 100%; border-radius: 10px; border: 1px solid var(--border); }

/* ---- status tags ----------------------------------------- */
.jcd-output .tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--accent-tint);
  color: var(--accent-fg);
}
.jcd-output .tag.ok   { background: rgba(34, 197, 94, 0.15);  color: #7fdca0; }
.jcd-output .tag.warn { background: rgba(216, 162, 58, 0.15); color: #e0c07a; }
.jcd-output .tag.err  { background: rgba(217, 106, 106, 0.15); color: #e89a9a; }

/* ---- KPI tiles ------------------------------------------- */
.jcd-output .kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.jcd-output .kpi {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.jcd-output .kpi b {
  display: block;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--heading);
}
.jcd-output .kpi b u { text-decoration: none; font-size: 13px; color: var(--text-mute); }
.jcd-output .kpi span { font-size: 12.5px; color: var(--text-dim); }
