:root {
  --canvas: #fafafc;
  --surface: #ffffff;
  --surface-subtle: #f5f5f8;
  --ink: #1c1b24;
  --ink-secondary: #555360;
  --ink-muted: #6b6976;
  --line: #e4e3e9;
  --line-strong: #c8c6d0;
  --brand: #5a4a91;
  --brand-tint: #f0eef7;
  --chart-blue: #4e79a7;
  --chart-orange: #e88928;
  --success: #2e7255;
  --warning: #98600f;
  --error: #a13f49;
  --info: #3f688a;
  --shadow: 0 8px 24px rgba(28, 27, 36, 0.08);
  --radius-control: 6px;
  --radius-panel: 8px;
  --focus: 3px solid var(--brand);
}

* { box-sizing: border-box; }

html { background: var(--canvas); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Geist, Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

button:disabled, input:disabled, select:disabled, textarea:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

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

[hidden] { display: none !important; }

.skip-link {
  position: absolute;
  left: 16px;
  top: -60px;
  z-index: 100;
  background: var(--ink);
  color: var(--surface);
  padding: 10px 14px;
  border-radius: var(--radius-control);
  text-decoration: none;
}
.skip-link:focus { top: 12px; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px; }
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: white;
  font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; }
.brand-text small { color: var(--ink-muted); font-size: 12px; }

.rail-nav { display: flex; flex-direction: column; gap: 4px; }
.rail-link {
  min-height: 44px;
  padding: 10px 12px;
  text-align: left;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink-secondary);
  font-weight: 500;
}
.rail-link:hover { background: var(--surface-subtle); color: var(--ink); }
.rail-link[aria-current="page"] { background: var(--brand-tint); color: var(--brand); font-weight: 600; }

.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.rail-foot p { margin: 0; color: var(--ink-muted); font-size: 12px; }

.workspace { min-width: 0; }
.topbar {
  min-height: 72px;
  padding: 14px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.topbar-title { min-width: 0; }
.crumb { margin: 0 0 2px; color: var(--ink-muted); font-size: 12px; font-weight: 500; }
h1 { margin: 0; font-size: 22px; line-height: 1.25; font-weight: 600; }
.topbar-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.scope-chip {
  max-width: 360px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-secondary);
  background: var(--surface-subtle);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

main { padding: 32px; max-width: 1360px; margin: 0 auto; }
.screen { display: flex; flex-direction: column; gap: 24px; }
.screen-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.screen-heading p { margin: 6px 0 0; color: var(--ink-secondary); max-width: 70ch; }
.eyebrow { margin: 0 0 4px; color: var(--brand); font-size: 12px; font-weight: 600; letter-spacing: 0.02em; }
h2 { margin: 0; font-size: 28px; line-height: 1.28; font-weight: 600; }
h3 { margin: 0 0 8px; font-size: 15px; line-height: 1.4; font-weight: 600; }
.lede { font-size: 16px; line-height: 1.6; max-width: 65ch; }

.hero-panel {
  max-width: 760px;
  margin: 6vh auto 0;
  padding: 40px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
}
.hero-panel h2 { font-size: 30px; }
.hero-panel .button { margin-top: 20px; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.segmented { display: flex; gap: 8px; flex-wrap: wrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
tr.selected-row { background: #f0ecf8; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--ink-muted); margin: 0; }
.hint { color: var(--ink-muted); font-size: 12px; margin: 8px 0 0; }
small { color: var(--ink-muted); font-size: 12px; }

.panel {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
}
.panel-muted { background: var(--surface-subtle); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-local { background: var(--surface-subtle); color: var(--ink-secondary); border: 1px solid var(--line); }
.badge-synthetic { background: var(--brand-tint); color: var(--brand); }
.badge-blocked { background: #fff4e5; color: var(--warning); }
.badge-success { background: #eaf5ef; color: var(--success); }
.badge-warning { background: #fff4e5; color: var(--warning); }
.badge-error { background: #f8eaec; color: var(--error); }
.badge-info { background: #eaf1f7; color: var(--info); }

.notice {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border-left: 4px solid var(--line-strong);
  background: var(--surface-subtle);
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
  color: var(--ink-secondary);
}
.notice strong { color: var(--ink); }
.notice-warning { border-left-color: var(--warning); background: #fff8ee; }
.notice-info { border-left-color: var(--info); background: #f0f6fa; }
.notice-error { border-left-color: var(--error); background: #fbf0f1; }

.button {
  min-width: 44px;
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.button:hover { background: var(--surface-subtle); }
.button-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
}
.button-primary:hover { background: #4b3d7a; border-color: #4b3d7a; }
.button-small { min-height: 44px; padding: 6px 10px; font-size: 12px; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.button-row-compact { margin-top: 0; }
.button-danger { color: var(--error); border-color: #d9b5ba; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--ink-secondary); }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
input[type="text"], input[type="url"], input[type="file"], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
}
textarea { resize: vertical; }
input[type="file"] { padding: 8px; background: var(--surface-subtle); }

.fieldset { margin: 20px 0 0; padding: 16px 0 0; border: 0; border-top: 1px solid var(--line); }
.fieldset legend { padding: 0 8px 0 0; font-weight: 600; }
.check-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.check-item {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
}
.check-item input { width: 18px; height: 18px; accent-color: var(--brand); }
.check-item.checked { background: var(--brand-tint); border-color: #cfc6e8; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--ink-secondary); font-size: 12px; font-weight: 600; background: var(--surface-subtle); }
tbody tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-panel); }
.table-wrap table { min-width: 640px; }

.plain-list { margin: 8px 0 12px; padding-left: 18px; color: var(--ink-secondary); }
.plain-list li + li { margin-top: 6px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.kpi-card {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-label { color: var(--ink-secondary); font-size: 12px; font-weight: 600; }
.kpi-value { font-size: 30px; line-height: 1.2; font-weight: 600; }
.kpi-meta { color: var(--ink-muted); font-size: 12px; }

.chart { min-height: 220px; display: flex; align-items: flex-end; gap: 14px; padding: 18px 8px 0; border-bottom: 1px solid var(--line-strong); }
.chart-bar-group { flex: 1; min-width: 44px; display: flex; flex-direction: column; align-items: center; gap: 6px; justify-content: flex-end; height: 190px; }
.chart-bar { width: 100%; max-width: 64px; background: var(--chart-blue); border-radius: 4px 4px 0 0; }
.chart-bar.secondary { background: var(--chart-orange); }
.chart-label { font-size: 11px; color: var(--ink-secondary); text-align: center; word-break: break-word; }
.chart-value { font-size: 11px; font-weight: 600; color: var(--ink); }

.progress-track { height: 8px; border-radius: 999px; background: var(--surface-subtle); overflow: hidden; }
.progress-fill { height: 100%; background: var(--brand); border-radius: inherit; width: 35%; }

.source-type-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.source-type-row:last-of-type { border-bottom: 0; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: var(--radius-control);
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--error); }

.noscript { padding: 24px; background: #fff4e5; color: var(--warning); }

.version-compare summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 6px 0;
  cursor: pointer;
}

@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; align-items: center; gap: 16px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail-nav { flex-direction: row; }
  .rail-foot { margin: 0 0 0 auto; min-width: 180px; }
  .topbar { padding: 14px 20px; }
  main { padding: 24px 20px; }
}

@media (max-width: 760px) {
  h1 { font-size: 19px; }
  h2 { font-size: 24px; }
  .grid-2, .field-grid { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .check-grid { grid-template-columns: 1fr 1fr; }
  .screen-heading { flex-direction: column; }
  .hero-panel { padding: 24px; margin-top: 0; }
  .rail-foot { display: none; }
  .topbar-meta { justify-content: flex-start; }
  .table-wrap table { min-width: 560px; }
}

@media (max-width: 480px) {
  .check-grid { grid-template-columns: 1fr; }
  main { padding: 20px 14px; }
  .topbar { padding: 12px 14px; }
}

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

.code-block { margin: 0; padding: 12px; overflow-wrap: anywhere; white-space: pre-wrap; background: var(--surface-subtle); border: 1px solid var(--line); border-radius: 8px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.button-secondary { color: var(--ink-secondary); }
