/* ==========================================================================
   Organize PDF Tool — Premium Upscaled & Fully Responsive Stylesheet
   Theme: Royal Blue (#1a3566), Amber Gold (#d97706), Slate, Glassmorphism
   Supported Breakpoints: 320px, 375px, 430px, 768px, 1024px, 1280px+
   ========================================================================== */

/* --- Tool Header & Badges --- */
.tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(26, 53, 102, 0.12);
  box-shadow: 0 4px 16px rgba(26, 53, 102, 0.05);
  font-size: 13px;
  font-weight: 600;
  color: var(--royal-dark, #122549);
  margin-bottom: 18px;
  max-width: 100%;
  text-align: center;
}

.tool-badge svg {
  width: 16px;
  height: 16px;
  color: #059669;
  flex-shrink: 0;
}

/* --- Dropzone Base & Responsive Ergonomics --- */
.dropzone {
  position: relative;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 2px dashed rgba(26, 53, 102, 0.22);
  border-radius: 24px;
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
  box-sizing: border-box;
}

.dropzone:hover {
  background: rgba(255, 255, 255, 0.95);
  border-color: var(--royal, #1a3566);
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(26, 53, 102, 0.08);
}

.dropzone.dragover,
.dropzone.drag-active {
  background: rgba(238, 246, 255, 0.95);
  border-color: #2563eb;
  border-style: solid;
  transform: scale(1.01);
  box-shadow: 0 0 0 5px rgba(37, 99, 235, 0.15), 0 20px 40px rgba(37, 99, 235, 0.12);
}

.file-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 10;
}

.dz-content {
  position: relative;
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.dz-icon-wrapper {
  width: 76px;
  height: 76px;
  border-radius: 22px;
  background: linear-gradient(135deg, #1a3566 0%, #2563eb 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  box-shadow: 0 12px 24px rgba(26, 53, 102, 0.22);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s ease;
}

.dropzone:hover .dz-icon-wrapper {
  transform: translateY(-4px) scale(1.06);
  box-shadow: 0 18px 36px rgba(37, 99, 235, 0.35);
}

.dz-icon-wrapper svg {
  width: 38px;
  height: 38px;
}

.dropzone h3 {
  font-size: 22px;
  font-weight: 800;
  color: var(--royal-dark, #122549);
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.dropzone p {
  font-size: 15px;
  color: var(--slate-600, #475569);
  margin-bottom: 18px;
  line-height: 1.5;
  max-width: 480px;
}

.dz-chips {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
  max-width: 100%;
}

.dz-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(26, 53, 102, 0.06);
  border: 1px solid rgba(26, 53, 102, 0.1);
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--royal, #1a3566);
  white-space: nowrap;
}

.dz-chip svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.dz-btn {
  pointer-events: auto;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 28px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(26, 53, 102, 0.22);
}

/* --- Processing Panel & File Bar --- */
.process-panel {
  animation: slideFadeIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideFadeIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.file-info {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 18px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.03);
  margin-bottom: 20px;
}

.file-icon-box {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(239, 68, 68, 0.25);
  flex-shrink: 0;
}

.file-icon-box svg {
  width: 26px;
  height: 26px;
}

.file-details {
  flex: 1;
  min-width: 0;
}

.file-details h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--slate-800, #1e293b);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-details p {
  font-size: 13px;
  color: var(--slate-500, #64748b);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.btn-icon {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #ef4444;
  transform: rotate(90deg);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

/* --- Error Alert --- */
#errorAlert {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 14px 18px;
  border-radius: 14px;
  margin-bottom: 20px;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* --- Workspace Toolbar --- */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 12px 18px;
  border-radius: 16px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.02);
  gap: 12px;
}

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

.instruction-text {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--slate-600, #475569);
  display: flex;
  align-items: center;
  gap: 6px;
}

.instruction-text svg {
  width: 16px;
  height: 16px;
  color: var(--royal, #1a3566);
  flex-shrink: 0;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-btn {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 10px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: var(--slate-700, #334155);
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.toolbar-btn:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #2563eb;
}

/* --- Page Grid Workspace --- */
.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 20px;
  padding: 22px;
  background: linear-gradient(135deg, rgba(248, 250, 252, 0.8) 0%, rgba(241, 245, 249, 0.9) 100%);
  border-radius: 20px;
  border: 1.5px solid rgba(203, 213, 225, 0.6);
  min-height: 380px;
  max-height: 65vh;
  overflow-y: auto;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.03);
}

/* Custom Scrollbar */
.page-grid::-webkit-scrollbar {
  width: 8px;
}

.page-grid::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.04);
  border-radius: 10px;
}

.page-grid::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.6);
  border-radius: 10px;
}

.page-grid::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.8);
}

/* --- Page Card --- */
.page-card {
  position: relative;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease, border-color 0.2s ease;
  cursor: grab;
  user-select: none;
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 12px 10px;
  box-sizing: border-box;
}

.page-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 25px rgba(26, 53, 102, 0.12);
  border-color: #cbd5e1;
}

.page-card:active {
  cursor: grabbing;
}

.page-card.selected {
  border-color: #2563eb;
  background: #eff6ff;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.18);
}

.page-card.selected .page-number-badge {
  background: linear-gradient(135deg, #1a3566, #2563eb);
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.page-card.dragging {
  opacity: 0.45;
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.page-number-badge {
  position: absolute;
  top: -8px;
  left: -8px;
  background: #f1f5f9;
  color: #334155;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
  z-index: 10;
  transition: all 0.2s ease;
}

.page-canvas-wrapper {
  width: 100%;
  aspect-ratio: 1 / 1.414; /* A4 aspect ratio */
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.04);
}

.page-canvas-wrapper canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.page-canvas-wrapper .loading-spinner {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 3px solid rgba(26, 53, 102, 0.1);
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Page Controls Bar --- */
.page-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 2px 4px 0;
  gap: 6px;
}

.page-control-btn {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: #64748b;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.page-control-btn:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #2563eb;
}

.page-control-btn.delete-btn:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #ef4444;
}

/* --- Sticky Action Footer / Dock --- */
.action-footer {
  margin-top: 22px;
  padding: 16px 22px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 18px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  bottom: 20px;
  z-index: 100;
  gap: 16px;
}

.selection-status {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--slate-700, #334155);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

#selectedCount {
  color: #2563eb;
  font-weight: 800;
  background: #eff6ff;
  padding: 2px 9px;
  border-radius: 9999px;
  border: 1px solid rgba(37, 99, 235, 0.2);
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-extract-action {
  min-height: 44px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 12px;
}

.btn-save-action {
  min-height: 44px;
  padding: 11px 24px;
  font-size: 14.5px;
  font-weight: 700;
  border-radius: 12px;
  background: linear-gradient(135deg, #1a3566 0%, #1e4080 100%);
  color: #ffffff;
  box-shadow: 0 8px 20px rgba(26, 53, 102, 0.25);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-save-action:hover {
  background: linear-gradient(135deg, #122549 0%, #1a3566 100%);
  transform: translateY(-2px);
  box-shadow: 0 12px 26px rgba(26, 53, 102, 0.35);
}

/* --- Section Headlines & Content Blocks --- */
.section-headline {
  font-size: 26px;
  font-weight: 900;
  color: var(--royal-dark, #122549);
  text-align: center;
  margin-bottom: 10px;
  letter-spacing: -0.02em;
}

.section-subtitle {
  font-size: 15px;
  color: var(--slate-600, #475569);
  text-align: center;
  max-width: 680px;
  margin: 0 auto 32px;
  line-height: 1.6;
}

/* --- Steps & Guidelines --- */
.steps-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.step-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.step-number {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1a3566, #2563eb);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(26, 53, 102, 0.2);
}

.step-text h5 {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--slate-800, #1e293b);
  margin-bottom: 3px;
}

.step-text p {
  font-size: 13.5px;
  color: var(--slate-600, #475569);
  line-height: 1.5;
  margin: 0;
}

.guidelines-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guideline-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  border: 1px solid rgba(226, 232, 240, 0.8);
}

.guideline-icon {
  width: 20px;
  height: 20px;
  color: #d97706;
  flex-shrink: 0;
  margin-top: 1px;
}

.guideline-text {
  font-size: 13.5px;
  color: var(--slate-700, #334155);
  line-height: 1.5;
}

.guideline-text strong {
  color: var(--slate-900, #0f172a);
}

/* ==========================================================================
   Comprehensive Responsive Breakpoints (Mobile, Tablet, Desktop)
   ========================================================================== */

/* --- Tablet (max-width: 768px) --- */
@media (max-width: 768px) {
  .page-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 14px;
    padding: 16px;
    max-height: 60vh;
  }

  .action-footer {
    flex-direction: column;
    gap: 14px;
    align-items: stretch;
    text-align: center;
  }

  .selection-status {
    justify-content: center;
  }

  .action-buttons {
    flex-direction: column;
    width: 100%;
    gap: 10px;
  }

  .action-buttons .btn {
    width: 100%;
  }

  .section-headline {
    font-size: 22px;
  }

  .section-subtitle {
    font-size: 14px;
    margin-bottom: 24px;
  }
}

/* --- Mobile Devices (max-width: 480px) --- */
@media (max-width: 480px) {
  .tool-badge {
    font-size: 11px;
    padding: 5px 12px;
    gap: 6px;
    margin-bottom: 12px;
  }

  .dropzone {
    padding: 24px 14px 20px;
    border-radius: 16px;
  }

  .dz-icon-wrapper {
    width: 54px;
    height: 54px;
    border-radius: 16px;
    margin-bottom: 12px;
  }

  .dz-icon-wrapper svg {
    width: 28px;
    height: 28px;
  }

  .dropzone h3 {
    font-size: 17px;
    margin-bottom: 4px;
  }

  .dropzone p {
    font-size: 12.5px;
    margin-bottom: 12px;
  }

  .dz-chips {
    gap: 6px;
    margin-bottom: 14px;
  }

  .dz-chip {
    font-size: 10.5px;
    padding: 3px 8px;
    gap: 4px;
  }

  .dz-btn {
    width: 100%;
    max-width: 260px;
    font-size: 14px;
    padding: 11px 18px;
    border-radius: 12px;
  }

  .file-info {
    padding: 12px 14px;
    gap: 10px;
    border-radius: 14px;
    margin-bottom: 16px;
  }

  .file-icon-box {
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  .file-icon-box svg {
    width: 20px;
    height: 20px;
  }

  .file-details h4 {
    font-size: 13.5px;
  }

  .file-details p {
    font-size: 11.5px;
  }

  .btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
    gap: 8px;
    border-radius: 12px;
  }

  .instruction-text {
    font-size: 12px;
    text-align: center;
    justify-content: center;
  }

  .toolbar-right {
    justify-content: center;
    width: 100%;
  }

  .toolbar-right .btn {
    flex: 1;
    text-align: center;
    justify-content: center;
    font-size: 12px;
    padding: 6px 10px;
  }

  .page-grid {
    grid-template-columns: repeat(auto-fill, minmax(125px, 1fr));
    gap: 10px;
    padding: 10px;
    max-height: 52vh;
    border-radius: 14px;
  }

  .page-card {
    padding: 10px 8px 8px;
    border-radius: 12px;
  }

  .page-number-badge {
    width: 22px;
    height: 22px;
    font-size: 10.5px;
    top: -6px;
    left: -6px;
  }

  .page-controls {
    gap: 4px;
  }

  .page-control-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
  }

  .page-control-btn svg {
    width: 15px;
    height: 15px;
  }

  .action-footer {
    padding: 12px 14px;
    border-radius: 14px;
    bottom: 12px;
    margin-top: 16px;
  }

  .selection-status {
    font-size: 13px;
  }

  .btn-extract-action,
  .btn-save-action {
    font-size: 14px;
    padding: 12px 18px;
    border-radius: 12px;
    min-height: 44px;
  }
}

/* --- Small Mobile (max-width: 360px) --- */
@media (max-width: 360px) {
  .page-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 8px;
  }

  .page-card {
    padding: 8px 6px 6px;
  }
}

/* --- Accessibility & Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  .dropzone,
  .page-card,
  .page-canvas-wrapper canvas,
  .btn-save-action,
  .btn-extract-action {
    transition: none !important;
    animation: none !important;
  }
}
