:root {
  --bg: #fafaf7;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e4e4dd;
  --accent: #2a4d3a;
  --proposed: #b58900;
  --ratified: #2a4d3a;
  --dismissed: #8a8a8a;
  --row-hover: #f3f3ee;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: white;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: baseline;
}

.brand .tag {
  color: var(--muted);
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 0;
}

.tabs button {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 16px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  border-radius: 0;
}

.tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tabs button:hover {
  color: var(--accent);
}

main {
  padding: 24px;
  max-width: 1600px;
  margin: 0 auto;
}

h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 32px 0 12px;
}

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

.queue-header .meta {
  display: flex;
  gap: 16px;
  color: var(--muted);
  font-size: 13px;
}

.filters button {
  background: white;
  border: 1px solid var(--line);
  padding: 6px 12px;
  margin-left: -1px;
  cursor: pointer;
  font-size: 13px;
}

.filters button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--line);
  font-size: 13px;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  background: #f3f3ee;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
}

tr:hover {
  background: var(--row-hover);
}

.id {
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--muted);
  font-size: 11px;
}

.field-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.field-list li {
  font-size: 12px;
  margin-bottom: 2px;
}

.field-list code {
  background: #f3f3ee;
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 12px;
}

.field-list .card {
  color: var(--muted);
  margin-left: 4px;
  font-size: 11px;
}

.rationale {
  max-width: 380px;
  color: var(--fg);
}

.rationale .pages {
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge.state-proposed {
  background: var(--proposed);
}

.badge.state-ratified {
  background: var(--ratified);
}

.badge.state-dismissed {
  background: var(--dismissed);
}

tr.state-dismissed {
  opacity: 0.5;
}

tr.state-ratified td {
  background: rgba(42, 77, 58, 0.04);
}

.actions {
  white-space: nowrap;
}

.actions button {
  background: white;
  border: 1px solid var(--line);
  padding: 4px 10px;
  margin-right: 4px;
  cursor: pointer;
  font-size: 12px;
  border-radius: 3px;
}

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

.edit-form {
  padding: 16px;
  background: #f9f9f4;
}

.edit-form label {
  display: block;
  margin-bottom: 8px;
}

.field-editor {
  margin: 12px 0;
}

.field-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

.field-row input,
.field-row select {
  padding: 4px 8px;
  border: 1px solid var(--line);
  font-size: 13px;
}

input,
select,
textarea {
  font: inherit;
  border: 1px solid var(--line);
  padding: 6px 8px;
  background: white;
  border-radius: 3px;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.instance-controls {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 3px;
}

.instance-controls label {
  display: flex;
  gap: 8px;
  align-items: center;
}

.instance-controls .count {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

.instance-table {
  table-layout: auto;
}

.instance-table th .field-type {
  font-weight: normal;
  font-size: 10px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  margin-top: 2px;
}

.instance-table .source a {
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--muted);
}

.image-input img {
  max-width: 120px;
  max-height: 60px;
  display: block;
  margin-bottom: 4px;
  object-fit: cover;
}

.list-input {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.list-input button {
  align-self: flex-start;
  padding: 2px 8px;
  border: 1px dashed var(--line);
  background: transparent;
  font-size: 11px;
  cursor: pointer;
  color: var(--muted);
}

.enum-multi {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.enum-multi label {
  display: flex;
  gap: 4px;
  font-size: 12px;
  white-space: nowrap;
}

.enum-multi input {
  width: auto;
}

.row-actions button {
  padding: 4px 10px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 3px;
  cursor: pointer;
}

.chrome {
  background: white;
  border: 1px solid var(--line);
  padding: 12px 24px;
  list-style: none;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
}

.chrome li {
  color: var(--muted);
}

.loading,
.empty {
  padding: 32px;
  text-align: center;
  color: var(--muted);
}

.type-jump {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.type-jump button {
  background: white;
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
  color: var(--fg);
}

.type-jump button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.orphan-warning {
  background: #fff8e0;
  border: 1px solid #d8c060;
  border-radius: 3px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: #5a4a10;
}

.orphan-warning code {
  font-family: ui-monospace, SFMono-Regular, monospace;
  background: white;
  padding: 1px 6px;
  border-radius: 2px;
  font-size: 12px;
}

.error {
  padding: 16px;
  background: #fff0f0;
  color: #8a2a2a;
  border: 1px solid #e0b0b0;
  border-radius: 3px;
}

/* ── Clickable table rows ─────────────────────────────────────────────── */
.clickable-row {
  cursor: pointer;
}
.clickable-row:hover td {
  background: var(--row-hover);
}

/* ── Structure surface header ─────────────────────────────────────────── */
.header-right {
  display: flex;
  gap: 12px;
  align-items: center;
}

.btn-publish {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 3px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-publish:hover { opacity: 0.88; }
.btn-publish:disabled { opacity: 0.5; cursor: default; }

.publish-msg {
  background: #e8f3eb;
  border: 1px solid #9ecba8;
  border-radius: 3px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 12px;
}

/* ── Revision bar (top-level prompt) ──────────────────────────────────── */
.revision-bar {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 20px;
  padding: 14px 16px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 3px;
}

.revision-input-sm {
  flex: 1;
  resize: vertical;
  min-height: 48px;
}

.revision-error {
  margin-top: 0;
  font-size: 12px;
}

/* ── Revision preview panel ───────────────────────────────────────────── */
.revision-preview {
  margin: 12px 0 20px;
  background: #f7f7f2;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 16px;
}

.revision-preview-header {
  display: flex;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 12px;
}

.revision-rationale {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

.diff-section {
  margin: 10px 0;
}

.diff-section h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 6px;
}

.diff-updated { color: #b58900; font-size: 13px; }
.diff-new     { color: var(--accent); font-size: 13px; }
.diff-removed { color: #8a2a2a; font-size: 13px; }

.diff-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
}

.diff-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 6px;
}

.revision-preview-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

/* ── Detail views (type + chrome) ─────────────────────────────────────── */
.detail-view {
  /* no max-width clamp — it's already inside main */
}

.detail-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.back-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}
.back-btn:hover { text-decoration: underline; }

.detail-actions {
  display: flex;
  gap: 8px;
}

.btn-ratify {
  background: var(--ratified);
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 3px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn-ratify:hover { opacity: 0.88; }

.btn-dismiss {
  background: white;
  color: var(--fg);
  border: 1px solid var(--line);
  padding: 6px 14px;
  border-radius: 3px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn-dismiss:hover { border-color: #8a2a2a; color: #8a2a2a; }

.detail-header {
  margin-bottom: 24px;
}

.detail-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 8px;
}

.detail-meta {
  display: flex;
  gap: 10px;
  align-items: center;
}

.detail-kind,
.detail-scope {
  font-size: 12px;
  color: var(--muted);
  background: #f3f3ee;
  padding: 2px 8px;
  border-radius: 10px;
}

.detail-url {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
  background: #f3f3ee;
  padding: 2px 8px;
  border-radius: 3px;
  color: var(--fg);
}

.detail-body section {
  margin-bottom: 32px;
}

.muted { color: var(--muted); }

/* ── Type detail: occurrences ─────────────────────────────────────────── */
.occurrence-list {
  background: white;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 14px 16px;
}

.occ-stat {
  font-size: 14px;
  margin-bottom: 10px;
}

.conf-badge {
  margin-left: 12px;
  font-size: 12px;
  color: var(--muted);
  background: #f3f3ee;
  padding: 2px 8px;
  border-radius: 10px;
}

.page-links {
  list-style: none;
  padding: 0;
  margin: 0 0 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.page-links a {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
  color: var(--accent);
}

.occ-rationale {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  margin: 0;
}

/* ── Type detail: revision section ────────────────────────────────────── */
.revision-section {
  background: white;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 20px;
}

.revision-hint {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 12px;
}

.revision-input {
  display: block;
  width: 100%;
  resize: vertical;
  margin-bottom: 10px;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 3px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

/* ── Chrome detail ────────────────────────────────────────────────────── */
.chrome-edit-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 16px;
  max-width: 600px;
}

.chrome-edit-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.chrome-edit-form span {
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chrome-selectors {
  list-style: none;
  padding: 0;
  margin: 0;
  background: white;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chrome-selectors code {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 13px;
}

.chrome-reclassify-hint {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 12px;
}

/* ── Content surface ──────────────────────────────────────────────────── */
.content-surface {
  position: relative;
}

.content-controls {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 3px;
}

.content-controls label {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.content-controls .count {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

.entries-table .entry-type-badge {
  font-size: 11px;
  background: #f3f3ee;
  padding: 2px 8px;
  border-radius: 10px;
  color: var(--muted);
}

/* ── Entry editor panel ───────────────────────────────────────────────── */
.entry-editor-panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 20px;
  margin-bottom: 16px;
}

.entry-editor-nav {
  margin-bottom: 16px;
}

.entry-editor {
  max-width: 640px;
}

.entry-meta {
  display: flex;
  gap: 16px;
  align-items: baseline;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.entry-type {
  font-weight: 600;
  font-size: 14px;
}

.entry-source {
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--muted);
}

.entry-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.entry-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.entry-field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.entry-field-name {
  font-weight: 600;
  font-size: 13px;
}

.entry-field-type {
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, monospace;
}

.entry-field-input {
  /* container for the input */
}

.entry-footer {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* ── Ref chips ────────────────────────────────────────────────────────── */
.ref-field {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ref-chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  background: #e8f3eb;
  border: 1px solid #9ecba8;
  border-radius: 14px;
  padding: 3px 10px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.ref-chip:hover { background: #d4ebda; }

.ref-chip-type {
  font-size: 11px;
  color: var(--muted);
  background: white;
  padding: 1px 6px;
  border-radius: 8px;
}

/* ── Flyout drawer ────────────────────────────────────────────────────── */
.flyout-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 100;
}

.flyout-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 520px;
  max-width: 90vw;
  background: white;
  border-left: 1px solid var(--line);
  z-index: 101;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.08);
}

.flyout-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: #f9f9f4;
  flex-shrink: 0;
}

.flyout-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  flex-wrap: wrap;
}

.breadcrumb-sep {
  color: var(--muted);
  margin: 0 2px;
}

.breadcrumb-link {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}
.breadcrumb-link:hover { text-decoration: underline; }

.breadcrumb-current {
  font-weight: 600;
  color: var(--fg);
}

.flyout-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
}
.flyout-close:hover { color: var(--fg); }

.flyout-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
