/* ============================================================
   COMPONENTS — all reusable UI pieces
   ============================================================ */

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--border-dark); background: var(--bg); }
.btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #dc2626; border-color: #dc2626; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); border-color: var(--border); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-icon { padding: 7px; border-radius: var(--radius-sm); }

/* ---- Card / Panel ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  flex-shrink: 0;
}
.card-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

/* ---- Dropzone ---- */
.dropzone {
  border: 1.5px dashed var(--border-dark);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-soft);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone-icon {
  width: 36px;
  height: 36px;
  margin: 0 auto 10px;
  color: var(--accent-dark);
}
.dropzone-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.dropzone-sub {
  font-size: 12px;
  color: var(--text-muted);
}
input[type="file"] { display: none; }

/* ---- Form fields ---- */
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}
.field-row { display: flex; gap: 8px; }
.field-row > * { flex: 1; }

input[type="text"],
input[type="number"],
input[type="email"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="number"] { font-family: var(--font-mono); }

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 10px;
}
.checkbox-line input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.collapsible { display: none; padding-top: 10px; border-top: 1px dashed var(--border); margin-top: 4px; }
.collapsible.open { display: block; }

/* ---- File list ---- */
.file-list { list-style: none; margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 12px;
}
.file-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.file-item-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.file-item-remove { background: none; border: none; color: var(--text-muted); font-size: 14px; padding: 2px 4px; }
.file-item-remove:hover { color: var(--danger); }

/* ---- Preview grid (thumbnails) ---- */
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.preview-header-title { font-size: 15px; font-weight: 700; color: var(--text); }
.preview-count { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.thumb-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  user-select: none;
  transition: box-shadow .15s;
}
.thumb-card:hover { box-shadow: var(--shadow); }
.thumb-card.dragging { opacity: .35; }
.thumb-card.drag-over { outline: 2px dashed var(--accent); outline-offset: 2px; }

.thumb-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  cursor: zoom-in;
}
.thumb-img {
  max-width: 92%;
  max-height: 92%;
  object-fit: contain;
  box-shadow: var(--shadow-sm);
}
.thumb-spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

.thumb-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}
.thumb-actions-group { display: flex; gap: 2px; }
.thumb-btn {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.thumb-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark); }
.thumb-btn.danger:hover { background: #fee2e2; border-color: var(--danger); color: var(--danger); }
.thumb-drag-handle { cursor: grab; color: var(--text-muted); touch-action: none; }

.thumb-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}
.thumb-pos {
  background: var(--accent);
  color: #fff;
  border-radius: 99px;
  padding: 1px 7px;
  font-weight: 700;
}
.thumb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 80px;
}

/* ---- Empty state ---- */
.empty-state {
  border: 1.5px dashed var(--border-dark);
  border-radius: var(--radius);
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
}
.empty-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  color: var(--border-dark);
}
.empty-state-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state-desc { font-size: 13px; color: var(--text-muted); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: min(900px, 94vw);
  width: 100%;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 14px; font-weight: 700; }
.modal-info { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }
.modal-body {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  padding: 20px;
  position: relative;
}
.modal-body canvas, .modal-body img {
  max-width: 100%;
  box-shadow: var(--shadow-lg);
  background: #fff;
}
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.modal-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.modal-nav-btn:hover { background: var(--bg); }
.modal-nav-btn.prev { left: 14px; }
.modal-nav-btn.next { right: 14px; }

/* ---- Zoom controls ---- */
.zoom-controls { display: flex; align-items: center; gap: 8px; }
.zoom-controls input[type="range"] { width: 120px; accent-color: var(--accent); }
.zoom-label { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); width: 44px; text-align: center; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 500;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---- Busy overlay ---- */
.busy-overlay {
  position: fixed;
  inset: 0;
  background: rgba(243,244,246,.88);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
}
.busy-overlay.open { display: flex; }
.busy-spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
.busy-text { font-family: var(--font-mono); font-size: 13px; color: var(--text-muted); }

/* ---- Divider ---- */
.divider { border: none; border-top: 1px dashed var(--border); margin: 12px 0; }

/* ---- Animations ---- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeIn .3s ease forwards; }

/* ---- Scrollbar (global thin style) ---- */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
*::-webkit-scrollbar-thumb:hover { background: var(--border-dark); }
