:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #e3e5e8;
  --accent: #7b2cbf;
  --bad: #d62839;
  --bad-bg: #fde8ea;
  --ok: #1f8a4c;
  --ok-bg: #e3f5ea;
  --muted-bg: #eef0f2;
  --warn: #c77700;
  --warn-bg: #fff4e0;
  --cancel: #7b3fb8;
  --cancel-bg: #f1e8fb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --card: #1f2226;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --border: #33373c;
    --accent: #b388eb;
    --bad: #ff6b78;
    --bad-bg: #3a1d21;
    --ok: #5fd08f;
    --ok-bg: #18301f;
    --muted-bg: #2a2e33;
    --warn: #f0a640;
    --warn-bg: #3a2c14;
    --cancel: #c79bf2;
    --cancel-bg: #2e2240;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 960px; margin: 0 auto; padding: 16px; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 4px 0; }
h2 { font-size: 18px; margin: 20px 0 8px; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.error { color: var(--bad); }
.bad-text { color: var(--bad); }
.notice { background: var(--card); border-left: 4px solid var(--accent); padding: 8px 12px; border-radius: 6px; }

.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin: 8px 0; }
.card.pin { max-width: 360px; margin: 15vh auto 0; display: flex; flex-direction: column; gap: 12px; }
.card.pin input[name=pin] { font-size: 28px; text-align: center; letter-spacing: 8px; }

input, select, button { font: inherit; }
input, select {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
}
button {
  padding: 10px 16px; border-radius: 8px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600;
}
button.small { padding: 6px 12px; font-size: 14px; }
button.secondary { background: var(--muted-bg); color: var(--text); }
button.danger { background: var(--bad); }
label.check { display: flex; gap: 8px; align-items: center; }
label.check input { width: auto; }
.slug-field { display: flex; align-items: center; gap: 4px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.slug-field input { flex: 1; }

.refresh-bar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 50;
  background: var(--accent); transition: width 1s linear;
}
.refresh-bar[hidden] { display: none; }
.sync { display: flex; gap: 8px; align-items: center; font-size: 14px; }

.alert { border-radius: 12px; padding: 12px 16px; margin: 16px 0; }
.alert h2 { margin: 0 0 4px; font-size: 22px; }
.alert p { margin: 0 0 8px; }
.alert.bad { background: var(--bad-bg); border: 2px solid var(--bad); }
.alert.bad h2 { color: var(--bad); }
.alert.ok { background: var(--ok-bg); border: 1px solid var(--ok); }
.alert.warn { background: var(--warn-bg); border: 1px solid var(--warn); }
.alert.ok h2 { color: var(--ok); }

ul.orders, ul.supplies { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.product {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.product.bad { border: 2px solid var(--bad); }
.product-head { display: flex; gap: 12px; align-items: center; }
.product .info { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.product .info .field + .field { margin-top: 4px; }
.product-name { font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.subject {
  display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 4px;
  background: var(--muted-bg); color: var(--text); font-size: 12px; font-weight: 600;
}
.qty {
  flex: none; min-width: 48px; padding: 6px 10px; border-radius: 10px; text-align: center;
  background: var(--accent); color: #fff; font-size: 22px; font-weight: 800;
}
.product.bad .qty { background: var(--bad); }
.photo {
  flex: none; width: 56px; height: 75px; border-radius: 6px; overflow: hidden;
  background: var(--muted-bg); display: block;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
ul.units { list-style: none; padding: 0; margin: 10px 0 0; }
.unit {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  padding: 8px 0; border-top: 1px solid var(--border);
}
.unit .sticker {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 20px; font-weight: 700;
  min-width: 150px; white-space: nowrap;
}
.unit.bad .sticker { color: var(--bad); }
.unit .fields { flex: 1; margin-top: 0; }
button.photo { padding: 0; border: 0; cursor: zoom-in; }
.zoom {
  position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, .85);
  display: flex; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out;
}
.zoom[hidden] { display: none; }
.zoom img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.lbl {
  display: block; font-size: 11px; line-height: 1.2; font-weight: 500;
  color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.unit .sticker .lbl { color: inherit; opacity: .7; }
.fields { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 4px; font-size: 14px; }
.right { text-align: right; }

.supply {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  color: inherit; text-decoration: none;
}
.supply.bad { border: 2px solid var(--bad); }
.count { margin-top: 4px; font-size: 14px; }
.big-count { font-size: 28px; font-weight: 800; color: var(--bad); line-height: 1; }
.big-count.warn { color: var(--warn); }
.alert.warn h2 { color: var(--warn); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.badge.bad { background: var(--bad); color: #fff; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.muted { background: var(--muted-bg); color: var(--muted); }
.badge.cancel { background: var(--cancel); color: #fff; }
.product.cancel { border: 2px solid var(--cancel); }
.unit.cancel .sticker { color: var(--cancel); text-decoration: line-through; }
.tab.active.cancel { background: var(--cancel); border-color: var(--cancel); }
.tab.cancel.alarm { border: 2px solid var(--cancel); color: var(--cancel); }
.tab.active.cancel.alarm { color: #fff; }
.supply { flex-wrap: wrap; }
.supply-cancels {
  flex-basis: 100%; font-size: 14px; padding: 8px 10px; border-radius: 8px;
  background: var(--cancel-bg); border-left: 4px solid var(--cancel);
}
.supply-cancels b { color: var(--cancel); }
.supply-cancels ul { list-style: none; padding: 0; margin: 4px 0 0; }
.supply-cancels li { padding: 3px 0; display: flex; gap: 8px; align-items: center; }
.photo.thumb { width: 30px; height: 40px; border-radius: 4px; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.supply.warn { border: 2px solid var(--warn); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; align-items: center; }
.filters input[type=search] { flex: 2 1 200px; width: auto; }
.filters select { flex: 1 1 160px; width: auto; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; flex: 1 1 100%; }
.tab {
  flex: 1; text-align: center; padding: 10px; border-radius: 8px; cursor: pointer;
  background: var(--card); border: 1px solid var(--border); font-weight: 600;
}
.tab input { display: none; }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tab.active.bad { background: var(--bad); border-color: var(--bad); }

.link-row { display: flex; gap: 8px; margin: 8px 0; }
.link-row input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
details summary { cursor: pointer; color: var(--accent); margin: 4px 0; }
.bulk-bar {
  position: sticky; bottom: 8px; z-index: 10; margin: 8px 0; padding: 10px 12px; border-radius: 10px;
  background: var(--card); border: 2px solid var(--accent); box-shadow: 0 4px 16px rgba(0, 0, 0, .15);
}
.bulk-bar[hidden] { display: none; }
.mark-buttons { justify-content: flex-end; margin-top: 6px; }
details.change summary { font-size: 13px; color: var(--muted); list-style: none; text-align: right; }
details.change summary::-webkit-details-marker { display: none; }
details.change[open] summary { display: none; }

table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--muted-bg); font-weight: 600; }
tr.bad-row td { background: var(--bad-bg); }
section { overflow-x: auto; }

@media (max-width: 560px) {
  /* стикер и статус в одну строку, номер заказа и прочее — мелко под ними */
  .unit { gap: 2px 8px; padding: 6px 0; }
  .unit .sticker { min-width: 0; flex: 1; font-size: 20px; }
  .unit .sticker .lbl { display: none; }
  .unit .right { order: 2; max-width: 50%; }
  .unit .fields { order: 3; flex-basis: 100%; font-size: 13px; }
  .unit .fields .lbl { display: inline; margin-right: 4px; }
  .supply { flex-direction: column; align-items: flex-start; }
  .supply .right { text-align: left; }
  .supply-cancels { flex-basis: auto; align-self: stretch; }
  .cancel-item .product-head { flex-wrap: wrap; align-items: flex-start; }
  .cancel-item .info { flex-basis: calc(100% - 110px); }
  .cancel-item .right { flex-basis: 100%; text-align: left; }
  .cancel-item .mark-buttons, .cancel-item details.change summary { justify-content: flex-start; text-align: left; }
  .alert .supply { flex-direction: row; align-items: center; }
  .alert .supply .right { text-align: right; }
}
