:root {
  --brand: #3ecf8e;
  --primary: #ededed;
  --secondary: #888888;
  --neutral: #1c1c1c;
  --surface: #2e2e2e;
  --surface-2: #262626;
  --surface-3: #222222;
  --line: #333333;
  --success: #3ecf8e;
  --warn: #f4bd50;
  --danger: #f66061;
  --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(--neutral);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--neutral);
  color: var(--primary);
  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(--line);
  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(--secondary);
  margin: 0;
}

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

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

.auth-field input {
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--primary);
  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(--neutral);
  font-size: 12px;
  font-weight: 700;
  min-height: 42px;
  padding: 10px 14px;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 24px;
}

.header-main {
  align-items: flex-start;
  display: flex;
  gap: 24px;
  justify-content: space-between;
}

.nav-row {
  display: flex;
}

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

.module-nav a {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--secondary);
  display: inline-flex;
  font-family: var(--font-code);
  font-size: 12px;
  min-height: 36px;
  padding: 8px 12px;
  text-decoration: none;
  text-transform: uppercase;
}

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

.title-block {
  min-width: 0;
}

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

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

h1 {
  font-family: var(--font-body);
  font-size: 48px;
  font-weight: 700;
  line-height: 1.1;
  margin: 0;
}

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

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

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

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

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

.filter,
.filter-toggle,
.export-button,
.row-action {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 38px;
  padding: 9px 12px;
}

.filter {
  background: var(--surface);
  color: var(--secondary);
  font-size: 12px;
}

.filter.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--neutral);
}

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

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

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

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

.filter-menu {
  background: var(--surface);
  border: 1px solid var(--line);
  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(--secondary);
  display: flex;
  font-size: 12px;
  gap: 10px;
  min-height: 34px;
  padding: 7px 8px;
}

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

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

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

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

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

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

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

.workspace {
  display: block;
  min-height: calc(100vh - 188px);
}

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

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

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

.detail-view .group-list {
  display: none;
}

.group-list,
.detail {
  min-width: 0;
}

.group-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

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

.list-items {
  padding: 8px;
}

.pagination {
  align-items: center;
  border-top: 1px solid var(--line);
  color: var(--secondary);
  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(--line);
  border-radius: 6px;
  color: var(--primary);
  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;
}

.group-item {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--primary);
  display: grid;
  gap: 8px;
  margin-bottom: 6px;
  padding: 11px;
  text-align: left;
  width: 100%;
}

.group-item:hover,
.group-item.is-active {
  background: var(--surface-2);
  border-color: var(--line);
}

.group-item.is-active {
  border-color: var(--brand);
  box-shadow: inset 3px 0 0 var(--brand);
}

.item-top,
.item-bottom,
.detail-top,
.decision-strip {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.item-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-reason {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 24px;
}

.item-signal-icon {
  align-items: center;
  border: 1px solid currentColor;
  border-radius: 6px;
  color: var(--brand);
  display: inline-flex;
  height: 24px;
  justify-content: center;
  width: 24px;
}

.item-signal-icon svg {
  fill: none;
  height: 15px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 15px;
}

.item-signal-icon.signal-document {
  color: var(--warn);
}

.item-signal-icon.signal-phone {
  color: var(--success);
}

.item-signal-icon.signal-name,
.item-signal-icon.signal-birthdate {
  color: var(--secondary);
}

.status {
  border: 1px solid var(--line);
  border-radius: 4px;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 12px;
  justify-content: center;
  min-width: 86px;
  padding: 3px 7px;
}

.status.correct {
  border-color: rgba(62, 207, 142, 0.4);
  color: var(--success);
}

.status.suspicious {
  color: var(--warn);
}

.status.duplicate {
  border-color: rgba(246, 96, 97, 0.5);
  color: var(--danger);
}

.decision-pill {
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--secondary);
  font-family: var(--font-code);
  font-size: 12px;
  padding: 2px 7px;
}

.decision-pill.applied {
  border-color: rgba(62, 207, 142, 0.6);
  color: var(--success);
}

.detail {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.back-button {
  align-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--primary);
  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);
}

.detail-top {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  margin-bottom: 16px;
  padding-bottom: 14px;
}

.detail-top > div:first-child {
  min-width: 0;
}

.detail h2 {
  font-family: var(--font-code);
  font-size: 32px;
  font-weight: 600;
  line-height: 1.2;
  margin: 8px 0 8px;
}

.reason {
  color: var(--secondary);
  margin: 0;
  max-width: 980px;
}

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

.reason-list li {
  align-items: start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--primary);
  display: grid;
  font-family: var(--font-code);
  font-size: 14px;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 12px;
  line-height: 1.6;
  padding: 8px 10px;
}

.signal-icon {
  align-items: center;
  border: 1px solid currentColor;
  border-radius: 6px;
  color: var(--brand);
  display: inline-flex;
  height: 22px;
  justify-content: center;
  width: 22px;
}

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

.signal-document .signal-icon {
  color: var(--warn);
}

.signal-phone .signal-icon {
  color: var(--success);
}

.signal-name .signal-icon,
.signal-birthdate .signal-icon {
  color: var(--secondary);
}

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

.meta-box {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.meta-label {
  color: var(--secondary);
  display: block;
  font-size: 12px;
}

.meta-value {
  display: block;
  font-family: var(--font-code);
  font-size: 22px;
  line-height: 1.1;
  margin-top: 4px;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

table {
  border-collapse: collapse;
  min-width: 1480px;
  width: 100%;
}

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

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

td {
  color: var(--primary);
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

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

tr.discard-row td {
  color: rgba(237, 237, 237, 0.46);
}

tr.applied-row td:first-child {
  box-shadow: inset 3px 0 0 var(--success);
}

td.match-cell {
  background: rgba(244, 189, 80, 0.14);
  box-shadow: inset 0 0 0 1px rgba(244, 189, 80, 0.42);
  color: var(--primary);
  position: relative;
}

td.match-cell::before {
  background: var(--warn);
  border-radius: 999px;
  content: "";
  height: 6px;
  left: 5px;
  position: absolute;
  top: 14px;
  width: 6px;
}

td.match-cell.exact-match {
  background: rgba(244, 189, 80, 0.2);
}

td.match-cell.signal-match {
  background: rgba(244, 189, 80, 0.1);
}

td.match-cell {
  padding-left: 18px;
}

.actions {
  display: grid;
  gap: 6px;
  min-width: 104px;
}

.row-action {
  align-items: center;
  background: var(--surface-3);
  border-color: var(--line);
  color: var(--primary);
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 8px;
  font-family: var(--font-code);
  font-size: 12px;
  letter-spacing: 0;
  min-height: 30px;
  padding: 5px 8px;
  text-transform: uppercase;
}

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

.row-action.discard {
  background: rgba(246, 96, 97, 0.1);
  border-color: rgba(246, 96, 97, 0.42);
  color: var(--danger);
}

.row-action.review {
  background: rgba(244, 189, 80, 0.1);
  border-color: rgba(244, 189, 80, 0.42);
  color: var(--warn);
}

.row-action:hover {
  filter: brightness(1.14);
}

.row-action svg {
  fill: none;
  height: 16px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
  width: 16px;
}

.row-action span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-action.keep.is-selected {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--neutral);
}

.row-action.discard.is-selected {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--neutral);
}

.row-action.review.is-selected {
  background: var(--warn);
  border-color: var(--warn);
  color: var(--neutral);
}

.applied-control {
  align-items: center;
  display: flex;
  gap: 8px;
  min-width: 92px;
}

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

.notes-cell {
  height: 1px;
  min-width: 300px;
  padding: 8px;
  width: 340px;
}

.notes {
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--primary);
  display: block;
  font-family: var(--font-code);
  font-size: 14px;
  height: 100%;
  line-height: 1.5;
  min-height: 132px;
  padding: 6px 8px;
  resize: vertical;
  width: 100%;
}

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

.correct-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.correct-card strong {
  display: block;
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: 6px;
}

.correct-card span {
  color: var(--secondary);
  display: block;
  font-family: var(--font-code);
  font-size: 13px;
}

.empty-state,
.error {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--secondary);
  padding: 24px;
}

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

@media (max-width: 1180px) {
  .topbar,
  .workspace,
  .detail-top {
    grid-template-columns: 1fr;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .meta-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-width: 0;
  }

}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 16px, 1680px);
    padding-top: 10px;
  }

  .metrics,
  .meta-grid,
  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .header-main {
    display: grid;
    grid-template-columns: 1fr;
  }

  .export-button {
    justify-self: start;
  }

  .detail-top,
  .item-top,
  .item-bottom {
    align-items: flex-start;
  }
}

@media (max-width: 560px) {
  .controls {
    grid-template-columns: 1fr;
  }
}
