/* ============================================================
   AmigoPDF — editor page styles
   ============================================================ */

.editor-body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--sheet);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  z-index: 50;
}
#topbar .brand-name { font-family: var(--font-display); font-weight: 700; }
#topbar .spacer { flex: 1; }
.btn.icon { padding: 7px; width: 36px; height: 36px; }
.btn.icon svg { width: 18px; height: 18px; }
.btn.toggle.active, .btn.align.active { background: var(--marker-soft); border-color: var(--ink-2); }
#fileName {
  font-family: var(--font-mono); font-size: .85rem;
  border: 1px solid transparent; border-radius: 7px;
  background: transparent; color: var(--ink);
  padding: 7px 8px; width: clamp(120px, 24vw, 280px);
}
#fileName:hover, #fileName:focus { border-color: var(--line); background: var(--paper); outline: none; }
#zoomBox { display: flex; align-items: center; gap: 2px; }
.zoom-label { font-variant-numeric: tabular-nums; font-size: .85rem; min-width: 56px; }
#pageIndicator { color: var(--ink-2); font-size: .85rem; font-variant-numeric: tabular-nums; padding: 0 4px; white-space: nowrap; }

/* ---------- workspace layout ---------- */
#workspace { flex: 1; display: flex; min-height: 0; position: relative; }

#toolbar {
  flex: 0 0 auto;
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 6px;
  background: var(--sheet);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  z-index: 40;
}
#toolbar[hidden] { display: none; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 58px; padding: 8px 2px;
  border: none; border-radius: 9px;
  background: none; color: var(--ink-2);
  font-size: .66rem;
}
.tool svg { width: 21px; height: 21px; }
.tool:hover { background: var(--paper); color: var(--ink); }
.tool.active { background: var(--marker-soft); color: var(--ink); font-weight: 600; }

/* ---------- viewer ---------- */
#viewer {
  flex: 1; overflow: auto; position: relative;
  background: var(--paper);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
#pages { padding: 20px 16px 80px; display: flex; flex-direction: column; align-items: center; gap: 18px; }

.page-shell {
  position: relative;
  background: var(--sheet);
  box-shadow: var(--shadow);
  flex: 0 0 auto;
}
.page-shell canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.page-num {
  position: absolute; bottom: -17px; left: 50%; transform: translateX(-50%);
  font-size: .7rem; color: var(--ink-2);
}
.overlay { position: absolute; inset: 0; overflow: visible; }
#viewer[data-tool="select"] .overlay { touch-action: pan-y; cursor: default; }
#viewer:not([data-tool="select"]) .overlay { touch-action: none; cursor: crosshair; }
#viewer[data-tool="text"] .overlay { cursor: text; }

/* ---------- dropzone ---------- */
#dropzone {
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
#dropzone.hidden { display: none; }
#dropzone.dragging .drop-inner { border-color: var(--sig); background: color-mix(in srgb, var(--sig) 6%, var(--sheet)); }
.drop-inner {
  text-align: center; max-width: 460px; width: 100%;
  border: 2px dashed var(--line); border-radius: 18px;
  padding: 44px 28px;
  background: var(--sheet);
  color: var(--ink-2);
  transition: border-color .15s, background .15s;
}
.drop-inner h1 { font-family: var(--font-display); color: var(--ink); font-size: 1.5rem; margin: 12px 0 6px; }
.drop-inner .privacy { margin-top: 14px; font-size: .88rem; }
.feat-list { list-style: none; margin-top: 18px; font-size: .88rem; }
.feat-list li { padding: 2px 0; }
.feat-list li::before { content: "· "; color: var(--sig); font-weight: 700; }
.drop-legal { margin-top: 18px; font-size: .82rem; color: var(--ink-2); }
.drop-legal a { color: var(--ink-2); text-decoration: underline; }
.drop-legal a:hover { color: var(--ink); }

/* ---------- annotations ---------- */
.anno { position: absolute; user-select: none; -webkit-user-select: none; touch-action: none; }
.anno.a-text {
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.25;
  min-height: 1em; cursor: move; outline: none;
  border: 1px dashed transparent; border-radius: 2px;
}
.anno.a-text.editing { cursor: text; user-select: text; -webkit-user-select: text; border-color: var(--sig); background: color-mix(in srgb, var(--sig) 5%, transparent); }
.anno.a-highlight { mix-blend-mode: multiply; border-radius: 2px; cursor: move; }
html[data-theme="dark"] .anno.a-highlight { mix-blend-mode: screen; }
.anno.a-rect { border-style: solid; cursor: move; background: transparent; }
.anno.a-ellipse { border-style: solid; border-radius: 50%; cursor: move; background: transparent; }
.anno.a-line, .anno.a-arrow { cursor: move; }
.anno.a-line svg, .anno.a-arrow svg { position: absolute; inset: 0; overflow: visible; }
.anno.a-image img, .anno.a-sign img { width: 100%; height: 100%; display: block; pointer-events: none; }
.anno.a-image, .anno.a-sign { cursor: move; }

.anno.selected { outline: 1.5px solid var(--sig); outline-offset: 1px; }
.anno.a-text.selected { border-color: var(--sig); border-style: dashed; outline: none; }

/* resize handles */
.handle {
  position: absolute; width: 12px; height: 12px;
  background: var(--sheet); border: 2px solid var(--sig); border-radius: 50%;
  z-index: 5; touch-action: none;
}
.handle.nw { top: -7px; left: -7px; cursor: nwse-resize; }
.handle.ne { top: -7px; right: -7px; cursor: nesw-resize; }
.handle.sw { bottom: -7px; left: -7px; cursor: nesw-resize; }
.handle.se { bottom: -7px; right: -7px; cursor: nwse-resize; }
.handle.p1, .handle.p2 { cursor: move; }
@media (pointer: coarse) {
  .handle { width: 18px; height: 18px; }
  .handle.nw { top: -10px; left: -10px; } .handle.ne { top: -10px; right: -10px; }
  .handle.sw { bottom: -10px; left: -10px; } .handle.se { bottom: -10px; right: -10px; }
}

/* selection floating actions */
#selActions {
  position: absolute; top: -42px; right: 0;
  display: flex; gap: 4px;
  background: var(--ink); border-radius: 9px; padding: 4px;
  box-shadow: var(--shadow-lift);
  z-index: 20;
}
#selActions[hidden] { display: none; }
#selActions button {
  background: none; border: none; color: var(--paper);
  width: 30px; height: 30px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
#selActions button:hover { background: rgba(255,255,255,.15); }

/* drawing preview */
.draw-preview { position: absolute; pointer-events: none; }

/* ---------- properties panel ---------- */
#props {
  position: absolute; top: 12px; right: 12px; z-index: 45;
  width: 210px;
  background: var(--sheet); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
#props[hidden] { display: none; }
.prop-group { display: flex; flex-direction: column; gap: 10px; }
.prop-group[hidden] { display: none; }
.prop-group label {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: .85rem; color: var(--ink-2);
}
.prop-group select, .prop-group input[type="number"] {
  font: inherit; font-size: .85rem;
  padding: 5px 7px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--paper); color: var(--ink);
  width: 110px;
}
.prop-group input[type="color"] {
  width: 40px; height: 28px; padding: 1px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--paper);
}
.prop-group input[type="range"] { width: 110px; accent-color: var(--sig); }
.prop-hint { font-size: .8rem; color: var(--ink-2); }
.prop-hint:empty { display: none; }

/* ---------- stamp hint ---------- */
#stampHint {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  z-index: 120;
  background: var(--ink); color: var(--paper);
  padding: 9px 16px; border-radius: 999px; font-size: .9rem;
  box-shadow: var(--shadow-lift);
}
#stampHint .linklike { color: var(--marker); }
#stampHint[hidden] { display: none; }

/* ---------- signature modal ---------- */
#signCanvas {
  width: 100%; height: 220px;
  background: var(--paper);
  border: 1px dashed var(--line); border-radius: 10px;
  touch-action: none; cursor: crosshair;
  margin-bottom: 14px;
}
.btn.pen {
  width: 34px; height: 34px; padding: 0; border-radius: 50%;
  background: var(--pen);
}
.btn.pen.active { outline: 2px solid var(--sig); outline-offset: 2px; }

/* ---------- pages modal ---------- */
.modal.tall { display: flex; flex-direction: column; max-height: 88vh; width: min(860px, 100%); }
#thumbGrid {
  flex: 1; overflow: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 12px;
  padding: 8px 2px; margin-bottom: 14px;
  min-height: 160px;
}
.thumb {
  position: relative;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper);
  padding: 8px 8px 4px;
  text-align: center;
  cursor: grab;
}
.thumb.drag-over { outline: 2px dashed var(--sig); outline-offset: 2px; }
.thumb.dragging { opacity: .4; }
.thumb img { width: 100%; height: auto; border: 1px solid var(--line); background: #fff; display: block; min-height: 60px; }
.thumb .t-num { font-size: .72rem; color: var(--ink-2); padding: 4px 0 2px; display: block; }
.thumb .t-check { position: absolute; top: 12px; left: 12px; width: 18px; height: 18px; accent-color: var(--sig); }
.thumb .t-del {
  position: absolute; top: 6px; right: 6px;
  width: 24px; height: 24px; border-radius: 50%;
  border: none; background: var(--sheet); color: var(--flag);
  box-shadow: var(--shadow); font-size: .8rem; line-height: 1;
}
.thumb .t-move { display: flex; justify-content: center; gap: 4px; padding-bottom: 4px; }
.thumb .t-move button {
  border: 1px solid var(--line); background: var(--sheet); color: var(--ink-2);
  border-radius: 6px; width: 30px; height: 22px; font-size: .7rem;
}

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  #workspace { flex-direction: column; }
  #toolbar {
    order: 2;
    flex-direction: row; justify-content: flex-start;
    overflow-x: auto; overflow-y: hidden;
    border-right: none; border-top: 1px solid var(--line);
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
  }
  .tool { width: 54px; padding: 6px 2px; flex: 0 0 auto; }
  #viewer { order: 1; }
  #props {
    top: auto; right: 0; left: 0; bottom: 0;
    width: auto; border-radius: 14px 14px 0 0;
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 14px;
    box-shadow: 0 -6px 24px rgba(0,0,0,.15);
    padding: 10px 14px;
  }
  .prop-group { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
  #topbar { gap: 6px; padding: 6px 8px; }
  #topbar .brand-name, #pageIndicator { display: none; }
  #fileName { width: clamp(80px, 20vw, 160px); }
  #pages { padding: 12px 8px 40px; }
}
