/* ============================================================
   PdfWorker — app.css
   ============================================================ */

/* Base */
body {
  background: #f8f9fa;
  color: #212529;
}

/* ============================================================
   Welcome Panel
   ============================================================ */

.welcome-panel {
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 0.5rem;
  padding: 1.5rem;
}

.welcome-panel-hero {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.welcome-icon {
  flex-shrink: 0;
  margin-top: 0.1rem;
  opacity: 0.85;
}

.welcome-features {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.welcome-feature {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
}

.welcome-feature-icon {
  font-size: 1.25rem;
  line-height: 1.3;
  flex-shrink: 0;
  width: 1.75rem;
  text-align: center;
}

.welcome-tip {
  margin-bottom: 0;
  font-size: 0.875rem;
  color: #6c757d;
  border-top: 1px solid #f1f3f5;
  padding-top: 1rem;
  text-align: center;
}

/* ============================================================
   Help Dialog
   ============================================================ */

#helpDialog {
  width: min(92vw, 680px);
  max-height: 85vh;
  padding: 0;
  border: none;
  border-radius: 0.5rem;
  box-shadow: 0 0.5rem 2rem rgba(0,0,0,.35);
  overflow: hidden;
  flex-direction: column;
}

#helpDialog[open] {
  display: flex;
}

#helpDialog::backdrop {
  background: rgba(0,0,0,.45);
}

.help-dialog-body {
  padding: 1.25rem;
  overflow-y: auto;
}

.help-features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
}

/* ============================================================
   Upload Zone
   ============================================================ */

.upload-zone {
  border: 2px dashed #adb5bd;
  border-radius: 0.5rem;
  background: #fff;
  transition: border-color 0.2s, background 0.2s, padding 0.3s;
  cursor: pointer;
}

.upload-zone:not(.compact) {
  padding: 2.5rem 1rem;
  text-align: center;
}

/* Compact mode — shrinks after files are loaded */
.upload-zone.compact {
  padding: 0.6rem 1rem;
  text-align: left;
  display: flex;
  align-items: center;
}

.upload-zone.compact .upload-label svg {
  display: none;
}

.upload-zone.compact .upload-label > div:nth-child(3) {
  display: none;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: #0d6efd;
  background: #f0f5ff;
}

.upload-label {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  color: #495057;
  user-select: none;
}

.upload-zone.compact .upload-label {
  flex-direction: row;
  gap: 0.5rem;
  font-size: 0.875rem;
}

/* ============================================================
   Global Toolbar
   ============================================================ */

.toolbar {
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
  padding: 0.6rem 0.75rem;
}

/* ============================================================
   Documents Container
   ============================================================ */

.documents-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ============================================================
   Document Pane
   ============================================================ */

.doc-pane {
  background: #fff;
  border: 2px solid #dee2e6;
  border-radius: 0.5rem;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.doc-pane--active {
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.12);
}

.doc-pane-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  background: #f8f9fa;
  border-bottom: 1px solid #dee2e6;
}

.doc-name-input {
  border: 1px solid transparent;
  background: transparent;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.2rem 0.4rem;
  border-radius: 0.25rem;
  flex: 1 1 140px;
  max-width: 280px;
  min-width: 0;
  color: #212529;
}

.doc-name-input:hover,
.doc-name-input:focus {
  border-color: #adb5bd;
  background: #fff;
  outline: none;
}

.doc-pane-body {
  padding: 0.75rem;
}

.doc-pane-empty {
  color: #adb5bd;
  font-size: 0.875rem;
  text-align: center;
  padding: 2rem 1rem;
  border: 2px dashed #dee2e6;
  border-radius: 0.375rem;
}

/* ============================================================
   Split Range Group (per-doc)
   ============================================================ */

.split-group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: nowrap;
  font-size: 0.8125rem;
  color: #6c757d;
}

.split-input {
  width: 5rem !important;
}

/* ============================================================
   Thumbnail Grid
   ============================================================ */

.thumbnail-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-content: flex-start;
  min-height: 2rem;
}

/* Visual indicator when a PDF file is dragged over the grid */
.thumbnail-grid.drag-over-files {
  outline: 2px dashed #198754;
  outline-offset: 4px;
  background: rgba(25, 135, 84, 0.04);
  border-radius: 0.375rem;
}

/* ============================================================
   Thumbnail Card
   ============================================================ */

.thumb-card {
  width: 130px;
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
  overflow: hidden;
  cursor: grab;
  transition: box-shadow 0.15s, border-color 0.15s, opacity 0.15s;
  user-select: none;
}

.thumb-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  border-color: #adb5bd;
}

.thumb-card.dragging {
  opacity: 0.4;
  cursor: grabbing;
}

.thumb-card.drag-over-card {
  border-color: #0d6efd;
  box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.35);
}

/* Selected state (keyboard navigation / click) */
.thumb-card--selected {
  border-color: #0d6efd;
  box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.5);
}

.thumb-img {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #f1f3f5;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Landscape container for pages rotated 90° or 270° */
.thumb-img--landscape {
  aspect-ratio: 4 / 3;
}

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

/*
 * Rotated 90°/270°: absolutely position the image so its dimensions are
 * swapped (portrait H×W inside a landscape W×H container), then rotate it
 * into place. This makes the page fill the landscape box correctly.
 *
 * Container: W × H  (aspect-ratio 4:3, so H = W × 3/4)
 * Image pre-rotation: H × W  (portrait, width = 75% of W, height = 133.33% of H)
 * After rotate(90deg) around center → fills W × H container exactly.
 */
.thumb-img--landscape img {
  position: absolute;
  width: 75%;       /* = container height / container width = (W·¾)/W */
  height: 133.33%;  /* = container width / container height = W/(W·¾)  */
  top: 50%;
  left: 50%;
  /* transform set by inline style: translate(-50%,-50%) rotate(Ndeg) */
}

.thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: #adb5bd;
  font-size: 0.75rem;
}

.thumb-placeholder--error {
  font-size: 0.7rem;
  color: #6c757d;
  letter-spacing: 0.05em;
}

.thumb-footer {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.3rem 0.4rem;
  border-top: 1px solid #f1f3f5;
  background: #fafafa;
  min-width: 0;
}

.thumb-num {
  font-size: 0.7rem;
  font-weight: 700;
  color: #6c757d;
  min-width: 1.4em;
  text-align: center;
  background: #e9ecef;
  border-radius: 3px;
  padding: 1px 3px;
  flex-shrink: 0;
}

.thumb-name {
  font-size: 0.65rem;
  color: #6c757d;
  flex: 1 1 0;
  min-width: 0;
  word-break: break-word;
  line-height: 1.2;
}

/* Rotate button */
.btn-rotate {
  background: none;
  border: none;
  color: #adb5bd;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}

.btn-rotate:hover {
  color: #0d6efd;
  background: #e7f1ff;
}

/* Remove button */
.btn-remove {
  background: none;
  border: none;
  color: #adb5bd;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}

.btn-remove:hover {
  color: #dc3545;
  background: #fff0f0;
}

/* ============================================================
   Right-click Context Menu
   ============================================================ */

.context-menu {
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  min-width: 210px;
  z-index: 10000;
  overflow: hidden;
  padding: 0.25rem 0;
}

.context-menu-item {
  padding: 0.45rem 0.85rem;
  font-size: 0.875rem;
  cursor: pointer;
  color: #212529;
  user-select: none;
  white-space: nowrap;
}

.context-menu-item:hover {
  background: #f0f5ff;
}

.context-menu-item--danger {
  color: #dc3545;
}

.context-menu-item--danger:hover {
  background: #fff0f0;
}

.context-menu-item--indent {
  padding-left: 1.5rem;
}

.context-menu-label {
  padding: 0.3rem 0.85rem 0.1rem;
  font-size: 0.7rem;
  color: #6c757d;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.context-menu-divider {
  height: 1px;
  background: #dee2e6;
  margin: 0.25rem 0;
}

/* ============================================================
   Toast (lightweight — no bootstrap.bundle.js needed)
   ============================================================ */

.toast {
  min-width: 220px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   Responsive tweaks
   ============================================================ */

/* Preview dialog */
#previewDialog {
  width: min(90vw, 1140px);
  height: 90vh;
  padding: 0;
  border: none;
  border-radius: 0.5rem;
  box-shadow: 0 0.5rem 2rem rgba(0,0,0,.4);
  overflow: hidden;
}
#previewDialog[open] {
  display: flex;
  flex-direction: column;
}
#previewDialog::backdrop {
  background: rgba(0,0,0,.5);
}
#previewDialogHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
  flex-shrink: 0;
}
#previewDialog iframe {
  flex: 1;
  width: 100%;
  border: none;
  min-height: 0;
}

/* ============================================================
   Password / Metadata dialogs (native <dialog>)
   ============================================================ */

#passwordDialog,
#metadataDialog {
  width: min(92vw, 380px);
  padding: 0;
  border: none;
  border-radius: 0.5rem;
  box-shadow: 0 0.5rem 2rem rgba(0,0,0,.35);
  overflow: hidden;
}

#passwordDialog::backdrop,
#metadataDialog::backdrop {
  background: rgba(0,0,0,.45);
}

.pwdialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid #dee2e6;
  font-weight: 600;
  font-size: 0.875rem;
  background: #f8f9fa;
}

.pwdialog-body {
  padding: 1rem;
}

.pwdialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-top: 1px solid #dee2e6;
  background: #f8f9fa;
}

@media (max-width: 576px) {
  .split-input {
    width: 4rem !important;
  }

  .thumb-card {
    width: 100px;
  }

  .doc-name-input {
    max-width: 180px;
  }
}
