:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #182033;
  --muted: #6b7588;
  --line: #dde5f0;
  --blue: #0969ff;
  --blue-dark: #0753c9;
  --green: #0a8754;
  --red: #d33c32;
  --yellow: #b7791f;
  --shadow: 0 18px 42px rgba(27, 44, 75, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(115deg, rgba(9, 105, 255, 0.1), transparent 36%),
    linear-gradient(270deg, rgba(10, 135, 84, 0.08), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.layout {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(32px, 4.5vw, 52px);
  line-height: 1;
}

h2 {
  font-size: 18px;
}

nav {
  display: flex;
  gap: 8px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 14px;
  cursor: pointer;
}

button.nav {
  min-width: 96px;
  border: 0;
  background: transparent;
}

button.nav.active {
  background: var(--text);
  color: #fff;
}

button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

button.primary:hover {
  background: var(--blue-dark);
}

button.ghost {
  min-height: 36px;
  color: var(--muted);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.metric {
  padding: 16px;
}

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

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

.view {
  display: none;
}

.view.active {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  align-items: start;
}

#ordersView.active,
#configView.active {
  display: block;
}

.panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.orders-head {
  align-items: center;
}

.orders-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(520px, 62%);
}

.orders-tools input {
  flex: 1;
}

textarea {
  width: 100%;
  min-height: 360px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  color: var(--text);
  padding: 12px;
  line-height: 1.55;
  outline: none;
}

textarea:focus,
input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(9, 105, 255, 0.13);
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

pre {
  min-height: 360px;
  margin: 14px 0 0;
  overflow: auto;
  border-radius: 8px;
  background: #111827;
  color: #eaf2ff;
  padding: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.grid {
  display: grid;
  gap: 12px;
}

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

label span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 7px;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  color: var(--text);
  outline: none;
  padding: 0 12px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
}

.switch input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--blue);
}

.note {
  margin-top: 14px;
  border-radius: 8px;
  background: #fff7e8;
  color: var(--yellow);
  padding: 12px;
  line-height: 1.6;
  font-size: 14px;
}

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

.row {
  display: grid;
  grid-template-columns: 160px 1fr 90px 120px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcff;
}

.order-row {
  grid-template-columns: 160px 1fr 90px 120px;
}

.codes-list {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.code-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
}

.code-item code {
  overflow: hidden;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-item small,
.muted {
  color: var(--muted);
}

.code-state {
  justify-self: start;
  border-radius: 999px;
  background: #eef3fb;
  color: var(--muted);
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
}

.code-state.ok {
  background: #e8f7ef;
  color: var(--green);
}

.code-state.bad {
  background: #ffeceb;
  color: var(--red);
}

.code-state.skipped {
  background: #fff7e8;
  color: var(--yellow);
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

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

.pill {
  display: inline-flex;
  justify-content: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 800;
}

.pill.submitted {
  background: #e8f7ef;
  color: var(--green);
}

.pill.saved {
  background: #eaf2ff;
  color: var(--blue);
}

.pill.failed {
  background: #ffeceb;
  color: var(--red);
}

.pill.partial_failed,
.pill.duplicate_blocked {
  background: #fff7e8;
  color: var(--yellow);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  pointer-events: none;
  border-radius: 8px;
  background: rgba(17, 24, 39, 0.94);
  color: #fff;
  padding: 12px 16px;
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
  .topbar,
  .view.active,
  .status-grid,
  .grid.two {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  nav {
    overflow-x: auto;
  }

  .row {
    grid-template-columns: 1fr;
  }

  .orders-head,
  .orders-tools,
  .code-item {
    align-items: stretch;
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .code-item code {
    white-space: normal;
    word-break: break-all;
  }
}

@media (max-width: 1120px) {
  .view.active {
    display: block;
  }

  .result-panel {
    margin-top: 18px;
  }

  pre {
    min-height: 220px;
  }
}

@media (max-width: 480px) {
  .layout {
    width: min(100% - 20px, 1180px);
    padding: 18px 0;
  }
}
