:root {
  color-scheme: light;
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #faf9f5;
  --ink: #1c1d1a;
  --ink-2: #4a4c46;
  --ink-3: #7a7d74;
  --line: #dedbd1;
  --line-2: #ecebe4;
  --accent: #e5551c;
  --accent-ink: #b8400f;
  --accent-bg: #fdeee6;
  --agent: #2a5bd7;
  --agent-bg: #e9eefb;
  --ok: #2c7a4b;
  --ok-bg: #e6f3ea;
  --warn-bg: #fff7e0;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, dl { margin: 0; }
h1 { font-size: 1.5rem; font-weight: 650; letter-spacing: -.01em; line-height: 1.25; }
h2 { font-size: 1rem; font-weight: 600; }
h3 { font-size: .875rem; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
a { color: inherit; }
code { font-family: var(--mono); font-size: .9em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
:focus-visible { outline: 2px solid var(--agent); outline-offset: 2px; }

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 500;
  font-size: .9375rem;
  transition: background .12s, border-color .12s;
}
.button:hover:not(:disabled) { background: var(--surface-2); border-color: #c9c6bb; }
.button.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.button.primary:hover:not(:disabled) { background: #000; border-color: #000; }
.button.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.accent:hover:not(:disabled) { background: var(--accent-ink); border-color: var(--accent-ink); }
.button.small { min-height: 30px; padding: 0 10px; font-size: .8125rem; }
.button.icon-button { width: 36px; padding: 0; font-size: 1.25rem; line-height: 1; }
.icon-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.button-row { display: flex; gap: 8px; margin-top: 16px; }
.button-row > .button { flex: 1; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 56px;
  padding: 0 clamp(16px, 3vw, 40px);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 5px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--bg), inset 0 0 0 5px var(--accent);
}
.brand-name { font-weight: 650; letter-spacing: -.01em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.status-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: .875rem;
  color: var(--ink-2);
}
.status-button:hover { background: var(--surface-2); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #b9b6ab; }
.status-dot.available { background: var(--ok); }
.status-dot.partial { background: var(--accent); }

/* Case header */
main { width: min(1320px, 100%); margin: 0 auto; padding: 0 clamp(16px, 3vw, 40px) 40px; }
.case-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 32px;
  align-items: end;
  padding: 32px 0 20px;
}
.case-ref { margin-bottom: 6px; font-family: var(--mono); font-size: .8125rem; color: var(--ink-3); }
.case-board { margin-left: 8px; font-weight: 400; color: var(--ink-3); font-size: 1rem; }
.case-symptom { margin-top: 8px; max-width: 60ch; color: var(--ink-2); }
.case-facts {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.case-facts > div { padding: 10px 16px; border-left: 1px solid var(--line-2); }
.case-facts > div:first-child { border-left: 0; }
.case-facts dt { font-size: .75rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.case-facts dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
#phase-badge { color: var(--accent-ink); }

/* Steps */
.steps { margin-bottom: 16px; }
.steps ol {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
.steps li {
  position: relative;
  padding: 8px 0 0;
  border-top: 2px solid var(--line);
  font-size: .8125rem;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.steps li::before { counter-increment: step; content: counter(step, decimal-leading-zero) " "; font-family: var(--mono); font-size: .75rem; }
.steps li.complete { border-top-color: var(--ink); color: var(--ink-2); }
.steps li.current { border-top-color: var(--accent); color: var(--ink); font-weight: 600; }

/* Workspace */
.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 1fr);
  gap: 16px;
  align-items: start;
}
.side-column { display: grid; gap: 16px; min-width: 0; }
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line-2);
}
.panel-kicker { font-size: .75rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.board-legend { display: flex; align-items: center; gap: 6px; font-size: .8125rem; color: var(--ink-3); }
.legend-focus, .legend-probe { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.legend-focus { border: 2px solid #f2b632; }
.legend-probe { margin-left: 10px; background: var(--accent); }

/* Board */
.board-shell { padding: 16px 16px 0; }
.board { display: block; width: 100%; height: auto; color: #dfe9d9; }
.board-base { fill: #1f5a3a; stroke: #16432b; stroke-width: 2; }
.mount { fill: #f4f2ec; stroke: #b9a273; stroke-width: 3; }
.trace { fill: none; stroke: #c78a4a; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
.trace-main { stroke: #d9a061; }
.trace.thin { stroke-width: 5; opacity: .6; }
.via { fill: #e0b071; stroke: #f5dcae; stroke-width: 3; }
.silk { fill: #e6efe2; font-family: var(--mono); letter-spacing: .08em; }
.board-name { font-size: 20px; font-weight: 700; }
.board-rev { font-size: 11px; }
.silk.tiny { font-size: 9px; }
.component { cursor: pointer; }
.component > rect:first-child { fill: #2b2b28; stroke: #6f746a; stroke-width: 2; transition: stroke .15s, fill .15s; }
.component text { fill: #e6efe2; font-family: var(--mono); font-size: 16px; font-weight: 700; text-anchor: middle; pointer-events: none; }
.component text.sub { font-size: 11px; font-weight: 500; letter-spacing: .1em; }
.component .component-detail, .chip-pins { fill: none; stroke: #b8bfb1; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.component .pin-one { fill: #b8bfb1; }
.component:hover > rect:first-child, .component:focus-visible > rect:first-child { stroke: #dfe9d9; }
.component.is-focus > rect:first-child { stroke: #f2b632; stroke-width: 4; fill: #3a3623; }
.component.is-focus text { fill: #ffd76a; }
.probe-point { opacity: 0; pointer-events: none; }
.probe-point circle { fill: var(--accent); stroke: #fff; stroke-width: 4; }
.probe-point text { fill: #fff; font-family: var(--mono); font-weight: 700; font-size: 18px; text-anchor: middle; paint-order: stroke; stroke: #1f5a3a; stroke-width: 4px; }
.probe-point.is-visible { opacity: 1; }
.board-callout { padding: 10px 20px 0; font-size: .875rem; color: var(--ink-2); }
.board-callout strong { color: var(--ink); }

/* Hypotheses */
.hypotheses { padding: 16px 20px 20px; }
.hypotheses h3 { margin-bottom: 12px; }
.hypothesis-list { display: grid; gap: 8px; }
.hypothesis-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(80px, 1fr) 58px;
  gap: 12px;
  align-items: center;
  font-size: .875rem;
}
.hypothesis-name { overflow: hidden; color: var(--ink-2); text-overflow: ellipsis; white-space: nowrap; }
.hypothesis-row.leading .hypothesis-name { color: var(--ink); font-weight: 600; }
.probability-track { height: 8px; overflow: hidden; border-radius: 4px; background: var(--line-2); }
.probability-fill { height: 100%; width: 0; background: #b9b6ab; transition: width .45s ease; }
.hypothesis-row.leading .probability-fill { background: var(--ink); }
.probability-value { font-family: var(--mono); font-size: .8125rem; text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.hypothesis-row.leading .probability-value { color: var(--ink); font-weight: 600; }

/* Action panel */
.action-content { padding: 20px; }
.action-lead { margin-bottom: 16px; color: var(--ink-2); font-size: .9375rem; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; background: var(--surface-2); }
.card h3 { margin-bottom: 4px; font-size: 1.0625rem; font-weight: 600; color: var(--ink); text-transform: none; letter-spacing: 0; }
.card-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.info-score { flex: none; text-align: right; }
.info-score strong { display: block; font-family: var(--mono); font-size: 1.125rem; }
.info-score span { display: block; font-size: .75rem; color: var(--ink-3); }
.card-reason { margin: 6px 0 12px; color: var(--ink-2); font-size: .875rem; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.meta-chip { border: 1px solid var(--line); border-radius: 4px; padding: 2px 8px; font-size: .75rem; color: var(--ink-2); background: var(--surface); }
.meta-chip.safe { border-color: transparent; background: var(--ok-bg); color: var(--ok); }
.hint { margin-top: 14px; font-size: .8125rem; color: var(--ink-3); }

.probe-instruction { margin: 12px 0; padding: 12px 14px; border-left: 3px solid var(--accent); background: var(--surface); font-size: .9375rem; }
.checkline { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; font-size: .875rem; }
.checkline input { width: 18px; height: 18px; margin: 2px 0 0; flex: none; accent-color: var(--ink); }
.field-label { display: block; margin: 12px 0 6px; font-size: .75rem; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.outcome-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice-button {
  min-height: 56px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: .875rem;
  font-weight: 500;
  text-align: center;
}
.choice-button:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-bg); }
.human-note {
  width: 100%;
  min-height: 64px;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: .875rem;
  resize: vertical;
}
.human-note::placeholder { color: var(--ink-3); }

.confidence { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.confidence strong { font-size: 2.25rem; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.confidence span { color: var(--ink-2); }
.confidence-bar { position: relative; height: 8px; margin: 4px 0 14px; border-radius: 4px; background: var(--line-2); overflow: visible; }
.confidence-bar > i { display: block; height: 100%; border-radius: 4px; background: var(--ink); transition: width .45s ease; }
.confidence-bar > b { position: absolute; top: -4px; width: 2px; height: 16px; background: var(--accent); }
.confidence-bar > b::after { content: attr(data-label); position: absolute; top: 18px; left: 50%; transform: translateX(-50%); font-size: .6875rem; color: var(--accent-ink); white-space: nowrap; font-weight: 500; }
.receipt { display: grid; margin: 22px 0 0; font-size: .875rem; }
.receipt div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line-2); }
.receipt span { color: var(--ink-2); }
.receipt strong { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

.repair-steps { counter-reset: repair; display: grid; gap: 8px; margin: 14px 0; padding: 0; list-style: none; }
.repair-steps li { position: relative; padding-left: 30px; font-size: .875rem; color: var(--ink-2); }
.repair-steps li::before {
  counter-increment: repair;
  content: counter(repair);
  position: absolute;
  left: 0;
  top: 1px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  font-family: var(--mono);
  font-size: .6875rem;
  color: var(--ink-2);
}
.approval-gate { padding: 12px 14px; border-radius: var(--radius); background: var(--warn-bg); font-size: .875rem; }
.approval-gate strong { display: block; margin-bottom: 2px; }
.approval-gate p { color: var(--ink-2); }
.verify-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-2); font-size: .9375rem; }
.verify-row:last-of-type { border-bottom: 0; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); padding: 2px; background: var(--surface); }
.segmented button { min-width: 64px; padding: 4px 10px; border: 0; border-radius: 6px; background: transparent; font-size: .8125rem; color: var(--ink-2); }
.segmented button.active { background: var(--ink); color: #fff; font-weight: 600; }
.card.resolved { border-color: #b7d8c2; background: var(--ok-bg); }
.resolved-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; margin-bottom: 10px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 1rem; font-weight: 700; }
.card.resolved p { color: var(--ink-2); font-size: .9375rem; }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.metric { padding: 10px 12px; border: 1px solid #b7d8c2; border-radius: var(--radius); background: var(--surface); }
.metric strong { display: block; font-size: 1.125rem; font-variant-numeric: tabular-nums; }
.metric span { font-size: .75rem; color: var(--ink-3); }

/* Activity */
.tool-pulse {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 20px 0;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--agent-bg);
  font-size: .8125rem;
  color: var(--ink-2);
}
.tool-pulse code { color: var(--agent); font-weight: 600; }
.tool-pulse span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pulse-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--agent); }
.tool-pulse.running .pulse-dot { animation: blink 1s infinite; }
.tool-pulse.error { background: var(--accent-bg); }
.tool-pulse.error .pulse-dot { background: var(--accent); }
.tool-pulse.error code { color: var(--accent-ink); }
.tool-pulse.success .pulse-dot { background: var(--ok); }
@keyframes blink { 50% { opacity: .2; } }
.audit-list { margin: 0; padding: 8px 20px 16px; list-style: none; }
.audit-item { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 12px; align-items: baseline; padding: 10px 0; border-bottom: 1px solid var(--line-2); font-size: .875rem; }
.audit-item:last-child { border-bottom: 0; }
.audit-actor { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
.audit-item.agent .audit-actor { color: var(--agent); }
.audit-item.human .audit-actor { color: var(--accent-ink); }
.audit-copy { color: var(--ink-2); }
.audit-meta { font-family: var(--mono); font-size: .75rem; color: var(--ink-3); white-space: nowrap; }

/* Footer */
.footer { display: flex; justify-content: space-between; gap: 16px; padding: 24px 0 0; font-size: .8125rem; color: var(--ink-3); }
.footer a { color: var(--ink-2); }

/* Dialogs */
.modal {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(28, 29, 26, .18);
}
.modal::backdrop { background: rgba(28, 29, 26, .35); }
.modal-shell { margin: 0; padding: 20px 24px 24px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-header h2 { font-size: 1.125rem; }
.modal-lead { margin: 8px 0 20px; max-width: 62ch; color: var(--ink-2); font-size: .9375rem; }
.tool-manifest { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tool-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: var(--radius); }
.tool-kind { align-self: start; margin-top: 2px; padding: 1px 6px; border-radius: 4px; font-size: .6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tool-kind.read { background: var(--agent-bg); color: var(--agent); }
.tool-kind.write { background: var(--accent-bg); color: var(--accent-ink); }
.tool-row strong { display: block; margin-bottom: 2px; font-family: var(--mono); font-size: .8125rem; font-weight: 600; }
.tool-row p { color: var(--ink-2); font-size: .8125rem; line-height: 1.45; }
.prompt-box { position: relative; margin-top: 16px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--line-2); }
.prompt-box .field-label { margin: 0 0 6px; }
.prompt-box p:not(.field-label) { padding-right: 72px; font-size: .9375rem; }
.prompt-box .button { position: absolute; top: 12px; right: 12px; }
.console-modal { width: min(980px, calc(100vw - 32px)); }
.console-layout { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); gap: 16px; }
.console-layout .field-label:first-child { margin-top: 0; }
#console-tool, #console-args { width: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
#console-tool { height: 36px; padding: 0 10px; }
#console-args { min-height: 240px; margin-bottom: 12px; padding: 10px; font-family: var(--mono); font-size: .8125rem; line-height: 1.5; resize: vertical; }
.console-output-wrap { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.console-output-head { display: flex; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--line-2); font-size: .75rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
#console-output { min-height: 320px; max-height: 460px; margin: 0; padding: 12px; overflow: auto; font-family: var(--mono); font-size: .8125rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 80;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: .875rem;
  box-shadow: 0 8px 24px rgba(28, 29, 26, .2);
}

@media (max-width: 1080px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .side-column { grid-template-columns: 1fr 1fr; align-items: start; }
}

@media (max-width: 860px) {
  .case-header { grid-template-columns: 1fr; align-items: start; gap: 16px; padding-top: 24px; }
  .case-facts { flex-wrap: wrap; }
  .case-facts > div { flex: 1 1 45%; border-left: 0; }
  .side-column { grid-template-columns: 1fr; }
  .steps ol { grid-template-columns: repeat(4, 1fr); row-gap: 10px; }
  .tool-manifest, .console-layout { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .topbar { padding: 0 14px; }
  #open-console { display: none; }
  .status-button { max-width: 160px; }
  #webmcp-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  main { padding-inline: 14px; }
  h1 { font-size: 1.25rem; }
  .case-board { display: block; margin: 2px 0 0; font-size: .875rem; }
  .panel-header, .action-content, .hypotheses, .board-callout, .audit-list { padding-inline: 14px; }
  .board-shell { padding-inline: 10px; }
  .board-legend { display: none; }
  .hypothesis-row { grid-template-columns: minmax(100px, 1fr) minmax(50px, .7fr) 52px; }
  .outcome-grid, .metric-grid { grid-template-columns: 1fr; }
  .audit-item { grid-template-columns: 44px minmax(0, 1fr); }
  .audit-meta { grid-column: 2; }
  .footer { flex-direction: column; gap: 6px; }
  .modal-shell { padding: 16px; }
  .prompt-box p:not(.field-label) { padding-right: 0; margin-bottom: 10px; }
  .prompt-box .button { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
