/* Keep the intro sentence at a comfortable reading width even though the
   card itself is wide — the working area (textareas, buttons, output)
   uses the full width below it. */
main > p:first-of-type {
  max-width: 640px;
}

.tool-about,
.tool-faq,
.related-tools {
  max-width: 720px;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.tool-about h2,
.tool-faq h2,
.related-tools h2 {
  font-size: 1rem;
  margin-bottom: 0.6rem;
  color: var(--text);
}
.tool-about p { color: var(--text-muted); font-size: 0.92rem; line-height: 1.65; }

.tool-faq .faq-item { margin-bottom: 1.1rem; }
.tool-faq .faq-item:last-child { margin-bottom: 0; }
.tool-faq .faq-item h3 { font-size: 0.92rem; font-weight: 600; margin-bottom: 0.3rem; color: var(--text); }
.tool-faq .faq-item p { font-size: 0.88rem; color: var(--text-muted); line-height: 1.6; }

.related-tools-list { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.related-tools-list a {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--primary);
  text-decoration: none;
  background: var(--bg);
  transition: border-color 0.2s, background 0.2s;
}
.related-tools-list a:hover {
  border-color: var(--primary);
  background: var(--primary-tint);
}

/* Numbered "how it works" steps, used on the PDF tools right below the
   intro line. Plain <ol> for real list semantics (role="list" works around
   Safari/VoiceOver dropping list semantics when list-style is removed);
   the numbered circle is purely decorative styling on top of that. */
.workflow-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin: 1rem 0 1.5rem;
  padding: 0;
  list-style: none;
}
.workflow-steps li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.workflow-steps li::before {
  content: counter(step);
  counter-increment: step;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: var(--primary-tint);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.workflow-steps { counter-reset: step; }

/* "What next" cross-links shown next to a finished result (e.g. after a
   PDF merge completes), separate from the general Related Tools section
   further down the page. */
.next-actions {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}
.next-actions p {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.back-link {
  position: absolute;
  top: 1.25rem;
  left: 1.25rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.back-link svg {
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.back-link:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-tint);
}

.back-link:hover svg {
  transform: translateX(-3px);
}

textarea {
  width: 100%;
  height: 200px;
  font-family: monospace;
  padding: 1rem;
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s, border-color 0.3s;
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

button {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border: none;
  padding: 0.65rem 1.3rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25), 0 1px 1px rgba(0, 0, 0, 0.03);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3);
}

button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.35);
}

button:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

pre {
  background: #f3f4f6;
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre-wrap;
  margin-top: 1rem;
  transition: background 0.3s;
}

:root.dark pre {
  background: #374151;
}

.copy-btn {
  margin-top: 0.5rem;
  padding: 0.5rem 1.1rem;
  font-size: 0.9rem;
}


.success { color: var(--success); }
.error { color: var(--error); }

/* --- Shared components for the wider tool set --- */

input[type="text"],
input[type="number"],
input[type="search"],
input[type="datetime-local"],
select {
  font-family: monospace;
  padding: 0.6rem 0.8rem;
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  transition: background 0.3s, color 0.3s, border-color 0.3s;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="datetime-local"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.field-group { margin-bottom: 1rem; }
.field-group label { display: block; margin-bottom: 0.4rem; font-weight: 500; font-size: 0.9rem; }

.btn-row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }

.btn-secondary {
  background: var(--card-bg);
  color: var(--primary);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--primary-tint);
  border-color: var(--primary);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.15);
}
.btn-secondary:focus-visible { box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.35); }
.btn-secondary:disabled { border-color: var(--border); box-shadow: none; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.8rem;
  margin-top: 1.5rem;
}
.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 0.5rem;
  text-align: center;
}
.stat-card .num { font-size: 1.4rem; font-weight: 700; color: var(--primary); }
.stat-card .lbl { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 0.2rem; }

mark.match { background: var(--primary-tint); color: var(--primary); border-radius: 3px; padding: 0 1px; }

.diff-add { background: rgba(22,163,74,0.15); color: #16a34a; display: block; padding: 0 0.5rem; white-space: pre-wrap; }
.diff-remove { background: rgba(220,38,38,0.15); color: #dc2626; display: block; padding: 0 0.5rem; white-space: pre-wrap; }
.diff-context { display: block; padding: 0 0.5rem; white-space: pre-wrap; color: var(--text-muted); }

.color-swatch {
  width: 100%;
  height: 80px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}

.output-box {
  background: #f3f4f6;
  padding: 1rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  transition: background 0.3s;
}
:root.dark .output-box { background: #374151; }

.copy-inline {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: normal;
  letter-spacing: normal;
  box-shadow: none;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.copy-inline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: none;
  transform: none;
  box-shadow: none;
}

.hint { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.5rem; }

/* --- File-upload based tools (PDF merge/split/export) --- */

.file-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  background: var(--bg);
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  margin-bottom: 1rem;
}
.file-drop:hover,
.file-drop.drag-over {
  border-color: var(--primary);
  background: var(--primary-tint);
  color: var(--primary);
}

.file-list { margin-bottom: 1rem; }

.file-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  background: var(--card-bg);
}
.file-item .file-name {
  flex: 1;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-item .file-size { font-size: 0.8rem; color: var(--text-muted); flex-shrink: 0; }
.file-item .file-actions { display: flex; gap: 0.3rem; flex-shrink: 0; }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 1.8rem;
  height: 1.8rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: normal;
  letter-spacing: normal;
  box-shadow: none;
  padding: 0;
  line-height: 1;
  transition: border-color 0.2s, color 0.2s;
}
.icon-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: none;
  transform: none;
  box-shadow: none;
}
.icon-btn:active:not(:disabled) { transform: none; box-shadow: none; }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; background: none; box-shadow: none; transform: none; }

.favorite-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.6rem;
  padding: 0.3rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: normal;
  box-shadow: none;
  cursor: pointer;
}
.favorite-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--card-bg);
  transform: none;
  box-shadow: none;
}
.favorite-toggle:active { transform: none; box-shadow: none; }
.favorite-toggle.is-favorite {
  background: var(--primary-tint);
  border-color: var(--primary);
  color: var(--primary);
}

.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 400;
  cursor: pointer;
}

.file-thumb {
  width: 44px;
  height: 58px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.65rem;
  text-align: center;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}
.file-thumb:hover {
  opacity: 0.85;
  transform: scale(1.04);
}

.file-thumb-lg {
  width: 72px;
  height: 96px;
  font-size: 0.75rem;
}

/* Page-level grid used by the Organize PDF tool — one card per page, with
   its own rotate/move/delete controls, as opposed to .file-list's one row
   per uploaded file on PDF Merge. */
.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.page-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
}

.page-thumb-wrap {
  width: 100%;
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg);
  border-radius: 4px;
  font-size: 1.4rem;
}

.page-thumb-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.2s ease;
}

.page-num { font-size: 0.75rem; color: var(--text-muted); }

.page-actions {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  justify-content: center;
}

.merge-result {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--primary-tint);
}

/* Force the "what next" cross-links onto their own row below the
   thumbnail/filename/download row, rather than fighting for space in it. */
.merge-result .next-actions {
  flex-basis: 100%;
}
/* Author-stylesheet `display` beats the browser's default [hidden]{display:none}
   rule regardless of source order, so it must be restated explicitly here. */
.merge-result[hidden] { display: none; }

.merge-result-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.rename-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.rename-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rename-row .icon-btn {
  flex-shrink: 0;
  border-color: transparent;
  background: none;
}
.rename-row .icon-btn:hover { border-color: var(--primary); background: none; }

.rename-input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
}

/* --- PDF reader modal --- */

.pdf-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.pdf-modal[hidden] { display: none; }

.pdf-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.pdf-modal-content {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  width: min(1100px, 96vw);
  height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.pdf-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.pdf-modal-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-modal-body {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg);
  position: relative;
  min-height: 320px;
}
.pdf-modal-body canvas {
  max-width: 100%;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  background: white;
}
.pdf-modal-loading { color: var(--text-muted); font-size: 0.9rem; }

.pdf-modal-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.85rem;
  border-top: 1px solid var(--border);
}
.pdf-modal-footer .hint { margin-top: 0; min-width: 6rem; text-align: center; }
