:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #697386;
  --line: #dfe5ef;
  --blue: #2563eb;
  --green: #15803d;
  --orange: #c2410c;
  --red: #b91c1c;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
}

button.secondary {
  background: #e8eef8;
  color: #1f2a44;
}

.button-like {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  padding: 0 12px;
  text-decoration: none;
  font-size: 12px;
  font-weight: 900;
}

.button-like.secondary {
  background: #e8eef8;
  color: #1f2a44;
}

button.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
}

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

input,
select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  background: #101827;
  color: #fff;
  padding: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #24a148;
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #b9c3d5;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav a {
  border-radius: 8px;
  color: #dce5f5;
  padding: 12px;
  text-decoration: none;
}

.nav a.active,
.nav a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.side-note {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 18px;
}

.side-note span,
.side-note strong {
  display: block;
}

.side-note span {
  color: #b9c3d5;
  font-size: 13px;
}

.workspace {
  margin-left: 260px;
  padding: 28px;
}

.topbar,
.panel-heading,
.actions,
.org-panel {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

.org-panel select {
  min-width: 260px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

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

.metric {
  padding: 18px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
}

.metric.success strong {
  color: var(--green);
}

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

.metric.danger strong {
  color: var(--red);
}

.section-grid {
  display: grid;
  grid-template-columns: 0.85fr 1.15fr;
  gap: 18px;
  margin-bottom: 18px;
}

.panel {
  display: grid;
  gap: 18px;
  padding: 20px;
}

.panel-heading {
  justify-content: space-between;
}

.wide-panel {
  margin-bottom: 18px;
}

.upload-panel .actions {
  justify-content: flex-start;
}

.upload-zones {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.dropzone {
  min-height: 156px;
  place-items: center;
  border: 1px dashed #9aa8bd;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  cursor: pointer;
  padding: 16px;
  text-align: center;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.dropzone strong,
.dropzone small {
  display: block;
}

.dropzone strong {
  margin-top: 10px;
  font-size: 15px;
}

.dropzone small {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.dropzone.is-dragover,
.dropzone:hover {
  border-color: var(--blue);
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.13);
  transform: translateY(-1px);
}

.dropzone.is-uploading {
  cursor: wait;
  pointer-events: none;
}

.dropzone.is-complete {
  border-color: var(--green);
}

.dropzone.is-error {
  border-color: var(--orange);
}

.progress-track {
  display: block;
  width: 100%;
  height: 8px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8f0;
}

.progress-bar {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
  transition: width 0.18s ease;
}

.dropzone.is-complete .progress-bar {
  background: var(--green);
}

.dropzone.is-error .progress-bar {
  background: var(--orange);
}

.progress-text {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.zone-kicker {
  display: inline-grid;
  min-width: 44px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  font-weight: 900;
}

.type-po .zone-kicker {
  background: #dbeafe;
  color: #1d4ed8;
}

.type-dn .zone-kicker {
  background: #dcfce7;
  color: var(--green);
}

.type-invoice .zone-kicker {
  background: #ffedd5;
  color: var(--orange);
}

.dropzone input {
  display: none;
}

.compact {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.compact input {
  max-width: 260px;
}

.compact select {
  max-width: 180px;
}

.queue-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.queue-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 900;
}

.queue-tab.active {
  border-color: var(--blue);
  background: #dbeafe;
  color: #1d4ed8;
}

.queue-count {
  display: inline-grid;
  min-width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.08);
  font-size: 12px;
}

.confidence {
  display: inline-flex;
  align-items: center;
  min-width: 58px;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 900;
}

.confidence.high {
  background: #dcfce7;
  color: var(--green);
}

.confidence.medium {
  background: #ffedd5;
  color: var(--orange);
}

.confidence.low {
  background: #fee2e2;
  color: var(--red);
}

.table-wrap {
  overflow: auto;
}

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

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

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

td {
  font-size: 14px;
}

td input,
td select {
  min-height: 36px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
}

.badge.ok {
  background: #dcfce7;
  color: var(--green);
}

.badge.warn {
  background: #ffedd5;
  color: var(--orange);
}

.badge.danger {
  background: #fee2e2;
  color: var(--red);
}

.badge.neutral {
  background: #e8eef8;
  color: #334155;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.row-actions button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: none;
  max-width: 420px;
  border-radius: 8px;
  background: #101827;
  color: #fff;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  font-weight: 700;
}

.toast.show {
  display: block;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  padding: 28px;
}

.modal.open {
  display: grid;
  place-items: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 39, 0.52);
}

.modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(1280px, 100%);
  max-height: min(840px, calc(100vh - 56px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 30px 70px rgba(16, 24, 39, 0.22);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 18px 20px;
}

.modal-body {
  display: grid;
  gap: 16px;
  overflow: auto;
  padding: 20px;
}

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

.detail-tile,
.document-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 14px;
}

.detail-tile span,
.document-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.detail-tile strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
}

.document-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.document-card {
  display: grid;
  gap: 10px;
  background: #fff;
}

.document-card h3 {
  margin: 0;
  font-size: 16px;
}

.field-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.field-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.field-list dt {
  color: var(--muted);
  font-weight: 800;
}

.field-list dd {
  margin: 0;
  text-align: right;
  font-weight: 800;
}

.raw-preview {
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101827;
  color: #e8eef8;
  padding: 14px;
  font-size: 12px;
}

.viewer-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.viewer-panel.is-expanded {
  position: fixed;
  inset: 18px;
  z-index: 30;
  background: #fff;
  box-shadow: 0 34px 80px rgba(16, 24, 39, 0.28);
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.viewer-toolbar span,
.viewer-toolbar strong {
  display: block;
}

.viewer-toolbar span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.document-viewer {
  min-height: 520px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f1f5f9;
}

.viewer-panel.is-expanded .document-viewer {
  height: calc(100vh - 128px);
}

.document-viewer iframe,
.document-viewer img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 520px;
  border: 0;
}

.document-viewer img {
  object-fit: contain;
  background: #0f172a;
}

@media (max-width: 920px) {
  .sidebar {
    position: static;
    width: auto;
  }

  .workspace {
    margin-left: 0;
    padding: 18px;
  }

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

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

  .upload-zones {
    grid-template-columns: 1fr;
  }

  .org-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .modal {
    padding: 12px;
  }

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