:root {
  color-scheme: dark;
  --green: #a0e020;
  --green-2: #c8ec90;
  --ink: #f4f6f6;
  --muted: #a0a8b0;
  --line: #2f3842;
  --panel: #111a23;
  --panel-2: #17212b;
  --bg: #0c141c;
  --danger: #ff6b6b;
  --warn: #ffc857;
  --ok: #4dd484;
  --radius: 8px;
  font-family: "Open Sans", "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body[data-view="login"] {
  display: grid;
  place-items: start center;
  padding: 40px;
}

button,
select,
input {
  font: inherit;
}

button {
  min-height: 36px;
  border: 0;
  border-radius: 18px;
  padding: 0 18px;
  background: var(--green);
  color: #101810;
  font-weight: 800;
  cursor: pointer;
}

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

.secondary-button {
  border: 1px solid var(--line);
  background: #0f1820;
  color: var(--ink);
}

select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0f1820;
  color: var(--ink);
  padding: 0 12px;
}

input[type="search"] {
  min-height: 40px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0f1820;
  color: var(--ink);
  padding: 0 12px;
}

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

body[data-view="login"] .shell {
  width: min(720px, 100%);
  display: grid;
  gap: 20px;
  margin: 0;
  padding: 20px 20px 60px;
  background: #283038;
  border-radius: 18px;
}

.topbar,
.workspace-head,
.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  min-height: 52px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

body[data-view="login"] .topbar {
  margin-bottom: 10px;
}

.topbar > div,
.workspace-head > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(160, 224, 32, 0.12);
}

.app-status,
.muted {
  color: var(--muted);
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.login-grid {
  display: grid;
  min-height: calc(100vh - 76px);
  place-items: start center;
}

body[data-view="login"] .login-grid {
  display: block;
  min-height: auto;
}

.qr-panel {
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  flex-wrap: wrap;
  text-align: center;
}

h1 {
  margin: 0;
  font-family: "Teko", "Arial Narrow", system-ui, sans-serif;
  font-size: 36px;
  line-height: 1;
  letter-spacing: 0;
}

.qr-panel h1 {
  color: var(--green);
  font-size: clamp(20px, 8vw, 50px);
  font-weight: 500;
}

.login-body {
  display: grid;
  gap: 14px;
  align-items: start;
  margin-top: 44px;
}

@media (min-width: 720px) {
  .login-body {
    grid-template-columns: 1fr 1fr;
  }
}

.login-copy {
  display: grid;
  gap: 20px;
  min-width: 0;
  align-self: center;
}

.login-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.login-status-row button {
  flex: 0 0 auto;
}

.login-copy .muted {
  flex: 1 1 auto;
  margin: 0;
  color: var(--ink);
  font-size: 0.875rem;
}

.login-qr-column {
  display: grid;
  gap: 30px;
  justify-items: center;
  align-items: start;
  align-content: start;
  margin-top: 30px;
}

.qr-code {
  display: grid;
  width: auto;
  min-height: auto;
  place-items: center;
  margin: 0;
  border: 0;
  border-radius: 18px;
  background: #0c141c;
  padding: 20px;
}

.qr-code canvas {
  width: 240px;
  height: 240px;
  display: block;
}

@media (max-width: 820px) {
  body[data-view="login"] {
    padding: 20px;
  }

  body[data-view="login"] .shell {
    width: min(720px, 100%);
  }

  .qr-panel h1 {
    font-size: 26px;
  }

  .login-body {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 32px;
  }

  .login-qr-column {
    order: -1;
  }

  .login-copy {
    gap: 20px;
  }

  .qr-code {
    padding: 20px;
    border-radius: 18px;
  }
}

.workspace {
  display: grid;
  gap: 16px;
}

.workspace-head {
  min-height: 48px;
}

.workspace-head > div {
  align-items: baseline;
}

.controls {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr) auto;
  gap: 14px;
  align-items: end;
  padding: 16px;
}

.user-explorer {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.user-explorer-head,
.user-current-head,
.user-history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.user-explorer h2 {
  margin: 0;
  font-family: "Teko", "Arial Narrow", system-ui, sans-serif;
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0;
}

.user-explorer-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(260px, 2fr);
  gap: 14px;
}

.user-current-fields,
.user-import-history {
  display: grid;
  gap: 10px;
}

.user-current-fields:empty,
.user-import-history:empty {
  display: none;
}

.user-current-head span,
.user-history-head span {
  color: var(--muted);
  font-size: 13px;
}

.user-current-fields dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1px;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.user-current-fields dl div {
  min-width: 0;
  background: #0f1820;
  padding: 10px;
}

.user-current-fields dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.user-current-fields dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.user-history-table {
  min-width: 1040px;
}

.user-history-table th:nth-child(1),
.user-history-table td:nth-child(1) {
  width: 150px;
}

.user-history-table th:nth-child(2),
.user-history-table td:nth-child(2) {
  width: 170px;
}

.user-history-table th:nth-child(3),
.user-history-table td:nth-child(3),
.user-history-table th:nth-child(4),
.user-history-table td:nth-child(4),
.user-history-table th:nth-child(6),
.user-history-table td:nth-child(6),
.user-history-table th:nth-child(7),
.user-history-table td:nth-child(7) {
  width: 120px;
}

.user-history-table th:nth-child(5),
.user-history-table td:nth-child(5) {
  width: auto;
}

label {
  display: grid;
  gap: 7px;
}

label > span {
  color: var(--muted);
  font-size: 13px;
}

.toggle {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 9px;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.drop-zone {
  display: grid;
  min-height: 180px;
  place-items: center;
  gap: 8px;
  border: 1px dashed #5b6873;
  border-radius: var(--radius);
  background: var(--panel-2);
  cursor: pointer;
}

.drop-zone:focus-visible,
.drop-zone.is-dragging {
  outline: 2px solid var(--green);
  outline-offset: 3px;
}

.drop-zone span {
  color: var(--muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.progress-panel {
  display: grid;
}

.csv-columns-panel {
  display: grid;
}

.diff-filter-panel {
  display: grid;
}

.diff-filter-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 12px 14px;
}

.diff-filter-card > div {
  display: grid;
  gap: 3px;
}

.diff-filter-card strong {
  font-size: 18px;
}

.diff-filter-card span {
  color: var(--muted);
  font-size: 13px;
}

.diff-filter-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.diff-filter-actions button {
  min-height: 34px;
  border-radius: 17px;
  font-size: 14px;
}

.csv-columns-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px;
}

.csv-columns-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.csv-columns-head strong {
  font-size: 18px;
}

.csv-columns-head span {
  color: var(--muted);
  font-size: 13px;
}

.csv-columns-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.csv-columns-list span {
  max-width: 100%;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #0f1820;
  color: var(--ink);
  padding: 5px 10px;
  font-size: 13px;
}

.progress-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px;
}

.progress-head,
.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.progress-head strong {
  font-size: 18px;
}

.progress-head span,
.progress-meta {
  color: var(--muted);
  font-size: 13px;
}

.progress-track {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #080d12;
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 180ms ease;
}

.progress-card p {
  margin: 0;
  color: var(--ink);
}

.progress-failed {
  border-color: rgba(255, 107, 107, 0.5);
}

.progress-failed .progress-track span {
  background: var(--danger);
}

.progress-completed {
  border-color: rgba(77, 212, 132, 0.5);
}

.metric {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.metric strong {
  font-size: 28px;
}

.ai-panel:empty,
.csv-columns-panel:empty,
.diff-filter-panel:empty,
.progress-panel:empty,
.summary-grid:empty,
.table-wrap:empty {
  display: none;
}

.ai-state {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px;
}

.ai-ok {
  border-color: rgba(77, 212, 132, 0.5);
}

.ai-failed {
  border-color: rgba(255, 107, 107, 0.5);
}

.ai-skipped {
  border-color: rgba(255, 200, 87, 0.5);
}

pre {
  max-height: 260px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border-radius: var(--radius);
  background: #080d12;
  color: var(--green-2);
}

.table-wrap {
  overflow: auto;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.empty-table {
  color: var(--muted);
  text-align: center;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: min(1600px, 100%);
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td span {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.field-section {
  display: grid;
  gap: 2px;
  margin-bottom: 10px;
}

.field-section:last-child {
  margin-bottom: 0;
}

.field-section strong {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

th:nth-child(1),
td:nth-child(1) {
  width: 52px;
}

th:nth-child(2),
td:nth-child(2) {
  width: 132px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 92px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 170px;
}

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

th:nth-child(7),
td:nth-child(7) {
  width: 16%;
}

th:nth-child(8),
td:nth-child(8) {
  width: 132px;
}

.status {
  display: inline-block;
  max-width: 100%;
  border-radius: 999px;
  padding: 4px 9px;
  color: #081008;
  font-weight: 800;
  overflow-wrap: normal;
  word-break: normal;
}

.status-matched {
  background: var(--ok);
}

.status-changed {
  background: var(--warn);
}

.status-missing {
  background: var(--danger);
}

.status-needs_review {
  background: var(--green);
}

.status-ignored {
  background: #87919a;
}

.changes,
.actions {
  color: var(--green-2);
}

.table-action {
  display: block;
  width: 100%;
  min-height: 30px;
  margin: 0 0 6px;
  border-radius: 15px;
  padding: 0 12px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.table-action-soft_delete_user {
  background: var(--warn);
}

.table-action-create_user {
  background: var(--ok);
}

.table-action-ignore_user_field,
.table-action-restore_ignored_user_field {
  background: #d7dee4;
}

.action-history-panel {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.action-history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.action-history-head strong {
  color: var(--ink);
}

.action-history-panel td span {
  display: block;
}

.history-status {
  font-weight: 700;
}

.history-status-active {
  color: var(--green-2);
}

.history-status-undone,
.history-status-undo {
  color: var(--muted);
}

.history-undo {
  background: #d7dee4;
}

.resolver-note {
  color: var(--green-2);
  margin-top: 4px;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 9, 12, 0.78);
}

.confirm-box {
  display: grid;
  width: min(520px, 100%);
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 18px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.4);
}

.confirm-box p {
  margin: 0;
  line-height: 1.5;
}

.confirm-box div {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.confirm-no {
  border: 1px solid var(--line);
  background: #0f1820;
  color: var(--ink);
}

@media (max-width: 760px) {
  .shell {
    width: calc(100vw - 16px);
    padding-top: 12px;
  }

  .topbar,
  .workspace-head,
  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .controls,
  .user-explorer-controls,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100% !important;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tr {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    padding: 12px;
  }

  td {
    display: grid;
    gap: 4px;
    border-bottom: 0;
    padding: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
  }

  td:empty {
    display: none;
  }

  .qr-panel {
    padding: 14px;
  }
}
