/* Acting on the assistant scorecard: the model card, "Improve this answer",
   and the list of what Pilcrow has been taught (assistant-improve.js).
   Every colour is a token from styles.css, so both themes come for free.
   Amber is kept for a caution, green for something that worked, red for
   something that did not — and each always carries a word. */

/* --- small pieces the scorecard's own lists gained --- */
.asc-head-side { display: inline-flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.asc-left { margin-left: 0.55rem; padding: 0.12rem 0.5rem; border-radius: var(--r-pill); background: var(--attn-bg); border: 1px solid var(--attn-border); color: var(--attn-text); font-size: 0.7rem; font-weight: 600; letter-spacing: 0; text-transform: none; vertical-align: 1px; }
.asc-done { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.1rem 0.45rem; border-radius: var(--r-xs); background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok); font-weight: 500; }
.asc-done .ic { width: 11px; height: 11px; }
.asc-now { display: inline-block; margin-left: 0.45rem; padding: 0.05rem 0.4rem; border-radius: var(--r-xs); background: var(--accent-tint); color: var(--accent); font-size: 0.68rem; font-weight: 600; vertical-align: 1px; white-space: nowrap; }
.asc-changed { display: block; margin-top: 0.15rem; font-size: 0.76rem; line-height: 1.45; color: var(--text-body); white-space: normal; }
/* A fingerprint row that says what changed needs room to say it. */
.asc-split tbody th:has(.asc-changed) { min-width: 18rem; max-width: 26rem; }
/* A quotation inside an answer is part of a reply, not a pull quote. */
#assistant-pane .asc-answer.markdown-body blockquote { margin: 0 0 0.65rem; padding: 0.1rem 0 0.1rem 0.8rem; font-size: inherit; }
#assistant-pane .asc-answer.markdown-body blockquote p { margin: 0; }
.asc-asker-note { margin: 0.6rem 0 0; padding: 0.5rem 0.75rem; border-left: 3px solid var(--attn-border); background: var(--attn-bg); border-radius: 0 var(--r-xs) var(--r-xs) 0; font-size: 0.86rem; line-height: 1.55; color: var(--text-body); overflow-wrap: anywhere; }
.asc-asker-note span { display: block; margin-bottom: 0.1rem; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--attn-text); }
.asc-run-actions button.primary .ic, .imp-actions .ic { width: 14px; height: 14px; }
.asc-run-actions .ghost-btn, .imp-actions .ghost-btn, .imp-actions button.primary, .asc-run-actions button.primary { min-height: 34px; }

/* --- shared --- */
.imp-input { width: 100%; padding: 0.5rem 0.65rem; border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--card); color: var(--text); font: 0.86rem/1.5 var(--font-ui); }
textarea.imp-input { resize: vertical; min-height: 4.4rem; }
.imp-input::placeholder { color: var(--text-faint); }
.imp-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.imp-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.75rem; }
.imp-actions button:disabled, .asc-run-actions button:disabled { opacity: 0.55; cursor: default; }
.imp-actions .ghost-btn:disabled:hover { border-color: var(--border-strong); color: var(--text-mid); }
.imp-fine { margin: 0.7rem 0 0; max-width: 78ch; font-size: 0.74rem; line-height: 1.55; color: var(--text-faint); }
.imp-quiet { margin: 0 0 0.6rem; max-width: 78ch; font-size: 0.82rem; line-height: 1.55; color: var(--text-quiet); }
.imp-caution, .imp-check { display: flex; align-items: flex-start; gap: 0.5rem; margin: 0.7rem 0 0; padding: 0.5rem 0.7rem; border-radius: var(--r-md); font-size: 0.8rem; line-height: 1.55; overflow-wrap: anywhere; }
.imp-caution { background: var(--attn-bg); border: 1px solid var(--attn-border); color: var(--attn-text); }
.imp-check.ok { background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok); }
.imp-check.bad { background: var(--danger-bg); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.imp-caution .ic, .imp-check .ic { width: 14px; height: 14px; flex: none; margin-top: 0.2rem; }
.imp-tag { display: inline-block; padding: 0.05rem 0.4rem; border-radius: var(--r-xs); background: var(--surface-sunken); border: 1px solid var(--border-soft); color: var(--text-quiet); font-size: 0.68rem; font-weight: 600; white-space: nowrap; }
.imp-tag.now { background: var(--accent-tint); border-color: transparent; color: var(--accent); }
.imp-tag.small { background: var(--attn-bg); border-color: var(--attn-border); color: var(--attn-text); }
.imp-scope { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.76rem; color: var(--text-quiet); }
.imp-under { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.3rem; }
.imp-count { font-size: 0.72rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.imp-count.over { color: var(--danger); font-weight: 600; }

/* --- the model card --- */
.imp-model-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.imp-model-now { min-width: 0; flex: 1 1 16rem; }
.imp-model-name { margin: 0.25rem 0 0; font-size: 1.35rem; font-weight: 700; line-height: 1.2; color: var(--text); overflow-wrap: anywhere; }
.imp-model-meta, .imp-model-review { margin: 0.25rem 0 0; font-size: 0.8rem; line-height: 1.5; color: var(--text-quiet); overflow-wrap: anywhere; }
.imp-model-review { margin-top: 0.7rem; padding-top: 0.6rem; border-top: 1px solid var(--border-soft); }
.imp-model-who { margin: 0; max-width: 16rem; font-size: 0.76rem; line-height: 1.5; color: var(--text-faint); text-align: right; }
.imp-model-toggle .ic { width: 13px; height: 13px; }
.imp-change { display: flex; align-items: flex-start; gap: 0.45rem; flex-wrap: wrap; margin: 0.6rem 0 0; font-size: 0.8rem; line-height: 1.5; color: var(--text-body); }
.imp-change > .ic { width: 13px; height: 13px; flex: none; margin-top: 0.22rem; color: var(--text-faint); }
.imp-change > span { min-width: 0; overflow-wrap: anywhere; }
.imp-change .text-btn { flex: none; margin-top: -0.2rem; }
/* On a phone the sentence keeps its place beside the clock and wraps within itself; the way back goes under it. */
@media (max-width: 768px) { .imp-change > span { flex: 1 1 12rem; } }
.imp-change b { font-weight: 600; color: var(--text); }
.imp-change .text-btn { color: var(--accent); }
.imp-run { margin-top: 0.8rem; padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-sunken); }
.imp-run-line { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; font-size: 0.8rem; line-height: 1.5; color: var(--text-body); }
.imp-run-line b { color: var(--text); }

.imp-panel { margin-top: 0.9rem; padding-top: 0.9rem; border-top: 1px solid var(--border); min-width: 0; }
.imp-tabs { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 0.7rem; border-radius: var(--r-md); background: var(--surface-sunken); border: 1px solid var(--border-soft); }
.imp-tab { min-height: 30px; padding: 0.25rem 0.7rem; border: 0; border-radius: var(--r-sm); background: none; font: 550 0.78rem var(--font-ui); color: var(--text-quiet); cursor: pointer; }
.imp-tab:hover { color: var(--text); }
.imp-tab[aria-selected="true"] { background: var(--card); color: var(--text); box-shadow: var(--e1); }
#imp-filter { margin-bottom: 0.5rem; max-width: 22rem; }
.imp-cands { display: grid; max-height: 21rem; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
.imp-cands-head, .imp-cands .imp-cand { display: grid; grid-template-columns: 1.1rem minmax(9rem, 1.3fr) minmax(0, 1fr) minmax(0, 1.25fr); gap: 0.25rem 0.75rem; align-items: start; padding: 0.55rem 0.75rem; }
.imp-cands.plain .imp-cand { grid-template-columns: 1.1rem minmax(0, 1fr); }
.imp-cands-head { position: sticky; top: 0; z-index: 1; padding-top: 0.4rem; padding-bottom: 0.4rem; background: var(--surface-sunken); border-bottom: 1px solid var(--border); font-size: 0.68rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-soft); }
.imp-cands-head span:first-child { grid-column: 2; }
.imp-cand { border-bottom: 1px solid var(--border-soft); cursor: pointer; font-size: 0.8rem; line-height: 1.45; color: var(--text-body); }
.imp-cands .imp-cand:last-child { border-bottom: 0; }
.imp-cand:hover { background: var(--surface-hover-card); }
.imp-cand.picked { background: var(--accent-wash); }
.imp-cand input[type="radio"] { margin: 0.2rem 0 0; accent-color: var(--accent); }
.imp-cand-name { display: flex; align-items: center; flex-wrap: wrap; gap: 0.3rem 0.4rem; min-width: 0; }
.imp-cand-fact { min-width: 0; font-variant-numeric: tabular-nums; }
.imp-cand-fact b { font-weight: 600; color: var(--text); }
.imp-cand-fact .asc-of { display: block; margin-left: 0; }
.imp-none { color: var(--text-faint); }
.imp-cand.custom { display: grid; grid-template-columns: 1.1rem auto minmax(0, 1fr); gap: 0.6rem; align-items: center; margin-top: 0.5rem; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: var(--r-md); }
.imp-cand.custom input[type="radio"] { margin: 0; }
.imp-cand.custom .imp-input { padding: 0.35rem 0.55rem; font-family: var(--font-mono); font-size: 0.8rem; }
.imp-cand:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }

/* --- improve this answer --- */
.imp-reviewed { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; color: var(--ok); }
.imp-reviewed .ic { width: 13px; height: 13px; }
.imp-flow { margin-top: 0.9rem; border: 1px solid var(--border-strong); border-radius: var(--r-lg); background: var(--bg-soft); min-width: 0; }
.imp-step { padding: 0.8rem 0.9rem; border-bottom: 1px solid var(--border-soft); min-width: 0; }
.imp-step:last-child { border-bottom: 0; }
.imp-step.waiting { opacity: 0.55; }
.imp-step-head { display: flex; align-items: center; gap: 0.55rem; }
.imp-step-head h4 { margin: 0; font: 600 0.86rem var(--font-ui); color: var(--text); }
.imp-step-n { display: grid; place-items: center; width: 1.4rem; height: 1.4rem; flex: none; border-radius: 50%; border: 1.5px solid var(--border-strong); font: 600 0.72rem var(--font-ui); color: var(--text-quiet); font-variant-numeric: tabular-nums; }
.imp-step-n.now { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.imp-step-n.done { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok); }
.imp-step-n .ic { width: 11px; height: 11px; }
.imp-step-body { margin: 0.65rem 0 0 1.95rem; min-width: 0; }
.imp-step-done { margin: 0.3rem 0 0 1.95rem; font-size: 0.8rem; line-height: 1.5; color: var(--text-quiet); overflow-wrap: anywhere; }
.imp-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.75rem; }
.imp-chip { min-height: 32px; padding: 0.3rem 0.75rem; border: 1px solid var(--border-strong); border-radius: var(--r-pill); background: var(--card); font: 500 0.78rem var(--font-ui); color: var(--text-mid); cursor: pointer; transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease; }
.imp-chip:hover { border-color: var(--accent); color: var(--accent); }
.imp-chip[aria-pressed="true"], .imp-chip[aria-pressed="true"]:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.imp-lesson-text { font-family: var(--font-doc); font-size: 0.95rem; line-height: 1.55; overflow: hidden; }
/* The spinner stays beside the first line of its sentence however narrow the screen. */
.imp-trying { display: flex; align-items: flex-start; gap: 0.55rem; margin: 0 0 0.5rem; font-size: 0.82rem; line-height: 1.5; color: var(--text-body); }
.imp-trying > span:not(.imp-spinner) { flex: 1 1 0; min-width: 0; }
.imp-trying .text-btn { flex: none; margin-top: -0.15rem; }
.imp-spinner { width: 14px; height: 14px; flex: none; margin-top: 0.2rem; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: imp-spin 0.8s linear infinite; }
@keyframes imp-spin { to { transform: rotate(360deg); } }
.imp-compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; margin-top: 0.2rem; }
.imp-side { min-width: 0; }
.imp-side h5 { margin: 0 0 0.35rem; font: 600 0.7rem var(--font-ui); letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-soft); }
.imp-side:last-child .asc-answer { border-color: var(--accent); background: var(--card); }
.imp-side .asc-run-figures { margin-top: 0.4rem; }

/* --- what Pilcrow has been taught --- */
.imp-lessons { list-style: none; margin: 0; padding: 0; display: grid; }
.imp-lesson { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0.75rem; align-items: start; padding: 0.8rem 0; border-top: 1px solid var(--border-soft); }
.imp-lesson:first-child { border-top: 0; padding-top: 0.2rem; }
.imp-lesson.editing { display: block; }
.imp-lesson-main { min-width: 0; }
.imp-lesson-words { margin: 0; font: 0.96rem/1.55 var(--font-doc); color: var(--text); overflow-wrap: anywhere; }
.imp-lesson.off .imp-lesson-words { color: var(--text-quiet); }
.imp-lesson-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.2rem 0.5rem; margin: 0.3rem 0 0; font-size: 0.74rem; color: var(--text-faint); }
.imp-tag.off { color: var(--text-quiet); }
.imp-from { padding: 0 0.15rem; font-size: 0.74rem; font-weight: 500; color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 2px; }
.imp-lesson-since { display: flex; flex-wrap: wrap; align-items: center; gap: 0.2rem 0.6rem; margin: 0.3rem 0 0; font-size: 0.78rem; color: var(--text-quiet); }
.imp-lesson-since b { color: var(--text); font-variant-numeric: tabular-nums; }
.imp-lesson-acts { display: flex; gap: 0.1rem; }
.imp-lesson-acts .ic { width: 14px; height: 14px; }
.imp-source { margin: 0.5rem 0 0; padding: 0.45rem 0.75rem; border-left: 3px solid var(--border-strong); background: var(--surface-sunken); border-radius: 0 var(--r-xs) var(--r-xs) 0; font-size: 0.82rem; line-height: 1.55; color: var(--text-body); overflow-wrap: anywhere; }
.imp-source span { display: block; margin-top: 0.3rem; font-size: 0.76rem; color: var(--text-quiet); }
.imp-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0.6rem 0 0; padding: 0.5rem 0.7rem; border-radius: var(--r-md); background: var(--danger-bg); font-size: 0.8rem; color: var(--text-body); }
.imp-switch { position: relative; width: 34px; height: 20px; flex: none; margin-top: 0.2rem; padding: 0; border: 0; border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: background 0.15s ease; }
.imp-switch i { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--card); box-shadow: var(--e1); transition: transform 0.15s ease; }
.imp-switch[aria-checked="true"] { background: var(--accent); }
.imp-switch[aria-checked="true"] i { transform: translateX(14px); }
.imp-switch:disabled { opacity: 0.5; cursor: default; }
/* A switch is small to look at and must still be easy to hit. */
.imp-switch::after { content: ''; position: absolute; inset: -10px -6px; }
.imp-add { margin-bottom: 0.9rem; padding: 0.8rem 0.9rem; border: 1px solid var(--border-strong); border-radius: var(--r-lg); background: var(--bg-soft); }
.imp-taught-empty { display: flex; align-items: center; gap: 0.8rem; padding: 0.4rem 0 0.2rem; }
.imp-taught-empty .asc-empty-icon { flex: none; margin: 0; }
.imp-taught-empty p { margin: 0; max-width: 68ch; font-size: 0.84rem; line-height: 1.6; color: var(--text-quiet); }
.imp-taught-empty strong { color: var(--text); }
#imp-taught-h:focus { outline: none; }

.imp-tab:focus-visible, .imp-chip:focus-visible, .imp-switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- "What was wrong?" under an Ask answer --- */
.chat-wrong { display: flex; gap: 6px; align-items: center; min-width: 0; }
.chat-wrong input { flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--card); color: var(--text); font: 12px var(--font-ui); }
.chat-wrong input::placeholder { color: var(--text-faint); }
.chat-wrong input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-tint); }
.chat-wrong-sent { display: flex; align-items: flex-start; gap: 5px; margin: 0; font-size: 11.5px; line-height: 1.5; color: var(--text-quiet); overflow-wrap: anywhere; }
.chat-wrong-sent .ic { width: 11px; height: 11px; flex: none; margin-top: 3px; color: var(--ok); }

@media (max-width: 768px) {
  .imp-model-who { text-align: left; max-width: none; }
  .imp-model-name { font-size: 1.15rem; }
  /* A candidate becomes a small card: its name, then what is known about it, each fact labelled. */
  .imp-cands-head { display: none; }
  .imp-cands .imp-cand { grid-template-columns: 1.1rem minmax(0, 1fr); }
  .imp-cand-fact { grid-column: 2; }
  .imp-cand-fact::before { content: attr(data-label) ': '; color: var(--text-faint); }
  .imp-cand-fact .asc-of { display: inline; margin-left: 0.3rem; }
  .imp-cand.custom { grid-template-columns: 1.1rem minmax(0, 1fr); }
  .imp-cand.custom .imp-input { grid-column: 1 / -1; }
  .imp-step-body, .imp-step-done { margin-left: 0; }
  /* A flow sits inside an answer inside a card: on a phone the three sets of
     padding leave too little to read in, so the inner two give some back. */
  .asc-run.open .asc-run-body { padding-left: 0.6rem; padding-right: 0.6rem; }
  .imp-step { padding: 0.7rem 0.65rem; }
  /* The first column of a table stays put while the rest scrolls; it cannot
     also be most of the screen. */
  .asc-split tbody th:has(.asc-changed) { min-width: 10.5rem; max-width: 12rem; }
  .imp-compare { grid-template-columns: minmax(0, 1fr); }
  .imp-lesson { grid-template-columns: auto minmax(0, 1fr); }
  .imp-lesson-acts { grid-column: 2; }
  .imp-actions .primary, .imp-actions .ghost-btn { flex: 1 1 auto; justify-content: center; }
  .imp-taught-empty { align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  .imp-switch, .imp-switch i, .imp-chip { transition: none; }
  .imp-spinner { animation-duration: 2.4s; }
}
