* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  background: #f5f5f7;
  color: #222;
}
header {
  background: #1f2937;
  color: #fff;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header a { color: #fff; text-decoration: none; }
header .nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
header .brand { font-weight: 700; font-size: 16px; margin-right: 10px; padding: 6px 4px; }
header .nav-btn {
  padding: 8px 16px;
  background: #374151;
  border: 1px solid #4b5563;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
header .nav-btn:hover { background: #4b5563; border-color: #6b7280; }
header .nav-btn:active { background: #2b3442; }
main { padding: 24px; max-width: 1280px; margin: 0 auto; }
/* Бланк отправок — на всю ширину экрана. */
main.shipments-page { max-width: none; padding: 16px 24px; }

table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { border: 1px solid #e5e7eb; padding: 8px 10px; text-align: left; font-size: 14px; }
th { background: #f9fafb; }
tr:hover { background: #fafafa; }

.btn {
  background: #2563eb;
  color: #fff;
  border: 0;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover { background: #1d4ed8; }
.btn:disabled { background: #9ca3af; cursor: not-allowed; }
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }

.toolbar { display: flex; gap: 8px; margin-bottom: 16px; }

.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

.btn-primary { background: #2563eb; }
.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }

.merge-options {
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: #fff;
}
.merge-options legend { font-weight: 600; padding: 0 6px; color: #374151; }
.merge-options .radio { display: block; margin: 6px 0; cursor: pointer; }
.merge-options select { margin-left: 6px; padding: 4px 8px; }

.table-toolbar {
  align-items: center;
  background: #fff;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  margin-bottom: 0;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
}
.table-toolbar .counter { margin-left: auto; font-size: 14px; color: #374151; }
.table-toolbar .hint { font-size: 12px; color: #6b7280; margin-right: 8px; }
.table-toolbar .btn-primary { margin-left: 8px; }

#docs-table { border-radius: 0 0 6px 6px; }
#docs-table tbody tr[data-state="canceled"] { opacity: 0.5; }
#docs-table tbody tr[data-state="reserve"] td:nth-child(5) { color: #c2410c; font-weight: 600; }
#docs-table tbody tr[data-state="draft"] td:nth-child(5) { color: #6b7280; }
#docs-table tbody tr.target-row {
  background: #dbeafe !important;
  outline: 2px solid #2563eb;
  outline-offset: -2px;
}
#docs-table tbody tr.target-row td:first-child {
  position: relative;
}
#docs-table tbody tr.target-row td:first-child::after {
  content: 'приёмник';
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  background: #2563eb;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
}
#docs-table td.cmt {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #4b5563;
  font-size: 13px;
}

/* Filter row in table head */
.filters-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-bottom: 0;
}
.filter-row th { background: #f3f4f6; padding: 4px 6px; }
.filter-row input.col-filter {
  width: 100%;
  box-sizing: border-box;
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
}
.filter-row input.col-filter.active {
  background: #fef3c7;
  border-color: #f59e0b;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-error   { background: #fee2e2; color: #991b1b; }
.badge-pending { background: #dbeafe; color: #1e40af; }

/* Header right + help button */
.header-right { display: flex; align-items: center; gap: 12px; }
.help-btn {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.help-btn:hover { background: rgba(255,255,255,0.30); }

/* Help panel (drawer справа) */
.help-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 480px; max-width: 95vw;
  background: #fff;
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  z-index: 900;
  display: flex; flex-direction: column;
  animation: slide-in .2s ease-out;
}
.help-panel[hidden] { display: none; }
@keyframes slide-in {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}
.help-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid #e5e7eb;
  background: #1f2937; color: #fff;
}
.help-panel-header h3 { margin: 0; font-size: 16px; }
.help-close {
  background: transparent; border: 0; color: #fff;
  font-size: 26px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.help-close:hover { color: #fbbf24; }
.help-panel-body {
  padding: 16px 20px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.5;
  color: #1f2937;
}
.help-panel-body h4 { margin: 16px 0 6px; color: #1e40af; font-size: 14px; }
.help-panel-body h4:first-child { margin-top: 0; }
.help-panel-body p { margin: 6px 0; }
.help-panel-body ol, .help-panel-body ul { margin: 6px 0; padding-left: 22px; }
.help-panel-body li { margin: 4px 0; }
.help-panel-body b { color: #111827; }

/* Shipments page */
.page-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 12px;
}
.page-header h1 { margin: 0; font-size: 22px; }
.page-header .dow {
  text-transform: capitalize;
  color: #6b7280;
  font-size: 16px;
}
.page-header .auto-refresh-hint {
  margin-left: auto;
  color: #6b7280;
  font-size: 12px;
  font-style: italic;
}

.shipments-nav { gap: 8px; }
.shipments-nav .btn { white-space: nowrap; }

/* Счётчик «осталось собрать/упаковать» в шапке бланка. */
.shipments-counters {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-left: 16px;
}
.counter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  font-size: 14px;
  white-space: nowrap;
}
.counter-pill strong {
  font-size: 16px;
  font-weight: 700;
  color: #c2410c;
}
.counter-pill.counter-done {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}
.counter-pill.counter-done strong { color: #047857; }

/* Меню «Колонки ▾» */
.cols-menu { position: relative; display: inline-block; }
.cols-menu > summary {
  list-style: none;
  cursor: pointer;
  display: inline-block;
  user-select: none;
}
.cols-menu > summary::-webkit-details-marker { display: none; }
.cols-menu .cols-list {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  padding: 8px 12px;
  min-width: 200px;
  max-height: 60vh;
  overflow-y: auto;
}
.cols-menu .cols-list label {
  display: block;
  padding: 3px 0;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.cols-menu .cols-list input { margin-right: 6px; }

/* Скрытие колонок по toggle */
.shipments-table.hide-col-storage .col-storage,
.shipments-table.hide-col-deal    .col-deal,
.shipments-table.hide-col-bazon   .col-bazon,
.shipments-table.hide-col-name    .col-name,
.shipments-table.hide-col-tk      .col-tk,
.shipments-table.hide-col-zhu     .col-zhu,
.shipments-table.hide-col-city    .col-city,
.shipments-table.hide-col-found   .col-found,
.shipments-table.hide-col-defect  .col-defect,
.shipments-table.hide-col-packed  .col-packed,
.shipments-table.hide-col-dim     .col-dim,
.shipments-table.hide-col-docs    .col-docs,
.shipments-table.hide-col-cut     .col-cut,
.shipments-table.hide-col-shipped .col-shipped,
.shipments-table.hide-col-cmt     .col-cmt,
.shipments-table.hide-col-label   .col-label,
.shipments-table.hide-col-move    .col-move { display: none; }

/* Горизонтальная прокрутка для широкой таблицы */
.shipments-scroll {
  overflow-x: auto;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
}

.shipments-table {
  font-size: 12px;
  table-layout: auto;
  width: auto;             /* не растягиваем — колонки минимальной ширины по заголовку/контенту */
  border-collapse: collapse;
}
.shipments-table thead th { white-space: nowrap; } /* заголовки не переносятся → колонка ≥ ширины заголовка */
.shipments-table th, .shipments-table td {
  padding: 5px 6px;
  vertical-align: middle;
  border: 1px solid #e5e7eb;
  overflow: hidden;
}
.shipments-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: #e5e7eb;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 0.2px;
  white-space: nowrap;
  padding: 0;
  vertical-align: top;
  box-sizing: border-box;
}
/* Двухуровневый заголовок: лейбл сверху (h=28px), фильтр/spacer снизу (h=28px). Итого ровно 56px. */
.shipments-table thead th > .th-label,
.shipments-table thead th > .th-spacer,
.shipments-table thead th > .col-filter {
  display: block;
  box-sizing: border-box;
  height: 28px;
  padding: 6px 4px;
  margin: 0;
}
.shipments-table thead th > .th-label {
  border-bottom: 1px solid #d1d5db;
  white-space: normal;
  line-height: 1.05;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shipments-table thead th > .th-spacer { background: #ececee; }
.shipments-table thead th > .col-filter {
  width: 100%;
  font-size: 11px;
  font-weight: normal;
  text-transform: none;
  letter-spacing: 0;
  border: 1px solid #d1d5db;
  border-radius: 0;
  background: #fff;
  text-align: left;
  padding: 4px 6px;
}
.shipments-table thead th > .col-filter.active {
  background: #fef3c7;
  border-color: #f59e0b;
}

/* Ширины колонок (px) — настроены под полное отображение заголовков */
/* === Колонки: ширина = max(заголовок, контент). Без явных width — браузер сам подгонит. === */
.col-num     { text-align: center; font-weight: 700; color: #6b7280; }
.col-pick    { text-align: center; }
.col-deal    { text-align: center; }
.col-bazon   { text-align: center; }
.col-label   { text-align: center; }
.col-name    { font-size: 12px; line-height: 1.3; min-width: 200px; }
.col-city    { white-space: nowrap; }
.col-city .track-text,
.col-city input.cell-input { white-space: nowrap; }

.shipments-table input.cell-input,
.shipments-table select.cell-input,
.shipments-table textarea.cell-input,
.shipments-table textarea.cell-textarea {
  /* Ширина = по содержимому (Chrome 123+/Edge), либо естественная ширина input. */
  field-sizing: content;
  width: auto;
  min-width: 60px;
  max-width: 220px;
  padding: 3px 5px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 12px;
  background: #fff;
  box-sizing: border-box;
}
.shipments-table textarea.cell-textarea { min-width: 70px; resize: none; }
.shipments-table input[type="date"].cell-input {
  font-size: 11px;
  padding: 2px 4px;
}
.shipments-table .col-label .btn {
  display: inline-block;
  width: 100%;
  padding: 5px 0;
  font-size: 11px;
  text-align: center;
  box-sizing: border-box;
  white-space: nowrap;
}
.shipments-table .col-label a { text-decoration: none; }
.shipments-table input[readonly] { background: #f3f4f6; }
.shipments-table input:disabled,
.shipments-table select:disabled { background: #f3f4f6; cursor: not-allowed; }
.shipments-table .cell-cb { text-align: center; }
.shipments-table .cell-cb input { transform: scale(1.3); }
.shipments-table .col-name div,
.shipments-table .col-bazon div { white-space: normal; line-height: 1.4; }
.shipments-table .bazon-id { font-family: ui-monospace, monospace; font-size: 12px; }
.shipments-table .muted { color: #6b7280; }
.shipments-table .muted.small { font-size: 10px; }

/* Гиперссылки */
.shipments-table .deal-link {
  font-weight: 700;
  color: #1d4ed8;
  text-decoration: none;
}
.shipments-table .deal-link:hover { text-decoration: underline; }
.shipments-table .track-link {
  font-family: ui-monospace, monospace;
  color: #047857;
  font-weight: 600;
  text-decoration: none;
}
.shipments-table .track-link:hover { text-decoration: underline; }

.shipments-table .track-link-muted {
  font-family: ui-monospace, monospace;
  color: #6b7280;
  font-style: italic;
}
.shipments-table .track-text {
  font-family: ui-monospace, monospace;
  color: #1f2937;
  font-size: 12px;
  word-break: break-all;
}

/* Сделка отменена/удалена в Bazon — остаётся в списке, светло-серая, со стрингтрук-номером */
/* Зебра-полоски — яркий серый/белый. !important чтобы перебить мелкие подсветки выше по файлу. */
.shipments-table tbody tr:nth-child(even):not(.row-cancelled):not(.row-late) td { background: #e5e7eb !important; }
.shipments-table tbody tr:nth-child(odd):not(.row-cancelled):not(.row-late)  td { background: #ffffff !important; }
.shipments-table tbody tr td { border-bottom: 2px solid #6b7280; }
.shipments-table tbody tr:hover td        { background: #fde68a !important; }
.shipments-table tbody tr.row-cancelled td { background: #f3f4f6 !important; color: #6b7280; }
.shipments-table tbody tr.row-cancelled .deal-link { text-decoration: line-through; color: #9ca3af; }
.shipments-table tbody tr.row-cancelled input,
.shipments-table tbody tr.row-cancelled select,
.shipments-table tbody tr.row-cancelled textarea {
  background: #f3f4f6 !important;
  color: #6b7280;
}
.badge-cancelled {
  display: inline-block;
  margin-top: 2px;
  padding: 2px 6px;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* Чередование строк */
.shipments-table tbody tr:nth-child(even) td { background: #fafafa; }
.shipments-table tbody tr:hover td { background: #fff7ed; }

/* Зелёные галочки в чекбоксах статусов (без подсветки всей строки). */
.shipments-table .col-found   input[type="checkbox"]:checked,
.shipments-table .col-packed  input[type="checkbox"]:checked,
.shipments-table .col-shipped input[type="checkbox"]:checked {
  accent-color: #16a34a;
  outline: 2px solid #16a34a;
  outline-offset: 1px;
}

/* Розовая подсветка проблемных сделок (не определилась ТК). Приоритет над зеброй. */
.shipments-table tbody tr.row-problem td { background: #fce7f3 !important; }
.shipments-table tbody tr.row-problem td:first-child { border-left: 4px solid #ec4899; }

/* Просроченные строки (overdue) — янтарная заливка + красная полоска слева. */
.shipments-table tbody tr.row-late td  { background: #fff7ed !important; }
.shipments-table tbody tr.row-late td:first-child { border-left: 4px solid #dc2626; }
.shipments-table tbody tr.row-late td.col-num::before {
  content: '⚠ ';
  color: #b91c1c;
  font-weight: 700;
}

.shipments-table tbody tr:hover td { background: #fffaf2 !important; }

/* Метка «АВИТО ДОСТАВКА» в колонке ТК для авито-сделок. */
.shipments-table .badge-avito {
  display: inline-block;
  padding: 3px 6px;
  background: #fef3c7;
  color: #92400e;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.shipments-table .badge-avito-mini {
  margin-top: 2px;
  font-size: 10px;
  color: #92400e;
  text-align: center;
  font-style: italic;
}

.shipments-table.compact th, .shipments-table.compact td { padding: 3px 6px; }

/* textarea с авто-resize в колонке комментариев и доп.дефектов */
.shipments-table .cell-textarea {
  resize: none;
  height: 26px;
  min-height: 26px;
  max-height: 100px;
  padding: 3px 5px;
  box-sizing: border-box;
  vertical-align: middle;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.35;
  overflow-y: hidden;
  display: block;
  width: 100%;
}
.shipments-table .cell-textarea:focus { overflow-y: auto; }

/* Toggle-кнопки в активном состоянии */
.btn-toggle-on {
  background: #2563eb !important;
  color: #fff !important;
}

/* Сворачиваемый список товаров (>3 в сделке) */
.shipments-table .items-collapse > summary {
  cursor: pointer;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 600;
  list-style: none;
  user-select: none;
  padding: 2px 0;
}
.shipments-table .items-collapse > summary::-webkit-details-marker { display: none; }
.shipments-table .items-collapse > summary::before {
  content: '▸ ';
  display: inline-block;
  transition: transform .15s;
}
.shipments-table .items-collapse[open] > summary::before { content: '▾ '; }
.shipments-table .items-collapse[open] > summary { margin-bottom: 4px; }
.shipments-table .items-collapse > div { margin-left: 4px; }

.overdue-section {
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
}
.overdue-section h3 { margin: 0 0 8px; font-size: 14px; }

/* Modal */
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5);
}
.modal-content {
  position: relative;
  background: #fff; border-radius: 8px;
  padding: 24px 28px;
  max-width: 500px; width: 90%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.modal-content h3 { margin: 0 0 12px; }
.modal-content p { white-space: pre-line; margin: 0 0 16px; line-height: 1.5; color: #374151; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
