:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #fafbfc;
  --line: #e7e9ee;
  --line-soft: #eff1f4;
  --field-line: #dfe2e8;
  --ink: #2a2f3a;
  --ink-2: #4a5160;
  --muted: #6b7280;
  --faint: #8a90a0;
  --accent: #5563b0;
  --accent-deep: #46529a;
  --accent-soft: #eef0f9;
  --accent-ink: #4a57a0;
  --pass: #2f7a55;
  --pass-soft: #e8f3ed;
  --fail: #a8453f;
  --fail-soft: #f9ecea;
  --warn: #80591b;
  --warn-soft: #f7f0e2;
  --neutral-soft: #f1f2f5;
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-deep); text-decoration: underline; text-underline-offset: 0.2em; }
:focus-visible { outline: 2px solid #8e99d6; outline-offset: 2px; }
code { font-family: var(--mono); font-size: 12px; padding: 2px 6px; border-radius: 4px; background: var(--neutral-soft); }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link {
  position: absolute; left: 1rem; top: -4rem; z-index: 10;
  padding: 0.5rem 0.8rem; border-radius: var(--radius-sm);
  background: var(--ink); color: #fff;
}
.skip-link:focus { top: 0.5rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  min-height: 48px;
  padding: 0 clamp(12px, 3vw, 32px);
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 600; letter-spacing: -0.01em; }
.brand:hover { color: var(--ink); text-decoration: none; }
.brand-mark { display: block; width: 28px; height: 28px; }
.project-badge {
  padding: 1px 6px; border-radius: 4px;
  background: var(--accent-soft); color: var(--accent);
  font-family: var(--mono); font-size: 11px;
}
.topbar-divider { width: 1px; height: 18px; background: var(--line); }
.topnav { display: flex; gap: 2px; margin-right: auto; }
.topnav a {
  display: inline-flex; align-items: center; height: 30px; padding: 0 10px;
  border-radius: 6px; color: var(--ink-2); font-size: 13px; font-weight: 500;
}
.topnav a:hover { background: #f3f4f7; color: var(--ink); text-decoration: none; }
.topnav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }
.session { display: flex; align-items: center; gap: 12px; margin-left: auto; font-size: 13px; }
.topnav + .session { margin-left: 0; }
.session-email { color: var(--muted); }
.session form { margin: 0; }

/* Page */
.page {
  display: flex; flex-direction: column; gap: 12px;
  padding: clamp(16px, 3vw, 32px);
  min-width: 0;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
h1 { font-size: 22px; letter-spacing: -0.015em; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
h4 { font-size: 13px; }
p { margin: 0; }

.lede { color: var(--ink-2); font-size: 15px; text-wrap: pretty; max-width: 40rem; }
.hint, .quiet { color: var(--muted); }
.hint { text-wrap: pretty; }
.kicker { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* Buttons */
.button, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff;
  font: inherit; font-weight: 500; white-space: nowrap;
  cursor: pointer;
}
.button:hover, button:hover { background: var(--accent-deep); color: #fff; text-decoration: none; }
.button-secondary, button.button-secondary {
  background: var(--surface); color: var(--ink); border-color: var(--field-line);
}
.button-secondary:hover, button.button-secondary:hover { background: var(--bg); color: var(--ink); }
.button-small { height: 30px; padding: 0 12px; font-size: 13px; }
.button-block { width: 100%; height: 40px; }
.link-button, button.link-button {
  height: auto; padding: 0; border: 0; background: none;
  color: var(--ink-2); font-size: inherit; font-weight: 400;
}
.link-button:hover, button.link-button:hover { background: none; color: var(--ink); }
button.link-accent { color: var(--accent); }
button.link-accent:hover { color: var(--accent-deep); text-decoration: underline; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions form { margin: 0; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 16px; margin: 0; }
label, .field {
  display: flex; flex-direction: column; gap: 6px;
  color: var(--ink-2); font-size: 13px; font-weight: 500;
}
.optional { font-weight: 400; color: var(--faint); }
input, select, textarea {
  width: 100%; min-height: 38px; padding: 0 12px;
  border: 1px solid var(--field-line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 400;
}
input:focus, select:focus, textarea:focus { border-color: #a9b1e0; outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { padding: 10px 12px; min-height: 8rem; resize: vertical; font-family: var(--mono); font-size: 13px; line-height: 1.6; }
input[readonly] { background: var(--surface-soft); font-family: var(--mono); font-size: 12px; }
.code-input { height: 48px; font-family: var(--mono); font-size: 20px; letter-spacing: 0.4em; text-align: center; }
.field-narrow { max-width: 240px; }

/* Banners */
.banner { margin: 0; padding: 10px 14px; border-radius: var(--radius-sm); text-wrap: pretty; }
.banner-danger { background: var(--fail-soft); color: #9a3f3a; }
.banner-warn { background: var(--warn-soft); color: var(--warn); }
.banner-info { background: var(--accent-soft); color: #3f4a8a; }

/* Pills and tags */
.pill, .tag {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 1.4; white-space: nowrap;
  background: var(--neutral-soft); color: var(--ink-2);
}
.tag { background: var(--surface); border: 1px solid var(--line); font-weight: 400; }
.pill-muted { background: var(--surface); color: var(--muted); border: 1px dashed #cfd3da; }
.pill-accent { background: var(--accent-soft); color: var(--accent-ink); }
.pill[data-status="passed" i] { background: var(--pass-soft); color: var(--pass); }
.pill[data-status="failed" i] { background: var(--fail-soft); color: var(--fail); }
.pill[data-status="blocked" i] { background: #f7efdf; color: #8a6320; }
.pill[data-status="skipped" i], .pill[data-status="invalid" i] { background: #eef0f3; color: #5f6b7a; }
.pill[data-status="retest" i], .pill[data-status="in_progress" i] { background: var(--accent-soft); color: var(--accent-ink); }

.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; color: var(--muted); font-size: 13px; }
.links { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }
.cache-state { display: inline-flex; align-items: center; gap: 6px; }
.cache-state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #b6bbc6; }
.cache-state[data-state="fresh"]::before { background: #86bea0; }

/* Centered pages: home, sign in, error */
.center-page {
  width: min(560px, 100%); margin: 8vh auto 0;
  display: flex; flex-direction: column; gap: 14px;
}
.center-page.text-center { align-items: center; text-align: center; }
.center-page h1 { font-size: 26px; letter-spacing: -0.02em; }

.auth {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 20px;
  padding: 6vh 0 24px;
}
.auth-card {
  width: min(400px, 100%);
  display: flex; flex-direction: column; gap: 20px;
  padding: 32px;
  box-shadow: 0 1px 2px rgba(20, 24, 40, 0.04);
}
.auth-head { display: flex; flex-direction: column; gap: 6px; }
.auth-head h1 { font-size: 20px; }
.auth-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; font-size: 13px; }
.auth-foot form { margin: 0; }
.auth-note { color: var(--muted); font-size: 12px; }

/* Link builder */
.composer { width: min(680px, 100%); display: flex; flex-direction: column; gap: 20px; }
.composer-head { display: flex; flex-direction: column; gap: 6px; }
.guide { width: min(44rem, calc(100% - 32px)); max-height: calc(100vh - 48px); overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; background: var(--surface); color: var(--ink); }
.guide::backdrop { background: rgba(20, 24, 40, 0.35); }
.guide form { display: flex; flex-direction: column; gap: 16px; margin: 0; }
.guide h2 { font-size: 18px; }
.guide-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.guide-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 0 8px 6px 0; }
.guide-table td { padding: 7px 12px 7px 0; border-top: 1px solid var(--line-soft); vertical-align: top; }
.guide-table td:first-child { white-space: nowrap; width: 6rem; }
.guide-examples { display: flex; flex-direction: column; gap: 8px; }
.guide-examples code { display: block; padding: 8px 10px; border-radius: 8px; background: var(--surface-soft); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; }
.composer .card { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.built-row { display: flex; flex-wrap: wrap; gap: 8px; }
.built-row input { flex: 1 1 280px; min-width: 0; }
.inject-row { display: grid; grid-template-columns: minmax(140px, 1fr) 150px minmax(180px, 1.4fr) auto; gap: 12px; align-items: end; }

/* Report */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px 16px; }
.page-head h1 { font-size: 18px; }
.page-head-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.crumbs { display: flex; gap: 6px; color: var(--muted); font-size: 13px; }
.crumbs span[aria-hidden] { color: #b6bbc6; }
.title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }

.run-summary { padding: 12px 14px; display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px 16px; }
.run-summary h2 { font-size: 15px; }
.run-summary-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tag-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.workspace { display: flex; align-items: flex-start; gap: 12px; }
.case-rail, .case-panel { min-width: 0; display: flex; flex-direction: column; }
.case-rail { flex: 0 0 auto; }
.workspace.is-list-open .case-rail { flex: 1 1 320px; }
.workspace.is-detail-open .case-panel { flex: 1.5 1 440px; }
.case-panel { flex: 0 0 auto; }
.case-list { overflow: hidden; }
.case-panel-body { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; padding: 4px 6px 4px 12px; }
.case-rail > .pane-head { border-bottom: 1px solid var(--line-soft); }
.case-panel > .pane-head { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.workspace.is-detail-open .case-panel > .pane-head { margin-bottom: 8px; }
.pane-title { font-weight: 600; white-space: nowrap; }
.pane-toggle {
  width: 28px; height: 28px; padding: 0; flex: none;
  border: 1px solid var(--field-line); border-radius: 6px;
  background: var(--surface); color: var(--ink-2);
}
.pane-toggle:hover { background: var(--bg); color: var(--ink); }
.pane-toggle .chevron { width: 16px; height: 16px; }
.case-rail .pane-toggle[aria-expanded="false"] .chevron,
.case-panel .pane-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.list-tools { padding: 12px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line-soft); }
.list-tools input { height: 36px; min-height: 0; }
.list-tools-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.status-chip, button.status-chip {
  height: 28px; padding: 0 10px; border-radius: 999px;
  border: 1px solid #e1e4ea; background: var(--surface); color: var(--ink-2);
  font-size: 12px; font-weight: 500; text-transform: capitalize;
}
.status-chip:hover, button.status-chip:hover { background: var(--bg); color: var(--ink); }
.status-chip[aria-pressed="true"], button.status-chip[aria-pressed="true"] { background: #2f3444; border-color: #2f3444; color: #fff; }
#filter-count { margin-left: auto; font-size: 12px; }

.list-group {
  padding: 10px 16px 6px; border-bottom: 1px solid var(--line-soft);
  background: var(--surface-soft); color: var(--muted); font-size: 12px; font-weight: 500;
}
.case-row {
  display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid #f1f2f5;
  color: inherit;
}
.case-row:hover { background: #f7f8fb; color: inherit; text-decoration: none; }
.case-row[aria-current="true"] { background: #f3f4fb; }
.case-row-id { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.case-row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.case-row-status { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.list-empty { padding: 32px 16px; text-align: center; color: var(--muted); }

/* Case detail */
.case-detail { scroll-margin-top: 64px; }
.case-detail:focus { outline: none; }
.case-head { padding: 14px 16px 0; display: flex; flex-direction: column; gap: 8px; }
.case-head h2 { font-size: 18px; text-wrap: pretty; }
.case-head:last-child { padding-bottom: 4px; }
.tabs { display: flex; gap: 20px; margin-top: 6px; border-bottom: 1px solid var(--line-soft); }
.tabs button {
  height: auto; padding: 8px 0 10px; margin-bottom: -1px;
  border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  background: none; color: var(--muted); font-weight: 500;
}
.tabs button:hover { background: none; color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.case-section { padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 18px; }
.case-section + .case-section { border-top: 1px solid var(--line-soft); }
.rich { color: #3a404c; text-wrap: pretty; overflow-wrap: anywhere; }
.rich p { margin: 0 0 0.5em; }
.rich p:last-child { margin-bottom: 0; }
.conditions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 12px; }
.box { padding: 12px 14px; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); background: var(--surface-soft); }
.field-label { margin-bottom: 2px; color: var(--muted); font-size: 12px; font-weight: 500; }
.none { color: #b6bbc6; }
.section-title { display: flex; align-items: baseline; gap: 8px; }

/* Steps */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps .steps { padding-left: 28px; }
.step { counter-increment: step; }
.step-row { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.step-num {
  flex: none; min-width: 26px; height: 24px; padding: 0 6px;
  display: grid; place-items: center; border-radius: 6px;
  background: var(--neutral-soft); color: var(--ink-2);
  font-family: var(--mono); font-size: 12px;
}
.step-num::before { content: counters(step, "."); }
.step-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.step-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 8px 18px; }
.step-outcome { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-soft); border: 1px solid var(--line-soft); }

/* Results */
.attempt { padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; gap: 10px; }
.attempt-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.attempt-head .links { margin-left: auto; }
.hash { font-family: var(--mono); font-size: 12px; color: var(--faint); }
.outcomes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.outcome { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line-soft); font-size: 13px; }
.outcome-head { display: flex; align-items: center; gap: 8px; }
.outcome-pos { font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--ink); }
.outcome-guide { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 8px 16px; width: 100%; padding: 8px 10px; border-radius: 8px; background: var(--surface-soft); }
.outcome-guide .rich { color: var(--ink-2); }
.outcome-recorded { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.empty-box { padding: 28px 16px; border: 1px dashed var(--field-line); border-radius: var(--radius-sm); text-align: center; color: var(--muted); }

/* Evidence */
.evidence { display: flex; flex-wrap: wrap; gap: 10px; }
.evidence a { display: flex; flex-direction: column; gap: 4px; max-width: 200px; color: var(--ink-2); font-size: 12px; overflow-wrap: anywhere; }
.evidence img { width: 200px; height: 124px; object-fit: cover; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.evidence .file { padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-soft); }

@media (min-width: 960px) {
  .workspace.is-detail-open .case-panel-body { position: sticky; top: 68px; max-height: calc(100vh - 120px); overflow: auto; }
}

@media (max-width: 800px) {
  .workspace { flex-direction: column; }
  .workspace.is-list-open .case-rail,
  .workspace.is-detail-open .case-panel { flex-basis: auto; width: 100%; }
}

@media (max-width: 640px) {
  .session-email { display: none; }
  .auth-card { padding: 24px 20px; }
  .page-head .actions { width: 100%; }
  .inject-row { grid-template-columns: 1fr; }
}
