:root {
  --bg: #f7f8fa;
  --fg: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --success: #059669;
  --card: #ffffff;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: #f3f4f6; padding: 1px 6px; border-radius: 4px; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 24px; background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; line-height: 0; }
.brand:hover { text-decoration: none; opacity: 0.85; }
.brand img { display: block; height: 22px; width: auto; }
.navlinks { display: flex; gap: 18px; }
.navlinks a { color: var(--fg); font-size: 14px; }
.navlinks a:hover { color: var(--primary); text-decoration: none; }
.navactions { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.who { color: var(--muted); font-size: 13px; }
.inline { display: inline; margin: 0; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 28px 24px 80px; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; }
.page-head-actions { display: flex; gap: 8px; }

h1 { margin: 0 0 16px; font-size: 24px; }
h2 { margin: 0 0 12px; font-size: 16px; color: var(--fg); }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.hint { color: var(--muted); font-weight: normal; font-size: 12px; }
.error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; padding: 10px 12px; border-radius: 8px; }
.flash { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; padding: 10px 12px; border-radius: 8px; margin-bottom: 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 420px; margin: 60px auto; }
.flash-success { border-color: #a7f3d0; background: #ecfdf5; }

.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  background: #fff; color: var(--fg); font-size: 14px; cursor: pointer; font-weight: 500;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--fg); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 500; color: var(--fg); }
label.checkbox { font-weight: normal; display: flex; align-items: center; gap: 8px; }
input[type=email], input[type=password], input[type=text], input[type=url],
input[type=search], input[type=datetime-local], textarea, select {
  display: block; width: 100%; padding: 9px 11px; margin-top: 5px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
input[readonly] { background: #f9fafb; color: var(--muted); }
input[type=color] { padding: 2px; width: 48px; height: 38px; margin-top: 0; }

.slug-input { display: flex; align-items: stretch; margin-top: 5px; }
.slug-prefix { padding: 9px 11px; background: #f3f4f6; border: 1px solid var(--line); border-right: 0;
  border-radius: 8px 0 0 8px; color: var(--muted); font-size: 14px; white-space: nowrap; }
.slug-input input { margin-top: 0; border-radius: 0; flex: 1; min-width: 0; }
.slug-input input:last-child { border-radius: 0 8px 8px 0; }
.btn-suggest {
  margin: 0; padding: 0 14px;
  background: #fff; border: 1px solid var(--line); border-left: 0;
  border-radius: 0 8px 8px 0; font-size: 13px; cursor: pointer; color: var(--fg); font-weight: 500;
  white-space: nowrap;
}
.btn-suggest:hover { background: #f3f4f6; }
.btn-suggest:disabled { opacity: .6; cursor: wait; }
.slug-input:has(.btn-suggest) input { border-radius: 0; }

.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.row-form { display: flex; gap: 8px; align-items: stretch; margin-bottom: 8px; }
.row-form input { margin-top: 0; }
.row-form input[type=text] { flex: 1; }

.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { flex: 1; min-width: 200px; margin-top: 0; }
.filters select { width: auto; margin-top: 0; min-width: 140px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: #fff; }
.seg label { display: inline-flex; align-items: center; gap: 4px; margin: 0; padding: 4px 10px; font-size: 13px; cursor: pointer; border-radius: 4px; }
.seg input[type=radio] { display: none; }
.seg input[type=radio]:checked + * { color: var(--primary); }
.seg label:has(input:checked) { background: #eef2ff; color: var(--primary); font-weight: 600; }

table.links { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.links th, table.links td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
table.links th { background: #f9fafb; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
table.links tr:last-child td { border-bottom: 0; }
table.links tr.inactive td { opacity: .55; }
table.links .num { text-align: right; }
table.links .actions { white-space: nowrap; text-align: right; }
table.links .actions a { margin-left: 10px; font-size: 13px; }
table.links .actions form { margin: 0; }
table.links .dest { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.links .short { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
table.links .copy { margin-left: 8px; padding: 2px 7px; font-size: 11px; background: #f3f4f6; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; color: var(--muted); }
table.links .copy:hover { background: #e5e7eb; color: var(--fg); }

.empty { text-align: center; padding: 60px 20px; background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { color: var(--muted); margin: 0 0 16px; }

.big-stat { font-size: 36px; font-weight: 700; margin: 8px 0 0; }
.big-stat span { font-size: 14px; font-weight: normal; color: var(--muted); margin-left: 6px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2-sm { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
@media (max-width: 720px) { .grid-2, .grid-2-sm { grid-template-columns: 1fr; } }

table.kv { width: 100%; border-collapse: collapse; }
table.kv td { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
table.kv td:last-child { text-align: right; color: var(--muted); }
table.kv tr:last-child td { border-bottom: 0; }

.qr-img { max-width: 200px; display: block; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }

.chip {
  display: inline-block; padding: 2px 8px; border-radius: 12px; color: #fff;
  font-size: 11px; font-weight: 600; text-decoration: none; margin: 1px 2px 1px 0;
  line-height: 1.5;
}
a.chip:hover { opacity: .85; text-decoration: none; }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 8px;
  background: #f3f4f6; color: var(--muted); font-size: 11px; font-weight: 600;
}
.badge.ok { background: #d1fae5; color: #065f46; }
.badge.danger { background: #fee2e2; color: #991b1b; }

.tag-picker { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 0 0 14px; }
.tag-picker legend { padding: 0 6px; font-size: 13px; font-weight: 600; color: var(--fg); }
.tag-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag-check { display: inline-flex; align-items: center; cursor: pointer; margin: 0; padding: 0; }
.tag-check input { margin-right: 4px; }
.tag-picker input[type=text] { margin-top: 0; }

.advanced { border: 1px solid var(--line); border-radius: 8px; padding: 0; margin: 0 0 14px; background: #fafbfc; }
.advanced summary { padding: 10px 14px; cursor: pointer; font-weight: 600; font-size: 13px; }
.advanced[open] summary { border-bottom: 1px solid var(--line); }
.advanced > *:not(summary) { padding: 14px; }
.advanced > .grid-2-sm { padding: 14px; }

.key-reveal { display: flex; gap: 8px; align-items: center; margin: 12px 0; }
.key-reveal code { flex: 1; padding: 10px 14px; font-size: 13px; word-break: break-all; }

.endpoints { list-style: none; padding: 0; margin: 8px 0 0; }
.endpoints li { padding: 4px 0; font-size: 13px; }

.errors { color: var(--danger); font-size: 13px; }
.errors li { margin-bottom: 4px; }

/* Stage 3: bulk actions, click trail, OG preview, user actions */
table.links th.sel, table.links td.sel { width: 32px; padding-left: 14px; padding-right: 0; }
.bulk-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 10px;
  background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 8px;
  font-size: 13px;
}
.bulk-bar select { width: auto; min-width: 140px; margin-top: 0; }
.bulk-bar .hint { margin-left: auto; }

.og-preview {
  margin-top: 2px;
  font-size: 11px; color: var(--muted);
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.og-card { display: flex; gap: 14px; align-items: flex-start; }
.og-img { width: 120px; height: 120px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); flex: 0 0 120px; }
.og-meta { flex: 1; min-width: 0; }
.og-title { font-weight: 600; margin: 0 0 4px; font-size: 14px; }
.og-desc { color: var(--muted); margin: 0; font-size: 13px; line-height: 1.5; }

.trail-scroll { max-height: 420px; overflow-y: auto; overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table.trail { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.trail th { position: sticky; top: 0; background: #f9fafb; padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
table.trail td { padding: 6px 10px; border-bottom: 1px solid #f3f4f6; vertical-align: top; }
table.trail tr:last-child td { border-bottom: 0; }
table.trail .nowrap { white-space: nowrap; }
table.trail .trunc { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-actions { white-space: nowrap; }
.linklike {
  background: transparent; border: 0; padding: 0; margin: 0 0 0 10px;
  color: var(--primary); font: inherit; font-size: 13px; cursor: pointer;
}
.linklike:hover { text-decoration: underline; }
.linklike.danger { color: var(--danger); }

.who { color: var(--muted); font-size: 13px; }
a.who:hover { color: var(--primary); text-decoration: none; }

/* Inline help tooltips */
.help-tip {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 16px; height: 16px;
  margin: 0 0 0 6px; padding: 0;
  background: #fff; color: var(--muted);
  border: 1px solid var(--line); border-radius: 50%;
  font: 600 11px/1 Georgia, "Times New Roman", serif;
  font-style: italic;
  cursor: pointer; vertical-align: middle;
  transition: background-color .12s, color .12s;
}
.help-tip:hover { background: #eef2ff; color: var(--primary); border-color: #c7d2fe; }
.help-tip:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.help-popover {
  position: fixed;
  z-index: 1000;
  width: 280px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  font-size: 13px; line-height: 1.5;
  animation: pop-in .12s ease-out;
}
.help-popover strong { display: block; margin: 0 0 6px; font-size: 13px; color: var(--fg); }
.help-popover p { margin: 0 0 10px; color: var(--fg); }
.help-popover a { font-size: 12px; font-weight: 600; }

.help-tip-demo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin: 0 2px;
  background: #fff; color: var(--muted);
  border: 1px solid var(--line); border-radius: 50%;
  font: italic 600 11px/1 Georgia, "Times New Roman", serif;
  vertical-align: middle;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: none; }
}

/* 404 / 410 friendly pages */
.oops {
  max-width: 520px;
  margin: 60px auto;
  padding: 36px 32px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}
.oops-icon { font-size: 56px; line-height: 1; margin-bottom: 8px; }
.oops h1 { font-size: 24px; margin: 0 0 12px; }
.oops .oops-lead { color: var(--fg); font-size: 15px; margin: 0 0 18px; }
.oops .oops-lead code {
  background: #f3f4f6; padding: 2px 8px; font-size: 14px;
}
.oops .oops-tips {
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px 14px 32px;
  margin: 0 0 16px;
}
.oops .oops-tips li { margin: 4px 0; }
.oops .oops-suggest { color: var(--muted); font-size: 14px; margin: 0 0 24px; }
.oops .oops-cta { margin: 0; }

/* Help page */
.help-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 32px;
  align-items: start;
}
@media (max-width: 820px) {
  .help-layout { grid-template-columns: 1fr; }
  .help-toc { position: static; }
}
.help-toc {
  position: sticky;
  top: 20px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: 13px;
}
.help-toc .toc-title {
  margin: 0 0 8px;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.help-toc ol {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: toc;
}
.help-toc li {
  counter-increment: toc;
  margin: 2px 0;
}
.help-toc li::before {
  content: counter(toc) ". ";
  color: var(--muted);
}
.help-toc a {
  color: var(--fg);
}
.help-toc a:hover {
  color: var(--primary);
  text-decoration: none;
}
.help-body {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 40px;
  max-width: 800px;
}
.help-body h1 {
  margin: 0 0 8px;
  font-size: 28px;
}
.help-body .help-lead {
  font-size: 15px;
  color: var(--muted);
  margin: 0 0 28px;
}
.help-body h2 {
  margin: 32px 0 12px;
  font-size: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  scroll-margin-top: 20px;
}
.help-body h2:first-of-type {
  border-top: 0;
  padding-top: 0;
}
.help-body h3 {
  margin: 20px 0 8px;
  font-size: 15px;
}
.help-body p, .help-body li {
  font-size: 14px;
  line-height: 1.65;
}
.help-body ul, .help-body ol {
  padding-left: 22px;
}
.help-body li {
  margin: 4px 0;
}
.help-body pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.55;
}
.help-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
}
.help-body code {
  font-size: 12.5px;
}
.help-body .kv {
  margin: 8px 0 16px;
}
.help-body .api-table td {
  vertical-align: top;
  padding: 8px 0;
}
.help-body .api-table td:first-child {
  width: 240px;
  padding-right: 16px;
}
