/* ===========================================================
   PDF Editor — additive styles only. Reuses color/font tokens
   already defined in styles.css (--ink, --paper, --stamp, etc.)
   Nothing here overrides or edits the shared stylesheet.
=========================================================== */

/* The [hidden] attribute only hides an element via the browser's default
   stylesheet ([hidden] { display: none }) — any author CSS that sets its
   own `display` on that same element (several rules below do, since
   these screens are flex containers) silently overrides it, because
   author-origin CSS always beats the browser's default styles regardless
   of selector specificity. Without this rule, setting .hidden = true in
   JS has no visible effect and screens stack on top of each other. */
[hidden] { display: none !important; }

.ed-shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* The upload landing page (editor.html) doesn't need to be height-locked
   the way the editing workspace does — that constraint exists purely to
   protect the workspace's canvas from ever fighting other content for
   vertical space. The landing page is just a normal form; letting it
   scroll naturally means an ad unit (or anything else) below the upload
   box sits comfortably instead of being squeezed to nothing or clipped
   by the workspace's overflow:hidden. */
.ed-shell-scrollable {
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: visible;
}
.ed-shell-scrollable .ed-upload-screen { flex: none; }

/* Self-contained branded bar — a flex child INSIDE .ed-shell, not a
   separate element competing with it for viewport height. This is what
   fixes the editor being squeezed/scrolling oddly: there's now exactly
   one height budget (the shell's 100vh) instead of two stacked ones. */
.ed-mini-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid var(--line); flex-shrink: 0;
  background: var(--paper);
}
.ed-mini-brand {
  display: flex; align-items: center; gap: 8px; text-decoration: none;
  color: var(--ink); font-family: var(--display); font-weight: 600; font-size: 15px;
}
.ed-mini-brand svg { color: var(--stamp); }

/* ---------------------------------------------------------
   Upload screen
--------------------------------------------------------- */
.ed-upload-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.ed-upload-inner { max-width: 520px; width: 100%; text-align: center; }
.ed-upload-inner h1 {
  font-family: var(--display); font-size: clamp(30px, 5vw, 42px); font-weight: 600;
  margin: 10px 0 12px; letter-spacing: -0.01em;
}
.ed-upload-sub { color: var(--ink-soft); font-size: 15.5px; margin: 0 0 26px; }
.ed-upload-inner .eyebrow { justify-content: center; }

/* ---------------------------------------------------------
   Editor screen shell
--------------------------------------------------------- */
.ed-editor-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.ed-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid var(--line); flex-shrink: 0;
  background: var(--paper);
}
.ed-topbar-left, .ed-topbar-right { display: flex; align-items: center; gap: 10px; }
.ed-filename {
  font-family: var(--mono); font-size: 13px; color: var(--ink-soft);
  max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.ed-icon-btn {
  background: none; border: 1px solid var(--line); border-radius: 6px;
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  color: var(--ink); cursor: pointer; flex-shrink: 0;
}
.ed-icon-btn:hover:not(:disabled) { border-color: var(--ink); }
.ed-icon-btn:disabled { opacity: 0.3; cursor: default; }

/* ---------------------------------------------------------
   Body layout: tool rail | stage | page nav
--------------------------------------------------------- */
.ed-body { flex: 1; display: flex; min-height: 0; }

.ed-toolrail {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 10px; border-right: 1px solid var(--line); flex-shrink: 0;
  background: var(--paper-dim);
}
.ed-tool {
  width: 40px; height: 40px; border-radius: 8px; border: 1px solid transparent;
  background: none; color: var(--ink-soft); display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.ed-tool:hover { background: var(--paper); color: var(--ink); }
.ed-tool.active { background: var(--ledger-light); color: var(--ledger); border-color: var(--ledger); }

/* ---------------------------------------------------------
   Stage (canvas area)
--------------------------------------------------------- */
.ed-stage-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }

.ed-tool-options {
  display: none; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--paper);
  font-size: 13px; color: var(--ink-soft); flex-shrink: 0;
}
.ed-tool-options.active { display: flex; }
.ed-tool-options label { display: flex; align-items: center; gap: 6px; }
.ed-tool-options input[type="color"] {
  width: 28px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
}
.ed-tool-options input[type="range"] { width: 100px; }
.ed-mode-pills { display: flex; gap: 6px; }
.ed-mode-pill {
  border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px; font-size: 12.5px; cursor: pointer;
}
.ed-mode-pill.active { border-color: var(--stamp); background: var(--paper-shadow); color: var(--stamp-dark); font-weight: 600; }
.ed-redact-warning {
  font-size: 12px; color: var(--stamp-dark); max-width: 320px; line-height: 1.4;
}

.ed-style-controls { display: flex; align-items: center; gap: 4px; }
.ed-style-btn {
  width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--paper); color: var(--ink); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 13px; padding: 0;
}
.ed-style-btn:hover { border-color: var(--ink-faint); }
.ed-style-btn.active { border-color: var(--stamp); background: var(--paper-shadow); color: var(--stamp-dark); }
.ed-style-controls select {
  height: 30px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper);
  color: var(--ink); font-family: var(--body); font-size: 12.5px; padding: 0 6px; cursor: pointer;
}
.ed-style-context-label {
  font-family: var(--mono); font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.04em;
}

.ed-stage-scroll {
  flex: 1; overflow: auto; background: var(--paper-shadow);
  display: flex; justify-content: center; padding: 24px;
}
.ed-stage {
  position: relative; box-shadow: var(--shadow-card); background: white; flex-shrink: 0;
  height: fit-content;
}
.ed-stage canvas { display: block; position: absolute; top: 0; left: 0; }
#pageCanvas { position: relative; }
#annotationCanvas { touch-action: none; cursor: crosshair; }
.ed-text-layer { position: absolute; top: 0; left: 0; right: 0; bottom: 0; pointer-events: none; }
.ed-text-box {
  position: absolute; pointer-events: auto; border: 1px dashed var(--ledger);
  background: rgba(255,255,255,0.75); min-width: 24px; min-height: 20px;
  font-family: var(--body); outline: none; padding: 2px; white-space: pre-wrap;
  overflow-wrap: break-word; word-wrap: break-word;
  resize: none; overflow: hidden; line-height: 1.25; box-sizing: content-box;
}
.ed-text-box:focus { border-style: solid; }
.ed-annotation-selected-outline {
  position: absolute; border: 1.5px dashed var(--stamp); pointer-events: none;
}

/* ---------------------------------------------------------
   Zoom controls — floating over the bottom-right of the stage
--------------------------------------------------------- */
.ed-zoom-controls {
  position: absolute; bottom: 16px; right: 16px; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 8px;
  padding: 4px; box-shadow: var(--shadow-card);
}
.ed-zoom-label {
  background: none; border: none; color: var(--ink-soft); cursor: pointer;
  font-family: var(--mono); font-size: 12px; padding: 0 8px; min-width: 44px; text-align: center;
}
.ed-zoom-label:hover { color: var(--ink); }

/* ---------------------------------------------------------
   Page navigator (right rail)
--------------------------------------------------------- */
.ed-pagenav {
  width: 148px; flex-shrink: 0; border-left: 1px solid var(--line);
  display: flex; flex-direction: column; background: var(--paper-dim);
}
.ed-page-indicator {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  padding: 10px; font-family: var(--mono); font-size: 12.5px; color: var(--ink-soft);
}
.ed-page-indicator input {
  width: 42px; text-align: center; font-family: var(--mono); font-size: 12.5px;
  border: 1px solid var(--line); border-radius: 4px; padding: 3px 2px; background: var(--paper); color: var(--ink);
}
.ed-thumb-strip { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.ed-thumb {
  border: 2px solid transparent; border-radius: 4px; overflow: hidden; cursor: pointer;
  background: var(--paper); position: relative;
}
.ed-thumb.active { border-color: var(--stamp); }
.ed-thumb img { width: 100%; display: block; }
.ed-thumb .ed-thumb-num {
  position: absolute; bottom: 2px; right: 4px; font-family: var(--mono); font-size: 10px;
  color: var(--ink-soft); background: rgba(255,255,255,0.85); padding: 0 3px; border-radius: 2px;
}
.ed-thumb .ed-thumb-dot {
  position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--stamp);
}

/* ---------------------------------------------------------
   Mobile
--------------------------------------------------------- */
@media (max-width: 760px) {
  .ed-body { flex-direction: column; }
  .ed-toolrail { flex-direction: row; border-right: none; border-bottom: 1px solid var(--line); width: 100%; justify-content: center; }
  .ed-pagenav { width: 100%; flex-direction: row; border-left: none; border-top: 1px solid var(--line); }
  .ed-thumb-strip { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .ed-thumb { flex-shrink: 0; width: 70px; }
  .ed-filename { max-width: 30vw; }
}
