:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --text-secondary: #5f6776;
  --text-muted: #8b92a0;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --green-border: #bbf7d0;
  --yellow: #ca8a04;
  --yellow-bg: #fef9c3;
  --yellow-border: #fef08a;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --red-border: #fecaca;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --blue-border: #bfdbfe;
  --purple: #7c3aed;
  --purple-bg: #ede9fe;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
  --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===== Top bar ===== */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 24px; }
.logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}
.logo svg { width: 22px; height: 22px; }
.topbar-nav { display: flex; gap: 4px; }
.topbar-nav a {
  background: none;
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition);
  text-decoration: none;
}
.topbar-nav a { position: relative; }
.topbar-nav a:hover { background: var(--bg); color: var(--text); }
.topbar-nav a.active { background: var(--bg); color: var(--text); }
.nav-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  margin-left: 4px;
  vertical-align: top;
  margin-top: 1px;
}
.topbar-right { display: flex; align-items: center; gap: 16px; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--blue-bg);
  color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}
.user-name { font-size: 14px; color: var(--text-secondary); }
.topbar-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: var(--transition);
}
.topbar-logout:hover { color: var(--text); background: var(--bg); }

/* ===== Main content ===== */
.main { max-width: 960px; margin: 0 auto; padding: 32px 24px 80px; }

/* ===== View transitions ===== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.page-content { animation: fadeIn 0.2s ease; }

/* ===== Trust status summary ===== */
.trust-summary { display: flex; gap: 16px; margin-bottom: 32px; }
.trust-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  color: inherit;
}
.trust-card:hover { box-shadow: var(--shadow-md); border-color: transparent; }
.trust-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.trust-dot.green { background: var(--green); }
.trust-dot.yellow { background: var(--yellow); }
.trust-dot.red { background: var(--red); }
.trust-count { font-size: 28px; font-weight: 700; line-height: 1; }
.trust-label { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.trust-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 32px; }

/* ===== Section headers ===== */
.section-header {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-header .count {
  background: var(--red-bg);
  color: var(--red);
  font-size: 12px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 10px;
}

/* ===== Drift cards ===== */
.drift-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 12px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  color: inherit;
}
.drift-card:hover { box-shadow: var(--shadow-md); border-color: transparent; }
.drift-indicator {
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}
.drift-indicator.red { background: var(--red); }
.drift-indicator.yellow { background: var(--yellow); }
.drift-body { flex: 1; }
.drift-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.drift-desc { font-size: 14px; color: var(--text-secondary); margin-bottom: 8px; }
.drift-meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 16px; flex-wrap: wrap; }
.drift-action {
  align-self: center;
  padding: 7px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  text-decoration: none;
}
.drift-action:hover { background: var(--surface); border-color: var(--blue); color: var(--blue); }

/* ===== Back button ===== */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 24px;
  transition: var(--transition);
  text-decoration: none;
}
.back-btn:hover { color: var(--text); }
.back-btn svg { width: 16px; height: 16px; }

/* ===== Review page ===== */
.review-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.save-status {
  font-size: 13px;
  font-weight: 500;
  margin-left: auto;
  transition: opacity 0.3s ease;
}
.save-status:empty { opacity: 0; }
.save-status.saving { color: var(--text-muted); }
.save-status.saved { color: var(--green, #22c55e); }
.save-status.error { color: var(--red, #ef4444); }
.review-title { font-size: 22px; font-weight: 700; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
}
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.review-subtitle { font-size: 14px; color: var(--text-muted); margin-bottom: 28px; }

/* ===== Comparison columns ===== */
.comparison {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}
.comp-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.comp-col-header {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.comp-col-body { font-size: 14px; line-height: 1.7; color: var(--text); }
.comp-col.intended { border-top: 3px solid var(--blue); }
.comp-col.current { border-top: 3px solid var(--red); }
.comp-col.changed { border-top: 3px solid var(--yellow); }

/* ===== Explanation box ===== */
.explanation-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}
.explanation-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.explanation-text { font-size: 14px; line-height: 1.7; color: var(--text-secondary); }
.evidence-box {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-top: 14px;
}
.evidence-label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.evidence-item { font-size: 13px; color: var(--text-secondary); padding: 2px 0; }
.evidence-item::before { content: "\b7"; margin-right: 8px; color: var(--text-muted); }

/* ===== Action buttons ===== */
.actions {
  display: flex;
  gap: 12px;
  margin-top: 28px;
}
.btn {
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: #15803d; }
.btn-danger { background: var(--red); color: #fff; border: 1px solid var(--red); }
.btn-danger:hover { background: #b91c1c; }
.btn-danger-outline { background: transparent; color: var(--red); border: 1px solid var(--red-border); }
.btn-danger-outline:hover { background: var(--red-bg); }
.btn-secondary { background: var(--surface); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-blue { background: var(--blue); color: #fff; }
.btn-blue:hover { background: #1d4ed8; }

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 14px;
  padding: 32px;
  max-width: 520px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.modal-list { list-style: none; margin-bottom: 20px; }
.modal-list li {
  padding: 6px 0;
  font-size: 14px;
  color: var(--text);
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.modal-list li::before { content: "\2022"; color: var(--text-muted); flex-shrink: 0; }
.modal-will { margin-bottom: 20px; }
.modal-will-label { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; }
.modal-will-item {
  font-size: 14px;
  color: var(--green);
  padding: 3px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.modal-will-item svg { width: 14px; height: 14px; flex-shrink: 0; }
.modal-note { margin-bottom: 24px; }
.modal-note label { font-size: 13px; color: var(--text-secondary); display: block; margin-bottom: 6px; }
.modal-note textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 70px;
  line-height: 1.5;
  color: var(--text);
}
.modal-note textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-bg); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ===== Feature/Intent card page ===== */
.feature-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
}
.feature-meta { font-size: 14px; color: var(--text-muted); margin-top: 6px; }
.feature-meta span { margin-right: 16px; }

.feature-goal {
  margin-bottom: 20px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.feature-goal-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.feature-goal-text { font-size: 15px; line-height: 1.6; }

.behavior-list { margin-bottom: 28px; }
.behavior-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.behavior-check {
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}
.behavior-check.green { background: var(--green-bg); color: var(--green); }
.behavior-check.yellow { background: var(--yellow-bg); color: var(--yellow); }
.behavior-check.red { background: var(--red-bg); color: var(--red); }
.behavior-check.gray { background: var(--bg); color: var(--text-muted); }
.behavior-check svg { width: 12px; height: 12px; }
.behavior-text { font-size: 14px; }
.behavior-detail { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.clause-detail { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Rendered markdown in view mode */
.markdown-content { font-size: 14px; line-height: 1.6; }
.markdown-content p { margin: 0; }
.markdown-content p + p { margin-top: 6px; }
.markdown-content ul, .markdown-content ol { padding-left: 22px; margin: 4px 0; }
.markdown-content li { margin: 2px 0; }
.markdown-content strong { font-weight: 600; color: var(--text); }
.markdown-content em { font-style: italic; }
.markdown-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 13px;
}
.markdown-content td, .markdown-content th {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.markdown-content th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.markdown-content del { text-decoration: line-through; color: var(--text-muted); }
.markdown-content code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.tab {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: var(--transition);
  text-decoration: none;
}
.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--text); border-bottom-color: var(--text); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Timeline ===== */
.timeline { padding: 0; }
.timeline-item {
  display: flex;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.timeline-icon.drift { background: var(--red-bg); color: var(--red); }
.timeline-icon.decision { background: var(--green-bg); color: var(--green); }
.timeline-icon.spec { background: var(--blue-bg); color: var(--blue); }
.timeline-icon.flag { background: var(--yellow-bg); color: var(--yellow); }
.timeline-icon svg { width: 16px; height: 16px; }
.timeline-date { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.timeline-title { font-size: 14px; font-weight: 500; }
.timeline-desc { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.timeline-note {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 8px;
  font-style: italic;
}

/* ===== Specs list ===== */
.specs-list { margin-top: 8px; }
.spec-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  color: inherit;
}
.spec-row:hover { box-shadow: var(--shadow); border-color: transparent; }
.spec-row-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.spec-row-name { font-size: 14px; font-weight: 600; flex: 1; }
.spec-row-meta { font-size: 13px; color: var(--text-muted); }
.spec-row-owner { font-size: 13px; color: var(--text-secondary); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 32px;
  right: 32px;
  background: var(--text);
  color: #fff;
  padding: 14px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  display: none;
  align-items: center;
  gap: 8px;
  animation: slideUp 0.3s ease;
}
.toast.active { display: flex; }
.toast svg { width: 18px; height: 18px; }

/* ===== Acceptance criteria list ===== */
.criteria-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.criteria-item {
  padding: 8px 0;
  font-size: 14px;
  color: var(--text-secondary);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border-bottom: 1px solid var(--bg);
}
.criteria-item:last-child { border-bottom: none; }
.criteria-check { color: var(--green); flex-shrink: 0; margin-top: 2px; }
.criteria-check.green { color: var(--green); }
.criteria-check.red { color: var(--red); }
.criteria-check.gray { color: var(--text-muted); }
.criteria-check svg { width: 14px; height: 14px; }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; color: var(--green); }
.empty-state h3 { font-size: 16px; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p { font-size: 14px; }

/* ===== Editor ===== */
.editor-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 400px;
  padding: 24px;
}
.editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.editor-meta-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.field-group { display: flex; flex-direction: column; gap: 4px; }
.field-group label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.field-group input,
.field-group select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
}
.field-group input:focus,
.field-group select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}

.editor-section {
  margin-bottom: 24px;
}
.editor-section-header {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.editor-section-header button {
  font-size: 12px;
  color: var(--blue);
  background: none;
  border: none;
  cursor: pointer;
  font-weight: 500;
}
.editor-section-header button:hover { text-decoration: underline; }

.statement-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  background: var(--surface);
  position: relative;
  transition: var(--transition);
}
.statement-item:hover { border-color: var(--blue-border); }
.statement-item:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-bg); }
.statement-bullet {
  color: var(--text-muted);
  margin-top: 2px;
  flex-shrink: 0;
  user-select: none;
}
.statement-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  color: var(--text);
  resize: none;
  min-height: 22px;
  background: transparent;
}
/* ===== Three-dot dropdown menu ===== */
.statement-menu {
  position: relative;
  flex-shrink: 0;
}
.menu-trigger {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 1px;
  line-height: 1;
  opacity: 0;
}
.statement-item:hover .menu-trigger,
.statement-item:focus-within .menu-trigger,
.menu-trigger.active,
.menu-trigger.loading {
  opacity: 1;
}
.menu-trigger:hover { background: var(--bg); color: var(--text); }
.menu-trigger.active { background: var(--bg); color: var(--text); }
.menu-trigger.loading {
  pointer-events: none;
  color: var(--purple);
  animation: spin 0.8s linear infinite;
}
@keyframes menuPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.menu-trigger.loading { animation: menuPulse 1s ease-in-out infinite; }

.menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 50;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 4px;
  margin-top: 4px;
}
.menu-dropdown.open { display: block; animation: fadeIn 0.12s ease; }

.menu-dropdown button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: var(--transition);
}
.menu-dropdown button:hover { background: var(--bg); }
.menu-dropdown button svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--text-muted);
}
.menu-dropdown button:hover svg { color: var(--purple); }
.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
.menu-danger { color: var(--red) !important; }
.menu-danger:hover { background: var(--red-bg) !important; }
.menu-danger svg { color: var(--red) !important; }

.ai-suggestion {
  background: var(--blue-bg);
  border: 1px solid var(--blue-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-top: 6px;
  margin-bottom: 6px;
}
.ai-suggestion-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--blue);
  margin-bottom: 6px;
}
.ai-suggestion-text { font-size: 14px; color: var(--text); line-height: 1.5; }
.ai-suggestion-actions { display: flex; gap: 8px; margin-top: 8px; }
.ai-suggestion-actions button {
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}
.ai-accept { background: var(--green); color: #fff; }
.ai-accept:hover { background: #15803d; }
.ai-reject { background: var(--surface); color: var(--text-secondary); border: 1px solid var(--border); }
.ai-reject:hover { background: var(--bg); }

/* ===== Loading indicator ===== */
.htmx-indicator {
  display: none;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-block;
}
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.htmx-request #tab-content {
  opacity: 0.5;
  transition: opacity 0.15s;
}

.ai-loading {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--purple);
  padding: 4px 8px;
}
.ai-loading .spinner {
  width: 12px; height: 12px;
  border-width: 1.5px;
  border-top-color: var(--purple);
}

/* ===== Page header ===== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.page-title { font-size: 20px; font-weight: 700; }

/* ===== Constraints list ===== */
.constraints-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.constraint-item {
  padding: 8px 0;
  font-size: 14px;
  color: var(--text-secondary);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border-bottom: 1px solid var(--bg);
}
.constraint-item:last-child { border-bottom: none; }
.constraint-icon { color: var(--yellow); flex-shrink: 0; margin-top: 2px; }
.constraint-icon.green { color: var(--green); }
.constraint-icon.red { color: var(--red); }
.constraint-icon.gray { color: var(--text-muted); }
.constraint-icon svg { width: 14px; height: 14px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .topbar { padding: 0 16px; }
  .main { padding: 20px 16px 60px; }
  .trust-summary { flex-direction: column; gap: 8px; }
  .comparison { grid-template-columns: 1fr; }
  .editor-meta-fields { grid-template-columns: 1fr; }
  .actions { flex-direction: column; }
  .actions .btn { width: 100%; justify-content: center; }
  .drift-card { flex-direction: column; gap: 12px; }
  .drift-action { align-self: flex-start; }
  .modal { margin: 16px; max-width: none; }
  .feature-header { flex-direction: column; gap: 16px; }
}

/* ===== Settings page ===== */
.settings-form { max-width: 640px; }
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.settings-section-header {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.settings-icon { width: 22px; height: 22px; color: var(--text-secondary); }
.settings-description {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}
.settings-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
}
.status-badge.connected { background: var(--green-bg); color: var(--green); }
.status-badge.disconnected { background: var(--bg); color: var(--text-muted); }
.settings-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}
.settings-fields .field-group input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
}
.settings-fields .field-group input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}
.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.field-hint a { color: var(--blue); text-decoration: none; }
.field-hint a:hover { text-decoration: underline; }
.field-hint code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}
.field-group-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.settings-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}


/* ===== Settings gear icon (topbar) ===== */
.topbar-settings {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: var(--transition);
  text-decoration: none;
}
.topbar-settings:hover { background: var(--bg); color: var(--text); }
.topbar-settings svg { width: 18px; height: 18px; }

/* ===== GitHub error banner ===== */
.gh-error-banner {
  background: var(--red-bg);
  border-bottom: 1px solid var(--red-border);
  padding: 10px 32px;
  font-size: 13px;
  color: var(--red);
  display: flex;
  align-items: center;
  gap: 8px;
}
.gh-error-banner svg { width: 16px; height: 16px; flex-shrink: 0; }
.gh-error-banner span { flex: 1; }
.gh-error-banner a {
  color: var(--red);
  font-weight: 600;
  text-decoration: underline;
  white-space: nowrap;
}

/* ===== Pending changes banner ===== */
.pending-banner {
  background: var(--blue-bg);
  border: 1px solid var(--blue-border);
  border-radius: var(--radius);
  padding: 14px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.pending-banner-text {
  font-size: 14px;
  color: var(--blue);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pending-banner-text svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ===== Submit preview modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: backdropIn 0.15s ease;
}
@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }
.modal-backdrop .dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 500px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  animation: dialogIn 0.2s ease;
}
@keyframes dialogIn { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
  flex-shrink: 0;
}
.dialog-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
.dialog-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.dialog-close:hover { color: var(--text); }
.dialog-body {
  padding: 16px 24px;
  overflow-y: auto;
  min-height: 0;
}
.dialog-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 14px;
}
.dialog-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--blue-bg);
  border: 1px solid var(--blue-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--blue);
  font-weight: 500;
  margin-bottom: 14px;
}
.dialog-notice svg { width: 16px; height: 16px; flex-shrink: 0; }
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.dialog-footer-right {
  display: flex;
  gap: 8px;
}
.dialog-footer-count {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ===== Submit preview list ===== */
.submit-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.submit-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
}
.submit-item:hover { background: var(--bg); }
.submit-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: var(--blue);
  cursor: pointer;
}
.submit-item-body { flex: 1; min-width: 0; }
.submit-item-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.submit-item-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}
.submit-item.unchecked .submit-item-name,
.submit-item.unchecked .submit-item-meta { opacity: 0.45; }
.submit-item-delete { border-left: 3px solid var(--red); }
.badge-delete {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--red);
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  border-radius: 4px;
  padding: 0 5px;
  margin-left: 6px;
  vertical-align: middle;
  line-height: 18px;
}
.submit-select-all {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.submit-select-all input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
  cursor: pointer;
}

/* ===== Secondary button ===== */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.btn-secondary:hover { background: var(--bg); }

@media (max-width: 768px) {
  .field-group-row { grid-template-columns: 1fr; }
  .settings-actions { flex-direction: column; }
  .settings-actions .btn { width: 100%; justify-content: center; }
  .pending-banner { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
  .topbar-nav { display: none; }
  .user-name { display: none; }
  .review-title { font-size: 18px; }
  .menu-trigger { opacity: 1; }
}

/* ===== Tiptap editors ===== */
.tiptap-wrapper {
  flex: 1;
  min-width: 0;
}
.tiptap-mount .ProseMirror {
  outline: none;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  color: var(--text);
  min-height: 22px;
  cursor: text;
  caret-color: var(--text);
}
.tiptap-mount .ProseMirror p { margin: 0; }
.tiptap-mount .ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  color: var(--text-muted);
  pointer-events: none;
  height: 0;
}

/* Context editor with toolbar */
.tiptap-context-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
  transition: var(--transition);
}
.tiptap-context-wrap:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}
.tiptap-context-wrap .tiptap-mount .ProseMirror {
  padding: 10px 14px;
  min-height: 80px;
}
.tiptap-mount .ProseMirror ul,
.tiptap-mount .ProseMirror ol {
  padding-left: 24px;
  margin: 4px 0;
}
.tiptap-mount .ProseMirror li { margin: 2px 0; }
.tiptap-mount .ProseMirror li p { margin: 0; }

/* Toolbar */
.tiptap-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.tiptap-toolbar button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: var(--transition);
}
.tiptap-toolbar button:hover { background: var(--surface); color: var(--text); }
.tiptap-toolbar button.active { background: var(--blue-bg); color: var(--blue); }
.tiptap-toolbar button:disabled { opacity: 0.3; cursor: default; }
.tiptap-toolbar button:disabled:hover { background: none; color: var(--text-secondary); }
.tiptap-toolbar-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 4px;
}

/* Bubble menu (floating on text selection) */
.tiptap-bubble-menu {
  position: fixed;
  z-index: 9999;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--text);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
}
.tiptap-bubble-menu .bubble-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  border-radius: 5px;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: color 0.12s ease, background 0.12s ease;
}
.tiptap-bubble-menu .bubble-btn:hover { color: #fff; }
.tiptap-bubble-menu .bubble-btn.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
}
.tiptap-bubble-menu .bubble-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.tiptap-bubble-menu .bubble-btn-danger { color: rgba(255, 100, 100, 0.8); }
.tiptap-bubble-menu .bubble-btn-danger:hover { color: #ff6b6b; }
.tiptap-bubble-menu .bubble-separator {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 2px;
}
.tiptap-bubble-menu .bubble-link-input {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0 2px 4px;
}
.tiptap-bubble-menu .bubble-link-url {
  width: 180px;
  padding: 3px 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 12px;
  font-family: inherit;
  outline: none;
}
.tiptap-bubble-menu .bubble-link-url::placeholder { color: rgba(255, 255, 255, 0.4); }
.tiptap-bubble-menu .bubble-link-url:focus { border-color: rgba(255, 255, 255, 0.5); }
.tiptap-bubble-menu .bubble-table-group { display: none; }

/* Tables inside tiptap editors */
.tiptap-mount .ProseMirror table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  table-layout: fixed;
  overflow: hidden;
}
.tiptap-mount .ProseMirror td,
.tiptap-mount .ProseMirror th {
  border: 1px solid var(--border);
  padding: 6px 10px;
  font-size: 13px;
  vertical-align: top;
  position: relative;
  min-width: 80px;
}
.tiptap-mount .ProseMirror th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.tiptap-mount .ProseMirror td p,
.tiptap-mount .ProseMirror th p {
  margin: 0;
}
.tiptap-mount .ProseMirror .selectedCell::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--blue-bg);
  pointer-events: none;
  z-index: 1;
}
.tiptap-mount .ProseMirror .column-resize-handle {
  position: absolute;
  right: -2px;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--blue);
  pointer-events: none;
}
.tiptap-mount .ProseMirror .tableWrapper {
  overflow-x: auto;
  margin: 8px 0;
}
.tiptap-context-editor.resize-cursor {
  cursor: col-resize;
}

/* Table controls in toolbar (context editor) */
.tiptap-toolbar-table-group {
  display: contents;
}
.tiptap-toolbar-table-group .tiptap-table-controls-danger:hover {
  color: var(--red, #ef4444) !important;
  background: rgba(239, 68, 68, 0.1);
}

/* Anchored table bar (statement editors) */
.tiptap-wrapper {
  position: relative;
}
.tiptap-anchored-table-bar {
  position: absolute;
  right: 0;
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 2px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  z-index: 10;
}
.tiptap-anchored-table-bar button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}
.tiptap-anchored-table-bar button:hover { background: var(--bg); color: var(--text); }
.tiptap-anchored-table-bar .tiptap-table-controls-danger:hover { color: var(--red, #ef4444); }
.tiptap-anchored-table-bar .tiptap-toolbar-sep {
  width: 1px;
  height: 14px;
  background: var(--border);
  margin: 0 2px;
}
