:root {
  --bg: #f6f6f9;
  --surface: #ffffff;
  --surface-2: #f1f0f6;
  --text: #191826;
  --muted: #6b6a7b;
  --faint: #9a99a8;
  --border: #e4e3ec;
  --edge: #c9c7d6;
  --brand: #7964ff;
  --brand-ink: #5b46e6;
  --danger: #c93d3d;
  --shadow-sm: 0 1px 2px rgba(25, 24, 38, 0.06), 0 1px 3px rgba(25, 24, 38, 0.05);
  --shadow-md: 0 6px 16px rgba(25, 24, 38, 0.08), 0 2px 4px rgba(25, 24, 38, 0.05);
  --shadow-lg: 0 18px 48px rgba(25, 24, 38, 0.16);
  --radius: 10px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111018;
    --surface: #1b1a25;
    --surface-2: #24232f;
    --text: #ecebf3;
    --muted: #a3a2b3;
    --faint: #75748a;
    --border: #2f2e3c;
    --edge: #44435a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

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

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
}

a {
  color: var(--brand-ink);
}

[hidden] {
  display: none !important;
}

.app {
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100vh;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 40%, #fff 0 2.6px, transparent 3px),
    radial-gradient(circle at 66% 40%, #fff 0 2.6px, transparent 3px),
    radial-gradient(circle at 50% 70%, #fff 0 2.6px, transparent 3px),
    var(--brand);
}

.brand-sub {
  color: var(--faint);
  font-size: 13px;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.me {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border-radius: 9px;
}

.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
}

.segmented button.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.segmented.small button {
  padding: 4px 10px;
  font-size: 13px;
}

/* Filters */
.filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.spacer {
  flex: 1;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-size: 12.5px;
  color: var(--muted);
}

.chip:hover {
  border-color: var(--edge);
  color: var(--text);
}

.chip.is-active {
  color: var(--text);
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 10%, var(--surface));
}

.pillar-toggle {
  padding-left: 9px;
}

.pillar-toggle.is-active {
  border-color: var(--pillar);
  background: color-mix(in srgb, var(--pillar) 12%, var(--surface));
}

.pillar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pillar);
  flex: none;
}

.custom-range {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.custom-range input,
.search,
.select {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 5px 9px;
  font-size: 13px;
}

.search {
  width: 220px;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

/* Buttons */
.button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
}

.button:hover {
  border-color: var(--edge);
}

.button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.button.primary:hover {
  background: var(--brand-ink);
}

.button.is-on {
  border-color: var(--brand);
  color: var(--brand-ink);
  background: color-mix(in srgb, var(--brand) 10%, var(--surface));
}

.button.ghost {
  background: transparent;
}

.button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.icon-button {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 6px;
}

.icon-button:hover {
  background: var(--surface-2);
  color: var(--text);
}

.link-button {
  border: 0;
  background: none;
  padding: 0;
  color: var(--brand-ink);
  cursor: pointer;
  text-align: left;
  font-size: inherit;
}

.link-button.danger {
  color: var(--danger);
}

/* Avatars */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
}

.avatar.small {
  width: 24px;
  height: 24px;
}

.avatar.tiny {
  width: 18px;
  height: 18px;
}

.avatar-fallback {
  display: inline-grid;
  place-items: center;
  background: color-mix(in srgb, var(--brand) 18%, var(--surface));
  color: var(--brand-ink);
  font-size: 11px;
  font-weight: 600;
}

.avatar.tiny.avatar-fallback {
  font-size: 8px;
}

/* Stage */
.stage {
  position: relative;
  overflow: auto;
  min-height: 0;
}

.stage-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 100%;
  padding: 40px;
  text-align: center;
  color: var(--muted);
}

.stage-message strong {
  color: var(--text);
  font-size: 16px;
}

/* Mind map */
.map {
  overflow: hidden;
  cursor: grab;
  background-color: var(--bg);
  background-image: radial-gradient(circle, color-mix(in srgb, var(--edge) 70%, transparent) 1px, transparent 1.2px);
  background-size: 22px 22px;
  touch-action: none;
}

.map.is-panning {
  cursor: grabbing;
}

.viewport {
  position: absolute;
  inset: 0 auto auto 0;
  transform-origin: 0 0;
}

.viewport.is-animating {
  transition: transform 0.32s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.edges {
  position: absolute;
  left: 0;
  overflow: visible;
  pointer-events: none;
}

.edge {
  fill: none;
  stroke-width: 1.6;
  opacity: 0.9;
}

.edge-leaf {
  opacity: 0.5;
}

.nodes {
  position: absolute;
  left: 0;
  top: 0;
}

.node {
  position: absolute;
  left: 0;
  top: 0;
  width: max-content;
  opacity: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.node.is-placed {
  opacity: 1;
  transition: opacity 0.2s ease;
}

.node-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.node-title {
  font-weight: 600;
}

.node-meta {
  color: var(--muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.node-root {
  background: #1f1d33;
  color: #fff;
  padding: 14px 20px;
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  max-width: 260px;
}

.node-root .node-title {
  font-size: 16px;
  white-space: nowrap;
}

.node-root .node-meta {
  color: rgba(255, 255, 255, 0.68);
}

.node-person,
.node-workstream,
.node-pillar {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  user-select: none;
}

.node-person:hover,
.node-workstream:hover,
.node-pillar:hover {
  box-shadow: var(--shadow-md);
}

.node-person {
  padding: 10px 30px 14px 10px;
  border-radius: 14px;
  min-width: 200px;
  max-width: 260px;
}

.node-person .node-title {
  font-size: 14.5px;
}

.node-workstream {
  padding: 9px 30px 12px 12px;
  border-radius: var(--radius);
  min-width: 170px;
  max-width: 250px;
}

.node-workstream .node-title {
  font-size: 13.5px;
}

.node-pillar {
  padding: 10px 30px 14px 12px;
  border-radius: 12px;
  min-width: 170px;
  border-left: 4px solid var(--pillar);
}

.pillar-bar {
  position: absolute;
  left: 12px;
  right: 30px;
  bottom: 6px;
  height: 3px;
  display: flex;
  gap: 2px;
  border-radius: 2px;
  overflow: hidden;
}

.pillar-bar span {
  display: block;
  height: 100%;
}

.toggle {
  position: absolute;
  right: -11px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--edge);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.is-collapsed .toggle {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.node-insight {
  width: 300px;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 9px 12px 9px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--pillar);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.node-insight:hover {
  box-shadow: var(--shadow-md);
  border-color: color-mix(in srgb, var(--pillar) 40%, var(--border));
  border-left-color: var(--pillar);
}

.node-insight .node-title {
  font-size: 13px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.node-insight .node-meta {
  font-size: 11.5px;
}

.node-insight.is-selected {
  outline: 2px solid var(--pillar);
  outline-offset: 1px;
}

.node-insight.is-rejected {
  opacity: 0.55;
}

.node-insight.is-rejected .node-title {
  text-decoration: line-through;
}

.kept,
.rejected-tag {
  font-size: 10.5px;
  padding: 0 6px;
  border-radius: 999px;
  line-height: 16px;
}

.kept {
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  color: var(--brand-ink);
  font-weight: 600;
}

.rejected-tag {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
}

.map-controls {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
}

.map-controls button {
  border: 0;
  background: transparent;
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

.map-controls button:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* Detail panel and rules drawer */
.panel,
.drawer {
  position: fixed;
  top: 12px;
  bottom: 12px;
  width: min(420px, calc(100vw - 24px));
  overflow-y: auto;
  padding: 18px 22px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 10;
  animation: slide-in 0.2s ease;
}

.panel {
  right: 12px;
}

.drawer {
  left: 12px;
  width: min(380px, calc(100vw - 24px));
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.pillar-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--pillar);
  background: color-mix(in srgb, var(--pillar) 12%, transparent);
}

.panel-title {
  font-size: 18px;
  line-height: 1.35;
  margin: 0 0 12px;
}

.panel-body {
  margin: 0 0 16px;
  white-space: pre-wrap;
  line-height: 1.55;
}

.panel-section h3,
.drawer-subtitle {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--faint);
  margin: 16px 0 6px;
}

.evidence {
  margin: 0;
  padding-left: 18px;
  word-break: break-all;
}

.meta {
  margin: 18px 0;
  display: grid;
  gap: 7px;
  font-size: 13px;
}

.meta-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 10px;
}

.meta-row dt {
  color: var(--faint);
}

.meta-row dd {
  margin: 0;
  min-width: 0;
  word-break: break-word;
}

.author {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.panel-actions,
.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.reject-form,
.rule-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.reject-form label {
  font-size: 12.5px;
  font-weight: 600;
}

.reject-form select,
.reject-form textarea,
.reject-form input,
.rule-form textarea,
.rule-form select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  background: var(--surface);
  font-size: 13px;
  resize: vertical;
}

.rejected-banner {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 9%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 25%, var(--border));
  font-size: 13px;
}

.rejected-banner p {
  margin: 6px 0 8px;
}

.panel-status {
  min-height: 18px;
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.panel-status.is-error {
  color: var(--danger);
}

.panel-footnote {
  margin-top: 18px;
  font-size: 12px;
  color: var(--faint);
}

.drawer-title {
  font-size: 16px;
  margin: 0;
}

.drawer-intro {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 14px;
}

.rules {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rule {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.rule p {
  margin: 4px 0 6px;
}

.rule-kind {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--danger);
}

.rule-prefer .rule-kind {
  color: #1f9d6b;
}

.rule-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--faint);
}

.empty-note {
  color: var(--muted);
  font-size: 13px;
}

/* Weekly review */
.review {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 24px 60px;
}

.review-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 22px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 22px;
}

.summary-total {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--muted);
}

.summary-total strong {
  font-size: 26px;
  color: var(--text);
}

.summary-pillars,
.summary-people,
.summary-workstreams {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.summary-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  background: color-mix(in srgb, var(--pillar) 12%, transparent);
  color: var(--text);
}

.summary-chip b {
  color: var(--pillar);
}

.summary-chip.is-empty {
  opacity: 0.45;
}

.summary-person {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  margin-right: 6px;
}

.summary-label {
  font-size: 12px;
  color: var(--faint);
}

.workstream-chip {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
}

.review-section {
  margin-bottom: 28px;
}

.review-section header {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding-left: 10px;
  border-left: 3px solid var(--pillar);
}

.review-section h2 {
  margin: 0;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.review-section header p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.count {
  font-size: 12px;
  color: var(--pillar);
  background: color-mix(in srgb, var(--pillar) 12%, transparent);
  padding: 0 8px;
  border-radius: 999px;
}

.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 10px;
}

.review-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--pillar);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.review-card:hover {
  box-shadow: var(--shadow-md);
}

.review-card.is-selected {
  outline: 2px solid var(--pillar);
}

.review-card.is-rejected {
  opacity: 0.55;
}

.review-card-title {
  font-weight: 600;
  line-height: 1.35;
}

.review-card-body {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.review-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--faint);
  margin-top: 2px;
}

@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
  }
  .search {
    width: 100%;
  }
  .review-grid {
    grid-template-columns: 1fr;
  }
}
