/* PdfPeaks Image Editor — modern, beginner-friendly shell */

.ie-app {
  --ie-ink: #0f0f11;
  --ie-muted: #5c5c66;
  --ie-border: #e2e0d8;
  --ie-panel: #ffffff;
  --ie-canvas-bg: #e8e6e0;
  --ie-accent: #2563eb;
  --ie-accent-soft: #eff4ff;
  --ie-danger: #e84848;
  --ie-ok: #16a34a;
  --ie-radius: 10px;
  --ie-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.06);
  --ie-toolbar-w: 300px;
  --ie-bottom-h: 0px;
  font-family: var(--pp-fb, "Instrument Sans", system-ui, sans-serif);
  color: var(--ie-ink);
}

.ie-app * { box-sizing: border-box; }

.ie-app .ie-hidden { display: none !important; }

.ie-app .ie-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Empty / upload state */
.ie-empty {
  max-width: 720px;
  margin: 1.5rem auto 2rem;
  padding: 0 1rem;
}

.ie-empty-card {
  background: var(--ie-panel);
  border: 1px solid var(--ie-border);
  border-radius: 16px;
  box-shadow: var(--ie-shadow);
  padding: 2.5rem 1.75rem;
  text-align: center;
}

.ie-empty-card h1 {
  font-family: var(--pp-ff, Fraunces, Georgia, serif);
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.ie-empty-card .ie-lead {
  color: var(--ie-muted);
  margin: 0 0 1.5rem;
  font-size: 1rem;
}

.ie-drop {
  border: 2px dashed #c9c6bc;
  border-radius: 14px;
  padding: 2rem 1.25rem;
  background: #faf9f7;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.ie-drop:hover,
.ie-drop:focus-visible,
.ie-drop.ie-dragover {
  border-color: var(--ie-accent);
  background: var(--ie-accent-soft);
  outline: none;
}

.ie-drop i {
  font-size: 2.75rem;
  color: var(--ie-accent);
  display: block;
  margin-bottom: 0.75rem;
}

.ie-drop-formats {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  color: var(--ie-muted);
}

.ie-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 550;
  font-size: 0.9rem;
  padding: 0.55rem 1rem;
  cursor: pointer;
  line-height: 1.2;
  background: #f3f2ee;
  color: var(--ie-ink);
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.ie-btn:hover { background: #e8e6e0; color: var(--ie-ink); text-decoration: none; }
.ie-btn:focus-visible {
  outline: 2px solid var(--ie-accent);
  outline-offset: 2px;
}
.ie-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ie-btn-primary {
  background: var(--ie-accent);
  color: #fff;
}
.ie-btn-primary:hover { background: #1d4ed8; color: #fff; }

.ie-btn-danger {
  background: var(--ie-danger);
  color: #fff;
}
.ie-btn-danger:hover { background: #d13c3c; color: #fff; }

.ie-btn-ghost {
  background: transparent;
  border-color: var(--ie-border);
}
.ie-btn-ghost:hover { background: #f5f4f0; }

.ie-btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.ie-btn-block { width: 100%; }

/* Editor shell */
.ie-shell {
  display: grid;
  grid-template-columns: var(--ie-toolbar-w) 1fr;
  grid-template-rows: auto 1fr auto;
  height: calc(100vh - 140px);
  min-height: 560px;
  max-height: 920px;
  background: var(--ie-canvas-bg);
  border: 1px solid var(--ie-border);
  border-radius: 14px;
  overflow: hidden;
  margin: 0 0.75rem 1.5rem;
  box-shadow: var(--ie-shadow);
}

.ie-topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.55rem 0.85rem;
  background: var(--ie-panel);
  border-bottom: 1px solid var(--ie-border);
}

.ie-topbar-left,
.ie-topbar-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.ie-file-meta {
  font-size: 0.78rem;
  color: var(--ie-muted);
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ie-mode-switch {
  display: flex;
  gap: 0.35rem;
  background: #f3f2ee;
  padding: 3px;
  border-radius: 10px;
}

.ie-mode-card {
  border: none;
  background: transparent;
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ie-muted);
}
.ie-mode-card i { font-size: 1rem; }
.ie-mode-card.active {
  background: #fff;
  color: var(--ie-accent);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.ie-mode-card:focus-visible {
  outline: 2px solid var(--ie-accent);
  outline-offset: 1px;
}

.ie-sidebar {
  grid-row: 2;
  background: var(--ie-panel);
  border-right: 1px solid var(--ie-border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.ie-cats {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.5rem;
  border-bottom: 1px solid var(--ie-border);
}

.ie-cat-btn {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 550;
  color: var(--ie-ink);
}
.ie-cat-btn i { width: 1.1rem; color: var(--ie-muted); text-align: center; }
.ie-cat-btn:hover { background: #f5f4f0; }
.ie-cat-btn.active {
  background: var(--ie-accent-soft);
  color: var(--ie-accent);
}
.ie-cat-btn.active i { color: var(--ie-accent); }
.ie-cat-btn:focus-visible {
  outline: 2px solid var(--ie-accent);
  outline-offset: -1px;
}

.ie-panel {
  padding: 0.75rem;
  flex: 1;
}

.ie-panel-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ie-muted);
  font-weight: 700;
  margin: 0 0 0.65rem;
}

.ie-quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.ie-quick-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--ie-border);
  border-radius: 8px;
  background: #faf9f7;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: left;
  color: var(--ie-ink);
}
.ie-quick-btn span { font-weight: 500; color: var(--ie-muted); font-size: 0.68rem; }
.ie-quick-btn:hover { border-color: var(--ie-accent); background: var(--ie-accent-soft); }
.ie-quick-btn:focus-visible {
  outline: 2px solid var(--ie-accent);
  outline-offset: 1px;
}

.ie-slider-row {
  margin-bottom: 0.85rem;
}
.ie-slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  margin-bottom: 0.25rem;
}
.ie-slider-row label .ie-val {
  color: var(--ie-accent);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.ie-slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--ie-accent);
}

.ie-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.ie-chip {
  border: 1px solid var(--ie-border);
  background: #fff;
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 550;
  cursor: pointer;
  color: var(--ie-ink);
}
.ie-chip:hover { border-color: var(--ie-accent); }
.ie-chip.active {
  background: var(--ie-accent);
  border-color: var(--ie-accent);
  color: #fff;
}
.ie-chip:focus-visible {
  outline: 2px solid var(--ie-accent);
  outline-offset: 1px;
}

.ie-field {
  margin-bottom: 0.65rem;
}
.ie-field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--ie-muted);
}
.ie-field input,
.ie-field select,
.ie-field textarea {
  width: 100%;
  border: 1px solid var(--ie-border);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  font-size: 0.875rem;
  background: #fff;
}
.ie-field input:focus,
.ie-field select:focus,
.ie-field textarea:focus {
  outline: 2px solid var(--ie-accent);
  outline-offset: 0;
  border-color: var(--ie-accent);
}

.ie-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.ie-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  margin-bottom: 0.65rem;
}

.ie-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.ie-doc-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.ie-doc-list button {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
  border: 1px solid var(--ie-border);
  background: #fff;
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 550;
}
.ie-doc-list button i { color: var(--ie-accent); }
.ie-doc-list button:hover { background: var(--ie-accent-soft); border-color: #bfd0f8; }
.ie-doc-list button:focus-visible {
  outline: 2px solid var(--ie-accent);
  outline-offset: 1px;
}

.ie-related {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--ie-border);
}
.ie-related a {
  display: block;
  font-size: 0.8rem;
  color: var(--ie-accent);
  text-decoration: none;
  padding: 0.25rem 0;
}
.ie-related a:hover { text-decoration: underline; }

.ie-workspace {
  grid-row: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--ie-canvas-bg);
}

.ie-canvas-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.4rem 0.65rem;
  background: rgba(255,255,255,0.85);
  border-bottom: 1px solid var(--ie-border);
}

.ie-tool-group {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.ie-canvas-stage {
  flex: 1;
  overflow: auto;
  padding: 1rem;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  position: relative;
  min-height: 280px;
}

.ie-canvas-wrap {
  position: relative;
  display: inline-block;
  transform-origin: top left;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
}

.ie-canvas-wrap canvas {
  display: block;
  max-width: none;
}

.ie-status {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4rem 0.75rem;
  background: var(--ie-panel);
  border-top: 1px solid var(--ie-border);
  font-size: 0.75rem;
  color: var(--ie-muted);
}

/* Crop overlay */
.ie-crop-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: auto;
}
.ie-crop-box {
  position: absolute;
  border: 2px solid var(--ie-accent);
  background: rgba(37, 99, 235, 0.12);
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.35);
  min-width: 12px;
  min-height: 12px;
}
.ie-crop-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to right, rgba(255,255,255,0.4) 1px, transparent 1px) 33.33% 0 / 33.34% 100%,
    linear-gradient(to right, rgba(255,255,255,0.4) 1px, transparent 1px) 66.66% 0 / 33.34% 100%,
    linear-gradient(to bottom, rgba(255,255,255,0.4) 1px, transparent 1px) 0 33.33% / 100% 33.34%,
    linear-gradient(to bottom, rgba(255,255,255,0.4) 1px, transparent 1px) 0 66.66% / 100% 33.34%;
}
.ie-crop-dims {
  position: absolute;
  bottom: -22px;
  left: 0;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
}
.ie-crop-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--ie-accent);
  border: 2px solid #fff;
  border-radius: 2px;
  z-index: 2;
}
.ie-crop-handle.nw { top: -5px; left: -5px; cursor: nwse-resize; }
.ie-crop-handle.ne { top: -5px; right: -5px; cursor: nesw-resize; }
.ie-crop-handle.sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.ie-crop-handle.se { bottom: -5px; right: -5px; cursor: nwse-resize; }
.ie-crop-handle.n  { top: -5px; left: 50%; margin-left: -5px; cursor: ns-resize; }
.ie-crop-handle.s  { bottom: -5px; left: 50%; margin-left: -5px; cursor: ns-resize; }
.ie-crop-handle.w  { top: 50%; left: -5px; margin-top: -5px; cursor: ew-resize; }
.ie-crop-handle.e  { top: 50%; right: -5px; margin-top: -5px; cursor: ew-resize; }

/* Text object overlay */
.ie-text-layer {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
}
.ie-text-obj {
  position: absolute;
  pointer-events: auto;
  cursor: move;
  min-width: 40px;
  padding: 2px 4px;
  outline: 1px dashed transparent;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
  transform-origin: center center;
}
.ie-text-obj.selected {
  outline: 2px solid var(--ie-accent);
  background: rgba(37, 99, 235, 0.06);
}
.ie-text-obj[contenteditable="true"] {
  outline: 2px solid var(--ie-accent);
  cursor: text;
}

/* Before/after */
.ie-ba {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  overflow: hidden;
  cursor: ew-resize;
  touch-action: none;
}
.ie-ba.active { display: block; }
.ie-ba-before,
.ie-ba-after {
  position: absolute;
  inset: 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}
.ie-ba-after { clip-path: inset(0 0 0 50%); }
.ie-ba-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 3px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35);
  transform: translateX(-50%);
}
.ie-ba-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-radius: 50%;
  background: var(--ie-accent);
  border: 2px solid #fff;
}

/* Mobile bottom categories */
.ie-mobile-cats {
  display: none;
  grid-column: 1 / -1;
  background: var(--ie-panel);
  border-top: 1px solid var(--ie-border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.35rem;
  gap: 0.25rem;
  scrollbar-width: thin;
}

.ie-mobile-cats .ie-cat-btn {
  flex: 0 0 auto;
  width: auto;
  flex-direction: column;
  font-size: 0.68rem;
  padding: 0.4rem 0.55rem;
  gap: 0.15rem;
  min-width: 64px;
}
.ie-mobile-cats .ie-cat-btn i { font-size: 1.05rem; }

.ie-sheet {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 55vh;
  background: var(--ie-panel);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.18);
  z-index: 1040;
  overflow: auto;
  padding: 0.75rem 0.85rem 1.25rem;
}
.ie-sheet.open { display: block; }
.ie-sheet-handle {
  width: 40px;
  height: 4px;
  background: #ccc;
  border-radius: 2px;
  margin: 0 auto 0.75rem;
}
.ie-sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 1035;
}
.ie-sheet-backdrop.open { display: block; }

/* Overlay / toast */
.ie-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,15,17,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.ie-overlay.open { display: flex; }
.ie-overlay-card {
  background: #fff;
  border-radius: 12px;
  padding: 1.5rem 1.75rem;
  text-align: center;
  min-width: 220px;
  box-shadow: var(--ie-shadow);
}
.ie-toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2100;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-width: 340px;
}
.ie-toast {
  background: #fff;
  border: 1px solid var(--ie-border);
  border-left: 4px solid var(--ie-accent);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  box-shadow: var(--ie-shadow);
  font-size: 0.875rem;
}
.ie-toast.error { border-left-color: var(--ie-danger); }
.ie-toast.success { border-left-color: var(--ie-ok); }
.ie-toast.warning { border-left-color: #d97706; }

.ie-passport-note {
  font-size: 0.75rem;
  color: var(--ie-muted);
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.75rem;
}

.ie-filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}
.ie-filter-btn {
  border: 1px solid var(--ie-border);
  background: #faf9f7;
  border-radius: 8px;
  padding: 0.55rem 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}
.ie-filter-btn.active {
  border-color: var(--ie-accent);
  background: var(--ie-accent-soft);
  color: var(--ie-accent);
}

.ie-page-title {
  text-align: center;
  padding: 1.25rem 1rem 0.25rem;
}
.ie-page-title h1 {
  font-family: var(--pp-ff, Fraunces, Georgia, serif);
  font-size: clamp(1.45rem, 2.5vw, 1.85rem);
  margin: 0 0 0.35rem;
}
.ie-page-title p {
  color: var(--ie-muted);
  margin: 0;
  font-size: 0.95rem;
}

/* Responsive */
@media (max-width: 900px) {
  .ie-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto auto;
    height: calc(100vh - 110px);
    min-height: 480px;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  .ie-sidebar {
    display: none;
  }
  .ie-workspace {
    grid-row: 2;
  }
  .ie-mobile-cats {
    display: flex;
    grid-row: 3;
  }
  .ie-status {
    grid-row: 4;
  }
  .ie-file-meta { max-width: 140px; }
  .ie-mode-card span.ie-mode-desc { display: none; }
}

@media (max-width: 480px) {
  .ie-topbar { padding: 0.45rem; }
  .ie-btn span.ie-label-full { display: none; }
  .ie-canvas-stage { padding: 0.5rem; }
}
