:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --border: #ebebeb;
  --border-strong: #d4d4d4;
  --text: #171717;
  --body: #4d4d4d;
  --muted: #666666;
  --accent: #0070f3;
  --accent-contrast: #ffffff;
  --ink: #171717;
  --ink-contrast: #ffffff;
  --danger: #ee0000;
  --radius: 8px;
  --shadow: 0 0 0 1px #00000014, 0 1px 1px #00000005, 0 2px 2px #0000000a;
  --shadow-lg: 0 0 0 1px #00000014, 0 2px 2px #0000000a, 0 8px 16px -4px #0000000a;
  --font: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #000000;
  --panel: #0a0a0a;
  --border: #242424;
  --border-strong: #3a3a3a;
  --text: #ededed;
  --body: #a1a1a1;
  --muted: #8f8f8f;
  --accent: #52a8ff;
  --accent-contrast: #000000;
  --ink: #ededed;
  --ink-contrast: #000000;
  --danger: #ff5555;
  --shadow: 0 0 0 1px #ffffff1a;
  --shadow-lg: 0 0 0 1px #ffffff1f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-size: 18px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: var(--ink);
  color: var(--ink-contrast);
  border-radius: 6px;
  flex-shrink: 0;
}
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
.tagline { margin: 1px 0 0; font-size: 12px; color: var(--muted); }
@media (max-width: 600px) { .tagline { display: none; } }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--border-strong); background: var(--bg); }
.btn.primary { background: var(--ink); color: var(--ink-contrast); border-color: var(--ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--ink) 85%, var(--panel)); }
.btn:focus-visible, .tmpl-card:focus-visible, .list-add:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--danger); border-color: transparent; }
.btn.danger-ghost:hover { border-color: var(--danger); background: transparent; }

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 16px;
  padding: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.form-side { max-height: calc(100vh - 96px); overflow: auto; position: sticky; top: 80px; }
@media (max-width: 900px) {
  .form-side { position: static; max-height: none; }
}
.panel-inner { padding: 16px; }

.control-block { margin-bottom: 20px; }
.block-label { display: block; font-weight: 600; font-size: 13.5px; letter-spacing: -0.01em; margin-bottom: 8px; }
.muted { color: var(--muted); font-weight: 400; }
.hint { font-size: 12px; color: var(--muted); margin: -4px 0 10px; }

input[type="text"], input[type="number"] {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13.5px;
  width: 100%;
}
input[type="text"]:focus, input[type="number"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.template-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.tmpl-card {
  font-family: inherit;
  text-align: left;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 11px;
  cursor: pointer;
}
.tmpl-card:hover { border-color: var(--border-strong); }
.tmpl-card.active { border-color: var(--ink); background: var(--panel); box-shadow: 0 0 0 1px var(--ink); }
.tmpl-name { font-weight: 700; font-size: 13px; }
.tmpl-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.field-group {
  border: 1px solid var(--border);
  border-radius: 9px;
  margin: 0 0 14px;
  padding: 10px 12px 12px;
}
.field-group legend {
  font-weight: 700;
  font-size: 12.5px;
  padding: 0 6px;
  color: var(--accent);
  max-width: 100%;
}
.field-box { padding: 8px 0; border-top: 1px dashed var(--border); }
.field-box:first-of-type { border-top: none; }
.field-box-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }

/* Editable label inputs — every static heading in the diagram (column
   headers, box titles, field labels, section bars) is one of these. Styled
   to read as text until focused, so the form doesn't look like a wall of
   input boxes. */
.label-input {
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  border-radius: 5px;
  padding: 2px 4px;
  margin: -2px -4px;
}
.label-input:hover { border-color: var(--border); }
.label-input:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.group-header-row { margin: -4px 0 8px; }
.legend-input { font-weight: 700; font-size: 12.5px; color: var(--accent); width: 100%; display: block; box-sizing: border-box; }
.title-input { font-weight: 600; font-size: 12.5px; flex: 1; min-width: 120px; }
.field-label-input { font-size: 12.5px; }
.phase-badge {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.phase-identification { color: #1c5fbf; }
.phase-screening { color: #b05a12; }
.phase-exclusions { color: #b0301f; }
.phase-included { color: #1c8a4a; }

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  margin-bottom: 6px;
}
.field-row span { flex: 1; }
.field-row input { width: 90px; flex: 0 0 auto; }
.field-row .label-input { flex: 1; width: auto; min-width: 0; }

.section-labels { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.section-label-tag {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  width: 92px;
  flex: 0 0 auto;
}
.section-label-input { flex: 1; border-color: var(--border); }

.list-editor { margin-top: 6px; }
.list-editor + .list-editor { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--border); }
.list-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.list-row { display: grid; grid-template-columns: 1fr 70px 26px; gap: 6px; align-items: center; }
.list-count { text-align: right; }
.list-remove {
  border: none; background: transparent; color: var(--muted);
  font-size: 18px; line-height: 1; cursor: pointer; border-radius: 6px; padding: 2px;
}
.list-remove:hover { color: var(--danger); background: var(--bg); }
.list-add {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
  width: 100%;
}
.list-add:hover { border-color: var(--ink); }
.list-add { font-family: inherit; }

.preview-side { padding: 16px; }
.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.toolbar-group { display: flex; gap: 8px; flex-wrap: wrap; }

.total-hint {
  font-size: 12px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--panel));
  padding: 6px 10px;
  border-radius: 7px;
  display: inline-block;
  margin-bottom: 10px;
}
.total-hint[hidden] { display: none; }

.preview {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  padding: 14px;
  overflow: auto;
}
.preview svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }

.autosave-note { font-size: 11.5px; color: var(--muted); margin: 10px 2px 0; }

.site-footer {
  padding: 18px 22px 36px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  max-width: 1100px;
}
.site-footer a { color: var(--accent); }
.site-footer .small { font-size: 11.5px; }

@media (max-width: 480px) {
  .template-picker { grid-template-columns: 1fr; }
  .list-row { grid-template-columns: 1fr 60px 24px; }
}

.faq {
  padding: 8px 22px 12px;
  max-width: 1100px;
  color: var(--text);
}
.faq h2 { font-size: 20px; margin: 18px 0 12px; }
.faq-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  padding: 0 14px;
}
.faq-item summary {
  cursor: pointer;
  padding: 12px 0;
  font-weight: 600;
  font-size: 14.5px;
}
.faq-item p { margin: 0 0 14px; font-size: 14px; line-height: 1.65; color: var(--muted); }

/* ---- Hero, how-to, footer nav ---- */
.hero { max-width: 1100px; padding: 56px 24px 8px; }
.eyebrow { font-family: var(--mono); font-size: 12px; color: var(--muted); margin: 0 0 12px; }
.hero h1 {
  font-size: clamp(32px, 5vw, 48px);
  line-height: 1.08;
  font-weight: 600;
  letter-spacing: -0.05em;
  margin: 0 0 16px;
}
.hero .lead { font-size: 17px; line-height: 1.6; color: var(--body); max-width: 680px; margin: 0 0 24px; }
.hero-cta { display: flex; gap: 10px; flex-wrap: wrap; }
.btn.pill { border-radius: 100px; padding: 9px 20px; text-decoration: none; display: inline-block; }

.howto { max-width: 1100px; padding: 40px 24px 8px; }
.howto h2, .faq h2 { font-size: 28px; font-weight: 600; letter-spacing: -0.04em; margin: 0 0 16px; }
.howto ol { list-style: none; counter-reset: step; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.howto li { counter-increment: step; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; font-size: 14px; line-height: 1.6; color: var(--body); }
.howto li::before { content: "0" counter(step); display: block; font-family: var(--mono); font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.howto li strong { display: block; color: var(--text); font-size: 15px; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 4px; }

.faq { padding-top: 40px; }
.faq h2 { font-size: 28px; margin: 0 0 16px; }
.faq-item { border: none; box-shadow: var(--shadow); border-radius: var(--radius); padding: 0 20px; }
.faq-item summary { font-weight: 500; font-size: 15px; letter-spacing: -0.01em; padding: 16px 0; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; font-family: var(--mono); color: var(--muted); }
.faq-item[open] summary::after { content: "\2212"; }
.faq-item p { font-size: 14.5px; }

.site-footer { border-top: 1px solid var(--border); margin-top: 48px; padding: 24px 24px 40px; }
.footer-nav { display: flex; gap: 16px; flex-wrap: wrap; margin: 0 0 12px; font-size: 13px; }
.footer-nav a { color: var(--text); text-decoration: none; }
.footer-nav a:hover { text-decoration: underline; }

/* ---- Responsive ---- */
html { -webkit-text-size-adjust: 100%; }
img, svg { max-width: 100%; }
.site-header, .layout, .hero, .howto, .faq, .site-footer { width: 100%; }
@media (min-width: 1700px) {
  .layout { max-width: 1680px; margin-inline: auto; }
}
@media (max-width: 900px) {
  .hero { padding: 40px 20px 4px; }
  .howto, .faq { padding-left: 20px; padding-right: 20px; }
  .layout { padding: 12px; gap: 12px; }
  .toolbar-group { flex: 1 1 100%; }
  .toolbar-group .btn { flex: 1 1 auto; }
}
@media (max-width: 600px) {
  .site-header { padding: 0 16px; height: 56px; }
  .hero { padding: 32px 16px 0; }
  .hero .lead { font-size: 16px; }
  .hero-cta .btn { flex: 1 1 100%; text-align: center; }
  .howto, .faq { padding-left: 16px; padding-right: 16px; padding-top: 32px; }
  .howto h2, .faq h2 { font-size: 22px; }
  .faq-item { padding: 0 14px; }
  .faq-item summary { font-size: 14.5px; }
  .panel-inner, .preview-side { padding: 12px; }
  .preview { padding: 8px; }
  .site-footer { padding: 20px 16px 32px; }
  .toolbar-group .btn { padding: 8px 10px; font-size: 13px; }
}
@media (max-width: 360px) {
  .field-row input { width: 76px; }
  .brand-name { font-size: 14px; }
}

/* ---- Legal pages ---- */
.legal { max-width: 760px; margin: 0 auto; padding: 48px 24px 24px; }
.legal h1 { font-size: clamp(28px, 5vw, 40px); font-weight: 600; letter-spacing: -0.04em; line-height: 1.1; margin: 0 0 8px; }
.legal .updated { font-family: var(--mono); font-size: 12px; color: var(--muted); margin: 0 0 32px; }
.legal h2 { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; margin: 32px 0 8px; }
.legal p, .legal li { font-size: 15px; line-height: 1.7; color: var(--body); }
.legal ul { padding-left: 20px; }
.legal a { color: var(--accent); }
.brand-link { color: inherit; text-decoration: none; }
@media (max-width: 600px) { .legal { padding: 32px 16px 16px; } }

/* ---- About (SEO copy) ---- */
.about { max-width: 820px; padding: 48px 24px 0; }
.about h2 { font-size: 28px; font-weight: 600; letter-spacing: -0.04em; line-height: 1.15; margin: 0 0 16px; }
.about h3 { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; margin: 28px 0 8px; }
.about p, .about li { font-size: 15.5px; line-height: 1.75; color: var(--body); }
.about ul { padding-left: 20px; }
@media (max-width: 600px) { .about { padding: 32px 16px 0; } .about h2 { font-size: 22px; } }

.brand-mark { background: url("../favicon.svg") center / cover no-repeat; color: transparent; font-size: 0; }

/* ---- MPA: nav, guides, cards ---- */
.site-nav { display: flex; gap: 4px; margin-left: auto; margin-right: 8px; }
.site-nav a { color: var(--body); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 100px; }
.site-nav a:hover { color: var(--text); background: var(--bg); }
@media (max-width: 760px) { .site-nav { display: none; } }
.guide .lead { font-size: 17px; color: var(--body); }
.guide table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 14px; display: block; overflow-x: auto; }
.guide th, .guide td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); color: var(--body); }
.guide th { color: var(--text); font-weight: 600; }
.guide h3 { font-size: 16px; font-weight: 600; margin: 20px 0 4px; }
.crumbs { font-size: 13px; color: var(--muted); margin: 0 0 16px; }
.crumbs a { color: var(--muted); }
.related { margin-top: 40px; padding: 20px; border-radius: var(--radius); box-shadow: var(--shadow); background: var(--panel); }
.related h2 { margin-top: 0; font-size: 16px; }
.cards { list-style: none; padding: 0; margin: 20px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.cards .card a { display: block; height: 100%; padding: 18px; border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); color: var(--text); text-decoration: none; transition: box-shadow .15s; }
.cards .card a:hover { box-shadow: var(--shadow-lg); }
.cards .card strong { display: block; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 6px; }
.cards .card span { font-size: 13.5px; line-height: 1.55; color: var(--body); }
.guides-home { max-width: 1100px; padding: 40px 24px 0; }
.guides-home h2 { font-size: 28px; font-weight: 600; letter-spacing: -0.04em; margin: 0 0 4px; }
@media (max-width: 600px) { .guides-home { padding: 32px 16px 0; } }
