
html { scroll-behavior: smooth; }

/* ── Upload Zone ────────────────────────────────────────────────── */
#uploadZone {
  background: var(--border-color);
  border: 2px dashed var(--primary-color);
  border-radius: 16px;
  padding: 60px 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  margin: 1.5rem;
  position: relative;
}
#uploadZone:hover, #uploadZone.dragover {
  border-color: var(--border-color);
  background: rgb(204 214 255 / 32%);
  transform: translateY(-1px);
}
#uploadZone.dragover { border-style: solid; }
.upload-icon {
  width: 60px; height: 60px;
  background: rgb(232 72 10 / 20%);
  color: #e8480a;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
  font-size: 1.6rem;
  box-shadow:0 4px 20px rgb(232 72 10 / 15%);
}
#uploadZone h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}
#uploadZone p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
}
.btn-upload {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #2fb344;
  color: #fff;
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 14px;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-upload:hover { background: #58C168; transform: translateY(-1px); }
.upload-formats {
  margin-top: 14px;
  font-size: 0.78rem;
  color: var(--text-main);
}
#fileInput { display: none; }

/* ── Toolbar ────────────────────────────────────────────────────── */
#toolbar {
  display: none;
  padding: 14px 20px;
  margin: 20px 0;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar-left { display: flex; align-items: center; gap: 10px; flex: 1; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.page-count-badge {
  background: rgb(104 173 231 / 31%);
  border: 1px solid var(--border-color);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--primary-color);
  padding: 5px 12px;
  border-radius: 5px;
}
.page-count-badge span { color: #e8480a; font-weight: 700; }

.btn-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgb(104 173 231 / 31%);
  border: none;
  color: var(--primary-color);
  font-family: 'Outfit', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-tool:hover { border-color: #e8480a; color: #e8480a; background: rgba(232,72,10,0.05); }
.btn-tool svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn-tool.danger:hover { border-color: #dc2626; color: #dc2626; background: rgba(220,38,38,0.05); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── Sort hint ──────────────────────────────────────────────────── */
#sortHint {
  display: none;
  text-align: center;
  font-size: 0.82rem;
  color:var(--text-muted);
  margin: 20px;
  padding: 8px;
  background: rgb(174 213 247 / 22%);
  border-radius: 4px;
  border: 1px solid var(--border-color);
}

/* ── Page Grid ──────────────────────────────────────────────────── */
#pagesGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 40px;
  padding: 0 20px;
}

.page-card {
  background: #f3f6fb;
  border: 2px solid var(--border-color);
  border-radius: 5px;
  overflow: hidden;
  cursor: grab;
  position: relative;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s, opacity 0.15s;
  user-select: none;
  animation: cardIn 0.3s ease both;
}
@keyframes cardIn {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.page-card:hover {
  border-color: var(--primary-color);
  box-shadow: 0 4px 20px rgb(104 173 231 / 31%);
  transform: translateY(-2px);
}
.page-card.selected {
  border-color: var(--primari-color);
  box-shadow: 0 0 0 3px rgb(104 173 231 / 31%);
}
.page-card.dragging {
  opacity: 0.35;
  transform: scale(0.97);
  cursor: grabbing;
}
.page-card.drag-over {
  border-color: var(--primary-color);
  border-style: dashed;
  background: rgb(104 173 231 / 31%);
}
.page-card.deleted {
  opacity: 0;
  transform: scale(0.85);
  transition: all 0.25s ease;
}

/* thumbnail */
.page-thumb-wrap {
  position: relative;
  aspect-ratio: 0.707;
  background: #fff;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.page-thumb-wrap canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: transform 0.3s ease;
}
.thumb-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #fafaf9;
}
.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--border-color);
  border-top-color: #e8480a;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* page actions overlay */
.page-actions {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 6px;
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
  background: linear-gradient(to bottom, rgba(0,0,0,0.4), transparent);
  border-radius: 10px 10px 0 0;
}
.page-card:hover .page-actions { opacity: 1; }

.act-btn {
  width: 26px; height: 26px;
  background: rgba(255,255,255,0.9);
  border: none;
  border-radius: 5px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  transition: background 0.1s, transform 0.1s;
  color: var(--text-main);
  backdrop-filter: blur(4px);
}
.act-btn:hover { background: #fff; transform: scale(1.1); }
.act-btn.del:hover { background: #fee2e2; color: #dc2626; }
.act-btn svg { width: 12px; height: 12px; }

/* page footer */
.page-footer {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-color);
}
.page-num {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}
.page-src {
  font-size: 0.65rem;
  color: var(--text-muded);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rotation-badge {
  font-size: 0.62rem;
  font-weight: 600;
  color: #e8480a;
  background: rgba(232,72,10,0.1);
  padding: 2px 5px;
  border-radius: 3px;
}

/* ── Select mode overlay ────────────────────────────────────────── */
.select-check {
  position: absolute;
  top: 6px; left: 6px;
  width: 20px; height: 20px;
  background: #fff;
  border: 2px solid var(--border-color);
  border-radius: 5px;
  display: none;
  align-items: center; justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.select-mode .select-check { display: flex; }
.select-mode .page-card.selected .select-check {
  background: #e8480a;
  border-color: #e8480a;
  color: #fff;
}

/* ── Progress overlay ───────────────────────────────────────────── */
#processingOverlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(240,237,232,0.85);
  backdrop-filter: blur(6px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
}
.overlay-card {
  background: rgb(204 214 255 / 32%);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 40px 48px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  min-width: 300px;
}
.overlay-spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 20px;
}
.overlay-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-main);
  margin-bottom: 6px;
}
.overlay-sub {
  font-size: 0.88rem;
  color: var(--text-muted);
}
.overlay-progress {
  margin-top: 20px;
  background: var(--bg-card);
  border-radius: 100px;
  height: 4px;
  overflow: hidden;
  width: 100%;
}
.overlay-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #ff6b35);
  border-radius: 100px;
  width: 0%;
  transition: width 0.4s ease;
}

/* ── Toast ──────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text-main);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 500;
  padding: 11px 22px;
  border-radius: 100px;
  z-index: 999;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
  white-space: nowrap;
  pointer-events: none;
  display: flex; align-items: center; gap: 7px;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.success { background: #16a34a; }
#toast.error   { background: #dc2626; }

/* ── Info Section ───────────────────────────────────────────────── */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin: 40px 0;
  padding: 0 20px;
}
.feature-card {
  background: rgb(133 199 255 / 9%);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  padding: 15px;
  transition: box-shadow 0.2s;
}
.feature-card:hover { box-shadow: var(--shadow); }
.feature-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  margin-bottom: 14px;
}
.feature-header {
    display: flex;
    gap: 10px;
    align-items: baseline;
    justify-content: flex-start;
}
.feature-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.2px;
}
.feature-card p { font-size: 0.85rem; color: var(--text-muted); line-height: 1.6; }

.section-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}
.section-sub { margin-bottom: 28px; }

/* ── Steps ──────────────────────────────────────────────────────── */
.steps-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 2px;
  margin-bottom: 48px;
  padding: 0 20px;
}
.step-item {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 10px 15px;
  position: relative;
  text-align: center;
}
.step-item:first-child { border-radius: 5px 0 0 5px; }
.step-item:last-child  { border-radius: 0 5px 5px 0; }
.step-n {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-weight: 500;
}
.step-icon { font-size: 1.4rem; margin-bottom: 8px; }
.step-item h3 {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.step-item p { font-size: 0.78rem; color: var(--text-muted); }

/* ── FAQ ────────────────────────────────────────────────────────── */
.faq-section { margin-bottom: 60px; padding:0 20px; }
.faq-item {
    border-bottom: 1px solid var(--border-color);
    border-radius: 5px;
    box-shadow: var(--shadow);
    padding: 0 10px;
}
.faq-q {
  width: 100%; background: none; border: none;
  color: var(--text-main); font-family: 'Outfit', sans-serif;
  font-size: 0.95rem; font-weight: 500; text-align: left;
  padding: 18px 0;
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  transition: color 0.15s;
}
.faq-q:hover { color: #e8480a; }
.faq-q .arr { font-size: 0.6rem; transition: transform 0.25s; color: var(--text-muted); }
.faq-q.open .arr { transform: rotate(180deg); color: #e8480a; }
.faq-a { max-height: 0; overflow: hidden; transition: max-height 0.3s ease; }
.faq-a-inner { padding: 0 0 16px; color: var(--text-muted); font-size: 0.9rem; line-height: 1.7; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #pagesGrid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
  #uploadZone { padding: 40px 20px; }
  h1 { font-size: 1.9rem; }
  .step-item:first-child, .step-item:last-child { border-radius: 0; }
  .step-item: { border-radius:5px !important }
  .steps-row { grid-template-columns: 1fr 1fr; }
}

/* ── Add more PDF button ────────────────────────────────────────── */
.add-more-card {
  background: rgb(204 214 255 / 32%);
  border: 2px dashed var(--border-color);
  border-radius: 10px;
  aspect-ratio: 0.707 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  min-height: 200px;
}
.add-more-card:hover {
  border-color: #e8480a;
  color: #e8480a;
  background: rgb(204 214 255 / 32%);
}
.add-more-card .plus {
  width: 36px; height: 36px;
  border: 2px dashed currentColor;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  line-height: 1;
}