:root {
  --brand: #3ecf8e;
  --bg: #1c1c1c;
  --surface: #2e2e2e;
  --surface-2: #262626;
  --surface-3: #222222;
  --text: #ededed;
  --muted: #888888;
  --border: #333333;
  --success: #3ecf8e;
  --error: #f66061;
  --warning: #f4bd50;
  --blue: #66a3ff;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --font-body: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-code: "Source Code Pro", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
}

body.auth-pending .shell,
body.auth-locked .shell {
  display: none;
}

.auth-gate {
  align-items: center;
  display: grid;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  display: grid;
  gap: 16px;
  margin: 0 auto;
  max-width: 460px;
  padding: 28px;
  width: min(100%, 460px);
}

.auth-card h1 {
  font-size: 34px;
}

.auth-eyebrow,
.auth-field span,
.auth-submit {
  font-family: var(--font-code);
  text-transform: uppercase;
}

.auth-eyebrow {
  color: var(--brand);
  font-size: 12px;
  margin: 0;
}

.auth-copy {
  color: var(--muted);
  margin: 0;
}

.auth-field {
  display: grid;
  gap: 8px;
}

.auth-field span {
  color: var(--muted);
  font-size: 12px;
}

.auth-field input {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  min-height: 44px;
  outline: 0;
  padding: 10px 12px;
}

.auth-field input:focus {
  border-color: var(--brand);
}

.auth-submit {
  background: var(--brand);
  border: 1px solid var(--brand);
  border-radius: 6px;
  color: var(--bg);
  font-size: 12px;
  font-weight: 700;
  min-height: 42px;
  padding: 10px 14px;
}

.auth-error {
  color: var(--error);
  font-family: var(--font-code);
  font-size: 13px;
  margin: 0;
  min-height: 20px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1760px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar {
  display: grid;
  gap: 18px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 22px;
}

.nav-row,
.title-row {
  align-items: flex-start;
  display: flex;
  gap: 18px;
  justify-content: space-between;
}

.module-nav {
  display: inline-flex;
  gap: 8px;
}

.module-nav a,
.filter,
.filter-toggle,
.export-button,
.row-action {
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 36px;
}

.module-nav a {
  align-items: center;
  background: var(--surface);
  color: var(--muted);
  display: inline-flex;
  font-family: var(--font-code);
  font-size: 12px;
  padding: 8px 12px;
  text-decoration: none;
  text-transform: uppercase;
}

.module-nav a.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--bg);
}

.eyebrow,
.metric-label,
.snapshot-meta,
.filter,
.filter-toggle,
.filter-option,
.search span,
th,
.badge,
.export-button,
.row-action,
.small-label {
  font-family: var(--font-code);
  letter-spacing: 0;
  text-transform: uppercase;
}

.eyebrow {
  color: var(--brand);
  font-size: 13px;
  margin: 0 0 4px;
}

h1 {
  font-size: 48px;
  font-weight: 700;
  line-height: 1.1;
  margin: 0;
}

.snapshot-meta {
  color: var(--muted);
  font-size: 12px;
  margin: 10px 0 0;
  text-align: right;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(8, minmax(104px, 1fr));
  gap: 8px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  min-height: 74px;
  padding: 14px;
}

.metric-value {
  display: block;
  font-family: var(--font-code);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.metric-label {
  color: var(--muted);
  display: block;
  font-size: 11px;
  margin-top: 8px;
}

.controls {
  align-items: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 480px);
  gap: 16px;
  padding: 16px 0;
}

.filter-dropdown {
  position: relative;
  width: min(100%, 320px);
  z-index: 10;
}

.filter-toggle {
  align-items: center;
  background: var(--surface);
  color: var(--muted);
  display: flex;
  font-size: 12px;
  gap: 12px;
  justify-content: space-between;
  padding: 8px 12px;
  width: 100%;
}

.filter-toggle strong {
  color: var(--text);
  font: inherit;
}

.filter-toggle[aria-expanded="true"] {
  border-color: var(--brand);
}

.filter-menu {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  display: grid;
  gap: 4px;
  left: 0;
  margin-top: 6px;
  min-width: 260px;
  padding: 8px;
  position: absolute;
  top: 100%;
}

.filter-menu[hidden] {
  display: none;
}

.filter-option {
  align-items: center;
  border-radius: 6px;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  gap: 10px;
  min-height: 34px;
  padding: 7px 8px;
}

.filter-option:hover {
  background: var(--surface-3);
  color: var(--text);
}

.filter-option input {
  accent-color: var(--brand);
  height: 16px;
  width: 16px;
}

.search {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
}

.search span {
  color: var(--muted);
  font-size: 12px;
}

.search input {
  background: transparent;
  border: 0;
  color: var(--text);
  font-family: var(--font-code);
  font-size: 14px;
  min-width: 0;
  outline: 0;
}

.export-button {
  background: transparent;
  color: var(--muted);
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 12px;
  white-space: nowrap;
}

.export-button:hover {
  border-color: rgba(62, 207, 142, 0.55);
  color: var(--brand);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(540px, 0.95fr) minmax(0, 1.45fr);
  gap: 16px;
  min-height: calc(100vh - 236px);
}

body:not(.detail-view) .workspace {
  display: block;
}

body:not(.detail-view) .detail-panel {
  display: none;
}

.detail-view .controls {
  display: none;
}

.detail-view .workspace {
  display: block;
}

.detail-view .findings-panel {
  display: none;
}

.findings-panel,
.detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.findings-panel {
  overflow: visible;
}

.list-meta {
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--font-code);
  font-size: 14px;
  min-height: 42px;
  padding: 10px 12px;
}

.table-wrap {
  overflow: auto;
}

.findings-wrap {
  max-height: none;
  overflow: hidden;
}

.findings-wrap table {
  min-width: 0;
  table-layout: fixed;
  width: 100%;
}

.findings-wrap th,
.findings-wrap td {
  max-width: none;
  overflow-wrap: anywhere;
}

.findings-wrap th:nth-child(1),
.findings-wrap td:nth-child(1) {
  width: 24%;
}

.findings-wrap th:nth-child(2),
.findings-wrap td:nth-child(2) {
  width: 8%;
}

.findings-wrap th:nth-child(3),
.findings-wrap td:nth-child(3) {
  width: 14%;
}

.findings-wrap th:nth-child(4),
.findings-wrap td:nth-child(4) {
  width: 7%;
}

.findings-wrap th:nth-child(5),
.findings-wrap td:nth-child(5) {
  width: 6%;
}

.findings-wrap th:nth-child(6),
.findings-wrap td:nth-child(6) {
  width: 9%;
}

.findings-wrap th:nth-child(7),
.findings-wrap td:nth-child(7) {
  width: 24%;
}

.findings-wrap th:nth-child(8),
.findings-wrap td:nth-child(8) {
  width: 8%;
}

.findings-wrap .reason {
  display: -webkit-box;
  line-clamp: 3;
  max-width: none;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.findings-wrap .badge {
  max-width: 100%;
  white-space: normal;
}

.findings-wrap td:nth-child(2) .badge,
.findings-wrap td:nth-child(6) .badge {
  white-space: nowrap;
}

.findings-wrap .review-button {
  width: 100%;
}

.pagination {
  align-items: center;
  border-top: 1px solid var(--border);
  color: var(--muted);
  display: flex;
  font-family: var(--font-code);
  font-size: 13px;
  gap: 10px;
  justify-content: flex-end;
  padding: 12px;
}

.pagination-button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-code);
  font-size: 12px;
  min-height: 34px;
  padding: 7px 10px;
  text-transform: uppercase;
}

.pagination-button:hover:not(:disabled) {
  border-color: rgba(62, 207, 142, 0.55);
  color: var(--brand);
}

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

table {
  border-collapse: collapse;
  min-width: 100%;
  width: max-content;
}

th {
  background: var(--surface-3);
  color: var(--muted);
  font-size: 12px;
  position: sticky;
  top: 0;
  z-index: 2;
}

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

td {
  color: var(--text);
  max-width: 280px;
}

tbody tr:hover {
  background: rgba(62, 207, 142, 0.06);
}

#groupRows tr {
  cursor: pointer;
}

tr.is-selected {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

.group-id,
.code,
.score {
  font-family: var(--font-code);
}

.group-id {
  color: var(--text);
  display: block;
  font-weight: 700;
}

.group-reason-preview {
  color: var(--muted);
  display: -webkit-box;
  font-size: 13px;
  line-height: 1.35;
  margin-top: 6px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.reason {
  color: var(--muted);
  max-width: 440px;
}

.badge {
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  gap: 6px;
  min-height: 26px;
  padding: 3px 8px;
  white-space: nowrap;
}

.badge.high {
  border-color: rgba(246, 96, 97, 0.7);
  color: var(--error);
}

.badge.medium {
  border-color: rgba(244, 189, 80, 0.7);
  color: var(--warning);
}

.badge.low,
.badge.pending {
  color: var(--muted);
}

.badge.reviewed {
  border-color: rgba(102, 163, 255, 0.6);
  color: var(--blue);
}

.badge.applied,
.badge.possible-test {
  border-color: rgba(62, 207, 142, 0.7);
  color: var(--brand);
}

.badge.dismissed {
  border-color: rgba(246, 96, 97, 0.5);
  color: var(--error);
}

.review-button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  min-height: 34px;
  padding: 7px 10px;
}

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

.detail-panel {
  padding: 18px;
}

.back-button {
  align-items: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  display: inline-flex;
  font-family: var(--font-code);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 18px;
  min-height: 38px;
  padding: 8px 12px;
  text-transform: uppercase;
}

.back-button:hover {
  border-color: rgba(62, 207, 142, 0.55);
  color: var(--brand);
}

.empty-state {
  align-items: center;
  color: var(--muted);
  display: flex;
  min-height: 240px;
  justify-content: center;
}

.detail-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(440px, 0.85fr);
  gap: 16px;
  padding-bottom: 16px;
}

.detail-title {
  font-size: 34px;
  line-height: 1.1;
  margin: 10px 0 8px;
}

.reason-list {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.reason-list li {
  align-items: flex-start;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 10px;
  padding: 9px 10px;
}

.signal-icon,
.row-action svg {
  color: currentColor;
  display: inline-block;
  flex: 0 0 auto;
}

.signal-icon svg,
.row-action svg {
  fill: none;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 18px;
}

.signal-document,
.signal-email,
.signal-phone,
.signal-name,
.signal-birthdate,
.signal-possible_test {
  color: var(--brand);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.meta-box {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 86px;
  padding: 14px;
}

.meta-label {
  color: var(--muted);
  display: block;
  font-family: var(--font-code);
  font-size: 12px;
  text-transform: uppercase;
}

.meta-value {
  display: block;
  font-family: var(--font-code);
  font-size: 23px;
  margin-top: 6px;
}

.section-title {
  align-items: center;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
  padding-top: 16px;
}

.section-title h3 {
  font-size: 18px;
  margin: 0;
}

.partner-table {
  margin-top: 10px;
  max-height: 420px;
}

.partner-table table {
  min-width: 1500px;
}

.partner-row.keep {
  background: rgba(62, 207, 142, 0.08);
}

.partner-row.duplicate,
.partner-row.ignore {
  opacity: 0.58;
}

.partner-row.needs_review {
  background: rgba(244, 189, 80, 0.06);
}

.test-tag {
  margin-left: 8px;
}

.applied-control {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  margin-bottom: 8px;
}

.applied-control input {
  accent-color: var(--brand);
  height: 18px;
  width: 18px;
}

.notes {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  display: block;
  height: 100%;
  min-height: 166px;
  outline: 0;
  padding: 10px;
  resize: vertical;
  width: 100%;
}

.notes:focus {
  border-color: rgba(62, 207, 142, 0.8);
}

.actions-cell {
  min-width: 188px;
}

.notes-cell {
  min-width: 280px;
  vertical-align: stretch;
}

.row-actions {
  display: grid;
  gap: 7px;
}

.row-action {
  align-items: center;
  background: var(--surface-3);
  color: var(--text);
  display: inline-flex;
  font-family: var(--font-code);
  font-size: 12px;
  font-weight: 700;
  gap: 8px;
  justify-content: flex-start;
  padding: 7px 10px;
  text-transform: uppercase;
}

.row-action.keep {
  border-color: rgba(62, 207, 142, 0.55);
  color: var(--success);
}

.row-action.duplicate {
  border-color: rgba(246, 96, 97, 0.55);
  color: var(--error);
}

.row-action.ignore {
  color: var(--muted);
}

.row-action.needs_review {
  border-color: rgba(244, 189, 80, 0.55);
  color: var(--warning);
}

.row-action.is-active.keep {
  background: rgba(62, 207, 142, 0.16);
}

.row-action.is-active.duplicate {
  background: rgba(246, 96, 97, 0.16);
}

.row-action.is-active.needs_review {
  background: rgba(244, 189, 80, 0.16);
}

.matrix-wrap {
  margin-top: 10px;
  max-height: 520px;
}

.matrix-wrap table {
  min-width: 980px;
}

.matrix-field {
  background: var(--surface-3);
  color: var(--muted);
  font-family: var(--font-code);
  position: sticky;
  left: 0;
  z-index: 1;
}

.matrix-cell.match {
  background: rgba(62, 207, 142, 0.12);
  border-color: rgba(62, 207, 142, 0.28);
}

.matrix-cell.empty {
  background: rgba(244, 189, 80, 0.1);
  border-color: rgba(244, 189, 80, 0.24);
  color: var(--warning);
}

.matrix-cell.conflict {
  background: rgba(246, 96, 97, 0.1);
  border-color: rgba(246, 96, 97, 0.22);
}

.matrix-cell.na {
  color: var(--muted);
}

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

.nowrap {
  white-space: nowrap;
}

.toast {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  bottom: 16px;
  box-shadow: var(--shadow-md);
  color: var(--text);
  padding: 10px 12px;
  position: fixed;
  right: 16px;
  z-index: 20;
}

@media (max-width: 1280px) {
  .metrics {
    grid-template-columns: repeat(4, minmax(110px, 1fr));
  }

  .workspace,
  .detail-header {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 760px) {
  .shell {
    width: min(100vw - 16px, 760px);
  }

  h1 {
    font-size: 34px;
  }

  .nav-row,
  .title-row {
    display: grid;
  }

  .controls,
  .metrics,
  .meta-grid {
    grid-template-columns: 1fr;
  }
}
