:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d8e0e7;
  --line-soft: #e8edf2;
  --text: #17202a;
  --muted: #657485;
  --strong: #0c2d37;
  --accent: #087f8c;
  --accent-dark: #075965;
  --green: #1f7a4d;
  --amber: #a06000;
  --red: #b42318;
  --blue: #225f9a;
  --shadow: 0 16px 44px rgba(22, 34, 45, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

input,
select {
  width: 100%;
  height: 36px;
  border: 1px solid #c8d3dc;
  background: #fff;
  color: var(--text);
  border-radius: 7px;
  padding: 0 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8, 127, 140, .14);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 14px 22px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--strong);
  color: #fff;
  font-weight: 850;
}

h1,
h2,
p {
  margin: 0;
}

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

.brand p,
.surface-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

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

.api-key {
  width: 260px;
}

.workspace {
  max-width: 1520px;
  margin: 0 auto;
  padding: 20px 22px 30px;
  display: grid;
  gap: 16px;
}

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

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

.metric {
  padding: 14px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

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

.surface {
  overflow: clip;
}

.barcode-form {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  display: grid;
  grid-template-columns: minmax(220px, 1.35fr) minmax(150px, .8fr) minmax(180px, 1fr) minmax(150px, .8fr) minmax(140px, .7fr) auto;
  gap: 10px;
  align-items: end;
  background: #fff;
}

.surface-header {
  min-height: 56px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

h2 {
  color: var(--strong);
  font-size: 14px;
}

.controls {
  width: min(260px, 100%);
}

.order-grid {
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 12px;
}

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

.order-topline,
.task-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.customer-block {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 13px;
}

.customer-block strong,
.strong {
  color: var(--strong);
}

.sample-list,
.inline-actions,
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.invoice-list {
  display: grid;
  gap: 7px;
}

.invoice-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line-soft);
  background: #fff;
  border-radius: 7px;
}

.invoice-row .task-error {
  grid-column: 1 / -1;
}

.invoice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.sample-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 4px 7px;
  border: 1px solid var(--line-soft);
  background: #fff;
  border-radius: 7px;
}

.progress {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
}

.step {
  height: 6px;
  border-radius: 999px;
  background: #dce4eb;
}

.step.done {
  background: var(--accent);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}

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

.badge.amber {
  background: #fff2db;
  color: var(--amber);
}

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

.badge.blue {
  background: #e8f1fb;
  color: var(--blue);
}

.badge.dark {
  background: #e6eef1;
  color: var(--strong);
}

.primary-button,
.action-button,
.ghost-button,
.danger-button,
.icon-button {
  min-height: 34px;
  border-radius: 7px;
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.primary-button,
.action-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover,
.action-button:hover {
  background: var(--accent-dark);
}

.ghost-button,
.icon-button {
  background: #e8eef3;
  color: #263746;
}

.ghost-button:hover,
.icon-button:hover {
  background: #d8e2ea;
}

.ghost-link {
  min-height: 22px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e8eef3;
  color: #263746;
  font-size: 11px;
  font-weight: 850;
  text-decoration: none;
}

.ghost-link:hover {
  background: #d8e2ea;
}

.danger-button {
  background: var(--red);
  color: #fff;
}

.icon-button {
  width: 36px;
  padding: 0;
  font-size: 17px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: .04em;
}

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

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, .9fr) minmax(320px, .9fr);
  gap: 16px;
}

.inventory-grid,
.task-list,
.manual-form,
.inventory-form {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.inventory-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  border-bottom: 1px solid var(--line-soft);
}

.inventory-form button {
  grid-column: 1 / -1;
}

.inventory-item,
.task-item {
  border: 1px solid var(--line-soft);
  background: var(--panel-soft);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 9px;
}

.inventory-item p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.inventory-numbers {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.inventory-numbers strong {
  color: var(--strong);
  font-size: 22px;
}

.stock-bar {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: #dce4eb;
  overflow: hidden;
  border: 0;
}

.stock-bar::-webkit-meter-bar {
  background: #dce4eb;
  border: 0;
  border-radius: 999px;
}

.stock-bar::-webkit-meter-optimum-value {
  background: var(--accent);
  border-radius: 999px;
}

.stock-bar::-moz-meter-bar {
  background: var(--accent);
  border-radius: 999px;
}

.manual-form label,
.inventory-form label,
.barcode-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.sample-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 220px auto;
  gap: 12px;
  align-items: end;
  padding: 14px 16px;
  border-top: 1px solid var(--line-soft);
  background: var(--panel-soft);
}

.sample-toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-height: 38px;
}

.pager button {
  min-width: 88px;
}

.manual-form .checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--strong);
}

.manual-form .checkbox-label input {
  width: 16px;
  height: 16px;
}

.message {
  min-height: 36px;
  padding: 9px 14px;
  border-top: 1px solid var(--line-soft);
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
}

.task-error {
  color: var(--red);
  font-size: 12px;
}

.endpoint-cell,
.response-cell {
  max-width: 360px;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
}

.response-cell {
  max-width: 440px;
}

.lis-payload summary {
  cursor: pointer;
  color: var(--strong);
  font-size: 12px;
  font-weight: 800;
}

.lis-payload pre {
  max-width: 320px;
  max-height: 180px;
  overflow: auto;
  margin: 8px 0 0;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 11px;
  white-space: pre-wrap;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

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

.empty-state {
  padding: 24px 16px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #102a33;
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow);
  transform: translateY(120%);
  transition: transform .18s ease;
}

.toast.show {
  transform: translateY(0);
}

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

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

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

  .api-key {
    width: 100%;
  }

  .barcode-form {
    grid-template-columns: 1fr 1fr;
  }

  .sample-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .pager {
    grid-column: 1 / -1;
    justify-content: space-between;
  }
}

@media (max-width: 740px) {
  .workspace,
  .topbar {
    padding-left: 14px;
    padding-right: 14px;
  }

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

  .top-actions,
  .surface-header {
    align-items: stretch;
    flex-direction: column;
  }

  .inventory-form,
  .barcode-form,
  .sample-toolbar {
    grid-template-columns: 1fr;
  }

  .pager {
    grid-column: auto;
  }
}
