/*
  DMI PDF Tools — design system
  Signature motif: prepress registration marks. PDF's lineage is print
  production, and this tool set (crop, rotate, split, page numbers,
  watermark) mirrors literal prepress operations — so the visual system
  borrows the registration mark / trim mark / plate-ink vocabulary of a
  print shop instead of generic "web app" chrome.
  No preprocessor. No inline styles. No web fonts (privacy-first product
  makes zero third-party requests; type is carried by weight/scale/case
  on system stacks instead).
*/

/* ---------- 1. Tokens ---------- */
:root {
  /* type */
  --font-display: ui-sans-serif, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-body: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", ui-serif, serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Segoe UI Mono", Consolas, "Liberation Mono", monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-md: 1.125rem;
  --text-lg: 1.375rem;
  --text-xl: 1.75rem;
  --text-2xl: 2.25rem;
  --text-3xl: 3rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4.5rem;

  --radius: 10px;
  --radius-sm: 6px;
  --border: 1px;
  --container: 72rem;

  --mark: 14px; /* registration-mark corner size */

  /* light palette (default) */
  --bg: #F1F3EF;
  --surface: #FFFFFF;
  --surface-2: #E4E8E1;
  --surface-3: #D7DCD2;
  --ink: #16211C;
  --ink-2: #46554D;
  --ink-3: #5A6961;
  --line: #748071;
  --accent: #0B6B73;
  --accent-strong: #094F55;
  --accent-ink: #FFFFFF;
  --accent-2: #9C2F5D;
  --danger: #B23A22;
  --danger-bg: #F6E4DE;
  --success: #256B45;
  --success-bg: #E1EEE3;
  --shadow: 0 1px 2px rgba(20, 30, 25, 0.06), 0 8px 24px rgba(20, 30, 25, 0.07);

  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #12181A;
  --surface: #1B2224;
  --surface-2: #232B2D;
  --surface-3: #2E373A;
  --ink: #E9EDE7;
  --ink-2: #ABB6AE;
  --ink-3: #7C8985;
  --line: #6E7B7E;
  --accent: #46D6DC;
  --accent-strong: #7BE5EA;
  --accent-ink: #062023;
  --accent-2: #ED84B2;
  --danger: #FF8A66;
  --danger-bg: #3A2019;
  --success: #6BD897;
  --success-bg: #163524;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12181A;
    --surface: #1B2224;
    --surface-2: #232B2D;
    --surface-3: #2E373A;
    --ink: #E9EDE7;
    --ink-2: #ABB6AE;
    --ink-3: #7C8985;
    --line: #6E7B7E;
    --accent: #46D6DC;
    --accent-strong: #7BE5EA;
    --accent-ink: #062023;
    --accent-2: #ED84B2;
    --danger: #FF8A66;
    --danger-bg: #3A2019;
    --success: #6BD897;
    --success-bg: #163524;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

/* ---------- 2. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  transition: background-color 0.25s ease, color 0.25s ease;
}
/* Ambient backdrop: a faint registration dot-grid across the whole page
   (echoes the corner trim-mark signature) plus two soft brand blooms
   anchored at the top so colour lands behind the hero and fades out
   before the tool area — cheerful but non-intrusive, and static, so the
   reduced-motion rule needs no exception. Both layers sit behind content
   (z-index: -1, pointer-events: none) and read from the theme tokens, so
   they recolour automatically in light and dark. */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}
body::before {
  background-image: radial-gradient(color-mix(in oklab, var(--ink) 6%, transparent) 1px, transparent 1.4px);
  background-size: 28px 28px;
}
body::after {
  background:
    radial-gradient(46rem 34rem at 14% -6%, color-mix(in oklab, var(--accent) 9%, transparent), transparent 60%),
    radial-gradient(42rem 32rem at 88% -2%, color-mix(in oklab, var(--accent-2) 8%, transparent), transparent 62%);
}
img, svg { max-width: 100%; display: block; }
a { color: var(--accent); }
a:hover { color: var(--accent-strong); }
h1, h2, h3 { font-family: var(--font-display); color: var(--ink); line-height: 1.15; margin: 0 0 var(--space-4); }
p { margin: 0 0 var(--space-4); }
ul, ol { margin: 0; padding: 0; }
button { font: inherit; color: inherit; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

:where(a, button, input, select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- 3. Registration-mark signature ---------- */
/* Two opposing corner trim marks — a deliberate minimal reference to
   duplex print-registration crosses, not a decorative frame on all four
   corners. Bound directly to the real panel selectors (hero, tool card,
   dropzone) rather than a separate utility class, so it renders without
   any PHP template changes. */
.hero,
.tool-card,
.dz-drop {
  position: relative;
}
.hero::before, .hero::after,
.tool-card::before, .tool-card::after,
.dz-drop::before, .dz-drop::after {
  content: "";
  position: absolute;
  width: var(--mark);
  height: var(--mark);
  pointer-events: none;
  opacity: 0.55;
  transition: opacity 0.2s ease, border-color 0.2s ease;
}
.hero::before, .tool-card::before, .dz-drop::before {
  top: 8px;
  left: 8px;
  border-top: 2px solid var(--accent-2);
  border-left: 2px solid var(--accent-2);
}
.hero::after, .tool-card::after, .dz-drop::after {
  bottom: 8px;
  right: 8px;
  border-bottom: 2px solid var(--accent);
  border-right: 2px solid var(--accent);
}
.tool-card:hover::before, .tool-card:hover::after,
.tool-card:focus-visible::before, .tool-card:focus-visible::after,
.dz-drop:hover::before, .dz-drop:hover::after,
.dz-drop:focus-within::before, .dz-drop:focus-within::after,
.dz-drop.dz-drag::before, .dz-drop.dz-drag::after { opacity: 1; }

@keyframes reg-spin { to { transform: rotate(360deg); } }

/* ---------- 4. Shell: header / footer ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--space-4) var(--space-5);
}
.brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--text-md);
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--ink);
}
.brand:hover { color: var(--accent); }

#theme-toggle {
  position: relative;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color 0.2s ease, transform 0.15s ease;
}
#theme-toggle:hover { border-color: var(--accent); transform: translateY(-1px); }
#theme-toggle::before {
  content: "\2600\FE0E"; /* sun glyph, shown in light theme */
  font-size: 1.05rem;
  line-height: 1;
}
:root[data-theme="dark"] #theme-toggle::before { content: "\263D\FE0E"; } /* moon glyph */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle::before { content: "\263D\FE0E"; }
}

main {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--space-5) var(--space-8);
  min-height: 60vh;
}

.site-footer {
  border-top: 1px solid var(--line);
  margin-top: var(--space-8);
}
.site-footer p {
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--space-5);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--ink-3);
  text-align: center;
}
.site-footer a { color: var(--ink-2); }

/* ---------- 5. Hero ---------- */
.hero {
  position: relative;
  padding: var(--space-7) var(--space-5);
  margin: var(--space-5) 0 var(--space-6);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero h1 {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  max-width: 34ch;
}
.hero p {
  font-family: var(--font-body);
  font-size: var(--text-md);
  color: var(--ink-2);
  max-width: 60ch;
  margin-bottom: 0;
}

/* ---------- 6. Tool grid / cards ---------- */
.tool-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.tool-card {
  position: relative;
  display: block;
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.tool-card:hover, .tool-card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.tool-card h2 {
  font-size: var(--text-md);
  font-weight: 700;
  margin-bottom: var(--space-2);
}
.tool-card p {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink-2);
  margin-bottom: 0;
}

/* ---------- 7. Tool page ---------- */
.tool-page { padding-top: var(--space-6); }
.tool-page h1 {
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: -0.01em;
}
.intro {
  font-family: var(--font-body);
  font-size: var(--text-md);
  color: var(--ink-2);
  max-width: 68ch;
  margin-bottom: var(--space-6);
}

.howto {
  margin: var(--space-7) 0;
}
.howto h2 { font-size: var(--text-lg); margin-bottom: var(--space-4); }
.howto ol {
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: var(--space-3);
}
.howto li {
  counter-increment: step;
  position: relative;
  padding: var(--space-3) var(--space-4) var(--space-3) 3.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
}
.howto li::before {
  content: counter(step);
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--text-sm);
  display: grid;
  place-items: center;
}

.faq { margin: var(--space-7) 0; }
.faq h2 { font-size: var(--text-lg); margin-bottom: var(--space-4); }
.faq details {
  border-bottom: 1px solid var(--line);
  padding: var(--space-3) 0;
}
.faq summary {
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-base);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+";
  font-family: var(--font-mono);
  color: var(--accent);
  flex: none;
  font-size: var(--text-md);
}
.faq details[open] summary::after { content: "\2212"; }
.faq p {
  font-family: var(--font-body);
  color: var(--ink-2);
  margin: var(--space-3) 0 0;
}

.related { margin: var(--space-7) 0; }
.related h2 { font-size: var(--text-lg); margin-bottom: var(--space-3); }
.related ul { display: flex; flex-wrap: wrap; gap: var(--space-3); list-style: none; }
.related li {
  border: 1px solid var(--line);
  border-radius: 999px;
}
.related a {
  display: block;
  padding: var(--space-2) var(--space-4);
  text-decoration: none;
  font-size: var(--text-sm);
  color: var(--ink-2);
}
.related a:hover { color: var(--accent); }

.privacy-note {
  margin: var(--space-7) 0;
  padding: var(--space-5);
  background: var(--surface-2);
  border-radius: var(--radius);
}
.privacy-note h2 { font-size: var(--text-lg); }
.privacy-note p { font-family: var(--font-body); color: var(--ink-2); margin-bottom: 0; }

/* ---------- 8. Dropzone ---------- */
#tool-root { margin: var(--space-5) 0 var(--space-7); }

.dz-root { display: grid; gap: var(--space-4); max-width: 42rem; }

.dz-drop {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 9rem;
  padding: var(--space-5);
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.dz-drop:hover { border-color: var(--accent); }
.dz-drop:focus-within {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.dz-drop.dz-drag {
  border-color: var(--accent-2);
  border-style: solid;
  background: var(--surface);
}
.dz-drop-text {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink-2);
  font-size: var(--text-base);
}
.dz-drop.dz-drag .dz-drop-text { color: var(--accent-2); }
.dz-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.dz-file-list {
  display: grid;
  gap: var(--space-2);
  list-style: none;
}
.dz-file {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}
.dz-file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dz-file-move,
.dz-file-remove {
  flex: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.dz-file-move:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.dz-file-move:disabled { opacity: 0.35; cursor: not-allowed; }
.dz-file-remove:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- 9. Options forms ---------- */
.dz-options { display: grid; gap: var(--space-4); }
.dz-options:empty { display: none; }
.dz-options fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4) var(--space-4);
  margin: 0;
  display: grid;
  gap: var(--space-2);
}
.dz-options legend {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-sm);
  padding: 0 var(--space-2);
  color: var(--ink-2);
}
.dz-options label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-family: var(--font-display);
  font-size: var(--text-sm);
  color: var(--ink-2);
}
.dz-options fieldset label {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
  font-weight: 500;
}
.dz-options input[type="text"],
.dz-options input[type="number"],
.dz-options select {
  font: var(--text-base) / 1.4 var(--font-mono);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
}
.dz-options input[type="text"]:focus-visible,
.dz-options input[type="number"]:focus-visible,
.dz-options select:focus-visible {
  border-color: var(--accent);
}
.dz-options input[type="number"] { max-width: 8rem; }
.dz-options input[type="radio"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.org-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-3);
}
.org-cell {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.org-thumb {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.org-label {
  justify-self: start;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--ink-2);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
}
.org-controls {
  display: flex;
  gap: var(--space-2);
}
.org-move,
.org-del {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.org-move:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.org-move:disabled { opacity: 0.35; cursor: not-allowed; }
.org-del:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- e-Sign signature pad ---------- */
.esign-panel { display: grid; gap: var(--space-2); }
.esign-pad {
  width: 100%;
  height: 200px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  touch-action: none;
  cursor: crosshair;
}
.esign-clear {
  justify-self: start;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.esign-clear:hover { border-color: var(--accent); color: var(--accent); }
.dz-options input.esign-typed {
  font-family: "Segoe Script", "Bradley Hand", "Brush Script MT", cursive;
  font-size: var(--text-xl);
}

/* ---------- 10. Primary action + status ---------- */
.dz-run {
  justify-self: start;
  padding: var(--space-3) var(--space-6);
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-base);
  text-transform: capitalize;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}
.dz-run:hover:not(:disabled) { background: var(--accent-strong); }
.dz-run:active:not(:disabled) { transform: translateY(1px); }
.dz-run:disabled { opacity: 0.4; cursor: not-allowed; }

.dz-status {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--ink-3);
  min-height: 1.5em;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.dz-status:empty { display: none; }
.dz-status-busy { color: var(--ink-2); }
.dz-status-busy::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-right-color: var(--accent-2);
  border-bottom-color: transparent;
  animation: reg-spin 0.8s linear infinite;
  flex: none;
}
@media (prefers-reduced-motion: reduce) {
  .dz-status-busy::before { animation: none; border-bottom-color: var(--accent); }
}
.dz-status-done { color: var(--success); }
.dz-status-done::before { content: "\2713"; font-weight: 700; }
.dz-status-error { color: var(--danger); }
.dz-status-error::before { content: "\26A0\FE0E"; }

/* ---------- 11. Responsive ---------- */
@media (min-width: 48em) {
  .site-header { padding: var(--space-5) var(--space-6); }
  main { padding: 0 var(--space-6) var(--space-8); }
  .hero { padding: var(--space-8) var(--space-6); }
  .hero h1 { font-size: var(--text-3xl); }
  .tool-grid { grid-template-columns: repeat(2, 1fr); }
  .howto ol { grid-template-columns: repeat(3, 1fr); }
  .related ul { flex-wrap: nowrap; }
}

@media (min-width: 80em) {
  main { padding: 0 var(--space-7) var(--space-8); }
  .tool-grid { grid-template-columns: repeat(4, 1fr); }
}
