/**
 * Edit PDF — workspace styles
 * ─────────────────────────────────────────────────────────────────────
 * Renders after a file is selected (inside #workspace-page).
 * Scoped under .ep-workspace so it never leaks into other tool pages.
 * Uses the shared design tokens from assets/css/variables.min.css so it
 * automatically follows the site's light/dark theme + header height.
 */

.ep-workspace,
.ep-workspace *,
.ep-workspace *::before,
.ep-workspace *::after { box-sizing: border-box; }
.ep-workspace {
  font-family: var(--font-base);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height, 68px));
}
.ep-workspace button,
.ep-workspace input,
.ep-workspace select { font-family: inherit; }
.ep-workspace svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ===================== TOP TOOLBAR ===================== */
.ep-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  flex-shrink: 0;
  padding: 0 14px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.ep-toolbar::-webkit-scrollbar { display: none; }
.ep-toolbar-group { display: flex; align-items: center; gap: 3px; flex-shrink: 0; }
.ep-divider { width: 1px; height: 24px; background: var(--color-border); margin: 0 6px; flex-shrink: 0; }
.ep-spacer { flex: 1; }

.ep-tbtn {
  display: flex; align-items: center; gap: 6px;
  border: none; background: transparent; color: var(--color-text);
  padding: 8px 10px; border-radius: var(--radius-sm);
  font-size: .82rem; font-weight: 600; cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
}
.ep-tbtn:hover:not(:disabled) { background: var(--color-primary-light); color: var(--color-primary-dark); }
.ep-tbtn:disabled { opacity: .4; cursor: not-allowed; }
.ep-tbtn.icon-only { padding: 8px; }
.ep-zoom-label { font-size: .78rem; color: var(--color-text-muted); min-width: 42px; text-align: center; font-weight: 600; }

/* ===================== BODY LAYOUT ===================== */
.ep-body {
  flex: 1;
  display: flex;
  min-height: 0;
  background: var(--color-bg);
}

/* ── Tool rail ── */
.ep-rail {
  width: 54px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column; align-items: center;
  padding: 10px 0; gap: 4px; overflow-y: auto;
}
.ep-rail-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--color-text-muted);
  border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition-fast);
}
.ep-rail-btn:hover { background: var(--color-primary-light); color: var(--color-primary); }
.ep-rail-btn.is-active { background: var(--color-primary); color: #fff; }
.ep-rail-divider { width: 24px; height: 1px; background: var(--color-border); margin: 6px 0; }

/* ── Pages sidebar ── */
.ep-pages {
  width: 200px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column; overflow: hidden;
}
.ep-side-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; font-size: .72rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .06em; color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border); flex-shrink: 0;
}
.ep-mini-btn {
  border: 1.5px solid var(--color-border); background: var(--color-surface); color: var(--color-text);
  padding: 5px 9px; border-radius: var(--radius-sm); font-size: .72rem; font-weight: 700; cursor: pointer;
  transition: var(--transition-fast);
}
.ep-mini-btn:hover { background: var(--color-primary-light); color: var(--color-primary-dark); border-color: var(--color-primary); }
.ep-mini-btn.danger:hover { background: var(--red-light); color: var(--red); border-color: var(--red); }

.ep-thumb-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 14px; }
.ep-thumb-item {
  position: relative;
  background: var(--color-bg);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  padding: 8px 8px 24px;
  cursor: grab;
  transition: border-color .12s ease;
}
.ep-thumb-item.is-active { border-color: var(--color-primary); }
.ep-thumb-item img { width: 100%; display: block; border-radius: 4px; box-shadow: var(--shadow-sm); background: #fff; }
.ep-thumb-index { position: absolute; left: 10px; bottom: 5px; font-size: .68rem; color: var(--color-text-muted); font-weight: 700; }
.ep-thumb-actions { position: absolute; right: 6px; bottom: 3px; display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.ep-thumb-item:hover .ep-thumb-actions,
.ep-thumb-item:focus-within .ep-thumb-actions { opacity: 1; }
.ep-thumb-actions button {
  width: 22px; height: 22px; border: none; border-radius: 5px; cursor: pointer;
  background: var(--color-surface); color: var(--color-text-muted); display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}
.ep-thumb-actions button:hover { background: var(--color-primary); color: #fff; }
.ep-thumb-actions svg { width: 13px; height: 13px; }
.ep-sortable-ghost { opacity: .4; }

/* ── Canvas area ── */
.ep-canvas-area {
  flex: 1;
  position: relative;
  overflow: auto;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 32px;
}
.ep-stage { display: flex; }
.ep-canvas-wrap {
  position: relative;
  background: #fff;
  box-shadow: var(--shadow-lg);
  border-radius: 2px;
}
#ep-pdf-canvas, #ep-fabric-canvas { position: absolute; top: 0; left: 0; display: block; }

.ep-progress-bar { position: absolute; top: 0; left: 0; right: 0; height: 3px; overflow: hidden; z-index: 5; }
.ep-progress-fill { height: 100%; width: 40%; background: var(--color-primary); animation: epIndeterminate 1.1s infinite ease-in-out; }
@keyframes epIndeterminate { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }

/* ── Properties sidebar ── */
.ep-props { width: 240px; flex-shrink: 0; background: var(--color-surface); border-left: 1px solid var(--color-border); overflow-y: auto; }
.ep-props-empty { padding: 16px 14px; font-size: .8rem; color: var(--color-text-muted); }
.ep-props-group { padding: 14px; border-bottom: 1px solid var(--color-border); flex-direction: column; gap: 10px; }
.ep-props-group:not([hidden]) { display: flex; }
.ep-props-group label { font-size: .72rem; font-weight: 700; color: var(--color-text-muted); display: flex; flex-direction: column; gap: 4px; text-transform: uppercase; letter-spacing: .3px; }
.ep-props-group input, .ep-props-group select {
  border: 1.5px solid var(--color-border); border-radius: var(--radius-sm); padding: 6px 8px;
  background: var(--color-bg); color: var(--color-text); font-size: .82rem; font-weight: 600; text-transform: none;
}
.ep-props-group input[type="color"] { padding: 2px; height: 30px; }
.ep-btn-row { display: flex; gap: 6px; }
.ep-btn-row.wrap { flex-wrap: wrap; }
.ep-toggle-btn {
  flex: 1; border: 1.5px solid var(--color-border); background: var(--color-bg);
  border-radius: var(--radius-sm); padding: 6px 0; color: var(--color-text); cursor: pointer;
}
.ep-toggle-btn.is-active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.ep-sub-head { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--color-text-muted); font-weight: 800; margin-bottom: 2px; }

/* ===================== MODALS ===================== */
.ep-modal-overlay {
  position: fixed; inset: 0; background: var(--color-overlay);
  align-items: center; justify-content: center; z-index: 1000;
}
.ep-modal-overlay:not([hidden]) { display: flex; }
.ep-modal {
  background: var(--color-surface); border-radius: var(--radius-lg);
  padding: 22px; width: 460px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  flex-direction: column; gap: 12px;
}
.ep-modal:not([hidden]) { display: flex; }
.ep-modal h3 { margin: 0; font-size: 1.15rem; font-weight: 800; }
.ep-modal label { display: flex; flex-direction: column; gap: 4px; font-size: .78rem; font-weight: 700; color: var(--color-text-muted); }
.ep-modal input, .ep-modal select {
  border: 1.5px solid var(--color-border); border-radius: var(--radius-sm); padding: 8px 10px;
  background: var(--color-bg); color: var(--color-text); font-size: .85rem; font-weight: 600;
}
.ep-modal-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; gap: 10px; flex-wrap: wrap; }
.ep-chk { flex-direction: row !important; align-items: center; gap: 6px !important; }
.ep-modal-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--color-border); padding-bottom: 8px; flex-wrap: wrap; }
.ep-mtab { border: none; background: transparent; padding: 6px 10px; border-radius: var(--radius-sm); font-size: .78rem; font-weight: 700; color: var(--color-text-muted); cursor: pointer; }
.ep-mtab.is-active { background: var(--color-primary-light); color: var(--color-primary-dark); }
.ep-cta-btn {
  background: var(--color-primary); color: #fff; border: none; cursor: pointer;
  padding: 9px 18px; border-radius: var(--radius-pill); font-weight: 800; font-size: .85rem;
  transition: var(--transition-fast);
}
.ep-cta-btn:hover { background: var(--color-primary-dark); }
#ep-sig-draw-canvas { background: #fff; border: 1.5px dashed var(--color-border); border-radius: var(--radius-md); width: 100%; touch-action: none; }
.ep-sig-type-preview { font-size: 34px; padding: 16px; text-align: center; background: #fff; color: #1a1a1a; border-radius: var(--radius-md); border: 1.5px dashed var(--color-border); }
#ep-sig-type-input { width: 100%; margin-bottom: 8px; }
.ep-sig-saved-list { display: flex; flex-wrap: wrap; gap: 8px; max-height: 200px; overflow-y: auto; }
.ep-sig-saved-list img { width: 110px; border: 1.5px solid var(--color-border); border-radius: var(--radius-sm); background: #fff; padding: 4px; cursor: pointer; }
.ep-sig-saved-list img:hover { border-color: var(--color-primary); }

/* ===================== TOAST ===================== */
.ep-toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--color-text); color: var(--color-bg-soft, #fff); padding: 10px 18px;
  border-radius: var(--radius-pill); font-size: .82rem; font-weight: 600; z-index: 1200;
  box-shadow: var(--shadow-md);
}

/* ===================== MOBILE ===================== */
.ep-mobile-only { display: none; }
.ep-backdrop { position: fixed; inset: 0; background: var(--color-overlay); z-index: 900; }

@media (max-width: 860px) {
  .ep-mobile-only { display: flex; }
  .ep-pages, .ep-props {
    position: fixed; top: var(--header-height, 68px); bottom: 0; z-index: 950;
    width: min(80vw, 300px);
    box-shadow: var(--shadow-lg);
    transform: translateX(-110%);
    transition: transform .2s ease;
  }
  .ep-pages.is-open { transform: translateX(0); left: 0; }
  .ep-props { transform: translateX(110%); right: 0; }
  .ep-props.is-open { transform: translateX(0); }
  .ep-canvas-area { padding: 16px; touch-action: none; }
  .ep-tbtn span:not(.ep-zoom-label) { display: none; }
  .ep-tbtn { padding: 8px; }
}
@media (max-width: 480px) {
  .ep-modal { padding: 16px; width: 94vw; }
}
