/* FrogPDF - tool-specific styles. Header, hero, footer, base resets, and the
   :root palette tokens come from the shared shell (tool-shell.css); this file
   carries the dropzone, settings form, page list, and result panel. */

/* ─── Panels ──────────────────────────────────────────────────────────── */

.panel__title {
  margin: 0 0 1.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}
.panel--result { border-color: rgba(25, 195, 125, 0.4); }

/* ─── Dropzone ────────────────────────────────────────────────────────── */

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  text-align: center;
  padding: 2.5rem 1.5rem;
  border: 2px dashed var(--border-dark);
  border-radius: var(--radius-md);
  background: var(--bg-deep);
  color: var(--text-light);
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.is-dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.dropzone__icon { color: var(--accent); pointer-events: none; }
.dropzone__text { font-size: 0.98rem; pointer-events: none; }
.dropzone__text strong { color: var(--accent); }
.dropzone__hint { font-size: 0.82rem; color: var(--muted); pointer-events: none; }

/* ─── Form fields ─────────────────────────────────────────────────────── */

.field { margin-bottom: 1.25rem; }
.field:last-child { margin-bottom: 0; }
.field[hidden] { display: none; }

label, .field__sublabel {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
}
.field__val {
  float: right;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent);
}

select, input[type="number"] {
  width: 100%;
  padding: 0.7rem 0.85rem;
  background: var(--bg-deep);
  color: var(--text-light);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}
select { cursor: pointer; }
select option { background: var(--bg-deep); color: var(--text-light); }
select:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--border-dark);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.field__hint {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

/* ─── Buttons ─────────────────────────────────────────────────────────── */

.btn--sm { padding: 0.5rem 0.7rem; font-size: 0.82rem; }
/* Anchor styled as button needs the disabled look driven by an attribute. */
a.btn[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
}
/* hidden attribute must win over the flex display above */
.action-row[hidden] { display: none; }
.action-row #downloadBtn { flex: 1; }
@media (max-width: 380px) {
  .action-row { flex-direction: column; }
}
@media (max-width: 560px) {
  .btn--sm { min-height: 44px; }
}

.progress-line {
  margin: 1rem 0 0;
  min-height: 1.2em;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
}
.progress-line:empty { margin-top: 0; }

/* ─── Page list ───────────────────────────────────────────────────────── */

.empty-state {
  margin: 0;
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
}

.pdf-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.pdf-list[hidden] { display: none; }

.pdf-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-deep);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-md);
}
.pdf-item__index {
  flex: 0 0 auto;
  min-width: 1.6rem;
  height: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.35rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
}
.pdf-item__thumb {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface-dark);
  border: 1px solid var(--border-dark);
}
/* Text files have no image thumbnail - show a small format badge instead. */
.pdf-item__thumb--text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  object-fit: unset;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.pdf-item__meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.1rem; }
.pdf-item__name {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pdf-item__dims { font-family: var(--mono); font-size: 0.76rem; color: var(--muted); }
.pdf-item__actions { display: flex; align-items: center; gap: 0.3rem; flex: 0 0 auto; }
.pdf-item__actions .btn { padding: 0.4rem 0.55rem; }
.pdf-item__actions .btn:disabled { opacity: 0.25; }

.result-info {
  margin: 0 0 1.25rem;
  padding: 0.7rem 0.9rem;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text-light);
  font-family: var(--mono);
}

/* ─── Live preview ────────────────────────────────────────────────────── */

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.results-head .panel__title { margin: 0; }
.preview-info { font-family: var(--mono); font-size: 0.82rem; color: var(--muted); }

.preview-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  max-height: 70vh;
  overflow-y: auto;
  padding: 0.25rem;
}
.preview-pages canvas {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border-dark);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
  background: #fff;
}
.preview-pages.is-stale { opacity: 0.5; transition: opacity 120ms ease; }

@media (max-width: 460px) {
  .pdf-item__name { font-size: 0.82rem; }
  .pdf-item__thumb { width: 38px; height: 38px; flex-basis: 38px; }
}

/* ─── Mode switcher (Build / Merge / Organize / Split) ─────────────────── */

.mode-switch {
  display: flex;
  justify-content: center;
  margin: 0 auto 1.5rem;
  padding: 0 1.25rem;
}
.seg-group {
  display: inline-flex;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-top: 1.5rem;
}
.seg {
  border: none;
  background: var(--bg-deep);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.seg + .seg { border-left: 1px solid var(--border-dark); }
.seg:hover { color: var(--text-light); }
.seg.is-active { background: var(--accent); color: #07140d; }
.seg:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.pdf-mode {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.pdf-mode[hidden] { display: none; }

@media (max-width: 460px) {
  .seg { padding: 0.5rem 0.7rem; font-size: 0.82rem; min-height: 44px; }
}

/* ─── Organize: page-thumbnail grid ───────────────────────────────────── */

.org-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.85rem;
}
.org-grid[hidden] { display: none; }

.org-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.5rem;
  background: var(--bg-deep);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-md);
}
.org-card.is-deleted { opacity: 0.35; }

.org-card__thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 130px;
  background: #fff;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: transform 120ms ease;
}
.org-card__thumb canvas {
  max-width: 100%;
  height: auto;
  display: block;
}
.org-card__placeholder {
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--muted);
}
.org-card__label {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
}
.org-card__actions {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  justify-content: center;
}
.org-card__actions .btn { padding: 0.35rem 0.5rem; line-height: 1; }

/* ─── Split: range input ──────────────────────────────────────────────── */

input[type="text"]#splitRange {
  width: 100%;
  padding: 0.7rem 0.85rem;
  background: var(--bg-deep);
  color: var(--text-light);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--mono);
}
input[type="text"]#splitRange:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ─── Sign mode: editor + signature modal (ported from FrogSign) ───────── */

.tool-status {
  margin: 1rem 0 0;
  min-height: 1.1em;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}
.tool-status.is-error { color: #ff8a8a; }

.sign-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.sign-pageinfo {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
}
@media (max-width: 560px) {
  .sign-pageinfo { margin-left: 0; }
  .sign-toolbar .btn { flex: 1 1 auto; }
}

.sign-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  margin-top: 1.25rem;
}
.sign-page {
  position: relative;
  max-width: 100%;
  box-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border-dark);
}
.sign-page__canvas { display: block; max-width: 100%; height: auto; }
/* The overlay layer sits exactly over the canvas; overlays are positioned
   inside it in page-relative percentages so they survive the responsive
   downscale of the canvas. */
.sign-page__layer { position: absolute; inset: 0; }

.sign-overlay {
  position: absolute;
  box-sizing: border-box;
  border: 1px dashed transparent;
  cursor: move;
  touch-action: none;
}
.sign-overlay:hover, .sign-overlay.is-selected { border-color: var(--accent); }
.sign-overlay--sig img { display: block; width: 100%; height: 100%; pointer-events: none; }
.sign-overlay--text {
  padding: 2px 4px;
  color: #111418;
  font-family: var(--font);
  white-space: pre;
  min-width: 1ch;
  outline: none;
}
.sign-overlay__del {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: #ff6b6b;
  color: #fff;
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  display: none;
}
.sign-overlay:hover .sign-overlay__del, .sign-overlay.is-selected .sign-overlay__del { display: block; }
.sign-overlay__handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border: 2px solid var(--bg-dark);
  border-radius: 50%;
  cursor: nwse-resize;
  display: none;
  touch-action: none;
}
.sign-overlay.is-selected .sign-overlay__handle { display: block; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(7, 9, 11, 0.78);
}
.modal[hidden] { display: none; }
.modal__card {
  width: min(640px, 100%);
  background: var(--surface-dark);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.modal__title { font-weight: 700; font-size: 1rem; }
.modal__close {
  width: 30px; height: 30px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
  color: var(--muted);
  cursor: pointer;
}
.modal__close:hover { border-color: var(--accent); color: var(--accent); }

.sig-tabs { display: inline-flex; margin-bottom: 1rem; }
.sig-view { margin-bottom: 1rem; }
.sig-pad {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 1;
  background: #ffffff;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  cursor: crosshair;
  touch-action: none;
}
.sig-type-input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  background: var(--bg-deep);
  color: var(--text-light);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}
.sig-type-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sig-type-preview {
  margin-top: 0.85rem;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border-radius: var(--radius-sm);
  color: #111418;
  font-family: 'Segoe Script', 'Brush Script MT', 'Snell Roundhand', cursive;
  font-size: 2.4rem;
}
.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  flex-wrap: wrap;
}
