:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --text: #172033;
  --muted: #647084;
  --line: #dce2e9;
  --line-strong: #c5ced9;
  --accent: #173f73;
  --accent-hover: #102f58;
  --success: #1f6b4f;
  --warning: #8a5a12;
  --danger: #a63c3c;
  --info-bg: #edf4fb;
  --success-bg: #edf7f2;
  --warning-bg: #fff7e8;
  --danger-bg: #fff0f0;
  --sans: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color: var(--text);
  background: var(--bg);
  font-family: var(--sans);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { min-width: 320px; min-height: 100vh; margin: 0; background: var(--bg); line-height: 1.55; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
code, pre { font-family: var(--mono); }

.skip-link { position: fixed; z-index: 10; top: .5rem; left: .5rem; padding: .55rem .75rem; color: white; background: var(--accent); transform: translateY(-160%); }
.skip-link:focus { transform: translateY(0); }

.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 60px; padding: 0 max(1.25rem, calc((100vw - 1180px) / 2)); background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { color: var(--text); font-size: 1rem; font-weight: 650; text-decoration: none; letter-spacing: -.01em; }
.service-state { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .75rem; }
.service-state span { width: .45rem; height: .45rem; border-radius: 50%; background: var(--success); }

.shell { width: min(1180px, calc(100% - 2.5rem)); margin: 0 auto; padding: 3.2rem 0 5rem; }
.intro { margin-bottom: 2.25rem; }
.section-label { margin: 0 0 .45rem; color: var(--accent); font-size: .7rem; font-weight: 650; letter-spacing: .06em; }
.intro h1 { max-width: 820px; margin: 0; font-size: clamp(2rem, 3.3vw, 2.9rem); font-weight: 650; line-height: 1.16; letter-spacing: -.04em; text-wrap: balance; }
.intro > div > p:last-child { max-width: 780px; margin: .95rem 0 0; color: var(--muted); font-size: .96rem; line-height: 1.75; text-wrap: pretty; }

.audit-form { display: grid; gap: 1rem; }
.form-section, .submit-section, .run-section, .report-section, .preflight-banner { background: var(--surface); border: 1px solid var(--line); border-radius: .55rem; }
.form-section { padding: 1.35rem; }
.form-section > header, .report-section > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.15rem; }
.form-section h2, .report-section h3 { margin: 0; font-size: 1rem; font-weight: 650; letter-spacing: -.01em; }
.form-section > header > p { margin: .25rem 0 0; color: var(--muted); font-family: var(--mono); font-size: .68rem; }
.field-help { margin: .85rem 0 0; color: var(--muted); font-size: .72rem; }
.step-heading { display: flex; align-items: flex-start; gap: .8rem; }
.step-index { display: grid; flex: 0 0 auto; place-items: center; width: 1.75rem; height: 1.75rem; color: var(--accent); background: var(--info-bg); border: 1px solid #d6e4f2; border-radius: .35rem; font-family: var(--mono); font-size: .7rem; font-weight: 700; }
.section-intro { display: flex; align-items: center; gap: .8rem; padding: .45rem .15rem 0; }
.section-intro strong { display: block; font-size: .83rem; }
.section-intro p { margin: .15rem 0 0; color: var(--muted); font-size: .68rem; }

.endpoint-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.endpoint-tag { padding: .25rem .5rem; color: var(--accent); background: var(--info-bg); border-radius: .25rem; font-size: .65rem; font-weight: 600; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .95rem; }
.basics-grid { grid-template-columns: 1fr 1fr; max-width: 650px; }
.agent-config-section { position: relative; overflow: hidden; background: #fbfcfe; border-color: #ccd9e8; }
.agent-config-section::before { position: absolute; inset: 0 auto 0 0; width: 3px; content: ""; background: var(--accent); }
.agent-grid { align-items: start; max-width: 790px; }
.optional-divider { display: flex; align-items: center; gap: .8rem; margin: .65rem 0 -.15rem; color: var(--muted); font-size: .65rem; font-weight: 600; letter-spacing: .03em; }
.optional-divider::before, .optional-divider::after { height: 1px; flex: 1; content: ""; background: var(--line-strong); }
.optional-mark { flex: 0 0 auto; margin-top: .05rem; padding: .26rem .48rem; color: var(--accent); background: var(--surface); border: 1px solid #cbd9e8; border-radius: .25rem; font-size: .63rem; font-weight: 650; }
.section-description { max-width: 650px; margin: .35rem 0 0; color: var(--muted); font-size: .72rem; font-weight: 400; line-height: 1.6; }
.agent-guidance { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.agent-guidance p { margin: 0; padding: .75rem .8rem; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: .35rem; font-size: .68rem; }
.agent-guidance strong { color: var(--text); font-weight: 600; }
.custom-agent-fields { display: grid; grid-template-columns: 1fr 1fr; gap: .95rem; padding-top: .95rem; border-top: 1px solid var(--line); }
.custom-agent-fields[hidden] { display: none; }
.field { display: grid; align-content: start; gap: .35rem; }
.field-wide { grid-column: 1 / -1; }
.field > span:first-child { font-size: .73rem; font-weight: 600; }
.field small { color: var(--muted); font-size: .65rem; }
input, select { width: 100%; min-height: 43px; padding: .6rem .7rem; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); border-radius: .35rem; outline: none; transition: border-color .18s ease, box-shadow .18s ease; }
input:hover, select:hover { border-color: #98a5b5; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23, 63, 115, .13); }
.secret-field { position: relative; display: block; }
.secret-field input { padding-right: 3.8rem; font-family: var(--mono); font-size: .74rem; }
.secret-field button { position: absolute; inset: 1px 1px 1px auto; width: 3.3rem; color: var(--muted); background: var(--surface-subtle); border: 0; border-left: 1px solid var(--line); border-radius: 0 .3rem .3rem 0; cursor: pointer; font-size: .67rem; }

.submit-section { display: grid; grid-template-columns: 1fr auto; gap: .8rem 1.5rem; align-items: center; padding: 1.25rem 1.35rem; }
.submit-section strong { font-size: .78rem; }
.submit-section p { margin: .25rem 0 0; color: var(--muted); font-size: .68rem; }
.primary-button { min-height: 44px; padding: .65rem 1.2rem; color: white; background: var(--accent); border: 1px solid var(--accent); border-radius: .35rem; cursor: pointer; font-weight: 600; transition: background .18s ease, transform .18s ease; }
.primary-button:hover { background: var(--accent-hover); }
.primary-button:active { transform: translateY(1px); }
.primary-button:disabled { opacity: .55; cursor: wait; }
.form-error { grid-column: 1 / -1; min-height: 0; margin: 0 !important; color: var(--danger) !important; }

.run-section { margin-top: 1.2rem; padding: 1.35rem; }
.run-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.run-heading h2 { margin: 0; font-size: 1rem; }
#progress-percent { color: var(--accent); font-family: var(--mono); font-size: 1rem; }
.run-section progress { width: 100%; height: .45rem; margin-top: 1rem; border: 0; border-radius: 1rem; appearance: none; overflow: hidden; background: var(--line); }
.run-section progress::-webkit-progress-bar { background: var(--line); }
.run-section progress::-webkit-progress-value { background: var(--accent); }
.run-section progress::-moz-progress-bar { background: var(--accent); }
.run-meta { display: flex; align-items: center; justify-content: space-between; margin-top: .55rem; color: var(--muted); font-family: var(--mono); font-size: .67rem; }
.run-meta button { padding: 0; color: var(--danger); background: none; border: 0; cursor: pointer; font-family: var(--sans); font-size: .7rem; }

.result-section { padding-top: 2.5rem; }
.report-heading { display: flex; align-items: end; justify-content: space-between; gap: 1.5rem; margin-bottom: 1rem; }
.report-heading h2 { margin: 0; font-size: clamp(1.65rem, 3vw, 2.25rem); letter-spacing: -.03em; }
.report-heading > div > p:last-child { max-width: 720px; margin: .55rem 0 0; color: var(--muted); font-size: .8rem; }
.report-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .45rem; }
.report-actions button, .report-actions a { padding: .48rem .65rem; color: var(--accent); background: var(--surface); border: 1px solid var(--line-strong); border-radius: .3rem; cursor: pointer; font-size: .68rem; text-decoration: none; white-space: nowrap; }
.report-actions button:hover, .report-actions a:hover { border-color: var(--accent); }
.report-actions button:disabled { opacity: .55; cursor: wait; }
.preflight-banner { margin-bottom: 1rem; padding: 1rem 1.15rem; border-left: 3px solid var(--success); }
.preflight-banner.fail { border-left-color: var(--danger); }
.preflight-banner strong { display: block; font-size: .82rem; }
.preflight-banner p { margin: .3rem 0 0; color: var(--muted); font-size: .72rem; }

.report-section { margin-top: 1rem; padding: 1.25rem; }
.report-section > header { padding-bottom: .85rem; border-bottom: 1px solid var(--line); }
.report-section > header p { max-width: 560px; margin: 0; color: var(--muted); font-size: .68rem; text-align: right; }
.report-two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.verdict-line { display: flex; align-items: baseline; flex-wrap: wrap; gap: .55rem; }
.verdict-line strong { font-size: 1.25rem; }
.verdict-line span { color: var(--muted); font-size: .68rem; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .65rem; margin: 1rem 0 0; }
.metrics div { padding: .75rem; background: var(--surface-subtle); border-radius: .35rem; }
.metrics dt { color: var(--muted); font-size: .63rem; }
.metrics dd { margin: .15rem 0 0; font-family: var(--mono); font-size: .76rem; font-weight: 650; overflow-wrap: anywhere; }
.comparison-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin-top: .9rem; }
.comparison-box { padding: .85rem; background: var(--surface-subtle); border-radius: .35rem; }
.comparison-box strong { display: block; font-size: .7rem; }
.comparison-box p { margin: .25rem 0 0; color: var(--muted); font-family: var(--mono); font-size: .68rem; }
.note { margin: .85rem 0 0; color: var(--muted); font-size: .68rem; }
.reason-list { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .75rem; }
.reason-list span, .status { display: inline-block; padding: .2rem .4rem; border-radius: .25rem; font-size: .62rem; }
.reason-list span { color: var(--muted); background: var(--surface-subtle); }
.status.normal, .status.basic { color: var(--success); background: var(--success-bg); }
.status.partial, .status.unknown { color: var(--warning); background: var(--warning-bg); }
.status.bad { color: var(--danger); background: var(--danger-bg); }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .68rem; }
th, td { padding: .65rem .55rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .61rem; font-weight: 600; white-space: nowrap; }
td:first-child { font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
.protocol-tag { display: block; margin-bottom: .15rem; color: var(--muted); font-family: var(--mono); font-size: .56rem; font-weight: 400; }
details { margin-top: .85rem; border-top: 1px solid var(--line); }
summary { padding-top: .7rem; color: var(--muted); cursor: pointer; font-size: .65rem; }
pre { max-height: 300px; overflow: auto; margin: .65rem 0 0; padding: .8rem; color: #dbe4ef; background: #172033; border-radius: .35rem; font-size: .59rem; white-space: pre-wrap; word-break: break-word; }
.empty-state { padding: .9rem; color: var(--muted); background: var(--surface-subtle); border: 1px dashed var(--line-strong); border-radius: .35rem; font-size: .72rem; }
.analysis-section { margin-bottom: 0; }

footer { padding: 1.2rem; color: var(--muted); background: var(--surface); border-top: 1px solid var(--line); text-align: center; font-size: .65rem; }

@media (max-width: 900px) {
  .endpoint-grid, .report-two-column { grid-template-columns: 1fr; }
}

@media (max-width: 650px) {
  .topbar { padding: 0 1rem; }
  .service-state { font-size: .65rem; }
  .shell { width: min(100% - 1.4rem, 1180px); padding-top: 2rem; }
  .field-grid, .basics-grid, .metrics, .comparison-grid, .agent-guidance { grid-template-columns: 1fr; }
  .form-basics > header, .agent-config-section > header { align-items: flex-start; flex-direction: column; }
  .agent-config-section .endpoint-tag { margin-left: 2.55rem; }
  .field-wide { grid-column: auto; }
  .submit-section { grid-template-columns: 1fr; }
  .primary-button { width: 100%; }
  .report-heading { align-items: flex-start; flex-direction: column; }
  .report-actions { justify-content: flex-start; }
  .report-section > header { align-items: flex-start; flex-direction: column; }
  .report-section > header p { text-align: left; }
  .parameter-section table, .parameter-section thead, .parameter-section tbody, .parameter-section tr, .parameter-section td { display: block; width: 100%; }
}

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