:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --border: #e3e5ea;
  --text: #1c1f24;
  --muted: #6b7280;
  --dim: #c8ccd3;
  --accent: #db0011;
  --accent-soft: #fce7e8;
  --line: #b5bac4;
  --line-hi: #db0011;
  --warn: #b45309;
  --warn-border: #f59e0b;
  --warn-soft: #fff7ed;

  /* Shoelace theme bridging */
  --sl-color-primary-600: var(--accent);
  --sl-color-primary-500: var(--accent);
  --sl-color-primary-700: #b8000f;
  --sl-input-required-content-color: var(--accent);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

/* App shell */
.app-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.app-bar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
}
.app-bar .spacer { flex: 1; }
.app-bar sl-button { font-size: 12px; }

.mode-pill {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.mode-pill.snapshot {
  background: #eef2ff;
  color: #4338ca;
  border: 1px solid #c7d2fe;
}
.mode-pill code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  background: rgba(67, 56, 202, 0.12);
  padding: 0 4px;
  border-radius: 3px;
}

.snapshot-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 24px;
  background: #eef2ff;
  border-bottom: 1px solid #c7d2fe;
  color: #312e81;
  font-size: 13px;
}
.snapshot-banner sl-icon {
  font-size: 16px;
  color: #4338ca;
  margin-top: 2px;
}
.snapshot-banner-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.snapshot-banner strong {
  font-weight: 600;
}
.snapshot-description {
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid #c7d2fe;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  color: #312e81;
  line-height: 1.5;
}
.snapshot-description .label {
  font-weight: 600;
  margin-right: 4px;
}
.snapshot-note {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: #4338ca;
  opacity: 0.85;
}

sl-tab-group { --indicator-color: var(--accent); }
sl-tab::part(base) { font-size: 13px; }
sl-tab[active]::part(base) { color: var(--accent); }

.tab-panel {
  padding: 0;
}

/* Viz styles (lifted from targeting.html) */
header.viz-header {
  padding: 24px 32px 8px;
}
header.viz-header h2 {
  font-size: 20px;
  margin: 0 0 4px;
  font-weight: 600;
}
header.viz-header p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
.notice {
  margin-top: 12px;
  padding: 10px 14px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-left: 3px solid #2563eb;
  border-radius: 6px;
  font-size: 13px;
  color: #1e3a8a;
  max-width: 900px;
}
.notice strong { font-weight: 600; }
.legend {
  display: flex;
  gap: 18px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
.legend kbd {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 11px;
}

.stage {
  position: relative;
  padding: 24px 32px 48px;
}
.columns {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr 1.1fr 1fr 1.15fr;
  gap: 40px;
  z-index: 1;
}
.col h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 12px;
  font-weight: 600;
}
.item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: default;
  transition: background 120ms, border-color 120ms, opacity 120ms, transform 120ms, box-shadow 120ms;
  position: relative;
}
.item .name { font-size: 14px; }
.item .meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.item .groups {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.item .group-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 2px;
  font-weight: 600;
}
.item .group-items {
  font-size: 12px;
  color: var(--text);
  line-height: 1.35;
}
.item .group-items div {
  margin-bottom: 1px;
}
body.has-hover .item.hl-source .group-label,
body.has-hover .item.hl-source .group-items {
  color: rgba(255,255,255,0.95);
}
body.has-hover .item.hl-source .group-label {
  color: rgba(255,255,255,0.7);
}
.item[data-kind="article"] {
  border-left-width: 3px;
  border-left-color: #475569;
  background: #eef2f7;
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.05),
    0 4px 10px rgba(15, 23, 42, 0.08);
}

.item.orphan {
  background: var(--warn-soft);
  border-color: var(--warn-border);
  border-style: dashed;
}
.item.orphan .name::before {
  content: "\26A0";
  color: var(--warn);
  margin-right: 6px;
  font-size: 13px;
}
.item.orphan .name::after {
  content: "no audiences";
  font-size: 11px;
  color: var(--warn);
  background: #fef3c7;
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 8px;
  vertical-align: middle;
  font-weight: 500;
}

.subhead {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 18px 0 8px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.subhead .count {
  background: #fef3c7;
  color: var(--warn);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10px;
}

/* highlighting */
body.has-hover .item { opacity: 0.35; }
body.has-hover .item.hl {
  opacity: 1;
  border-color: var(--accent);
  background: var(--accent-soft);
}
body.has-hover .item.hl-source {
  opacity: 1;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
body.has-hover .item.hl-source .meta { color: rgba(255,255,255,0.85); }

svg.connectors {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}
svg.connectors path {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.2;
  opacity: 0.55;
  transition: stroke 120ms, opacity 120ms, stroke-width 120ms;
}
svg.connectors path.skip {
  stroke-dasharray: 4 4;
}
body.has-hover svg.connectors path { opacity: 0.08; }
svg.connectors path.hl {
  stroke: var(--line-hi);
  stroke-width: 1.8;
  opacity: 1;
}

.tag-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px 32px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.tag-bar .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-right: 4px;
}
.tag-chip {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, color 120ms;
  user-select: none;
}
.tag-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.tag-chip .count {
  color: var(--muted);
  margin-left: 6px;
  font-size: 11px;
}

.item .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.item .tag {
  background: #f1f2f4;
  color: var(--muted);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.item .tag:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
body.has-hover .item.hl-source .tag {
  background: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.95);
}

/* tag modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 32px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel);
  border-radius: 12px;
  width: 100%;
  max-width: 680px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.modal-header .meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  width: 28px;
  height: 28px;
  border-radius: 6px;
}
.modal-close:hover { background: #f1f2f4; color: var(--text); }
.modal-body {
  padding: 16px 24px 24px;
  overflow-y: auto;
}
.modal-section {
  margin-bottom: 24px;
}
.modal-section:last-child { margin-bottom: 0; }
.modal-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.modal-section h3 .count {
  background: #f1f2f4;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 10px;
}
.modal-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.modal-card:last-child { margin-bottom: 0; }
.modal-card .title {
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 4px;
}
.modal-card .body {
  font-size: 14px;
  margin-bottom: 4px;
}
.modal-card .by {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.modal-card .where {
  font-size: 12px;
  color: var(--muted);
}
.modal-card .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.modal-card .tag {
  background: #f1f2f4;
  color: var(--muted);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
}
.modal-card.ugc .tag {
  background: var(--accent-soft);
  color: var(--accent);
}
.modal-empty {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

.questions {
  margin: 16px 32px 32px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 20px 24px;
}
.questions h2 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--warn);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.questions h2::before {
  content: "?";
  background: var(--warn);
  color: #fff;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}
.questions ol {
  margin: 0;
  padding-left: 22px;
  color: var(--text);
  font-size: 14px;
}
.questions ol > li {
  margin-bottom: 12px;
}
.questions ol > li:last-child { margin-bottom: 0; }
.questions ul {
  margin: 8px 0 0;
  padding-left: 20px;
  color: var(--text);
  font-size: 14px;
}
.questions ul li {
  margin-bottom: 6px;
}
.questions ul li:last-child { margin-bottom: 0; }

.questions ol > li.answered::marker {
  color: #047857;
  font-weight: 600;
}
.questions .answer {
  margin-top: 10px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-left: 3px solid #10b981;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  color: #064e3b;
  line-height: 1.5;
}
.questions .answer-label {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: #047857;
  margin-bottom: 4px;
}
.questions .answer-body {
  white-space: pre-wrap;
}
.questions h2 .answered-count {
  background: #d1fae5;
  color: #047857;
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 10px;
  font-weight: 600;
  margin-left: 4px;
}
.questions ul li.answered::marker {
  color: #047857;
  font-weight: 600;
}
.questions .answer.sub-answer {
  margin-top: 6px;
  padding: 6px 10px;
  font-size: 13px;
}

.sub-question-block {
  border-left: 3px solid var(--border);
  padding: 10px 12px;
  margin: 12px 0;
  background: #f9fafb;
  border-radius: 4px;
}
.sub-question-block.locked {
  border-left-color: #4f46e5;
  background: #f5f3ff;
}
.sub-question-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.sub-question-index {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sub-question-actions {
  display: flex;
  gap: 2px;
}

.editor-card.locked {
  border-left: 3px solid #4f46e5;
}
.editor-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.lock-pill {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  background: #ede9fe;
  color: #4338ca;
  border-radius: 999px;
  padding: 1px 8px;
}
sl-icon-button.lock-toggle::part(base) {
  color: var(--muted);
}
sl-icon-button.lock-toggle.lock-on::part(base) {
  color: #4338ca;
}
sl-icon-button[disabled]::part(base) {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Admin */
.admin {
  padding: 24px 32px 48px;
  max-width: 1100px;
}
.admin h2 {
  font-size: 18px;
  margin: 0 0 4px;
  font-weight: 600;
}
.admin .hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 20px;
}

.editor-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 12px;
}
.editor-card.compact { padding: 10px 14px; }
.editor-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 12px;
}
.editor-row:last-child { margin-bottom: 0; }
.editor-row sl-input,
.editor-row sl-select,
.editor-row sl-textarea { flex: 1; }
.editor-row sl-icon-button {
  flex-shrink: 0;
  margin-bottom: 2px;
}
.editor-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}
.editor-card-title {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
}
.editor-card-title-input {
  flex: 1;
}
.editor-card-title-input sl-input::part(input) {
  font-weight: 600;
  font-size: 14px;
}
.editor-card-title-input sl-input::part(base) {
  background: transparent;
  border-color: transparent;
}
.editor-card-title-input sl-input:hover::part(base),
.editor-card-title-input sl-input:focus-within::part(base) {
  background: var(--panel);
  border-color: var(--border);
}
.add-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
}
.add-row sl-input { flex: 1; }

.issues {
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
  border-left: 3px solid var(--warn);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--warn);
}
.issues ul { margin: 6px 0 0; padding-left: 20px; }
.issues li { margin-bottom: 2px; }

.raw-pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 16px;
  border-radius: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  max-height: 60vh;
  overflow: auto;
  white-space: pre;
}
