:root {
  --bg: #f7f7f5;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --line: #e4e4e0;
  --brand: #1d4ed8;
  --brand-ink: #ffffff;
  --ok: #15803d;
  --warn: #b45309;
  --error: #b91c1c;
  --info: #1d4ed8;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --card: #1b1b1f;
    --text: #ececef;
    --muted: #9b9ba3;
    --line: #2c2c33;
    --brand: #5b8cff;
    --brand-ink: #0b0b0d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.75rem; margin: 0.5rem 0 1rem; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.5rem; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; color: var(--text); font-size: 1.1rem; }
.topbar nav { display: flex; gap: 1rem; flex-wrap: wrap; flex: 1; }
.topbar nav a { color: var(--muted); }
.topbar nav a.active { color: var(--text); font-weight: 600; }
.topbar-right { display: flex; gap: 0.75rem; align-items: center; margin-left: auto; }
@media (max-width: 640px) {
  .topbar { gap: 0.5rem 1rem; padding: 0.6rem 1rem; }
  .topbar nav { order: 3; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; gap: 1.1rem; padding-bottom: 0.15rem; }
  .topbar nav a { white-space: nowrap; }
  .hero h1 { font-size: 1.9rem; }
}

main { width: 100%; max-width: 860px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; flex: 1; }
main.wide { max-width: 1200px; }

.footer { display: flex; gap: 1rem; justify-content: center; padding: 1.5rem; color: var(--muted); font-size: 0.875rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card.narrow { max-width: 440px; margin: 2rem auto; }
.card.highlight { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 15%, transparent); }
.card.tile { display: block; color: var(--text); }
.card.tile:hover { border-color: var(--brand); text-decoration: none; }

.hero { padding: 2.5rem 0 1.5rem; }
.hero h1 { font-size: 2.4rem; max-width: 18ch; }
.lead { font-size: 1.1rem; color: var(--muted); max-width: 60ch; }

.steps, .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.steps { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 760px) { .steps { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .steps { grid-template-columns: 1fr; } }
.steps .card { margin: 0; }
.step-n {
  width: 2rem; height: 2rem; border-radius: 50%;
  background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 700; margin-bottom: 0.5rem;
}

.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 180px; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }

label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 400; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }
legend { font-size: 0.85rem; color: var(--muted); padding: 0 0.25rem; }

input, textarea, select {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
input[type="checkbox"] { width: auto; }
input[type="file"] { padding: 0.4rem; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
textarea { resize: vertical; }
.row input, .row select { width: auto; }
.row input.grow { width: 100%; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 600;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: var(--brand-ink);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.small { padding: 0.35rem 0.75rem; font-size: 0.875rem; }
.btn.danger, .link.danger { color: var(--error); border-color: var(--error); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn[aria-busy="true"] { opacity: 0.7; cursor: progress; }
.link { background: none; border: none; padding: 0; color: var(--brand); font: inherit; cursor: pointer; }
.link:hover { text-decoration: underline; }
form.inline { display: inline; }

.flash { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; word-break: break-word; }
.flash.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 8%, transparent); }
.flash.error { color: var(--error); border-color: color-mix(in srgb, var(--error) 40%, transparent); background: color-mix(in srgb, var(--error) 8%, transparent); }
.flash.info { color: var(--info); border-color: color-mix(in srgb, var(--info) 40%, transparent); background: color-mix(in srgb, var(--info) 8%, transparent); }

.badge { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 0.15rem 0.55rem; border-radius: 999px; border: 1px solid; white-space: nowrap; }
.badge-ok { color: var(--ok); }
.badge-warn { color: var(--warn); }
.badge-error { color: var(--error); }
.badge-info { color: var(--info); }
.badge-muted { color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); margin-bottom: 1rem; }

.list { list-style: none; padding: 0; margin: 0 0 1rem; }
.list li { padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: none; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-bottom: 1rem; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
main > table { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
@media (max-width: 640px) { table { display: block; overflow-x: auto; } }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0 0 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.prd, .secret {
  white-space: pre-wrap;
  word-break: break-word;
  font: 0.9rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  margin: 0 0 0.75rem;
  max-height: 480px;
  overflow: auto;
}
.secret { user-select: all; }

.chat .messages { display: flex; flex-direction: column; gap: 0.6rem; max-height: 60vh; overflow-y: auto; margin-bottom: 0.75rem; padding-right: 0.25rem; }
.msg { padding: 0.6rem 0.8rem; border-radius: 10px; max-width: 90%; }
.msg .who { font-size: 0.75rem; font-weight: 600; color: var(--muted); margin-bottom: 0.15rem; }
.msg .text { white-space: pre-wrap; }
.msg.agent { background: var(--bg); border: 1px solid var(--line); align-self: flex-start; }
.msg.user { background: color-mix(in srgb, var(--brand) 12%, var(--card)); align-self: flex-end; }

.subnav { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.subnav a { padding: 0.5rem 0.75rem; color: var(--muted); border-bottom: 2px solid transparent; }
.subnav a.active { color: var(--text); border-color: var(--brand); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem; }
.stat-v { font-size: 1.4rem; font-weight: 700; }
.stat-l { font-size: 0.8rem; color: var(--muted); }

details summary { cursor: pointer; color: var(--brand); font-size: 0.9rem; margin-bottom: 0.5rem; }
code { font-family: ui-monospace, Menlo, monospace; font-size: 0.85em; }
