/* PDF Toolkit — shared stylesheet. Plain CSS, no framework.
 * Mobile-first, responsive, works as static files on S3 hosting. */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #5b6478;
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-soft: #eef0ff;
  --accent: #06b6d4;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --line: #e5e8f0;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}
a { color: var(--brand); }
img, svg { display: block; }

/* ---------- layout ---------- */
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.page { padding: 32px 0 64px; }
.section { margin-top: 56px; }
.section-head { max-width: 640px; margin-bottom: 24px; }
.section-head h2 { margin: 0 0 6px; font-size: 1.6rem; letter-spacing: -0.01em; }
.section-head p { margin: 0; color: var(--muted); }

/* ---------- header / nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.nav { display: flex; align-items: center; gap: 20px; padding: 14px 20px; max-width: 1120px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 800; font-size: 1.1rem; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.95rem; font-weight: 800;
}
.nav-links { display: flex; gap: 4px; margin-left: auto; }
.nav-links a {
  text-decoration: none; color: var(--muted); font-weight: 600; font-size: 0.95rem;
  padding: 8px 12px; border-radius: 9px;
}
.nav-links a:hover { background: var(--brand-soft); color: var(--brand-dark); }
.nav-links a.active { color: var(--brand-dark); background: var(--brand-soft); }
@media (max-width: 640px) {
  .nav-links a { padding: 8px; font-size: 0.85rem; }
  .brand span { display: none; }
}

/* ---------- hero ---------- */
.hero {
  background: linear-gradient(135deg, #1e1b4b 0%, #4f46e5 55%, #06b6d4 130%);
  color: #fff; border-radius: 0 0 28px 28px; padding: 64px 0 56px;
}
.hero h1 { margin: 0 0 12px; font-size: clamp(1.9rem, 4.5vw, 3rem); letter-spacing: -0.02em; line-height: 1.15; }
.hero p { margin: 0 0 28px; max-width: 620px; color: #e0e7ff; font-size: 1.08rem; }
.hero-cta { display: flex; gap: 12px; flex-wrap: wrap; }
.eyebrow {
  display: inline-block; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: #c7d2fe; margin-bottom: 12px;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; cursor: pointer; text-decoration: none;
  font: 600 1rem/1 var(--font);
  padding: 14px 22px; border-radius: 12px;
  background: var(--brand); color: #fff;
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { background: var(--brand-dark); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { background: #9aa3b5; cursor: not-allowed; transform: none; }
.btn.secondary { background: #fff; color: var(--brand-dark); box-shadow: inset 0 0 0 2px rgba(255,255,255,.9); }
.btn.ghost { background: var(--brand-soft); color: var(--brand-dark); }
.btn.ghost:hover { background: #e1e5ff; }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }

/* ---------- tool cards ---------- */
.tools-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.tool-card {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
  text-decoration: none; color: inherit; box-shadow: var(--shadow);
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
a.tool-card:hover { transform: translateY(-3px); border-color: var(--brand); box-shadow: 0 14px 34px rgba(79, 70, 229, 0.16); }
.tool-icon {
  flex: 0 0 46px; width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-soft); color: var(--brand);
}
.tool-icon svg { width: 24px; height: 24px; }
.tool-card.soon .tool-icon { background: #f1f2f6; color: #8a93a8; }
.tool-card h3 { margin: 0 0 4px; font-size: 1.02rem; }
.tool-card p { margin: 0 0 10px; font-size: 0.88rem; color: var(--muted); }
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 700;
  padding: 3px 10px; border-radius: 999px; letter-spacing: 0.02em;
}
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.soon { background: #f1f2f6; color: #6b7280; }

/* ---------- workflow strip ---------- */
.steps-strip { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.step-chip {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.step-chip strong { display: block; margin-bottom: 2px; }
.step-chip span { color: var(--muted); font-size: 0.9rem; }

/* ---------- tool page ---------- */
.tool-hero { background: var(--surface); border-bottom: 1px solid var(--line); padding: 40px 0 32px; }
.tool-hero h1 { margin: 0 0 8px; font-size: clamp(1.6rem, 3.5vw, 2.2rem); letter-spacing: -0.02em; }
.tool-hero p { margin: 0; color: var(--muted); max-width: 640px; }
.back-link { display: inline-block; margin-bottom: 16px; font-weight: 600; font-size: 0.9rem; text-decoration: none; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px;
}
.stack { display: grid; gap: 16px; max-width: 760px; }

/* dropzone */
.dropzone {
  display: block; border: 2px dashed #b9bef5; border-radius: var(--radius);
  background: #fafbff; padding: 40px 24px; text-align: center; cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--brand); background: var(--brand-soft); }
.dropzone input { display: none; }
.dropzone .dz-icon { font-size: 2rem; }
.dropzone strong { display: block; margin: 8px 0 4px; font-size: 1.05rem; }
.dropzone p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.file-meta { margin-top: 12px; font-size: 0.9rem; color: var(--muted); overflow-wrap: anywhere; }
.file-meta strong { color: var(--ink); }

/* progress + steps */
.progress { height: 12px; background: #e9ecf4; border-radius: 999px; overflow: hidden; margin: 16px 0 6px; }
.progress > div { height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--accent)); transition: width 0.25s ease; }
.progress-row { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); }
.stepper { list-style: none; display: flex; gap: 6px; padding: 0; margin: 18px 0 0; flex-wrap: wrap; }
.stepper li {
  flex: 1 1 120px; text-align: center; font-size: 0.8rem; font-weight: 700;
  padding: 8px 6px; border-radius: 9px; background: #f1f2f6; color: #8a93a8;
}
.stepper li.done { background: #dcfce7; color: #15803d; }
.stepper li.now { background: var(--brand-soft); color: var(--brand-dark); }

/* status / result / error */
.status-line { font-weight: 600; }
.result { border-left: 5px solid var(--ok); }
.result dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 12px 0 18px; font-size: 0.95rem; }
.result dt { color: var(--muted); }
.result dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.error-box { border-left: 5px solid var(--danger); background: #fef2f2; }
.error-box p { margin: 0 0 8px; font-weight: 600; color: #991b1b; }
.error-box details { font-size: 0.85rem; color: #7f1d1d; }
.error-box summary { cursor: pointer; }
[hidden] { display: none !important; }

/* feature list (editor placeholder) */
.feature-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); padding: 0; margin: 16px 0 0; list-style: none; }
.feature-list li { background: #fafbff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; font-size: 0.92rem; }

/* merge file list */
.merge-totals {
  display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  margin: 14px 0 8px; font-size: 0.88rem; font-weight: 700; color: var(--muted);
}
.merge-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.merge-item {
  display: flex; align-items: center; gap: 10px;
  background: #fafbff; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
}
.merge-item.dragging { opacity: 0.5; border-color: var(--brand); }
.merge-pos {
  flex: 0 0 28px; height: 28px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-soft); color: var(--brand-dark);
  font-weight: 800; font-size: 0.85rem;
}
.merge-icon { font-size: 1.3rem; }
.jpg-thumb {
  flex: 0 0 56px; width: 56px; height: 56px; border-radius: 8px;
  object-fit: cover; background: #eef0ff; border: 1px solid var(--line);
}
.merge-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.merge-name {
  font-weight: 700; font-size: 0.92rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.merge-size { font-size: 0.8rem; color: var(--muted); }
.merge-controls { display: flex; gap: 6px; flex: 0 0 auto; }
.mini-btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 8px; min-width: 34px; height: 34px; padding: 0 8px;
  font-weight: 800; cursor: pointer; font-size: 0.95rem;
}
.mini-btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand-dark); }
.mini-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.mini-btn.danger { color: var(--danger); }
.merge-hint { font-size: 0.85rem; color: var(--muted); }

/* extract page picker: compact responsive checkbox grid + range row */
.extract-select-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.extract-tiles { display: grid; gap: 8px; margin: 4px 0 12px;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.extract-tile { display: flex; align-items: center; gap: 8px;
  background: #fafbff; border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font-size: 0.88rem;
  font-weight: 600; cursor: pointer; }
.extract-tile.checked { border-color: var(--brand); background: var(--brand-soft); }
.extract-tile input { width: 16px; height: 16px; accent-color: var(--brand); }
.extract-range-row { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.extract-range-row input { flex: 1 1 220px; min-width: 0; padding: 10px; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); margin-top: 64px; }
.footer-grid { display: grid; gap: 24px; grid-template-columns: 2fr 1fr 1fr; padding: 36px 20px; max-width: 1120px; margin: 0 auto; }
.site-footer h4 { margin: 0 0 8px; font-size: 0.95rem; }
.site-footer p, .site-footer a { font-size: 0.88rem; color: var(--muted); }
.site-footer ul { list-style: none; margin: 0; padding: 0; }
.site-footer li { margin: 4px 0; }
.fineprint { border-top: 1px solid var(--line); padding: 14px 20px; text-align: center; font-size: 0.8rem; color: var(--muted); }
@media (max-width: 700px) { .footer-grid { grid-template-columns: 1fr; } }

/* ---------- PDF editor workspace ---------- */
.editor-topbar { position: sticky; top: 57px; z-index: 15; background: var(--surface); border-bottom: 1px solid var(--line); }
.editor-topbar-inner { display: flex; align-items: center; gap: 12px; padding-top: 10px; padding-bottom: 10px; }
.editor-top-status { color: var(--muted); font-size: 0.85rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-top-actions { display: flex; gap: 8px; margin-left: auto; }
.btn-sm { padding: 9px 14px; font-size: 0.88rem; }
.editor-toolbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.editor-toolbar-inner { display: flex; gap: 6px; padding-top: 10px; padding-bottom: 6px; overflow-x: auto; }
.tool-btn { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 8px 12px; font: 600 0.85rem/1 var(--font); color: var(--ink); cursor: pointer; white-space: nowrap; }
.tool-btn:hover { border-color: var(--brand); color: var(--brand-dark); }
.tool-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.editor-props { display: flex; flex-wrap: wrap; gap: 4px 18px; padding-top: 4px; padding-bottom: 10px; font-size: 0.88rem; }
.props-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.props-id { color: var(--muted); font-size: 0.78rem; }
.props-hint { color: var(--muted); }
.editor-main { display: flex; align-items: stretch; gap: 0; min-height: 60vh; }
.editor-thumbs { width: 190px; flex: 0 0 190px; background: var(--surface); border-right: 1px solid var(--line); padding: 12px; overflow-y: auto; max-height: calc(100vh - 200px); position: sticky; top: 110px; align-self: flex-start; }
.editor-thumbs-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
ol.editor-thumbs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
li.thumb { border: 2px solid var(--line); border-radius: 10px; padding: 6px; background: #fff; cursor: pointer; }
li.thumb.active { border-color: var(--brand); }
li.thumb canvas { width: 100%; height: auto; border-radius: 4px; background: #fff; }
.thumb-label { display: block; font-size: 0.78rem; font-weight: 700; margin: 4px 0; }
.thumb-bar { display: flex; gap: 4px; flex-wrap: wrap; }
.thumb-bar .mini-btn { padding: 3px 7px; font-size: 0.78rem; }
.editor-stage { flex: 1; min-width: 0; padding: 20px 0 40px; }
.editor-canvas-wrap { position: relative; margin: 0 auto; width: fit-content; max-width: 100%; box-shadow: var(--shadow); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.editor-canvas-wrap canvas { display: block; }
#edOverlay { position: absolute; left: 0; top: 0; touch-action: none; }
#edTextLayer { position: absolute; left: 0; top: 0; overflow: hidden; }
#edTextLayer span { position: absolute; color: transparent; white-space: pre; user-select: text; line-height: 1; transform-origin: left top; }
#edTextInput { position: absolute; z-index: 5; min-width: 120px; border: 2px solid var(--brand); border-radius: 4px; padding: 2px 6px; background: rgba(255,255,255,.92); }
.editor-canvas-bar { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.editor-zoom { display: inline-flex; align-items: center; gap: 6px; margin-left: 12px; }
.editor-replace-bar { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: 10px; font-size: 0.9rem; color: var(--muted); }
.editor-note { color: var(--muted); font-size: 0.88rem; }
/* Replace panel: compact bar below the toolbar (never covers the PDF). */
.editor-replace-panel { border-top: 1px solid var(--line); background: #fafbff; }
.editor-replace-panel-inner { display: grid; gap: 10px; padding: 12px 0 14px; }
.editor-replace-panel-inner > strong { font-size: 1rem; }
.replace-note { margin: 0; color: var(--muted); font-size: 0.85rem; }
.replace-label { font-weight: 700; font-size: 0.88rem; }
.replace-orig { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 4px; max-height: 76px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.replace-new { width: 100%; min-height: 64px; margin-top: 4px; padding: 8px 10px; font: 500 1rem/1.5 var(--font); border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.replace-controls { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 0.9rem; }
.replace-controls input[type="number"] { width: 72px; }
.replace-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.danger-text { color: var(--danger); }
@media (max-width: 900px) {
  .editor-main { flex-direction: column; }
  .editor-thumbs { width: 100%; flex: none; position: static; max-height: none; border-right: none; border-bottom: 1px solid var(--line); }
  ol.editor-thumbs { display: flex; overflow-x: auto; }
  li.thumb { min-width: 120px; }
  .editor-top-status { display: none; }
}
