* {
  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;
  }
}

/* Переключатель страниц (В работе / Архив) */
.view-tabs {
  display: flex;
  gap: 6px;
  padding: 0 12px 8px;
  border-bottom: 1px solid #eee;
}

.view-tab {
  flex: 0 0 auto;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 999px;
  border: 1px solid #ddd;
  background: #f9fafb;
  cursor: pointer;
}

.view-tab.active {
  background: #111827;
  color: #f9fafb;
  border-color: #111827;
}


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

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

  position: relative;      
}

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

#status {
  position: absolute;          /* выводим из потока, чтобы не двигал кнопки */
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: flex-end;

  width: 160px;                /* фиксированная ширина */
  height: 20px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* кнопку оставляем только для js, на экране её не видно */
#scanItemBtn {
  display: none;
}

/* блок пользователя после ввода имени */
.user.user-locked #userName,
.user.user-locked #saveUser {
  display: none;
}

#userNameDisplay {
  display: none;
  font-size: 13px;
}

.user.user-locked #userNameDisplay {
  display: inline;
}


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

.orders {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 10px 12px 16px;
  border-bottom: 1px solid #eee;
  max-height: none;
  overflow: visible;
}

/* переключение страниц: активные / архив */
body[data-view="active"] .orders.archive {
  display: none;
}

body[data-view="archive"] #ordersTabs {
  display: none;
}

/* "Вернуть заявку" показываем только на странице архива */
#reopenOrderBtn {
  display: none;
}

body[data-view="archive"] #reopenOrderBtn {
  display: inline-block;
}

/* Карточка заявки целиком */

.order-card {
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 6px 8px 8px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  cursor: pointer;
}


.order-card.active {
  border-color: #111;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
}

.order-card-header {
  margin-bottom: 4px;
  font-size: 13px;
}

.order-card-title {
  font-size: 13px;
}

.order-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.order-card-items {
  display: flex;
  flex-direction: column;
  gap: 4px;              /* было 8px через .items */
}

.order-card-items .item {
  padding: 4px 6px 3px;
  border-radius: 6px;
  gap: 3px;
}

.order-card-items .item-name {
  flex: 1 1 auto;
  font-size: 13px;
  line-height: 1.25;
}

.order-card-items .item-name .cat {
  font-size: 12px;
}

.order-card-items .item-qty {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  white-space: nowrap;
}

.order-card-items .item-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}

.order-card-items .item.ok {
  border-color: #3aa13a;
  background: #f5fff5;
}

.order-card-items .item-bc {
  margin-top: 1px;
  font-size: 10px;
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


.chip-small {
  padding: 1px 4px;
  font-size: 11px;
  line-height: 1.2;
}

.chip-left {
  background: #e4f5ff;
}

/* чтобы чипы в шапке заявки тоже не раздувались на маленьком экране */
.order-card-meta .chip {
  font-size: 11px;
  padding: 2px 6px;
}


/* карточки в архиве чуть бледнее */

.order-card-archive {
  opacity: 0.65;
  background: #f5f5f5;
}

.orders.archive {
  border-top: none;
  border-bottom: 1px solid #eee;
  background: #fafafa;
}


.orders .tab {
  display: none;
}

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

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

.orderView {
  display: none;
}

.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 12px 8px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #ffffff;
}

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

.item .title .cat {
  font-weight: 500;
  color: #6b7280;
}

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

.item .barcode .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", 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;
}

.last-scan {
  display: block;          /* чтобы занял всю строку */
  width: 100%;             /* растягиваем по родителю */
  max-width: 100%;
  box-sizing: border-box;

  margin-top: 4px;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 12px;
  background: #e6f9e8;
  color: #111827;

  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  word-break: break-word;
}



.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #f9fafb;
  font-size: 14px;
}

.logout-btn {
  padding: 4px 10px;
  font-size: 13px;
  border-radius: 999px;
  border: 1px solid #f87171;
  background: transparent;
  color: #fecaca;
  cursor: pointer;
}

.logout-btn:hover {
  background: #7f1d1d;
}

.last-scan-ok {
  background: #e6f9ed;
  color: #065f46;
}

.last-scan-err {
  background: #fee2e2;
  color: #991b1b;
}

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

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

  .item {
    display: grid;
    grid-template-columns: minmax(0, 1.8fr) minmax(0, 1.3fr) auto 28px;
    align-items: center;
    column-gap: 12px;
    row-gap: 4px;
  }

  .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;
}

