:root {
  color-scheme: dark;
  --font-display:
    'Clash Grotesk', 'Avenir Next', ui-sans-serif, system-ui, sans-serif;
  --font-body:
    'DM Sans', Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  --ground: #0a0a0a;
  --surface: #111112;
  --surface-raised: #171719;
  --surface-muted: #202023;
  --surface-hover: #29292d;
  --text: #fafafa;
  --text-muted: #a3a3a3;
  --text-soft: #737373;
  --border: rgba(250, 250, 250, 0.12);
  --border-strong: rgba(250, 250, 250, 0.22);
  --accent: #8d2146;
  --accent-soft: rgba(141, 33, 70, 0.2);
  --accent-ring: rgba(232, 106, 82, 0.34);
  --success: #4ade80;
  --success-soft: rgba(34, 197, 94, 0.14);
  --warning: #fbbf24;
  --warning-soft: rgba(245, 158, 11, 0.13);
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.13);
  --focus: #a3a3a3;
  --shadow: 0 18px 70px rgba(0, 0, 0, 0.28);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

[data-theme='light'] {
  color-scheme: light;
  --ground: #f5f5f5;
  --surface: #ffffff;
  --surface-raised: #fafafa;
  --surface-muted: #eeeeef;
  --surface-hover: #e7e7e9;
  --text: #0a0a0a;
  --text-muted: #525252;
  --text-soft: #737373;
  --border: rgba(10, 10, 10, 0.12);
  --border-strong: rgba(10, 10, 10, 0.22);
  --accent-soft: rgba(141, 33, 70, 0.1);
  --accent-ring: rgba(141, 33, 70, 0.25);
  --success: #15803d;
  --success-soft: rgba(22, 163, 74, 0.1);
  --warning: #b45309;
  --warning-soft: rgba(217, 119, 6, 0.1);
  --danger: #b91c1c;
  --danger-soft: rgba(220, 38, 38, 0.09);
  --focus: #525252;
  --shadow: 0 18px 60px rgba(10, 10, 10, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--ground);
  scroll-padding-top: 90px;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
}

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

button,
a,
input,
textarea,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  transform: translateY(-160%);
  border-radius: var(--radius-md);
  background: var(--text);
  color: var(--ground);
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--ground) 92%, transparent);
  backdrop-filter: blur(16px);
}

.brand-block,
.topbar-actions,
.editor-actions,
.editor-actions-primary,
.rule-position,
.summary-heading,
.evidence-header,
.dialog-actions {
  display: flex;
  align-items: center;
}

.brand-block {
  min-width: 0;
  gap: 12px;
}

.brand-block h1 {
  overflow: hidden;
  margin: 1px 0 0;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  margin: 0;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-transform: uppercase;
}

.back-link,
.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--text-muted);
  text-decoration: none;
}

.back-link:hover,
.icon-button:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
  color: var(--text);
}

.topbar-actions {
  gap: 8px;
}

.button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button-primary {
  border-color: var(--text);
  background: var(--text);
  color: var(--ground);
}

.button-primary:hover:not(:disabled) {
  opacity: 0.82;
}

.button-secondary {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.button-secondary:hover:not(:disabled),
.button-quiet:hover:not(:disabled) {
  background: var(--surface-hover);
}

.button-quiet {
  border-color: var(--border);
  background: transparent;
  color: var(--text-muted);
}

.button-danger {
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}

.button-danger:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--danger) 65%, transparent);
}

.text-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.publication-notice {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 7px;
  padding: 8px 20px;
  border-bottom: 1px solid color-mix(in srgb, var(--warning) 20%, var(--border));
  background: var(--warning-soft);
  color: var(--text-muted);
  font-size: 12px;
}

.publication-notice strong {
  color: var(--text);
}

.notice-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--warning);
}

.dataset-label {
  margin-left: auto;
  color: var(--text-soft);
  font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace;
}

.state-card {
  display: flex;
  width: min(620px, calc(100% - 32px));
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin: 15vh auto 0;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.state-card h2,
.editor-empty h2,
.dialog h2 {
  margin: 5px 0 6px;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
}

.state-card p,
.editor-empty p,
.dialog p {
  margin: 0;
  color: var(--text-muted);
}

.state-card-error {
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.spinner {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.workspace {
  display: grid;
  min-height: calc(100vh - 111px);
  grid-template-columns: minmax(260px, 310px) minmax(460px, 1fr) minmax(
      300px,
      380px
    );
}

.queue-panel,
.evidence-panel {
  position: sticky;
  top: 111px;
  height: calc(100vh - 111px);
  overflow: auto;
  background: var(--surface);
}

.queue-panel {
  border-right: 1px solid var(--border);
}

.evidence-panel {
  padding: 22px 18px 40px;
  border-left: 1px solid var(--border);
}

.queue-summary,
.queue-tools {
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.summary-heading {
  justify-content: space-between;
  gap: 12px;
}

.progress-copy {
  margin: 4px 0 0;
  color: var(--text);
  font-weight: 700;
}

.progress-percent {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
}

.progress-track {
  height: 4px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #6a1f36, #8d2146, #e86a52);
  transition: width 180ms ease;
}

.counts {
  display: grid;
  margin: 16px 0 0;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.counts div {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

.counts dt {
  overflow: hidden;
  color: var(--text-soft);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.counts dd {
  margin: 2px 0 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.queue-tools {
  display: grid;
  gap: 12px;
}

.search-field {
  display: flex;
  height: 38px;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--ground);
  color: var(--text-soft);
}

.search-field:focus-within {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.search-field input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

.search-field input::placeholder,
.field textarea::placeholder {
  color: var(--text-soft);
}

.status-filters {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
}

.status-filters button {
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
}

.status-filters button[aria-pressed='true'] {
  border-color: var(--border-strong);
  background: var(--surface-muted);
  color: var(--text);
}

.select-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
}

.select-field select {
  min-width: 126px;
  height: 32px;
  padding: 0 28px 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--ground);
}

.rule-list {
  padding: 8px;
}

.rule-item {
  position: relative;
  display: block;
  margin-bottom: 5px;
  padding: 12px 12px 11px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  text-decoration: none;
}

.rule-item::before {
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 5px;
  width: 3px;
  border-radius: 3px;
  background: transparent;
  content: '';
}

.rule-item:hover {
  background: var(--surface-raised);
}

.rule-item[aria-current='page'] {
  border-color: var(--border);
  background: var(--surface-muted);
}

.rule-item[aria-current='page']::before {
  background: var(--accent);
}

.rule-item-top,
.rule-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rule-item-title {
  display: -webkit-box;
  overflow: hidden;
  margin: 7px 0;
  color: var(--text);
  font-weight: 700;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.rule-item-meta {
  color: var(--text-soft);
  font-size: 10px;
}

.rule-item-id {
  overflow: hidden;
  font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scope-chip,
.evidence-kind {
  display: inline-flex;
  min-height: 20px;
  align-items: center;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.status-badge {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  content: '';
}

.status-proposed {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-approved {
  background: var(--success-soft);
  color: var(--success);
}

.status-active {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--border));
  background: var(--accent-soft);
  color: var(--text);
}

.status-rejected {
  background: var(--danger-soft);
  color: var(--danger);
}

.queue-empty,
.evidence-empty {
  padding: 24px 18px;
  color: var(--text-muted);
  text-align: center;
}

.queue-empty p {
  margin-top: 0;
}

.editor-panel {
  min-width: 0;
  padding: 30px clamp(20px, 3.4vw, 54px) 120px;
}

#ruleForm {
  width: min(760px, 100%);
  margin: 0 auto;
}

.editor-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.rule-position {
  gap: 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.revision-copy {
  margin: 5px 0 0;
  color: var(--text-soft);
  font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace;
  font-size: 11px;
}

.invalidation-note {
  margin-bottom: 18px;
  padding: 11px 12px;
  border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent);
  border-radius: var(--radius-md);
  background: var(--warning-soft);
  color: var(--text-muted);
  font-size: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 21px 18px;
}

.field {
  display: grid;
  min-width: 0;
  gap: 7px;
  margin: 0;
  padding: 0;
  border: 0;
}

.field-wide {
  grid-column: 1 / -1;
}

.field > span,
.field legend {
  padding: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.field > span em {
  margin-left: 4px;
  color: var(--text-soft);
  font-size: 10px;
  font-style: normal;
  font-weight: 500;
}

.field input[type='text'],
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: 0;
  background: var(--surface);
  color: var(--text);
}

.field input[type='text'] {
  min-height: 42px;
  padding: 0 12px;
  font-size: 15px;
  font-weight: 700;
}

.field textarea {
  min-height: 82px;
  padding: 11px 12px;
  line-height: 1.55;
  resize: vertical;
}

.field input[type='text']:focus,
.field textarea:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.field input[aria-invalid='true'],
.field textarea[aria-invalid='true'] {
  border-color: var(--danger);
}

.field > small,
.strength-field small {
  color: var(--text-soft);
  font-size: 10px;
}

.scope-field,
.strength-field {
  align-content: start;
}

.scope-field legend,
.strength-field legend {
  margin-bottom: 8px;
}

.scope-field label,
.strength-field label {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
}

.scope-field label:has(input:checked),
.strength-field label:has(input:checked) {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.scope-field input,
.strength-field input {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.strength-field label > span {
  display: grid;
  gap: 1px;
}

.strength-field strong {
  font-size: 12px;
}

.field-error {
  margin: 0;
  color: var(--danger);
  font-size: 11px;
}

.save-state {
  min-height: 18px;
  margin-top: 18px;
  color: var(--text-soft);
  font-size: 11px;
}

.editor-actions {
  position: sticky;
  z-index: 12;
  bottom: 16px;
  justify-content: space-between;
  gap: 16px;
  margin-top: 22px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.editor-actions-primary {
  justify-content: flex-end;
  gap: 8px;
}

.editor-empty {
  width: min(620px, 100%);
  margin: 14vh auto;
  padding: 28px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-xl);
  text-align: center;
}

.evidence-header {
  justify-content: space-between;
  gap: 12px;
}

.evidence-header h2 {
  margin: 3px 0 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
}

.evidence-count {
  display: inline-grid;
  min-width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
}

.evidence-intro {
  margin: 10px 0 18px;
  color: var(--text-soft);
  font-size: 11px;
}

.verification-panel {
  margin: 0 0 18px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
}

.verification-panel h3 {
  margin: 3px 0 7px;
  font-size: 13px;
}

.verification-panel > p:not(.eyebrow) {
  margin: 0;
  color: var(--text-soft);
  font-size: 10px;
}

.verification-panel ul {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.45;
}

.evidence-list {
  display: grid;
  gap: 10px;
}

.evidence-card {
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
}

.evidence-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.evidence-product {
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.evidence-path {
  overflow-wrap: anywhere;
  margin: 10px 0 0;
  color: var(--text-soft);
  font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace;
  font-size: 10px;
}

.evidence-excerpt {
  margin: 10px 0 0;
  padding: 10px;
  border-left: 2px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 11px;
  white-space: pre-wrap;
}

.evidence-rationale {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-size: 11px;
}

.evidence-link {
  display: inline-flex;
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 800;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.dialog {
  width: min(480px, calc(100% - 28px));
  padding: 22px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(10, 10, 10, 0.72);
  backdrop-filter: blur(2px);
}

.dialog .field {
  margin-top: 20px;
}

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

.toast {
  position: fixed;
  z-index: 80;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100% - 36px));
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--text);
  color: var(--ground);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 700;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(250px, 300px) minmax(480px, 1fr);
  }

  .evidence-panel {
    position: relative;
    top: auto;
    height: auto;
    grid-column: 2;
    padding: 24px clamp(20px, 3.4vw, 54px) 60px;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  .evidence-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 800px) {
  .topbar {
    position: relative;
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .publication-notice {
    flex-wrap: wrap;
  }

  .dataset-label {
    width: 100%;
    margin-left: 14px;
  }

  .workspace {
    display: block;
  }

  .queue-panel,
  .evidence-panel {
    position: relative;
    top: auto;
    height: auto;
    border: 0;
  }

  .queue-panel {
    border-bottom: 1px solid var(--border);
  }

  .rule-list {
    display: flex;
    overflow-x: auto;
    padding: 8px 14px 14px;
    scroll-snap-type: x proximity;
  }

  .rule-item {
    width: 250px;
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  .queue-empty {
    padding: 18px;
  }

  .editor-panel {
    padding-top: 24px;
  }

  .evidence-panel {
    grid-column: auto;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 560px) {
  .topbar,
  .publication-notice {
    padding-right: 14px;
    padding-left: 14px;
  }

  .topbar-actions .button {
    min-height: 36px;
    padding: 0 11px;
  }

  .counts {
    grid-template-columns: repeat(3, minmax(72px, 1fr));
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .field-wide {
    grid-column: auto;
  }

  .editor-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .editor-actions-primary {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  #approveNextButton {
    grid-column: 1 / -1;
  }

  .evidence-list {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
