* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #222;
  background: #f5f5f5;
}

body.lightbox-open,
body.modal-open {
  overflow: hidden;
}

.hidden { display: none !important; }

.screen { display: none; height: 100vh; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- ЭКРАН ЗАГРУЗКИ ---------- */

#screen-load {
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 16px;
  overflow-y: auto;
}

#screen-load h1 { margin-bottom: 16px; font-weight: 500; }

.load-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 420px;
}

.load-block label { font-weight: 500; }

.load-status {
  font-size: 12px;
  color: #666;
  min-height: 16px;
}

.load-hint { font-size: 12px; color: #888; }
.load-hint.error { color: #b00; }

.load-error {
  color: #b00;
  min-height: 20px;
  margin-top: 8px;
}

/* ---------- КНОПКИ И ПОЛЯ ---------- */

.btn {
  padding: 6px 12px;
  border: 1px solid #bbb;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}
.btn:hover:not(:disabled) { background: #eee; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: #2a6; color: #fff; border-color: #2a6; }
.btn.primary:hover:not(:disabled) { background: #1a5; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn.toggle.active { background: #fa0; color: #fff; border-color: #fa0; }

.btn:focus-visible,
input:focus-visible {
  outline: 2px solid #2a6;
  outline-offset: 1px;
}

input[type="text"], input[type="number"] {
  padding: 6px 8px;
  border: 1px solid #bbb;
  border-radius: 4px;
  font-size: 13px;
}
input[type="number"] { width: 100px; }
#input-number { width: 190px; }

input.invalid {
  border-color: #b00;
  background: #fff5f5;
  box-shadow: 0 0 0 1px #b00;
}

/* ---------- ЭКРАН РАБОТЫ ---------- */

#topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid #ddd;
  font-size: 13px;
  gap: 12px 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#topbar-row {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 440px;
}

#progress-bar {
  width: 160px;
  height: 8px;
  flex: 0 0 auto;
  accent-color: #2a6;
}

#topbar-progress { white-space: nowrap; }

#topbar-preview-progress { color: #888; font-size: 12px; }

#help-panel {
  background: #fff;
  border-bottom: 1px solid #ddd;
  padding: 10px 16px;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 6px 18px;
  color: #555;
  font-size: 12px;
}

kbd {
  display: inline-block;
  background: #f0f0f0;
  border: 1px solid #ccc;
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0 4px;
  font-family: inherit;
  font-size: 11px;
}

#work-area {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

#col-new {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px;
  overflow: hidden;
  border-right: 1px solid #ddd;
  min-width: 0;
}

#new-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 500;
  flex-wrap: wrap;
}

#new-status {
  margin-left: auto;
  font-size: 12px;
  font-weight: 400;
  color: #666;
}

.flag {
  display: none;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 50%;
  background: #fa0;
  color: #fff;
  font-size: 12px;
  cursor: help;
}
.flag.visible { display: inline-block; }

#new-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
  align-content: start;
}

.thumb {
  position: relative;
  background: #eee;
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
  cursor: zoom-in;
  aspect-ratio: 4 / 3;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.thumb img.pending,
.old-card .card-thumb img.pending {
  visibility: hidden;
}

.thumb .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #aaa;
  font-size: 12px;
}

.thumb .placeholder.error { color: #b00; }

.thumb .name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 11px;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#new-txt-hint {
  margin-top: 8px;
  font-size: 12px;
  color: #999;
  font-style: italic;
  min-height: 16px;
  white-space: pre-wrap;
}

#col-old {
  width: 480px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#old-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid #eee;
  font-weight: 500;
}

#old-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.old-card {
  display: flex;
  gap: 8px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 6px;
  align-items: center;
  transition: box-shadow 0.2s, border-color 0.2s, background 0.2s;
}

.old-card.assigned {
  border-color: #2a6;
  background: #f0faf4;
}

.old-card.flash {
  box-shadow: 0 0 0 3px #fa0;
}

.old-card .card-thumb {
  width: 120px;
  height: 90px;
  background: #eee;
  border-radius: 3px;
  overflow: hidden;
  cursor: zoom-in;
  flex-shrink: 0;
  position: relative;
}

.old-card .card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-thumb .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #aaa;
  font-size: 12px;
}
.card-thumb .placeholder.error { color: #b00; }

.old-card .card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.old-card .card-number {
  font-weight: 600;
  font-size: 15px;
}

.old-card .card-meta {
  font-size: 11px;
  color: #888;
}

.old-card .card-assign {
  font-size: 11px;
  color: #2a6;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 16px;
  flex-wrap: wrap;
}
.old-card .card-assign:empty { display: none; }

.old-card .card-actions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

/* ---------- НИЖНЯЯ ПАНЕЛЬ ---------- */

#bottombar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: #fff;
  border-top: 1px solid #ddd;
}

.bottom-left, .bottom-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

#number-hint {
  flex-basis: 100%;
  font-size: 11px;
  color: #888;
}

.action-message {
  flex-basis: 100%;
  min-height: 16px;
  font-size: 12px;
}
.action-message.error { color: #b00; }
.action-message.success { color: #2a6; }
.action-message.info { color: #555; }

#warnings {
  flex-basis: 100%;
  font-size: 12px;
  color: #b00;
  min-height: 16px;
  max-height: 72px;
  overflow-y: auto;
}

.warning-item {
  display: inline;
  margin-right: 10px;
}

.warning-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: #b00;
  text-decoration: underline;
  cursor: pointer;
}
.warning-link:hover { color: #800; }

/* ---------- ЛАЙТБОКС ---------- */

#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
#lightbox.hidden { display: none; }

#lightbox-content {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#lightbox-img {
  max-width: 95vw;
  max-height: 90vh;
  object-fit: contain;
  display: none;
}
#lightbox-img.loaded { display: block; }

#lightbox-spinner {
  color: #fff;
  font-size: 16px;
  position: absolute;
}

.lightbox-btn {
  position: absolute;
  background: none;
  border: 0;
  color: #fff;
  cursor: pointer;
  user-select: none;
  line-height: 1;
  padding: 0;
  font-family: inherit;
  z-index: 2;
}
.lightbox-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 4px;
  border-radius: 4px;
}

#lightbox-close { top: 16px; right: 24px; font-size: 36px; }
#lightbox-prev, #lightbox-next {
  top: 50%;
  transform: translateY(-50%);
  font-size: 60px;
  padding: 0 20px;
}
#lightbox-prev { left: 0; }
#lightbox-next { right: 0; }

#lightbox-caption {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 13px;
  background: rgba(0,0,0,0.5);
  padding: 4px 12px;
  border-radius: 4px;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- МОДАЛ ЭКСПОРТА ---------- */

#export-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
#export-modal.hidden { display: none; }

.modal-box {
  background: #fff;
  border-radius: 6px;
  padding: 24px;
  min-width: 400px;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-box h2 { margin-bottom: 16px; font-weight: 500; }

#export-summary { font-size: 13px; margin-bottom: 12px; }
#export-summary div + div { margin-top: 2px; }

#export-unsure {
  font-size: 12px;
  color: #a60;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ---------- АДАПТИВНОСТЬ ---------- */

@media (max-width: 960px) {
  #work-area { flex-direction: column; }

  #col-new { min-height: 0; }

  #col-old {
    width: 100%;
    max-height: 45vh;
    border-right: 0;
    border-top: 1px solid #ddd;
  }

  .load-block { width: min(420px, 100%); }

  #topbar { align-items: flex-start; }
  .topbar-progress-wrap { order: 3; flex-basis: 100%; max-width: none; }
  #topbar-preview-progress { order: 4; }
}

@media (max-height: 700px) {
  #screen-load { justify-content: flex-start; }
}

@media (max-width: 600px) {
  #screen-load { padding: 24px 16px; }

  #new-grid { grid-template-columns: 1fr; }

  .bottom-left, .bottom-right { width: 100%; }
  .bottom-right { justify-content: flex-end; }

  .modal-box {
    min-width: 0;
    width: calc(100vw - 32px);
    padding: 18px;
  }

  #progress-bar { width: 110px; }
}
