:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --border: #e4e9f1;
  --border-strong: #d3dae6;
  --text: #1d2433;
  --text-muted: #5a6478;
  --text-faint: #8a93a6;
  --accent: #0e8a8a;
  --accent-soft: #e6f4f4;
  --accent-strong: #0a6e6e;
  --warn: #b8860b;
  --warn-soft: #fef6e1;
  --ok: #2f9e6c;
  --danger: #c0392b;
  --shadow-sm: 0 1px 2px rgba(20, 30, 50, 0.04);
  --shadow-md: 0 4px 14px rgba(20, 30, 50, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }
h3 { font-size: 14px; color: var(--text); }

.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  display: grid; place-items: center;
}
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: 0.01em; }
.brand-sub { font-size: 12px; color: var(--text-muted); }
.topbar-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-muted);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(47,158,108,0.12); }
.dot-warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(184,134,11,0.12); }
.dot-err { background: var(--danger); box-shadow: 0 0 0 3px rgba(192,57,43,0.12); }

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 60px;
  display: grid;
  gap: 24px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.hint { font-size: 12px; color: var(--text-faint); }

.cases-note {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 12px;
  line-height: 1.5;
}

.case-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.case-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 880px) {
  .case-grid { grid-template-columns: repeat(2, 1fr); }
  .case-grid-3 { grid-template-columns: 1fr; }
}
.hint code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-muted);
}

.case {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: left;
  cursor: pointer;
  position: relative;
  transition: border-color 120ms, box-shadow 120ms, transform 120ms;
  font: inherit; color: inherit;
  display: flex; flex-direction: column; gap: 6px;
}
.case:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.case.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14,138,138,0.10);
}
.case .case-num {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  color: var(--text-muted); text-transform: uppercase;
}
.case .case-title { font-weight: 600; font-size: 14px; }
.case .case-desc { font-size: 12px; color: var(--text-muted); }

.case.locked {
  background: var(--surface-2);
  cursor: not-allowed;
  color: var(--text-faint);
}
.case.locked:hover { transform: none; box-shadow: none; border-color: var(--border); }
.case.locked .case-title { color: var(--text-muted); }
.case .lock-badge {
  position: absolute;
  top: 10px; right: 10px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  color: var(--text-faint);
}
.case .soon {
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-top: auto;
  text-transform: uppercase;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "input output"
    "action output";
  gap: 16px;
}
.panel-input { grid-area: input; }
.panel-action { grid-area: action; }
.panel-output { grid-area: output; }
@media (max-width: 880px) {
  .workspace { grid-template-columns: 1fr; grid-template-areas: "input" "action" "output"; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.tag {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.tag-muted { background: var(--surface-2); color: var(--text-muted); }
.tag-ok { background: rgba(47,158,108,0.10); color: var(--ok); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-err { background: rgba(192,57,43,0.08); color: var(--danger); }

.json {
  margin: 0;
  padding: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--surface);
  white-space: pre;
  overflow: auto;
  border-radius: 0 0 var(--radius) var(--radius);
  tab-size: 2;
}
.json .k { color: #2c5282; }
.json .s { color: #2f855a; }
.json .n { color: #b7791f; }
.json .b { color: #6b46c1; }
.json .p { color: var(--text-faint); }
.json-edit { min-height: 380px; }

.j-input {
  font: inherit;
  background: transparent;
  border: 0;
  margin: 0;
  padding: 0 3px;
  border-radius: 3px;
  outline: none;
  cursor: text;
  field-sizing: content;
  min-width: 1ch;
  vertical-align: baseline;
  line-height: inherit;
  transition: background 100ms, box-shadow 100ms;
}
.j-input:hover { background: var(--surface-2); }
.j-input:focus { background: var(--accent-soft); box-shadow: 0 0 0 1px rgba(14,138,138,0.45); }
.j-input.invalid {
  background: rgba(192,57,43,0.08);
  box-shadow: 0 0 0 1px rgba(192,57,43,0.40);
  color: var(--danger);
}
.j-num { color: #b7791f; }
.j-str { color: #2f855a; }
.j-bool {
  color: #6b46c1;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.j-enum {
  color: #2f855a;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 14px;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 8px) 55%,
    calc(100% - 5px) 55%;
  background-size: 3px 3px, 3px 3px;
  background-repeat: no-repeat;
}

.panel-head-actions { display: flex; align-items: center; gap: 8px; }
.preset-select {
  font: inherit;
  font-size: 12px;
  padding: 4px 8px;
  background: var(--surface-2, #fff);
  color: var(--text, inherit);
  border: 1px solid var(--border, #d0d0d0);
  border-radius: 6px;
  cursor: pointer;
  max-width: 280px;
}
.preset-select:hover { border-color: var(--border-strong, #b0b0b0); }
.preset-select:focus { outline: 2px solid var(--accent, #4a90e2); outline-offset: 1px; }
.btn-ghost {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:active { transform: translateY(1px); }

.panel-action {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms, transform 60ms;
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { background: var(--text-faint); border-color: var(--text-faint); cursor: not-allowed; }
.btn-primary.loading svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.run-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex; gap: 12px; flex-wrap: wrap;
}
.run-meta b { color: var(--text); font-weight: 600; }

.guardrails-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
  margin-left: 14px;
  cursor: pointer;
  user-select: none;
}
.guardrails-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.guardrails-toggle .switch {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background 120ms;
  flex-shrink: 0;
}
.guardrails-toggle .switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 120ms;
}
.guardrails-toggle input:checked + .switch { background: var(--accent); }
.guardrails-toggle input:checked + .switch::after { transform: translateX(16px); }
.guardrails-toggle input:focus-visible + .switch { box-shadow: 0 0 0 3px var(--accent-soft); }
.guardrails-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }

.stage-track {
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stage-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 3px 0;
}
.stage-item .stage-ic {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}
.stage-item.done .stage-ic { background: var(--accent-soft); color: var(--accent-strong); }
.stage-item.running .stage-ic { color: var(--accent); }
.stage-item.done.g-guard .stage-ic { background: var(--warn-soft); color: var(--warn); }
.stage-item.running .stage-name { color: var(--text); font-weight: 600; }
.stage-name { flex-shrink: 0; }
.stage-meta {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-faint);
}
.stage-meta.ok { color: var(--ok); border-color: rgba(47,158,108,0.3); }
.stage-meta.warn { color: var(--warn); border-color: rgba(184,134,11,0.35); background: var(--warn-soft); }
.stage-ms {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
  font-size: 12px;
}
.stage-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--border-strong);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.stage-total .stage-ms { color: var(--text); }
svg.spin { animation: spin 0.9s linear infinite; }

.output-body { padding: 16px; }
.empty {
  text-align: center;
  color: var(--text-faint);
  padding: 28px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  font-size: 13px;
}
.empty-icon {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid; place-items: center;
  color: var(--text-faint);
}

.field {
  padding: 14px 0;
  border-bottom: 1px dashed var(--border);
}
.field:last-child { border-bottom: 0; padding-bottom: 0; }
.field:first-child { padding-top: 0; }
.field-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px;
}
.field-label .swatch {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
}
.field-label .swatch.q { background: var(--warn); }
.field-label .swatch.p { background: #6b46c1; }
.field-label .swatch.s { background: var(--ok); }
.field-text { font-size: 13.5px; color: var(--text); }
.field-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  line-height: 1.45;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}
.field-desc code,
.output-note code,
.footbar code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text);
}

.uc-tag {
  margin-left: 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  white-space: nowrap;
}
.uc-tag.uc-1 { background: var(--accent-soft); color: var(--accent-strong); }
.uc-tag.uc-3 { background: rgba(107,70,193,0.10); color: #6b46c1; }
.uc-tag.uc-soft { background: var(--surface-2); color: var(--text-muted); }

.output-note {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
  line-height: 1.5;
}

.confidence {
  display: flex; align-items: center; gap: 10px;
  margin-top: 4px;
}
.bar {
  flex: 1; height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar > span {
  display: block; height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 240ms ease;
}
.confidence-val {
  font-variant-numeric: tabular-nums;
  font-size: 12px; color: var(--text-muted);
}

.error-box {
  background: rgba(192,57,43,0.05);
  border: 1px solid rgba(192,57,43,0.20);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
}

.footbar {
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  padding: 24px 0 32px;
}
.footbar .sep { margin: 0 8px; opacity: 0.6; }

/* ---- UC2 — Pattern Intelligence -------------------------------------- */

.uc-tag.uc-2 { background: rgba(184,134,11,0.10); color: var(--warn); }

.pattern-list {
  display: flex; flex-direction: column; gap: 14px;
}
.pattern-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  background: var(--surface);
}
.pattern-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.pattern-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.pattern-pill {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  text-transform: uppercase;
}
.pattern-pill.severity-marked {
  background: rgba(192,57,43,0.10);
  color: var(--danger);
}
.pattern-pill.severity-borderline {
  background: var(--warn-soft);
  color: var(--warn);
}
.pattern-pill.side {
  background: var(--accent-soft);
  color: var(--accent-strong);
  text-transform: none;
  letter-spacing: 0;
}
.pattern-rationale {
  font-size: 12px;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 6px 8px;
  margin-bottom: 10px;
  word-break: break-word;
}
.pattern-note {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 8px;
}
.pattern-checks {
  font-size: 12.5px;
  color: var(--text);
  border-left: 2px solid var(--accent);
  padding-left: 10px;
  background: var(--accent-soft);
  border-radius: 0 4px 4px 0;
  padding: 8px 10px;
}
.pattern-checks-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent-strong);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.uc2-summary {
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  margin-bottom: 14px;
}

.uc2-quality-block {
  font-size: 13px;
  color: var(--warn);
  background: var(--warn-soft);
  border: 1px solid rgba(184,134,11,0.20);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.pattern-pill.in-range {
  background: rgba(47,158,108,0.10);
  color: var(--ok);
  text-transform: none;
  letter-spacing: 0;
}

.uc2-no-patterns {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.uc2-no-patterns-head {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ok);
}
.uc2-no-patterns-head .check-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(47,158,108,0.10);
}
.uc2-no-patterns-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.uc2-no-patterns-sub {
  font-size: 12.5px;
  color: var(--text-muted);
}
.uc2-checklist {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.checklist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text);
  padding: 2px 0;
}
.checklist-name {
  font-weight: 500;
}
