/* anvil — "drafting table"
 *
 * The sheet metaphor is structural, not decorative. A technical drawing
 * carries its metadata in a title block, its history in a revision block, and
 * its notes as annotations pinned to construction lines. Those are exactly
 * the four things this UI has to show, so each one takes the form its
 * drafting equivalent already has.
 *
 * Rules: no border radius anywhere, no fills where a hairline will do, and
 * one colour — drafting red — reserved for live state and failure.
 */

/* ---------- faces ---------- */

@font-face {
  font-family: "Tektur";
  src: url("fonts/Tektur-Medium.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("fonts/InstrumentSans-Regular.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("fonts/InstrumentSans-Italic.woff2") format("woff2");
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("fonts/InstrumentSans-Bold.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/IBMPlexMono-Regular.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/IBMPlexMono-Bold.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}

/* ---------- tokens ---------- */

:root {
  /* Blueprint: cyanotype ground. The neutrals are blue-biased on purpose —
     a true grey would read as unconsidered next to this ink. */
  --sheet:      #0c1e33;
  --sheet-2:    #0f2740;
  --sheet-3:    #16344f;
  --rule:       #2b5074;
  --rule-faint: #18334d;
  --grid:       rgba(127, 168, 201, .055);

  --chalk:       #e6eef6;
  --chalk-dim:   #9dbad4;
  --chalk-faint: #5f86ab;

  --red:   #e0503a;   /* live state and failure only */
  --green: #4fb286;

  --display: "Tektur", ui-sans-serif, system-ui, sans-serif;
  --body: "Instrument Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --gut: 20px;
  /* Absolute, not ch: the sheet mixes mono and sans, and `ch` resolves
     against each element's own font, so a ch-based measure would leave the
     tool column and the prose column on different edges. */
  --measure: 660px;
}

@media (prefers-color-scheme: light) {
  :root {
    /* Vellum: tracing paper over a light table. */
    --sheet:      #e7e6de;
    --sheet-2:    #eeece4;
    --sheet-3:    #f7f6f1;
    --rule:       #9daebd;
    --rule-faint: #c7d0d7;
    --grid:       rgba(16, 40, 63, .05);

    --chalk:       #10283f;
    --chalk-dim:   #3d5f7d;
    --chalk-faint: #7a91a5;

    --red:   #bf3a26;
    --green: #2c7d5c;
  }
}

/* Explicit choice always beats the OS preference, in both directions. */
:root[data-theme="vellum"] {
  --sheet: #e7e6de; --sheet-2: #eeece4; --sheet-3: #f7f6f1;
  --rule: #9daebd; --rule-faint: #c7d0d7; --grid: rgba(16, 40, 63, .05);
  --chalk: #10283f; --chalk-dim: #3d5f7d; --chalk-faint: #7a91a5;
  --red: #bf3a26; --green: #2c7d5c;
}
:root[data-theme="blueprint"] {
  --sheet: #0c1e33; --sheet-2: #0f2740; --sheet-3: #16344f;
  --rule: #2b5074; --rule-faint: #18334d; --grid: rgba(127, 168, 201, .055);
  --chalk: #e6eef6; --chalk-dim: #9dbad4; --chalk-faint: #5f86ab;
  --red: #e0503a; --green: #4fb286;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--sheet);
  color: var(--chalk);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 1px solid var(--red); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Every label on the sheet is set the same way: drafting lettering, tracked,
   sitting on its own hairline. */
.eyebrow, .field-label {
  display: block;
  font-family: var(--display);
  font-size: 9.5px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--chalk-faint);
  line-height: 1;
}

button {
  font-family: var(--display);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--chalk);
  border-radius: 0;
  padding: 7px 12px;
}
button:hover { border-color: var(--chalk-dim); }
button:disabled { opacity: .35; cursor: default; border-color: var(--rule-faint); }
.ghost { border-color: transparent; color: var(--chalk-faint); }
.ghost:hover { color: var(--chalk); border-color: var(--rule); }

/* Drafting corner marks, on opposing corners, instead of a rounded box. */
.tick { position: relative; }
.tick::before, .tick::after {
  content: "";
  position: absolute;
  width: 9px; height: 9px;
  border: 1px solid var(--rule);
  pointer-events: none;
}
.tick::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.tick::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: flex; gap: 8px; }
input, select, textarea {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--chalk);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  padding: 6px 2px;
}
input:focus, select:focus, textarea:focus { outline: none; border-bottom-color: var(--red); }
select { font-family: var(--mono); }

/* ---------- access ---------- */

.gate {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
  background: var(--sheet);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 8px 8px;
}
.gate-card {
  width: min(340px, 100%);
  display: flex; flex-direction: column; gap: 16px;
  background: var(--sheet-2);
  border: 1px solid var(--rule);
  padding: 30px;
}
.gate-card h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 30px; font-weight: 500;
  letter-spacing: .06em;
  text-transform: lowercase;
}
.gate-card button { padding: 10px; border-color: var(--chalk-dim); }
.gate-error { margin: 0; font-size: 12px; color: var(--red); font-family: var(--mono); }

/* ---------- drawing index ---------- */

.app { display: flex; height: 100%; }

.sidebar {
  width: 244px; flex: 0 0 244px;
  display: flex; flex-direction: column;
  background: var(--sheet-2);
  border-right: 1px solid var(--rule);
}
.index-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px var(--gut) 12px;
  border-bottom: 1px solid var(--rule-faint);
}
.brand {
  font-family: var(--display);
  font-size: 17px; letter-spacing: .1em;
  color: var(--chalk);
}
.index-eyebrow { margin: 14px var(--gut) 8px; }

.session-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.session-list li {
  position: relative;
  padding: 9px var(--gut) 9px calc(var(--gut) + 12px);
  cursor: pointer;
  border-top: 1px solid var(--rule-faint);
  color: var(--chalk-dim);
}
.session-list li:last-child { border-bottom: 1px solid var(--rule-faint); }
.session-list li:hover { background: var(--sheet-3); color: var(--chalk); }
/* The active sheet is marked in the gutter, the way a drawing is flagged —
   no fill, so the index stays a list of rules rather than a stack of cards. */
.session-list li.active { color: var(--chalk); }
.session-list li.active::before {
  content: "";
  position: absolute; left: var(--gut); top: 50%;
  width: 6px; height: 6px; margin-top: -3px;
  background: var(--red);
}
.session-list .name {
  display: block; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-list .when {
  font-family: var(--mono); font-size: 10.5px;
  color: var(--chalk-faint); font-variant-numeric: tabular-nums;
}

.index-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 4px 8px; flex-wrap: wrap;
  padding: 10px 12px 10px var(--gut);
  border-top: 1px solid var(--rule);
}
/* Four actions do not fit 244px on one line. Wrapping beats shrinking the
   type below the point where it can be read. */
.foot-actions { display: flex; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }
.index-foot button { white-space: nowrap; }
.index-foot button { font-size: 9.5px; padding: 5px 7px; letter-spacing: .12em; }
.conn {
  font-family: var(--display); font-size: 9.5px;
  letter-spacing: .16em; text-transform: uppercase;
}
.conn-on { color: var(--green); }
.conn-off { color: var(--chalk-faint); }

/* ---------- title block ---------- */

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.titleblock {
  display: flex; align-items: stretch;
  border-bottom: 1px solid var(--rule);
  padding-top: env(safe-area-inset-top);
  background: var(--sheet-2);
}
.titleblock .menu { display: none; align-self: center; margin-left: 12px; }

.tb-name, .tb-field {
  display: flex; flex-direction: column; gap: 5px; justify-content: center;
  padding: 11px 16px;
  border-right: 1px solid var(--rule-faint);
}
.tb-name { flex: 1; min-width: 0; }
.tb-title { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.tb-name h2 {
  margin: 0; min-width: 0;
  font-family: var(--display); font-weight: 500;
  font-size: 15px; letter-spacing: .01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tb-title .state {
  flex: none;
  font-family: var(--mono); font-size: 11px;
  color: var(--chalk-faint);
}
.tb-value {
  font-family: var(--mono); font-size: 12px;
  color: var(--chalk-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.3;
}
.tb-num .tb-value { font-variant-numeric: tabular-nums; }
.tb-field { min-width: 0; }

.model-btn {
  border: 0; background: none; text-align: left;
  text-transform: none; letter-spacing: 0;
  max-width: 26ch;
  padding: 6px 0; margin: -6px 0;
}
.model-btn:hover { color: var(--chalk); }
.model-btn::after { content: " \25BE"; color: var(--chalk-faint); }

.mode-btn {
  border: 0; background: none; text-align: left;
  text-transform: none; letter-spacing: 0;
  /* Padded out and pulled back in: the tap target is ~28px without the
     title block growing to match. At 16px these were a thumb-width miss. */
  padding: 6px 0; margin: -6px 0;
}
.mode-btn:hover:not(:disabled) { color: var(--chalk); }
.mode-btn:disabled { opacity: .5; }
/* An unapproved plan is a held drawing, so it carries the same red as the
   running state: both mean "do not read this as finished". */
.mode-btn.planning { color: var(--red); }
.mode-btn.planning::before {
  content: "";
  display: inline-block; width: 6px; height: 6px;
  margin-right: 8px; vertical-align: 0;
  border: 1px solid var(--red);
  transform: rotate(45deg);
}

/* State is shown as a form as well as a word: a filled square means running. */
.state::before {
  content: "";
  display: inline-block; width: 6px; height: 6px;
  margin-right: 7px; vertical-align: 1px;
  border: 1px solid var(--chalk-faint);
}
.state.working { color: var(--red); }
.state.working::before { background: var(--red); border-color: var(--red); }

.stop {
  align-self: center; margin: 0 16px;
  border-color: var(--red); color: var(--red);
}
.stop:hover { border-color: var(--red); background: var(--red); color: var(--sheet); }

/* ---------- revision block ---------- */

.revisions {
  border-bottom: 1px solid var(--rule);
  padding: 12px var(--gut);
  background: var(--sheet-2);
}
.revision-rows { margin-top: 8px; display: grid; gap: 3px; }
.todo {
  display: grid; grid-template-columns: 22px 1fr; align-items: baseline;
  font-size: 13px; color: var(--chalk-dim);
}
.todo .mark {
  font-family: var(--mono); font-size: 11px;
  color: var(--chalk-faint);
}
.todo.in_progress { color: var(--chalk); }
.todo.in_progress .mark { color: var(--red); }
.todo.completed { color: var(--chalk-faint); }
.todo.completed .text { text-decoration: line-through; text-decoration-thickness: 1px; }

/* ---------- the sheet ---------- */

.sheet {
  flex: 1;
  overflow-y: auto;
  padding: 26px var(--gut) 12px;
  display: flex; flex-direction: column; gap: 20px;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 8px 8px;
  scroll-behavior: smooth;
}

.msg { max-width: var(--measure); width: 100%; margin: 0 auto; }
.msg .who {
  font-family: var(--display); font-size: 9.5px;
  letter-spacing: .18em; text-transform: uppercase;
  color: var(--chalk-faint); margin-bottom: 7px;
}
.msg .body { overflow-wrap: anywhere; }

/* A user turn is an annotation pinned to the drawing. */
.msg.user .body {
  white-space: pre-wrap;
  background: var(--sheet-2);
  border: 1px solid var(--rule);
  padding: 12px 15px;
  font-size: 14.5px;
}
.msg.user .who { color: var(--red); }
.msg.error .body { color: var(--red); font-family: var(--mono); font-size: 13px; }

/* Assistant prose sits directly on the sheet — no container, because it is
   the content the sheet exists to carry. */
.msg .body.md { white-space: normal; }
.msg .body.md > :first-child { margin-top: 0; }
.msg .body.md > :last-child { margin-bottom: 0; }
.msg .body.md p { margin: 0 0 12px; max-width: 68ch; }
.msg .body.md h3, .msg .body.md h4, .msg .body.md h5, .msg .body.md h6 {
  margin: 22px 0 8px;
  font-family: var(--display); font-weight: 500;
  font-size: 13px; letter-spacing: .04em;
  text-wrap: balance;
}
.msg .body.md ul, .msg .body.md ol { margin: 0 0 12px; padding-left: 20px; }
.msg .body.md li { margin: 4px 0; }
.msg .body.md li::marker { color: var(--chalk-faint); font-family: var(--mono); font-size: .85em; }
.msg .body.md a { color: var(--chalk); text-decoration-color: var(--red); text-underline-offset: 3px; }
.msg .body.md strong { font-weight: 700; }
.msg .body.md code {
  font-family: var(--mono); font-size: .84em;
  color: var(--chalk);
  border-bottom: 1px solid var(--rule);
  padding: 0 1px;
}
.msg .body.md pre.code {
  margin: 14px 0;
  padding: 13px 15px;
  background: var(--sheet-2);
  border: 1px solid var(--rule-faint);
  border-left: 1px solid var(--rule);
  overflow-x: auto;
}
.msg .body.md pre.code code {
  border: 0; padding: 0;
  font-size: 12.5px; line-height: 1.55;
  white-space: pre;
  color: var(--chalk-dim);
}

/* Tool calls are construction lines: they run in the gutter, carry the
   working, and are not the drawing itself. */
.tool {
  max-width: var(--measure); width: 100%; margin: 0 auto;
  font-family: var(--mono); font-size: 12px;
  border-left: 1px solid var(--rule);
  padding: 1px 0 1px 14px;
  color: var(--chalk-dim);
  position: relative;
}
.tool::before {
  content: ""; position: absolute; left: 0; top: 9px;
  width: 7px; height: 1px; background: var(--rule);
}
.tool summary { cursor: pointer; list-style: none; color: var(--chalk-dim); }
.tool summary::-webkit-details-marker { display: none; }
.tool .name { color: var(--chalk); }
.tool .args { color: var(--chalk-faint); }
.tool pre {
  margin: 7px 0 3px;
  white-space: pre-wrap; overflow-wrap: anywhere;
  color: var(--chalk-faint);
  font-size: 11.5px;
  max-height: 330px; overflow-y: auto;
}
.tool.failed { border-left-color: var(--red); }
.tool.failed::before { background: var(--red); }
.tool.failed .name { color: var(--red); }

/* A gate rides on the construction line whose call it is holding, so the
   decision is read next to the arguments it is about. */
.tool.gated { border-left-color: var(--red); }
.tool.gated::before { background: var(--red); }

.approval {
  max-width: var(--measure); width: 100%; margin: 8px auto 0;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 12px;
  color: var(--chalk);
  border: 1px dashed var(--red);
  padding: 8px 12px;
}
.approval .approval-q { flex: 1; min-width: 0; }
.approval .approval-tool { font-weight: 700; }
.approval .approval-actions { display: flex; gap: 8px; }
.approval .approval-allow { border-color: var(--red); color: var(--red); }
.approval .approval-allow:hover { background: var(--red); color: var(--sheet); border-color: var(--red); }
.approval.settled {
  border-style: solid; border-color: var(--rule-faint);
  color: var(--chalk-faint);
  padding: 3px 0; border-width: 0;
}
.approval.settled .approval-q::before { content: "\2014\00a0"; }
.approval.denied, .approval.expired { color: var(--red); }

/* The approval block: where a drawing gets signed, or does not. */
.plan {
  max-width: var(--measure); width: 100%; margin: 0 auto;
  border: 1px solid var(--rule);
  border-left: 2px solid var(--red);
  background: var(--sheet-2);
  padding: 16px 18px;
}
.plan .eyebrow { margin: 0 0 12px; color: var(--red); }
.plan .body.md { font-size: 14.5px; }
.plan-decide {
  display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap;
  margin-top: 16px; padding-top: 14px;
  border-top: 1px solid var(--rule-faint);
}
.plan-note { flex: 1; min-width: 200px; }
.plan-note::placeholder { color: var(--chalk-faint); }
.plan-actions { display: flex; gap: 8px; }
.plan-approve { border-color: var(--green); color: var(--green); }
.plan-approve:hover:not(:disabled) { background: var(--green); color: var(--sheet); border-color: var(--green); }
.plan-outcome {
  margin: 14px 0 0; padding-top: 12px;
  border-top: 1px solid var(--rule-faint);
  font-family: var(--mono); font-size: 11px;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--green);
}
.plan-outcome.bad { color: var(--red); }
/* A settled plan is reference, not a prompt: it drops the red edge and the
   weight so a live one further down the sheet is the thing that stands out. */
.plan.settled { border-left-color: var(--rule); background: transparent; }
.plan.settled .eyebrow { color: var(--chalk-faint); }
.plan.superseded { opacity: .6; }
.plan.superseded .plan-outcome { color: var(--chalk-faint); }

.thinking, .usage {
  max-width: var(--measure); width: 100%; margin: 0 auto;
  font-family: var(--mono); font-size: 11px;
  color: var(--chalk-faint);
  font-variant-numeric: tabular-nums;
}
.thinking { font-family: var(--body); font-style: italic; font-size: 13px; }

.shots { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.shots img {
  max-width: min(300px, 100%); max-height: 230px;
  border: 1px solid var(--rule);
  object-fit: contain; background: var(--sheet);
}

/* ---------- empty sheet ---------- */

.empty { margin: auto; max-width: 480px; width: 100%; padding: 20px 0; }
.empty-mark { display: none; }
.empty-lead {
  margin: 0 0 20px;
  font-family: var(--display); font-weight: 500;
  font-size: 17px; letter-spacing: .01em;
  text-wrap: balance;
}
.empty-facts {
  display: grid; grid-template-columns: max-content 1fr;
  gap: 0; margin: 0 0 18px;
  border-top: 1px solid var(--rule);
}
.empty-facts dt {
  font-family: var(--display); font-size: 9.5px;
  letter-spacing: .18em; text-transform: uppercase;
  color: var(--chalk-faint);
  padding: 9px 18px 9px 0;
  border-bottom: 1px solid var(--rule-faint);
}
.empty-facts dd {
  margin: 0; padding: 9px 0;
  border-bottom: 1px solid var(--rule-faint);
  overflow-wrap: anywhere;
}
.empty-facts .mono { font-family: var(--mono); font-size: 12px; color: var(--chalk-dim); }
#empty-tools { line-height: 1.9; }
.empty-hint { margin: 0; font-family: var(--mono); font-size: 11px; color: var(--chalk-faint); }

/* ---------- instruction block ---------- */

.composer { padding: 14px var(--gut) max(14px, env(safe-area-inset-bottom)); }
.composer-box {
  border: 1px solid var(--rule);
  background: var(--sheet-2);
  padding: 10px 12px 8px;
  max-width: var(--measure); margin: 0 auto;
}
.composer-box:focus-within { border-color: var(--chalk-dim); }
.composer-label { margin-bottom: 6px; }
.composer-row { display: flex; align-items: flex-end; gap: 10px; }
.composer textarea {
  flex: 1;
  font-family: var(--body); font-size: 14.5px;
  resize: none; max-height: 190px;
  border: 0; padding: 2px 0 4px;
}
.composer textarea:focus { border: 0; }
.composer-actions { display: flex; gap: 6px; align-items: center; }
.composer #send { border-color: var(--chalk-dim); }
.composer #send:not(:disabled):hover { background: var(--chalk); color: var(--sheet); }

.tray { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 9px; }
.chip {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--rule-faint);
  padding: 4px 8px 4px 4px;
  font-family: var(--mono); font-size: 11px;
  color: var(--chalk-dim);
  max-width: 210px;
}
.chip img { width: 28px; height: 28px; object-fit: cover; border: 1px solid var(--rule-faint); }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-sp { color: var(--chalk-faint); }
.chip-x {
  border: 0; padding: 0 2px; font-size: 13px; line-height: 1;
  color: var(--chalk-faint); letter-spacing: 0;
}
.chip-x:hover { color: var(--red); border-color: transparent; }
.chip-error { border-color: var(--red); color: var(--red); max-width: none; }

/* ---------- specification dialog ---------- */

.model-dialog {
  border: 1px solid var(--rule);
  border-radius: 0;
  background: var(--sheet-2);
  color: var(--chalk);
  padding: 0;
  width: min(500px, 92vw);
  /* The dialog scrolls, not the page behind it. Without a bound the servers
     dialog runs past the viewport and its own buttons become unreachable —
     which is exactly the part you came here to press. */
  max-height: 88vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.model-dialog::backdrop { background: rgba(3, 12, 22, .62); }
.model-inner { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.model-inner header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.model-inner h3 {
  margin: 5px 0 0;
  font-family: var(--display); font-weight: 500;
  font-size: 18px; letter-spacing: .03em;
}
.model-note { margin: 0; font-family: var(--mono); font-size: 11px; color: var(--chalk-faint); }

/* ---------- schedule of parts (mcp) ---------- */

.mcp-dialog { width: min(640px, 100%); }
.mcp-lead { margin: 0; font-size: 13px; color: var(--chalk-dim); line-height: 1.55; }
.mcp-lead code, .mcp-hint code {
  font-family: var(--mono); font-size: .86em;
  color: var(--chalk); border-bottom: 1px solid var(--rule); padding: 0 1px;
}

.mcp-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; background: var(--rule-faint); }
.mcp-none {
  padding: 14px; background: var(--sheet-2);
  font-family: var(--mono); font-size: 12px; color: var(--chalk-faint);
}
.mcp-row { padding: 12px 14px; background: var(--sheet-2); }
/* A failed server keeps its row rather than vanishing: knowing it is
   configured and broken is the useful state. */
.mcp-row.failed { border-left: 2px solid var(--red); }

.mcp-head { display: flex; align-items: baseline; gap: 10px; }
.mcp-name { font-family: var(--display); font-size: 14px; color: var(--chalk); }
.mcp-kind-tag {
  font-family: var(--display); font-size: 9.5px;
  letter-spacing: .16em; text-transform: uppercase; color: var(--chalk-faint);
}
.mcp-count {
  margin-left: auto;
  font-family: var(--mono); font-size: 11px; color: var(--chalk-faint);
  font-variant-numeric: tabular-nums;
}
.mcp-row.failed .mcp-count { color: var(--red); }
.mcp-drop { padding: 3px 8px; font-size: 9.5px; }

.mcp-at, .mcp-tools, .mcp-err {
  font-size: 11px; line-height: 1.5;
  overflow-wrap: anywhere;
}
.mcp-at { color: var(--chalk-faint); margin-top: 5px; }
.mcp-tools { color: var(--chalk-dim); margin-top: 5px; }
.mcp-tools:empty, .mcp-err:empty { display: none; }
.mcp-err { color: var(--red); margin-top: 5px; }

.mcp-add { border-top: 1px solid var(--rule); padding-top: 14px; }
.mcp-add > summary {
  cursor: pointer; list-style: none;
  font-family: var(--display); font-size: 11px;
  letter-spacing: .1em; text-transform: uppercase; color: var(--chalk-dim);
}
.mcp-add > summary::-webkit-details-marker { display: none; }
.mcp-add > summary::before { content: "+ "; color: var(--red); }
.mcp-add[open] > summary::before { content: "\2212 "; }
.mcp-add[open] > summary { margin-bottom: 14px; }
.mcp-add .field { margin-bottom: 12px; }
.mcp-add textarea { width: 100%; resize: vertical; line-height: 1.5; }

.mcp-kind { display: flex; gap: 18px; margin-bottom: 14px; }
.mcp-kind label {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--chalk-dim); cursor: pointer;
}
.mcp-kind input { accent-color: var(--red); }

.mcp-hint { margin: 0 0 12px; font-size: 12px; color: var(--chalk-faint); line-height: 1.5; }
.mcp-result {
  margin: 0 0 12px; padding: 9px 11px;
  border-left: 2px solid var(--green);
  background: var(--sheet-3);
  font-family: var(--mono); font-size: 11.5px; line-height: 1.55;
  color: var(--chalk-dim); overflow-wrap: anywhere;
}
.mcp-result.bad { border-left-color: var(--red); color: var(--red); }
.mcp-actions { display: flex; gap: 8px; justify-content: flex-end; }
.model-warn { margin: 0; font-size: 12px; color: var(--chalk-faint); line-height: 1.5; }
.model-row { display: flex; align-items: center; gap: 8px; }

.model-list {
  list-style: none; margin: 0; padding: 0;
  max-height: 42vh; overflow-y: auto;
  border-top: 1px solid var(--rule);
}
.model-list li {
  display: grid; grid-template-columns: 1fr auto;
  gap: 1px 12px; align-items: baseline;
  padding: 9px 2px; cursor: pointer;
  border-bottom: 1px solid var(--rule-faint);
  position: relative;
}
.model-list li:hover { background: var(--sheet-3); }
.model-list li.active { color: var(--chalk); }
.model-list li.active::after {
  content: ""; position: absolute; right: 2px; top: 12px;
  width: 6px; height: 6px; background: var(--red);
}
.model-list .mid { font-family: var(--mono); font-size: 12.5px; }
.model-list .mname { grid-column: 1; font-size: 11.5px; color: var(--chalk-faint); }
.model-list .mcap {
  grid-row: 1; grid-column: 2;
  font-family: var(--display); font-size: 9px;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--chalk-faint); padding-right: 14px;
}

/* ---------- narrow sheets ---------- */

.scrim { position: fixed; inset: 0; background: rgba(3, 12, 22, .55); z-index: 9; }

@media (max-width: 780px) {
  .sidebar {
    position: fixed; z-index: 10; top: 0; bottom: 0; left: 0;
    transform: translateX(-100%);
    transition: transform .16s ease;
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.open { transform: none; }
  .titleblock { flex-wrap: wrap; }
  .titleblock .menu { display: block; }
  .tb-name { flex: 1 0 100%; border-right: 0; padding-left: 16px; }
  /* Four fields in one phone-width row leave a model id about eight
     characters; two rows of two keeps every field legible, and a title block
     is a ruled grid anyway, so the wrap reads as intended. */
  .tb-field { flex: 1 1 44%; border-top: 1px solid var(--rule-faint); }
  .stop { margin: 8px 16px; }
  :root { --gut: 14px; }

  /* At phone width the buttons crowd the field and clip the placeholder.
     Give the instruction its full measure and drop the actions beneath it. */
  .composer-row { flex-wrap: wrap; }
  .composer textarea { flex: 1 0 100%; }
  .composer-actions { margin-left: auto; }
}
