/* ==========================================================================
   PDF Toolkit — style.css.  Tokens come from /assets/site.css.
   ========================================================================== */
:root {
  --bg: var(--gk-bg);
  --surface: var(--gk-surface);
  --surface-2: var(--gk-surface-2);
  --text: var(--gk-text);
  --muted: var(--gk-muted);
  --border: var(--gk-border);
  --accent: var(--gk-accent);
  --radius: 14px;
  --radius-sm: 9px;
  --font: var(--gk-font);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- App bar ---------- */
.app-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.app-bar__brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.app-bar__logo { display: grid; place-items: center; width: 28px; height: 28px; }
.app-bar__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.app-bar__sep { width: 1px; height: 22px; flex: none; background: var(--border); margin: 0 3px; }
@media (max-width: 560px) { .app-bar__sep { display: none; } }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; padding: 8px 12px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .12s, border-color .12s, transform .04s, opacity .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[disabled] { opacity: .4; pointer-events: none; }
.btn--icon { padding: 8px 10px; line-height: 1; }
.btn--icon svg { width: 16px; height: 16px; display: block; }
.btn--sm { padding: 6px 10px; font-size: 13px; }
.btn--dl { display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; font-size: 14px; }
.btn--dl svg { width: 16px; height: 16px; }
.linklike {
  appearance: none; border: 0; background: none; padding: 0;
  color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline;
}

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(340px, 420px) 1fr;
  gap: 24px; padding: 22px; align-items: start; max-width: 1400px; margin: 0 auto;
}
.editor { display: flex; flex-direction: column; gap: 16px; }
.results { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

body:not(.has-files) .layout { display: block; max-width: 780px; }
body:not(.has-files) .editor { display: none; }

/* ---------- Tabs — five, one tidy row ---------- */
.tabs {
  display: flex; flex-wrap: nowrap; gap: 3px; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px;
}
.tab {
  appearance: none; flex: 1 1 0; min-width: 0;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 4px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; font-size: 12px; letter-spacing: -.01em;
  white-space: nowrap; cursor: pointer;
  transition: background .14s, color .14s, box-shadow .14s;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.10); }
@media (max-width: 400px) { .tab { font-size: 11px; } }

.tab-lead { margin: 2px 0 -2px; font-size: 13px; line-height: 1.55; color: var(--muted); display: none; }
body[data-pdftool="merge"]   .lead-merge,
body[data-pdftool="split"]   .lead-split,
body[data-pdftool="compress"] .lead-compress,
body[data-pdftool="img2pdf"] .lead-img2pdf,
body[data-pdftool="pdf2img"] .lead-pdf2img,
body[data-pdftool="stamp"]   .lead-stamp { display: block; }

/* ---------- Fieldsets, gated per tool ---------- */
.fieldset { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.fieldset__title {
  display: block; margin-bottom: 12px;
  font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
}
.grp-merge, .grp-split, .grp-compress, .grp-img2pdf, .grp-pdf2img, .grp-stamp { display: none; }
body[data-pdftool="merge"]   .grp-merge,
body[data-pdftool="split"]   .grp-split,
body[data-pdftool="compress"] .grp-compress,
body[data-pdftool="img2pdf"] .grp-img2pdf,
body[data-pdftool="pdf2img"] .grp-pdf2img,
body[data-pdftool="stamp"]   .grp-stamp { display: block; }

.grp-stamp hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.grp-stamp input[type="range"] { width: 100%; accent-color: var(--gk-ink); }
.grp-stamp input[type="color"] { width: 42px; height: 28px; padding: 0; border: 1px solid var(--border); border-radius: 7px; background: none; cursor: pointer; vertical-align: middle; }
.grp-stamp .fieldset__title .n { float: right; text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--text); }
.grp-stamp .field--check + .fieldset__title { margin-top: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field--full { width: 100%; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.field--check { flex-direction: row; align-items: center; gap: 10px; }
.field--check > span { color: var(--text); font-weight: 500; }
.field + .field { margin-top: 12px; }
input[type="text"] {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; width: 100%;
}
input[type="text"]:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
code {
  padding: 1px 5px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--border);
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88em;
}
.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; line-height: 1.55; }

/* iOS switch */
.field--check input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 40px; height: 24px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); position: relative; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.field--check input[type="checkbox"]::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s;
}
.field--check input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.field--check input[type="checkbox"]:checked::before { transform: translateX(16px); }
[data-theme="dark"] .field--check input[type="checkbox"]::before { background: #e8eaed; }

/* segmented control */
.seg-row {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.seg-row button {
  appearance: none; flex: 1 1 auto; min-width: 52px; padding: 8px 8px; border: 0;
  border-radius: calc(var(--radius-sm) - 2px); background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; transition: background .12s, color .12s;
}
.seg-row button:hover { color: var(--text); }
.seg-row button.is-active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 2px rgba(17,24,39,.12); }
[data-theme="dark"] .seg-row button.is-active { background: #2a2f3a; }

/* ---------- Dropzone ---------- */
.dropzone {
  display: grid; place-items: center; gap: 4px; text-align: center;
  padding: 26px 20px; border: 1.5px dashed var(--gk-border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--muted); transition: border-color .14s, background .14s;
}
.dropzone.is-over { border-color: var(--accent); background: var(--surface-2); }
.dropzone__icon { font-size: 26px; color: var(--muted); }
.dropzone__title { margin: 6px 0 2px; font-size: 16px; font-weight: 700; color: var(--text); }
.dropzone__sub { margin: 0; font-size: 13px; }
.dropzone__privacy { margin: 8px 0 0; font-size: 12px; color: var(--gk-faint); }
/* once files are in, the whole right panel is for the grid + result.
   Adding more files: the top-bar "Add files" button, or drop anywhere on the page. */
body.has-files .dropzone { display: none; }
body:not(.has-files) .dropzone { min-height: min(56vh, 420px); border-width: 2px; }
/* subtle page-wide drop affordance */
body.is-dragover::after {
  content: "Drop to add"; position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center;
  font-size: 18px; font-weight: 700; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
  border: 3px dashed var(--accent); pointer-events: none;
}
body:not(.has-files) .dropzone__icon { font-size: 40px; }
body:not(.has-files) .dropzone__title { font-size: 22px; }

/* ---------- Page / file cards ---------- */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.pgrid:empty { display: none; }
.pgrid__note { grid-column: 1 / -1; margin: 4px 0 0; font-size: 12px; color: var(--muted); }

/* merge & images->pdf: fewer, larger, obviously-draggable file boards */
body[data-pdftool="merge"] .pgrid,
body[data-pdftool="img2pdf"] .pgrid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }

.pcard {
  position: relative; margin: 0; padding: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  display: flex; flex-direction: column; gap: 8px;
  transition: border-color .14s, box-shadow .14s, transform .06s;
}
.pcard[draggable] { cursor: grab; padding-top: 34px; }
.pcard[draggable]:active { cursor: grabbing; }
.pcard.is-drag { opacity: .4; }
.pcard.is-over { border-color: var(--accent); box-shadow: 0 0 0 3px var(--gk-accent-soft); }
.pcard__grip {
  position: absolute; top: 0; left: 0; right: 0; height: 26px;
  display: flex; align-items: center; gap: 6px; padding: 0 10px;
  border-bottom: 1px solid var(--gk-border-soft);
  color: var(--gk-faint); font-size: 11px; font-weight: 700; letter-spacing: .04em;
}
.pcard__grip::before { content: "\2807\2807"; font-size: 13px; letter-spacing: -3px; }
.pcard__grip::after { content: "DRAG TO REORDER"; }
.pcard__thumb {
  display: grid; place-items: center; aspect-ratio: 3 / 4; overflow: hidden;
  border-radius: 8px; background: var(--surface-2); border: 1px solid var(--gk-border-soft);
}
.pcard__thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.pcard figcaption { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.pcard figcaption b { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard figcaption span { font-size: 11.5px; color: var(--muted); }
.pcard__x {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  font-size: 15px; line-height: 1; cursor: pointer;
}
.pcard__x:hover { color: #dc2626; border-color: #dc2626; }

.pcard--page { cursor: pointer; }
.pcard--page .pcard__check {
  position: absolute; top: 8px; right: 8px; width: 20px; height: 20px; border-radius: 6px;
  border: 2px solid var(--gk-border-strong); background: var(--surface);
}
.pcard--page.is-sel { border-color: var(--accent); }
.pcard--page.is-sel .pcard__check { background: var(--accent); border-color: var(--accent); }
.pcard--page.is-sel .pcard__check::after {
  content: ""; position: absolute; left: 5px; top: 1px; width: 6px; height: 11px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.pcard--page:not(.is-sel) .pcard__thumb { opacity: .45; }

/* ---------- Progress ---------- */
.progress { display: flex; flex-direction: column; gap: 8px; padding: 4px 2px; }
.progress__bar { height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.progress__bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s ease; }
.progress__txt { margin: 0; font-size: 12.5px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
body.is-busy .tab, body.is-busy [data-action="tool"] { pointer-events: none; opacity: .6; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  max-width: 90vw; text-align: center;
  background: #14181f; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px; background: rgba(10,13,18,.55); }
.modal__box {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.35); padding: 20px 22px; max-width: 560px; width: 100%;
}
.modal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.modal__head h3 { margin: 0; font-size: 17px; }
.modal__lead { color: var(--muted); margin: 0 0 6px; }
.modal__scroll { max-height: 64vh; overflow-y: auto; padding-right: 4px; }
.modal__scroll h4 { margin: 16px 0 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.modal__scroll p { margin: 4px 0; }
.modal__scroll b { color: var(--text); }
.modal__actions { display: flex; justify-content: flex-end; margin-top: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .layout { padding: 14px; gap: 16px; }
  .pgrid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
}

/* ---------- CTA processing state — spinner + live page count ---------- */
.btn__spin {
  display: none; width: 15px; height: 15px; flex: none;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  border-radius: 50%; animation: gb-spin .7s linear infinite;
}
@keyframes gb-spin { to { transform: rotate(360deg); } }
body.is-busy #goBtn { pointer-events: none; }
body.is-busy #goBtn .btn__spin { display: inline-block; }
body.is-busy #goBtn .btn__dlicon { display: none; }
#goBtn { min-width: 190px; }
@media (max-width: 560px) { #goBtn { min-width: 0; } }

/* Stamp tool: live page-1 preview with the watermark + numbers */
.stamp-prev { max-width: 460px; }
.stamp-prev__frame {
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  background: var(--surface-2);
  min-height: 220px; display: flex; align-items: center; justify-content: center;
}
.stamp-prev__frame canvas { display: block; width: 100%; height: auto; background: #fff; }
.stamp-prev__msg { color: var(--muted); font-size: 13px; padding: 44px 16px; text-align: center; }
.stamp-prev__cap {
  display: flex; align-items: baseline; gap: 10px; margin-top: 10px; font-size: 13px;
}
.stamp-prev__cap b { font-weight: 700; }
.stamp-prev__cap span { color: var(--muted); }
.stamp-prev__cap .linklike { margin-left: auto; }

body[data-pdftool="stamp"] .pgrid { display: block; }
