/* PDF Tools: styles for these tools only. Shared styles live in /tools/shared/tools.css. */

:root {
  /* Rendered PDF pages stay white in both themes */
  --page: #ffffff;
}

/* ---------- app shell ---------- */

body.app {
  --stage-pad: 1rem; /* inset around the content in every tool view */
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.stage-col {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
}

#stage {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--color-bg);
}

#stage.is-file-over::after {
  content: "Drop to add";
  position: absolute;
  inset: 0.75rem;
  display: grid;
  place-items: center;
  border: 2px dashed var(--color-accent);
  border-radius: var(--radius-lg);
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-weight: var(--weight-bold);
  pointer-events: none;
  z-index: 30;
}

.scroll {
  overflow-y: auto;
  min-height: 0;
}
.ad-slot {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 0.75rem 1.5rem 0;
}

/* Side panel */
.panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 0;
  min-width: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  background: var(--color-surface);
  border-radius: var(--radius-2xl);
  margin: 1rem 0;
  transition:
    width 0.3s ease-out,
    min-width 0.3s ease-out,
    margin 0.3s ease-out,
    opacity 0.3s ease-out;
}
body.panel-open .panel {
  width: 25%;
  min-width: 18rem;
  margin: 1rem 1rem 1rem 0;
  opacity: 1;
  pointer-events: auto;
}
.panel > * {
  min-width: 18rem;
}
.panel-head {
  padding: 1.5rem 1.5rem 1rem;
}
.panel-head h2 {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.panel-head p {
  margin-top: 0.5rem;
  line-height: 1.5;
  font-size: var(--text-sm);
  color: var(--color-muted);
}
.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
/* Labels line up with the controls below them and share one weight */
.panel-body .field-label {
  padding: 0.75rem 0 0.25rem;
  font-weight: var(--weight-regular);
}
.panel-body .field {
  height: 2.75rem;
}
.panel-foot {
  margin-top: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.panel-foot .privacy-note {
  justify-content: center;
}
.panel-done {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  padding: 3rem 1.5rem 1rem;
}
.panel-done .done-icon {
  width: 4rem;
  height: 4rem;
  color: var(--color-success);
  stroke-width: 1.5;
}
.panel-done h2 {
  margin-top: 0.5rem;
  font-size: var(--text-lg);
  font-weight: var(--weight-regular);
}
.big-stat {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--color-success);
}
.files-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--stage-pad);
}
.files-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  margin-bottom: 1.5rem;
}

.card-grid {
  display: grid;
  width: 100%;
  gap: 1rem;
  justify-items: center;
  align-items: start;
}
.card-grid.cols-1 {
  grid-template-columns: minmax(0, 1fr);
}
.card-grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.card-grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.card-grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.file-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  max-width: 18rem;
  padding-bottom: 1rem;
}
.draggable {
  cursor: grab;
  -webkit-touch-callout: none;
  user-select: none;
}
.file-thumb {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 210 / 297;
  padding: 0.5rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--page);
  overflow: hidden;
}
.file-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.file-thumb > .icon {
  color: #a3a3a3;
}
.remove-btn {
  padding: 0;
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: var(--radius-full);
  border: 0;
  background: #c62b1e;
  color: #fff;
  transition:
    background-color var(--duration),
    transform var(--duration) ease-out;
}
.remove-btn .icon {
  width: 0.875rem;
  height: 0.875rem;
}
.done-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.4);
  transition: background-color 0.15s;
  color: #fff;
}
a.done-overlay:hover {
  background: rgba(0, 0, 0, 0.5);
}
.done-overlay.busy {
  background: rgba(255, 255, 255, 0.6);
  color: #404040;
}
.done-check {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-full);
  background: #1e7f4f;
  color: #fff;
}
.done-check .icon {
  width: 1.25rem;
  height: 1.25rem;
}
.file-meta {
  min-width: 0;
}
.file-name {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* drag & drop */
.drag-ghost {
  position: fixed !important;
  left: 0 !important;
  top: 0 !important;
  margin: 0 !important;
  z-index: 1000;
  pointer-events: none;
  box-shadow: var(--shadow-float);
  border-radius: var(--radius-lg);
  opacity: 0.95;
  will-change: transform;
}
.drag-source {
  opacity: 0.3;
}
body.is-dragging,
body.is-dragging * {
  cursor: grabbing !important;
  user-select: none;
}

/* ---------- page cards (organize / remove / split / extract) ---------- */

.pages-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--stage-pad);
}
.pages-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 18rem;
  padding: 0.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--page);
  color: #0a0a0a;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.page-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  padding-bottom: 0.5rem;
  min-height: 1.75rem;
}
.page-card-head .page-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  color: #737373;
}
.page-card-actions {
  display: flex;
  gap: 0.25rem;
}
.mini-btn {
  padding: 0;
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: var(--radius-full);
  border: 0;
  background: #f4f4f5;
  color: #404040;
  transition:
    background-color var(--duration),
    transform var(--duration) ease-out;
}
.mini-btn:hover {
  background: #e4e4e7;
}
.mini-btn .icon {
  width: 0.8rem;
  height: 0.8rem;
}
.mini-btn.danger {
  background: #c62b1e;
  color: #fff;
}
.mini-btn.danger:hover {
  background: #a52317;
}
.page-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 210 / 297;
  overflow: hidden;
}
.page-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s ease;
}
.page-card.selectable {
  cursor: pointer;
}
.page-card.selected {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-accent);
}
/* Same checkbox as the design system (.check-row input), drawn on a span */
.page-card .select-mark {
  position: relative;
  flex-shrink: 0;
  width: 1.125rem;
  height: 1.125rem;
  box-sizing: border-box;
  border: 1.5px solid var(--color-muted);
  border-radius: 6px;
  background: transparent;
  transition:
    background-color 0.15s,
    border-color 0.15s,
    transform 0.15s;
}
.page-card .select-mark .icon {
  display: none;
}
.page-card .select-mark::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 15px;
  height: 15px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 15 15' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 7.8l2.8 2.8 5.2-6'/%3E%3C/svg%3E") center / 100% 100% no-repeat; /* always white, on the accent fill */
  clip-path: inset(0 100% 0 0);
}
.page-card.selected .select-mark {
  border-color: var(--color-accent);
  background: var(--color-accent);
}
.page-card.selected .select-mark::after {
  clip-path: inset(0);
  animation: check-draw 0.22s ease-out 0.05s backwards;
}
.page-card:active .select-mark {
  transform: scale(0.9);
}
@media (prefers-reduced-motion: reduce) {
  .page-card .select-mark,
  .page-card .select-mark::after {
    transition: none;
    animation: none;
  }
}
.page-card.dimmed .page-thumb {
  opacity: 0.35;
}

/* ---------- merge animation ---------- */

.merge-stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 1.5rem;
}
.merge-stage .card-grid {
  max-width: 48rem;
}
.merge-stage .file-card {
  transition:
    transform 0.6s ease-in-out,
    opacity 0.6s ease-in-out;
}
.merge-spinner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  color: var(--color-muted);
}
.merged-result {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  max-width: 18rem;
  text-align: center;
  animation: pop-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pop-in {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: grid;
  place-items: center;
  overflow: visible;
}
.confetti span {
  position: absolute;
  border-radius: 1px;
  animation: confetti 1s ease-out forwards;
}
@keyframes confetti {
  from {
    transform: translate(0, 0) rotate(0);
    opacity: 1;
  }
  to {
    transform: translate(var(--x), var(--y)) rotate(var(--r));
    opacity: 0;
  }
}

/* ---------- split ---------- */

.split-sections {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  width: 100%;
  max-width: 64rem;
}
.split-section-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.split-title {
  field-sizing: content;
  min-width: 2ch;
  max-width: 50%;
  border: 0;
  background: transparent;
  font-family: var(--font);
  font-size: var(--text-lg);
  font-weight: var(--weight-regular);
  color: var(--color-ink);
  outline: none;
  padding: 0.1rem 0.25rem;
  border-radius: var(--radius-sm);
}
.split-title:hover,
.split-title:focus {
  background: var(--color-surface);
}
.split-rule {
  flex: 1;
  height: 1px;
  min-width: 2rem;
  background: var(--color-border);
}
.split-grid {
  display: grid;
  gap: 2.5rem 2rem;
  /* room on the right so the split line after the last card in a row stays visible */
  padding-right: 2rem;
  min-height: 6rem;
  border-radius: var(--radius-lg);
}
body.is-dragging .split-grid {
  outline: 1px dashed var(--color-border);
  outline-offset: 0.5rem;
}
.split-slot {
  position: relative;
  width: 100%;
}
/* Cards sit centred in equal columns, so the split line (on the column edge) is always midway between two cards */
.split-slot .page-card {
  margin-inline: auto;
}
.split-gap {
  position: absolute;
  top: 0;
  right: -2rem;
  z-index: 5;
  width: 2rem;
  height: 100%;
  display: flex;
  justify-content: center;
  cursor: pointer;
  border: 0;
  background: transparent;
  padding: 0;
}
.split-gap::before {
  content: "";
  margin: 0.5rem 0;
  border-left: 2px dotted transparent;
  transition: border-color 0.15s;
}
.split-gap:hover::before,
.split-gap:focus-visible::before {
  border-color: color-mix(in srgb, var(--color-muted) 45%, transparent);
}
.split-gap .split-tip {
  position: absolute;
  top: -1.75rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.1rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--color-muted);
  color: var(--color-surface);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.split-gap:hover .split-tip,
.split-gap:focus-visible .split-tip {
  opacity: 1;
}
body.is-dragging .split-gap {
  pointer-events: none;
}
.split-slot:last-child .split-gap {
  display: none;
}
.split-hint-mobile {
  display: none;
}

.menu {
  position: relative;
}
.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 0.25rem);
  z-index: 40;
  min-width: 10rem;
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.25);
}
.menu-list button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.45rem 0.6rem;
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}
.menu-list button:hover {
  background: var(--color-field);
}

/* ---------- viewer ---------- */

.viewer {
  display: flex;
  flex: 1;
  min-height: 0;
}
.viewer-thumbs {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1rem 0 1rem 1rem;
  padding: 1rem;
  background: var(--color-surface);
  border-radius: var(--radius-2xl);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}
.viewer-thumbs button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  border: 0;
  background: transparent;
  padding: 0;
}
.viewer-thumbs .thumb-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--page);
  overflow: hidden;
}
.viewer-thumbs button:hover .thumb-box {
  border-color: rgba(127, 127, 127, 0.5);
}
.viewer-thumbs button.current .thumb-box {
  border: 2px solid var(--color-accent);
}
.viewer-thumbs img,
.viewer-thumbs canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.viewer-resizer {
  width: 1rem;
  flex-shrink: 0;
  cursor: col-resize;
  touch-action: none;
}
.viewer-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding-top: var(--stage-pad);
}
.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  flex-wrap: wrap;
}
.viewer-toolbar .divider {
  width: 1px;
  height: 1.25rem;
  background: var(--color-border);
}
.viewer-toolbar .btn-icon[aria-pressed="true"] {
  background: var(--color-field);
}
.viewer-file-name {
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-left: auto;
}
.viewer-file-name + .btn {
  margin-left: 0 !important;
}
@media (max-width: 1200px) {
  .viewer-file-name {
    display: none;
  }
}
.zoom-label {
  width: 2.75rem;
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-muted);
}
/* Compact version of the shared .field, sized to match the 2rem icon buttons */
.page-field {
  width: 3.25rem;
  height: 2rem;
  padding: 0 0.25rem;
  border-radius: var(--radius-md);
}
.page-field input {
  text-align: center;
  font-size: var(--text-sm);
}
.viewer-scroll {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
}
.viewer-pages {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  transition: width 0.2s ease-out;
}
.viewer-page {
  position: relative;
  width: 100%;
  background: var(--page);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.viewer-page img {
  width: 100%;
  height: 100%;
}
.viewer-page .page-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #a3a3a3;
}

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
  .card-grid.cols-4 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  body.app {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }
  .workspace {
    flex-direction: column;
    overflow: visible;
  }
  #stage {
    min-height: 70vh;
  }
  .scroll {
    overflow: visible;
  }
  .panel {
    width: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    border-top: 1px solid var(--color-border);
    max-height: 0;
    transition: opacity 0.3s ease-out;
  }
  body.panel-open .panel {
    width: 100%;
    min-width: 0;
    margin: 0;
    max-height: none;
    position: sticky;
    bottom: 0;
    z-index: 20;
    box-shadow: 0 -8px 24px -12px rgba(0, 0, 0, 0.25);
  }
  .panel > * {
    min-width: 0;
  }
  .panel-head {
    padding: 1rem 1rem 0.5rem;
  }
  .panel-head p {
    display: none;
  }
  .panel-body {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 0.25rem 1rem;
    max-height: 40vh;
  }
  .panel-body > * {
    flex: 1 1 100%;
  }
  .panel-body > .option {
    flex: 1 1 30%;
    flex-direction: column;
    text-align: center;
    gap: 0.25rem;
    padding: 0.5rem;
  }
  .panel-body > .option .option-desc {
    display: none;
  }
  .panel-foot {
    padding: 0.75rem 1rem 1rem;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .panel-foot > .btn {
    flex: 1 1 40%;
    height: 2.75rem;
  }
  .panel-foot > .privacy-note,
  .panel-foot > .info-note,
  .panel-foot > p {
    flex: 1 1 100%;
  }
  .panel-done {
    padding: 1rem 1rem 0.25rem;
  }
  .panel-done .done-icon {
    width: 2.5rem;
    height: 2.5rem;
  }
  .card-grid.cols-3,
  .card-grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .split-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 1.5rem 1.5rem;
  }
  .split-gap {
    right: -1.5rem;
    width: 1.5rem;
  }
  .split-grid {
    padding-right: 1.5rem;
  }
  .split-gap::before {
    border-color: var(--color-border);
  }
  .viewer {
    flex-direction: column;
  }
  .viewer-thumbs,
  .viewer-resizer {
    display: none;
  }
  .viewer-scroll {
    overflow: visible;
  }
}

@media (max-width: 520px) {
  .card-grid.cols-2,
  .card-grid.cols-3,
  .card-grid.cols-4 {
    gap: 0.75rem;
  }
  body.app {
    --stage-pad: 0.75rem;
  }
}

/* Press feedback on the small round card buttons */
.mini-btn:active,
.remove-btn:active {
  transform: scale(0.88);
}
@media (prefers-reduced-motion: reduce) {
  .mini-btn,
  .remove-btn {
    transition: none;
  }
  .mini-btn:active,
  .remove-btn:active {
    transform: none;
  }
}

/* Rotate PDF: the two turn buttons share the panel width equally */
.rotate-buttons {
  display: flex;
  align-self: stretch;
  gap: var(--space-2);
}
.rotate-buttons .btn {
  flex: 1 1 0;
  min-width: 0;
  padding-inline: var(--space-2);
}

/* Format menu on the page download button: same look as the theme menu */
.format-menu {
  position: fixed;
  z-index: 50;
  min-width: 132px;
  padding: 4px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-float);
  font-size: 13px;
  line-height: 1.2;
}
.format-menu[hidden] {
  display: none;
}
.format-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.format-menu button:hover,
.format-menu button:focus-visible {
  background: rgba(128, 128, 128, 0.14);
  outline: 0;
}
.format-menu .icon {
  width: 0.9rem;
  height: 0.9rem;
}
