* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: #f4f5f7;
  color: #1a1a1a;
}

#login-screen, #app-screen, #receive-screen {
  display: none;
}
body.state-login #login-screen { display: flex; }
body.state-app #app-screen { display: block; }
body.state-receive #receive-screen { display: flex; }

/* ---------- Login ---------- */
#login-screen {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
}
#login-box {
  background: #fff;
  padding: 32px;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
  width: 320px;
}
#login-box .brand { margin-bottom: 20px; }
#login-box h1 { font-size: 20px; margin: 0; }
#login-box input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 15px;
}
#login-box button {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: #6c5ce7;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}
#login-error { color: #d63031; font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ---------- App shell ---------- */
header {
  background: #fff;
  border-bottom: 1px solid #e2e4e8;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
header h1 { font-size: 18px; margin: 0; flex: 0 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand-logo { width: 30px; height: 30px; flex: none; border-radius: 8px; }
#login-box .brand-logo { width: 40px; height: 40px; }
header nav { display: flex; gap: 8px; }
header nav button {
  padding: 8px 14px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: #444;
}
header nav button.active { background: #ecebfe; color: #6c5ce7; font-weight: 600; }
.spacer { flex: 1; }
#btn-start-receive {
  background: #00b894;
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
#user-info { font-size: 13px; color: #777; }
#btn-logout { background: none; border: none; color: #d63031; cursor: pointer; font-size: 13px; }

main { padding: 20px; max-width: 1100px; margin: 0 auto; }
.tab-page { display: none; }
.tab-page.active { display: block; }

/* ---------- Table page ---------- */
#search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
#search-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 14px;
}

table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid #eee; font-size: 13px; vertical-align: middle; }
th { background: #fafafa; font-weight: 600; color: #777; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
#items-table td:first-child { width: 52px; }
.item-thumb { width: 44px; height: 44px; object-fit: contain; border-radius: 8px; background: #f4f5f7; border: 1px solid #f0f0f0; }
.group-row td:nth-child(2) { font-weight: 500; }
tr:hover td { background: #fafbff; }
.cell-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  background: #ecebfe;
  color: #6c5ce7;
  font-weight: 600;
  font-size: 12px;
}
.marketplace-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 11px;
}
.marketplace-badge.wb { background: #f3e6ff; color: #8b1fce; }
.marketplace-badge.ozon { background: #dbf3ff; color: #005bff; }

.qty-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border-radius: 8px;
  background: #e8f8f0;
  color: #00a37a;
  font-weight: 700;
  font-size: 13px;
}
.group-summary-cell { color: #666; }
.group-cells { color: #999; font-size: 12px; }
.expand-btn {
  border: 1px solid #e4e2fb;
  background: #f6f5ff;
  color: #6c5ce7;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  white-space: nowrap;
}
.expand-btn:hover { background: #ecebfe; }
.group-details-row td { padding: 4px 12px 16px; border-bottom: 1px solid #eee; background: #fafbfd; }
.group-details-table { width: 100%; background: #fff; border-radius: 10px; overflow: hidden; border: 1px solid #eee; }
.group-details-table th, .group-details-table td { padding: 9px 12px; font-size: 12px; border-bottom: 1px solid #f0f0f0; }
.group-details-table th { background: #f7f7fb; text-transform: none; letter-spacing: normal; font-size: 11px; }
.group-details-table tr:last-child td { border-bottom: none; }
.issue-btn {
  border: 1px solid #eee;
  background: #fff;
  color: #d63031;
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.issue-btn:hover { background: #fdecea; border-color: #fbdadb; }
#pagination { display: flex; gap: 8px; justify-content: center; margin-top: 16px; align-items: center; }
#pagination button {
  padding: 6px 12px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
}
#pagination button:disabled { opacity: .4; cursor: default; }

/* ---------- Settings page ---------- */
.settings-section {
  background: #fff;
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 16px;
}
.settings-section h3 { margin-top: 0; }
.settings-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.settings-row label { width: 220px; font-size: 14px; color: #444; }
.settings-row input, .settings-row select { padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 14px; }
.btn { padding: 8px 16px; border: none; border-radius: 8px; background: #6c5ce7; color: #fff; cursor: pointer; font-size: 14px; }
.btn.secondary { background: #eee; color: #333; }
.btn.danger { background: #d63031; }
.small-input { width: 90px; }

.catalog-key-row {
  background: #f9f9fb;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.catalog-key-row .row-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.catalog-key-row .row-top strong { font-size: 14px; }
.catalog-status-badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #eee;
  color: #555;
}
.catalog-status-badge.running { background: #dff5ee; color: #00b894; }
.catalog-status-badge.done { background: #eaf6ff; color: #0984e3; }
.catalog-status-badge.error, .catalog-status-badge.interrupted { background: #fdecea; color: #d63031; }
.catalog-progress-bar {
  height: 6px;
  background: #eee;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}
.catalog-progress-bar-fill { height: 100%; background: #6c5ce7; transition: width .3s; }
.catalog-key-row .row-meta { font-size: 12px; color: #888; }
.catalog-key-row .row-error { font-size: 12px; color: #d63031; margin-top: 4px; }

#cells-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.cell-chip {
  background: #f4f5f7;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cell-chip button { border: none; background: none; color: #d63031; cursor: pointer; font-size: 14px; line-height: 1; }

/* ---------- Receive mode ---------- */
#receive-screen {
  position: fixed;
  inset: 0;
  background: #1a1a2e;
  color: #fff;
  flex-direction: column;
  z-index: 100;
}
#receive-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
}
#receive-close {
  background: rgba(255,255,255,.1);
  border: none;
  color: #fff;
  font-size: 22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
}
#receive-cell-label { font-size: 16px; color: #aaa; }
#receive-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}
#receive-cell-code {
  font-size: 28px;
  color: #00cec9;
  font-weight: 700;
  margin-bottom: 30px;
}
#receive-product-photo {
  display: none;
  max-height: 220px;
  max-width: 320px;
  border-radius: 12px;
  margin-bottom: 20px;
  object-fit: contain;
  background: #fff;
}
#receive-product-photo.visible { display: block; }
#receive-product-name {
  font-size: 40px;
  font-weight: 700;
  max-width: 900px;
  line-height: 1.3;
  margin-bottom: 16px;
}
#receive-product-meta {
  font-size: 18px;
  color: #ccc;
  margin-bottom: 10px;
}
#receive-status {
  font-size: 20px;
  min-height: 28px;
  margin-top: 10px;
}
#receive-status.ok { color: #55efc4; }
#receive-status.err { color: #ff7675; }
#receive-hint { color: #888; font-size: 15px; margin-top: 40px; }

#receive-bottom {
  padding: 24px;
  display: flex;
  gap: 12px;
  justify-content: center;
  background: rgba(0,0,0,.2);
}
#receive-input {
  padding: 14px 18px;
  font-size: 18px;
  border-radius: 10px;
  border: none;
  width: 320px;
}
#receive-submit {
  padding: 14px 24px;
  font-size: 16px;
  border: none;
  border-radius: 10px;
  background: #6c5ce7;
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}

.cell-chip input[type="checkbox"] { margin-right: 2px; }

/* ---------- Sync modal ---------- */
#sync-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  align-items: center;
  justify-content: center;
  z-index: 200;
}
body.sync-modal-open #sync-modal { display: flex; }
#sync-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px 28px;
  width: 480px;
  max-width: 90vw;
}
#sync-box-header { display: flex; justify-content: space-between; align-items: center; }
#sync-box-header h2 { font-size: 18px; margin: 0; }
#sync-box-header button { border: none; background: none; font-size: 20px; cursor: pointer; color: #888; }
#sync-required-notice { color: #d63031; font-size: 13px; background: #fdecea; padding: 10px 12px; border-radius: 8px; }
#sync-required-notice.hidden { display: none; }
#sync-period-presets { display: flex; gap: 8px; }
#sync-period-presets .btn.active { background: #6c5ce7; color: #fff; }
#sync-date-from, #sync-date-to { padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; }
#sync-keys-list { display: flex; flex-direction: column; gap: 6px; }
#sync-keys-list label { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: normal; width: auto; }
#sync-status-line { font-size: 13px; color: #666; margin: 12px 0; }
#sync-run-btn { width: 100%; }
#sync-run-btn:disabled { opacity: .5; cursor: default; }
#sync-error { color: #d63031; font-size: 13px; margin-top: 10px; min-height: 16px; }
#sync-error.schema-mismatch {
  background: #fff3cd;
  color: #856404;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 600;
}
#sync-indicator { font-size: 12px; color: #888; }
#sync-indicator.stale { color: #d63031; }

/* ---------- Export modal ---------- */
#export-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  align-items: center;
  justify-content: center;
  z-index: 200;
}
body.export-modal-open #export-modal { display: flex; }
#export-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px 28px;
  width: 480px;
  max-width: 90vw;
}
#export-box-header { display: flex; justify-content: space-between; align-items: center; }
#export-box-header h2 { font-size: 18px; margin: 0; }
#export-box-header button { border: none; background: none; font-size: 20px; cursor: pointer; color: #888; }
.export-hint { color: #888; font-size: 13px; margin: 4px 0 16px; }
#export-period-presets { display: flex; gap: 8px; }
#export-period-presets .btn.active { background: #6c5ce7; color: #fff; }
#export-date-from, #export-date-to { padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; }
.export-buttons { display: flex; gap: 10px; margin-top: 18px; }
.export-buttons .btn { flex: 1; }
#export-error { color: #d63031; font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ---------- Print labels (этикетка 75x120мм) ---------- */
#print-area { display: none; }
body.printing-labels #app-screen,
body.printing-labels #login-screen,
body.printing-labels #receive-screen { display: none !important; }
body.printing-labels #print-area { display: block; }

@page {
  size: 75mm 120mm;
  margin: 0;
}

.print-label-page {
  page-break-after: always;
  width: 75mm;
  height: 120mm;
  box-sizing: border-box;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.print-label-page:last-child { page-break-after: auto; }

/* Контент рисуется в "landscape"-системе координат (120x75мм — как если бы
   этикетка была развёрнута на 90°), затем весь блок целиком поворачивается
   на 90° вокруг своего центра. Раз ширина/высота уже заданы под повёрнутое
   расположение, transform не обрезается родительским overflow:hidden. */
.print-label-rotate {
  width: 120mm;
  height: 75mm;
  flex: none;
  transform: rotate(90deg);
  box-sizing: border-box;
  padding: 4mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3mm;
}
.print-label-code {
  font-size: 15mm;
  line-height: 1;
  font-weight: 800;
  font-family: Arial, sans-serif;
}
.print-label-page svg { width: 95mm; height: auto; max-width: 100%; flex: none; }
