* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body.scanner-open {
  overflow: hidden; /* чтобы при сканере нельзя было прокручивать фон */
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background: #fff;
  color: #111;
  overflow-x: hidden;
}

/* ===== Шапка ===== */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #111;
  color: #fff;
  flex-wrap: wrap;
  gap: 8px;
}

h1 {
  font-size: 16px;
  margin: 0;
}

.user {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
}

.user label {
  font-size: 13px;
}

.user input {
  padding: 6px 8px;
  min-width: 120px;
  flex: 1 1 auto;
}

.user button {
  margin-left: 0;
  padding: 6px 10px;
  flex: 0 0 auto;
}

@media (min-width: 768px) {
  header {
    padding: 12px 16px;
  }

  h1 {
    font-size: 18px;
  }

  .user {
    flex-wrap: nowrap;
  }

  .user input {
    width: 160px;
    flex: 0 0 auto;
  }
}

/* ===== Панель управления ===== */

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
  flex-wrap: wrap;
}

.controls button {
  padding: 8px 12px;
  font-size: 14px;
}

#status {
  margin-left: auto;
  color: #666;
  min-height: 1em;
  font-size: 13px;
}

/* ===== Вкладки заявок ===== */

.orders {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid #eee;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.orders .tab {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  flex: 0 0 auto;
}

.orders .tab.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

/* ===== Заявка / список позиций ===== */

.orderView {
  padding: 10px 12px 16px;
}

.orderView h2 {
  font-size: 16px;
  margin: 0 0 10px;
}

.items {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  padding: 10px 10px 8px;
  border: 1px solid #eee;
  border-radius: 8px;
  background: #fff;
}

.item .title {
  font-weight: 600;
  font-size: 14px;
  word-break: break-word;
}

.item .barcode {
  font-size: 12px;
  color: #666;
  word-break: break-all;
}

.item .barcode .code {
  font-family: monospace;
}

.item .qty {
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.item .qty b {
  font-weight: 600;
}

.item.ok {
  border-color: #3aa13a;
  background: #f7fff7;
}

.item .check {
  width: 18px;
  height: 18px;
  border: 2px solid #3aa13a;
  border-radius: 50%;
  margin-top: 2px;
}

/* Десктопный / широкий вид: табличная раскладка */

@media (min-width: 720px) {
  .orderView {
    padding-inline: 42px;
  }

  .item {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) auto 28px;
    align-items: center;
    gap: 6px 10px;
  }

  .item .title {
    grid-column: 1 / 2;
  }

  .item .barcode {
    grid-column: 2 / 3;
    justify-self: start;
  }

  .item .qty:nth-of-type(1) {
    grid-column: 3 / 4;
    justify-self: end;
  }

  .item .qty:nth-of-type(2) {
    grid-column: 3 / 4;
    justify-self: end;
  }

  .item .check {
    grid-column: 4 / 5;
    justify-self: center;
    align-self: center;
    margin-top: 0;
  }
}

/* ===== Кнопка настроек / чип прогресса ===== */

.chip {
  display: inline-block;
  margin-left: .5rem;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .85rem;
  background: #eef5ff;
}

.chip-progress {
  background: #ffe9b3;
}

#settingsBtn {
  margin-left: 8px;
  padding: 4px 8px;
  font-size: 16px;
}

/* ===== Старый вариант settings-panel (запасной, сейчас не используется, но оставим) ===== */

.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
}

.settings-panel[hidden] {
  display: none !important;
}

.settings-card {
  background: #fff;
  padding: 16px 20px;
  border-radius: 10px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

.settings-card h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin-bottom: 12px;
}

/* ===== Dialog настроек ===== */

#settingsDialog {
  border: none;
  padding: 0;
  border-radius: 12px;
  max-width: 340px;
  width: calc(100% - 32px);
}

#settingsDialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

#settingsDialog .settings {
  padding: 16px 18px 12px;
}

#settingsDialog .settings h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

#settingsDialog .settings label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin-bottom: 10px;
}

#settingsDialog .settings input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

#settingsDialog .settings menu {
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#settingsDialog .settings menu button {
  padding: 6px 12px;
  font-size: 14px;
}

/* ===== НОВОЕ: блок выбора форматов ШК в настройках ===== */

#settingsDialog .settings .settings-formats {
  margin-top: 12px;
  padding: 10px 10px 6px;
  border-radius: 8px;
  border: 1px solid #eee;
  background: #fafafa;
}

#settingsDialog .settings .settings-formats legend {
  padding: 0 4px;
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 500;
  color: #555;
}

#settingsDialog .settings .settings-formats label {
  margin-bottom: 6px;
  font-size: 13px;
}

/* ===== Сканер: полноэкранный оверлей ===== */

.scanner {
  position: fixed;
  inset: 0;
  background: #000;
  display: none;
  z-index: 1000;
  overflow: hidden;
}

.scanner.active {
  display: block;
}

/* Динамические рамки по найденным штрих-кодам (BarcodeDetector) */
#scanBoxes {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Контейнер с динамическими рамками найденных ШК */
.scan-boxes {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.scan-box {
  position: absolute;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 6px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  /* анимируем только цвет/подсветку, но не геометрию */
  transition: border-color 80ms linear, box-shadow 80ms linear;
}

.scan-box.found {
  border-color: #00ff5a;
  box-shadow: 0 0 0 2px rgba(0, 255, 90, 0.8);
}

/* видео на всю область, обрезка по краям */
.scanner video#preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* рамка по центру */

.scan-frame {
  position: absolute;
  left: 0;
  right: 0;
  top: 6vh;
  bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scan-frame-box {
  width: min(90vw, 52vh);
  max-width: 520px;
  aspect-ratio: 9 / 14;
  border-radius: 18px;
  position: relative;
  box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.45);
}

.scan-frame-box::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid rgba(255, 255, 255, 0.25);
}

/* уголки рамки */

.scan-frame-box .corner {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 3px solid #ffffff;
}

/* верхний левый */
.scan-frame-box .corner.tl {
  top: -2px;
  left: -2px;
  border-right: none;
  border-bottom: none;
}

/* верхний правый */
.scan-frame-box .corner.tr {
  top: -2px;
  right: -2px;
  border-left: none;
  border-bottom: none;
}

/* нижний левый */
.scan-frame-box .corner.bl {
  bottom: -2px;
  left: -2px;
  border-right: none;
  border-top: none;
}

/* нижний правый */
.scan-frame-box .corner.br {
  bottom: -2px;
  right: -2px;
  border-left: none;
  border-top: none;
}

/* (опциональный индикатор фокуса) */
#focusFrame {
  position: absolute;
  border: 2px solid #00ff99;
  border-radius: 8px;
  pointer-events: none;
  transition: all 0.1s linear;
  opacity: 0;
}

/* строка статуса (прогресс / ошибки) над нижней панелью */

.scanner-info {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 20px);
  padding: 10px 14px;              /* было 8px 10px */
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #f5f5f5;
  font-size: 15px;                 /* было 13px */
  font-weight: 500;
  line-height: 1.35;
  text-align: center;
  backdrop-filter: blur(2px);
  max-width: min(92vw, 640px);
  margin-inline: auto;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}
/* нижняя панель: подсказка и кнопки */

.scanner-info-ok {
  background: rgba(0, 90, 0, 0.85);
}

/* красная заливка при ошибке */
.scanner-info-err {
  background: rgba(140, 0, 0, 0.9);
}

.scanner .overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  pointer-events: auto;
}

#scanHint {
  flex: 1 1 100%;
  text-align: center;
  font-size: 14px;
  color: #f5f5f5;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  margin-bottom: 4px;
}

#triggerScan,
#stopScan {
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  min-width: 120px;
}

#triggerScan {
  background: #21c25e;
  color: #ffffff;
}

#stopScan {
  background: rgba(0, 0, 0, 0.55);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

@media (max-width: 420px) {
  #triggerScan,
  #stopScan {
    flex: 1 1 45%;
    text-align: center;
  }
}

/* ===== Подвал ===== */

footer {
  padding: 8px 12px;
  color: #999;
  border-top: 1px solid #eee;
  font-size: 12px;
}
