:root {
  color-scheme: dark;
  --bg: #080b10;
  --panel: #101823;
  --panel-soft: #151f2c;
  --line: #26384e;
  --text: #f3f7fb;
  --muted: #93a8bf;
  --brand: #16c784;
  --brand-strong: #31d99b;
  --accent: #ffbd2e;
  --danger: #ff5a6b;
  --blue: #58a6ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  width: min(1440px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

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

.button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 15px;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.button.primary {
  border-color: #0ea56d;
  background: var(--brand);
  color: #06100b;
}

.button.secondary {
  background: #111a25;
}

.button.danger {
  border-color: #7a2b37;
  background: #251018;
  color: #ff9aa5;
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.status,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 11px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status.ok,
.pill.done {
  color: var(--brand-strong);
}

.status.error,
.pill.review {
  color: var(--danger);
}

.overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0 14px;
}

.section-title p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.upload-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px 18px;
  align-items: center;
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
}

.upload-panel p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.upload-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.region-control {
  display: grid;
  gap: 8px;
  min-width: 220px;
}

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

.region-control select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0b1420;
  color: var(--text);
  padding: 8px 10px;
}

.file-input {
  min-height: 40px;
  max-width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0d141e;
  color: var(--text);
  padding: 7px;
  cursor: pointer;
}

.file-input::file-selector-button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111a25;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  margin-right: 10px;
}

.button.upload {
  border-color: #2f6fae;
  background: var(--blue);
  color: #06101c;
}

.selected-files {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.selected-files span {
  border: 1px solid #253850;
  border-radius: 999px;
  background: #0d141e;
  padding: 6px 10px;
  color: #c5d6e8;
}

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

.metric {
  min-height: 104px;
  padding: 20px 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 14px;
}

.metric strong {
  display: block;
  margin-top: 12px;
  color: var(--brand);
  font-size: 30px;
  line-height: 1;
}

.metric.warning strong {
  color: var(--accent);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
  gap: 18px;
}

.layout.lower {
  margin-top: 18px;
}

.layout.erp-layout {
  grid-template-columns: minmax(320px, 0.8fr) minmax(620px, 1.2fr);
}

.history-panel {
  min-height: 0;
  margin-top: 18px;
}

.panel {
  min-height: 340px;
  padding: 18px;
}

.documents-panel {
  min-width: 0;
}

.documents-panel table {
  min-width: 760px;
}

.documents-panel th:nth-child(1),
.documents-panel td:nth-child(1) {
  width: 38%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.documents-panel th:nth-child(2),
.documents-panel td:nth-child(2) {
  width: 170px;
}

.documents-panel th:nth-child(3),
.documents-panel td:nth-child(3) {
  width: 70px;
}

.documents-panel th:nth-child(4),
.documents-panel td:nth-child(4) {
  width: 90px;
}

.documents-panel th:nth-child(5),
.documents-panel td:nth-child(5) {
  width: 130px;
  overflow-wrap: anywhere;
}

.erp-panel {
  min-width: 0;
}

.erp-table-wrap {
  width: 100%;
}

.erp-table {
  min-width: 820px;
}

.erp-table th:nth-child(1),
.erp-table td:nth-child(1) {
  width: 190px;
  overflow-wrap: anywhere;
}

.erp-table th:nth-child(2),
.erp-table td:nth-child(2) {
  width: 220px;
  overflow-wrap: anywhere;
}

.erp-table th:nth-child(3),
.erp-table td:nth-child(3),
.erp-table th:nth-child(4),
.erp-table td:nth-child(4),
.erp-table th:nth-child(6),
.erp-table td:nth-child(6) {
  width: 90px;
  white-space: nowrap;
}

.erp-table th:nth-child(5),
.erp-table td:nth-child(5) {
  width: 140px;
  text-align: right;
  white-space: nowrap;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-header p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid #223247;
  padding: 12px 10px;
  text-align: left;
  font-size: 14px;
  vertical-align: top;
}

th {
  color: #8eb2d8;
  font-size: 12px;
  text-transform: uppercase;
}

td {
  color: var(--text);
}

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

.empty-card {
  border: 1px dashed var(--line);
  border-radius: 7px;
  padding: 16px;
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 10px;
}

.review-card,
.event-card {
  border: 1px solid #223247;
  border-radius: 7px;
  background: #0c121a;
  padding: 13px;
}

.review-card strong,
.event-card strong {
  display: block;
  margin-bottom: 5px;
}

.review-card span,
.event-card span {
  color: var(--muted);
  font-size: 13px;
}

.review-form {
  display: grid;
  gap: 10px;
}

.review-title {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.review-title strong,
.review-title span {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.review-form label {
  display: grid;
  gap: 5px;
}

.review-form label span {
  color: #8eb2d8;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.review-form input {
  width: 100%;
  min-height: 38px;
  border: 1px solid #26384e;
  border-radius: 7px;
  background: #090f17;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}

.review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.timeline {
  display: grid;
  max-height: 420px;
  overflow: auto;
  gap: 10px;
  padding-right: 4px;
}

.event-card {
  border-left: 3px solid var(--blue);
}

.event-card.decision {
  border-left-color: var(--accent);
}

.event-card.success {
  border-left-color: var(--brand);
}

.event-card.review {
  border-left-color: var(--danger);
}

.status-text {
  display: inline-block;
  max-width: 100%;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.status-registered {
  color: var(--brand);
}

.status-human_review {
  color: var(--accent);
}

.status-duplicate_blocked {
  color: var(--accent);
}

.status-completed,
.status-approved {
  color: var(--brand);
}

.status-processing,
.status-queued {
  color: var(--blue);
}

.status-failed,
.status-rejected {
  color: var(--danger);
}

.history-row {
  cursor: pointer;
}

.history-row:hover td,
.history-row.selected td {
  background: #0c1520;
}

@media (max-width: 980px) {
  .shell {
    width: min(100% - 24px, 1440px);
    padding-top: 18px;
  }

  .topbar,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .overview,
  .layout,
  .upload-panel {
    grid-template-columns: 1fr;
  }

  .upload-actions {
    justify-content: stretch;
  }

  .file-input,
  .button.upload {
    flex: 1;
  }
}
