/* Edit PDF tool (static/edit-tool.js). Uses the design tokens from style.css. */

.ed {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--text-main);
  font-size: 13px;
}

.ed-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 8px 0;
}

.ed-main {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ed-main[hidden] { display: none; }

/* Toolbar */
.ed-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 6px;
  background: rgba(var(--ink), 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  position: sticky;
  top: -24px;
  z-index: 5;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background-color: rgba(17, 24, 39, 0.92);
}

.ed-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
  flex: 1 1 auto;
}

.ed-sep {
  width: 1px;
  height: 22px;
  margin: 0 4px;
  background: var(--border-subtle);
}

.ed-tool,
.ed-icon-btn,
.ed-zoomval,
.ed-seg button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.ed-tool {
  padding: 7px 10px;
  min-height: 36px;
  white-space: nowrap;
}

.ed-tool:hover,
.ed-icon-btn:hover:not(:disabled),
.ed-zoomval:hover {
  color: var(--text-strong);
  background: rgba(var(--ink), 0.07);
}

.ed-tool.active {
  color: var(--text-strong);
  background: var(--primary-light);
  border-color: rgba(99, 102, 241, 0.65);
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.25), 0 0 18px rgba(99, 102, 241, 0.18);
}

.ed-tool:focus-visible,
.ed-icon-btn:focus-visible,
.ed-zoomval:focus-visible,
.ed-seg button:focus-visible,
.ed-field input:focus-visible,
.ed-field select:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 1px;
}

.ed-icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
}
.ed-icon-btn:disabled { opacity: 0.32; cursor: default; }
.ed-icon-btn.ed-danger:hover:not(:disabled) { color: #fca5a5; background: rgba(239, 68, 68, 0.14); }

.ed-history {
  display: inline-flex;
  gap: 2px;
  margin-left: auto;
  padding-left: 6px;
}

.ed-tool-icon { padding: 7px 9px; }
.ed-tool-icon .ed-tool-label { display: none; }

@container (max-width: 920px) {
  .ed-tool-label { display: none; }
  .ed-tool { padding: 7px 9px; }
}

/* Properties bar */
.ed-props {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  min-height: 44px;
  padding: 6px 12px;
  background: rgba(var(--ink), 0.025);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.ed-props-empty,
.ed-props-note {
  color: var(--text-dim);
  font-size: 12px;
}

.ed-field {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.ed-field select,
.ed-field input[type="number"] {
  font: inherit;
  font-size: 12px;
  color: var(--text-main);
  background: var(--sunken);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 5px 8px;
  height: 30px;
}
.ed-field select { padding-right: 4px; }
.ed-field select option { background: var(--surface-modal); }
.ed-num input { width: 64px; }

.ed-color input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid rgba(var(--ink), 0.18);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  overflow: hidden;
}
.ed-color input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.ed-color input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }
.ed-color input[type="color"]::-moz-color-swatch { border: none; border-radius: 50%; }
.ed-color input[type="color"]:disabled { opacity: 0.3; cursor: default; }

.ed-range input[type="range"] {
  width: 92px;
  accent-color: var(--primary);
}
.ed-range output {
  min-width: 34px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.ed-check { cursor: pointer; }
.ed-check input { accent-color: var(--primary); width: 15px; height: 15px; }

.ed-seg {
  display: inline-flex;
  padding: 2px;
  background: var(--sunken);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
}
.ed-seg button {
  width: 30px;
  height: 28px;
  font-size: 14px;
  border-radius: 7px;
}
.ed-seg button svg { width: 16px; height: 16px; }
.ed-seg button[aria-pressed="true"] { color: #fff; background: var(--primary); }

.ed-obj-actions {
  display: flex;
  gap: 2px;
  margin-left: auto;
}
.ed-obj-actions .ed-icon-btn { width: 32px; height: 32px; }

.ed-raster-note {
  flex-basis: 100%;
  font-size: 12px;
  color: #fcd34d;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: 8px;
  padding: 6px 10px;
}
.ed-raster-note[hidden] { display: none; }

.ed-hint {
  margin: -2px 2px 0;
  font-size: 12px;
  color: var(--text-dim);
}

/* Page view */
.ed-stage {
  position: relative;
  overflow: auto;
  max-height: min(72vh, 1100px);
  min-height: 240px;
  padding: 20px;
  background:
    radial-gradient(circle at 1px 1px, rgba(var(--ink), 0.05) 1px, transparent 0) 0 0 / 18px 18px,
    #0a0e17;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  outline: none;
  overscroll-behavior: contain;
}

.ed-page {
  position: relative;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 12px 40px -8px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(var(--ink), 0.06);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}
.ed-page[data-tool="select"],
.ed-page[data-tool="edittext"] {
  cursor: default;
  touch-action: pan-x pan-y pinch-zoom;
}
.ed-page[data-tool="text"] { cursor: text; }

.ed-canvas {
  display: block;
}

.ed-covers,
.ed-runs,
.ed-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ed-cover { position: absolute; }

.ed-run {
  position: absolute;
  pointer-events: auto;
  cursor: text;
  border-radius: 2px;
  outline: 1px dashed rgba(99, 102, 241, 0.45);
  background: rgba(99, 102, 241, 0.06);
  transition: background 0.12s ease, outline-color 0.12s ease;
}
.ed-run:hover {
  outline: 1.5px solid var(--primary);
  background: rgba(99, 102, 241, 0.16);
}

.ed-obj {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
}
[data-tool="select"] .ed-obj,
[data-tool="edittext"] .ed-obj { cursor: move; }
[data-tool="text"] .ed-text { cursor: text; }
.ed-obj svg { display: block; overflow: visible; }

/* Lines and drawings are hit only on (a thick invisible copy of) their stroke. */
.ed-line,
.ed-arrow,
.ed-pen { pointer-events: none; }
.ed-hit { pointer-events: stroke; }
.ed-page:not([data-tool="select"]):not([data-tool="edittext"]) .ed-hit { pointer-events: none; }

.ed-highlight { mix-blend-mode: multiply; }
.ed-whiteout { box-shadow: inset 0 0 0 1px rgba(100, 116, 139, 0.35); }

.ed-image img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.ed-text { white-space: pre; }
.ed-text-inner {
  white-space: pre;
  min-width: 4px;
  outline: none;
  caret-color: var(--primary);
}
.ed-text.is-editing { cursor: text; }
.ed-text.is-editing .ed-text-inner {
  user-select: text;
  -webkit-user-select: text;
  min-width: 1em;
}
.ed-text-inner:empty::before {
  content: "Type here";
  color: #94a3b8;
}

.ed-ink {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

/* Selection frame and handles */
.ed-sel {
  position: absolute;
  pointer-events: none;
  outline: 1.5px solid var(--primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}
.ed-sel.is-line { outline: 1px dashed rgba(99, 102, 241, 0.6); box-shadow: none; }
.ed-sel.is-editing {
  outline: 1.5px dashed var(--accent-cyan);
  box-shadow: 0 0 0 4px rgba(6, 182, 212, 0.12);
}
.ed-sel[hidden] { display: none; }

.ed-h {
  --hs: 10px;
  position: absolute;
  width: var(--hs);
  height: var(--hs);
  margin: calc(var(--hs) / -2) 0 0 calc(var(--hs) / -2);
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 3px;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.ed-h-pt { border-radius: 50%; cursor: move; }
.ed-h-nw { left: -2px; top: -2px; cursor: nwse-resize; }
.ed-h-n { left: 50%; top: -2px; cursor: ns-resize; }
.ed-h-ne { left: calc(100% + 2px); top: -2px; cursor: nesw-resize; }
.ed-h-e { left: calc(100% + 2px); top: 50%; cursor: ew-resize; }
.ed-h-se { left: calc(100% + 2px); top: calc(100% + 2px); cursor: nwse-resize; }
.ed-h-s { left: 50%; top: calc(100% + 2px); cursor: ns-resize; }
.ed-h-sw { left: -2px; top: calc(100% + 2px); cursor: nesw-resize; }
.ed-h-w { left: -2px; top: 50%; cursor: ew-resize; }

@media (pointer: coarse) {
  .ed-h { --hs: 18px; }
}

.ed-loading {
  position: absolute;
  top: 14px;
  right: 14px;
}
.ed-loading[hidden] { display: none; }
.ed-spinner {
  display: block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(var(--ink), 0.15);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: edSpin 0.7s linear infinite;
}
@keyframes edSpin { to { transform: rotate(360deg); } }

/* Page navigation and zoom */
.ed-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.ed-nav-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  background: rgba(var(--ink), 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: 11px;
}
.ed-nav-group .ed-icon-btn { width: 32px; height: 32px; }
.ed-pagebox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
  padding: 0 4px;
}
.ed-pagenum {
  width: 54px;
  height: 28px;
  font: inherit;
  font-size: 12px;
  text-align: center;
  color: var(--text-main);
  background: var(--sunken);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  -moz-appearance: textfield;
}
.ed-pagenum::-webkit-inner-spin-button { display: none; }
.ed-zoomval {
  min-width: 52px;
  height: 32px;
  font-family: var(--font-mono);
  font-size: 11px;
}
.ed-count {
  font-size: 12px;
  color: var(--text-dim);
}

/* Phones: give the page as much room as possible. */
@media (max-width: 600px) {
  .modal-body:has(.ed-main:not([hidden])) { padding: 14px 10px; }
  .modal-backdrop:has(.ed-main:not([hidden])) { padding: 8px; }
  .ed-stage { padding: 8px; max-height: 64vh; border-radius: 12px; }
  .ed-bar { top: -14px; padding: 4px; }
  .ed-sep { margin: 0 1px; }
  .ed-history { padding-left: 0; }
  .ed-props { gap: 8px 10px; padding: 6px 8px; }
  .ed-range input[type="range"] { width: 70px; }
  .ed-obj-actions { margin-left: 0; }
  .ed-count { order: 3; flex-basis: 100%; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  .ed-spinner { animation-duration: 2s; }
}
