:root {
  --bg: #eef2f5;
  --panel: #ffffff;
  --panel-2: #f7f9fb;
  --line: #d8e0e8;
  --text: #101828;
  --muted: #64748b;
  --brand: #0f6b4f;
  --brand-2: #0a4d39;
  --ok: #067647;
  --warn: #b54708;
  --bad: #b42318;
  --blue: #1d4ed8;
  --shadow: 0 10px 30px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Arial, "Segoe UI", sans-serif;
}

button, input, select {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

button {
  cursor: pointer;
  font-weight: 700;
  background: var(--brand);
  color: #fff;
  border-color: transparent;
  min-height: 38px;
  padding: 8px 12px;
}

button.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

button.warn { background: var(--warn); }
button.bad { background: var(--bad); }
button.blue { background: var(--blue); }

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

input, select {
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

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

.priemka-home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  background: var(--wms-bg-muted, #f0f1f3);
  border: 1px solid var(--wms-line, #e3e5e8);
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}
.priemka-home-link:hover { background: var(--wms-line, #e3e5e8); }

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

h1, h2, h3, p { margin: 0; }
h1 { font-size: 20px; line-height: 1.1; }
h2 { font-size: 17px; margin-bottom: 10px; }
h3 { font-size: 15px; margin-bottom: 8px; }
.brand p { color: var(--muted); font-size: 12px; margin-top: 3px; }

.mode-switch {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mode-btn {
  background: #fff;
  color: #334155;
  border: 1px solid var(--line);
  min-height: 34px;
  padding: 6px 10px;
}

.mode-btn.active {
  background: var(--brand);
  color: #fff;
}

#root { padding: 12px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 12px;
  min-width: 0;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(100px, 1fr));
  gap: 8px;
}

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

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.kpi strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
  line-height: 1;
}

.desktop-grid {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.side-stack, .main-stack {
  display: grid;
  gap: 12px;
  align-content: start;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.span-2 {
  grid-column: 1 / -1;
}

.loading-panel {
  max-width: 720px;
  margin: 28px auto;
}

.supply-panel,
.start-hint {
  margin-bottom: 12px;
}

.start-screen {
  display: grid;
  gap: 12px;
}

.start-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.start-head h2 {
  margin-bottom: 4px;
}

.start-stats {
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

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

.supply-cards .placeholder {
  grid-column: 1 / -1;
}

.supply-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 7px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

.supply-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.supply-card h3 {
  margin: 0;
  font-size: 17px;
  font-family: Consolas, "SF Mono", monospace;
}

.supply-client {
  font-weight: 800;
}

.supply-stats {
  display: flex;
  gap: 18px;
  color: var(--muted);
}

.supply-stats b {
  color: var(--text);
}

.supply-preview {
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.supply-actions {
  display: flex;
  justify-content: flex-end;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.scan-row {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(220px, 1fr) auto auto;
  gap: 8px;
  align-items: end;
  width: 100%;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

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

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

th {
  background: #edf5f2;
  color: #334155;
  font-size: 12px;
  position: sticky;
  top: 0;
}

.num { text-align: right; font-variant-numeric: tabular-nums; }
.ok { color: var(--ok); font-weight: 800; }
.warn-text { color: var(--warn); font-weight: 800; }
.bad-text { color: var(--bad); font-weight: 800; }

.box-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
}

.box-card, .item-card, .event-card, .error-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  padding: 10px;
}

.item-card-body {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.item-image-slot {
  width: 74px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  overflow: hidden;
}

.item-image-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.item-info {
  min-width: 0;
}

.box-card.active {
  border-color: var(--brand);
  box-shadow: inset 4px 0 0 var(--brand);
}

.box-head, .item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: start;
}

.code {
  font-weight: 900;
  letter-spacing: .2px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  background: #e7f5ee;
  color: var(--ok);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.pill.gray {
  background: #f1f5f9;
  color: #475569;
}

.pill.warn {
  background: #fff4e5;
  color: var(--warn);
}

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

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

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

.matrix {
  min-width: 1050px;
}

.matrix td, .matrix th {
  text-align: center;
  padding: 6px;
}

.tablet-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(280px, .92fr);
  gap: 12px;
  margin-top: 12px;
  align-items: start;
}

.tablet-primary {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.scan-card {
  background: var(--panel);
  border: 2px solid var(--brand);
  border-radius: 12px;
  padding: 12px;
  min-width: 0;
}

.active-box {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  min-width: 0;
}

.active-box-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.active-box-title span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.active-box strong {
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: .3px;
  overflow-wrap: anywhere;
}

.scan-input {
  font-size: 19px;
  height: 54px;
  border-width: 2px;
}

.box-dims {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  margin: 10px 0;
}

.dim-summary {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 6px 9px;
}

.dim-summary span,
.active-content-head span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.dim-summary strong,
.active-content-head strong {
  display: block;
  font-size: 14px;
  line-height: 1.2;
}

.active-content {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 8px;
  margin-top: 10px;
}

.active-content-head,
.content-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.active-content-head {
  margin-bottom: 6px;
}

.content-row {
  border-top: 1px solid var(--line);
  padding-top: 6px;
  margin-top: 6px;
}

.content-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.content-row strong {
  font-variant-numeric: tabular-nums;
}

.tablet-tabs, .phone-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.tab-btn {
  background: #fff;
  color: #334155;
  border: 1px solid var(--line);
}

.tab-btn.active {
  background: var(--brand);
  color: #fff;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.phone-shell {
  max-width: 460px;
  margin: 0 auto;
  display: grid;
  gap: 10px;
}

.phone-shell .cards-grid {
  grid-template-columns: 1fr;
}

.phone-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.tsd-shell {
  max-width: 420px;
  margin: 0 auto;
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(120px, 1fr) auto;
  gap: 8px;
}

.tsd-status {
  border-radius: 10px;
  background: #052e23;
  color: #fff;
  padding: 10px;
}

.tsd-status .label {
  font-size: 11px;
  text-transform: uppercase;
  color: #b7f7df;
  font-weight: 800;
}

.tsd-status strong {
  display: block;
  font-size: 34px;
  line-height: 1;
  margin-top: 4px;
}

.tsd-input {
  height: 58px;
  font-size: 22px;
  border: 2px solid var(--brand);
}

.tsd-last {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
}

.tsd-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.print-sheet {
  display: none;
}

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .desktop-grid, .tablet-layout { grid-template-columns: 1fr; }
  .scan-row { grid-template-columns: 1fr 1fr; }
  .mode-tablet .panel,
  .mode-tablet .scan-card {
    box-shadow: none;
  }
  .mode-tablet .actions button {
    flex: 1 1 150px;
  }
  .mode-tablet .form-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .mode-tablet .form-grid .span-2 {
    grid-column: span 2;
  }
  .mode-tablet .box-dims {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .topbar { align-items: stretch; flex-direction: column; }
  #root { padding: 8px; }
  .kpis, .form-grid, .scan-row, .cards-grid, .phone-summary { grid-template-columns: 1fr; }
  .mode-tablet .form-grid,
  .mode-tablet .form-grid .span-2 {
    grid-template-columns: 1fr;
    grid-column: 1 / -1;
  }
  .mode-switch { justify-content: stretch; }
  .mode-btn { flex: 1 1 auto; }
  table { min-width: 720px; }
  .start-head { align-items: start; flex-direction: column; }
  .supply-cards { grid-template-columns: 1fr; }
}

.mode-tsd .topbar {
  position: static;
  flex-direction: row;
  align-items: center;
  padding: 4px 6px;
  gap: 6px;
  min-height: 44px;
}

.mode-tsd .brand-mark,
.mode-tsd .brand p {
  display: none;
}

.mode-tsd .brand {
  gap: 6px;
  flex: 0 0 auto;
}

.mode-tsd .priemka-home-link {
  width: 32px;
  height: 32px;
}

.mode-tsd h1 {
  font-size: 15px;
}

.mode-tsd #root {
  height: calc(100vh - 44px);
  overflow: hidden;
  padding: 6px;
}

.mode-tsd .mode-switch {
  flex: 1 1 auto;
  justify-content: flex-end;
  gap: 4px;
}

.mode-tsd .mode-btn {
  min-height: 32px;
  padding: 5px 7px;
  font-size: 11px;
  flex: 0 1 auto;
}

.mode-tsd .mode-btn.active {
  min-width: 44px;
}

.mode-tsd .supply-cards,
.mode-phone .supply-cards {
  grid-template-columns: 1fr;
}

.mode-tsd .start-head {
  align-items: start;
  flex-direction: column;
}

.mode-tsd .supply-card {
  padding: 10px;
}
