/* ================================================================
   PDF EDITOR — InkEgg
   Full-viewport layout, terminal/cyberpunk aesthetic
   ================================================================ */

/* ── Wrapper: fills viewport below the fixed nav ── */
#pdf-editor-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nav-height, 53px));
  overflow: hidden;
  background: var(--color-bg-dark, #1a1a1a);
  color: #eee;
  font-family: 'Roboto Mono', 'Courier New', monospace;
}

/* Prevent body from scrolling while editor is open */
body:has(#pdf-editor-wrap) {
  overflow: hidden;
}

/* ── Toolbar ── */
#pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  background: var(--color-bg-primary, #2c292d);
  border-bottom: 1px solid #3e3b3f;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.pdf-toolbar-label {
  font-size: 11px;
  color: var(--color-text-muted, #6c6a6c);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#pdf-toolbar input[type="color"] {
  width: 32px;
  height: 24px;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
}

#pdf-toolbar input[type="number"] {
  width: 50px;
  padding: 3px 5px;
  background: #1a1a1a;
  border: 1px solid #3e3b3f;
  color: var(--color-terminal-green, #33ff33);
  border-radius: 3px;
  font-size: 12px;
  font-family: inherit;
}

#pdf-toolbar button {
  padding: 4px 11px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  line-height: 1.4;
  transition: opacity 0.15s;
}
#pdf-toolbar button:hover { opacity: 0.85; }

/* Named action buttons */
#btn-add-text  { background: #4a9eff; color: #fff; }
#btn-signature { background: var(--color-accent-purple, #ac9ef2); color: #1a1a1a; }
#btn-save-egg  { background: var(--color-accent-yellow, #ffd866); color: #1a1a1a; }
#btn-export    { background: var(--color-terminal-green, #33ff33); color: #1a1a1a; }
#btn-undo      { background: #3e3b3f; color: #eee; }
#btn-clear     { background: var(--color-accent-red, #f94646); color: #fff; }
#btn-help {
  background: #3e3b3f;
  color: var(--color-text-muted, #6c6a6c);
  border: 1px solid #575558;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 13px;
  font-weight: bold;
  margin-left: auto;
  flex-shrink: 0;
}
#btn-help:hover { background: #575558; color: var(--color-terminal-green, #33ff33); }

/* Format / align toggle buttons */
.fmt-btn, .aln-btn {
  background: #3e3b3f;
  color: #ccc;
  border: 1px solid #575558;
  min-width: 26px;
  padding: 3px 7px;
}
.fmt-btn.active, .aln-btn.active {
  background: var(--color-terminal-green, #33ff33);
  color: #1a1a1a;
  border-color: var(--color-terminal-green, #33ff33);
}
.fmt-btn:hover, .aln-btn:hover { background: #575558; }
.fmt-btn.active:hover, .aln-btn.active:hover { opacity: 0.85; }

/* Separator */
.pdf-sep { width: 1px; height: 20px; background: #3e3b3f; flex-shrink: 0; }

/* Page nav */
#page-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--color-text-muted, #6c6a6c);
}
#page-nav button {
  padding: 3px 9px;
  background: #3e3b3f;
  color: #eee;
  border: none;
  border-radius: 3px;
  cursor: pointer;
}

/* ── Drop zone ── */
#drop-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.drop-zone-label {
  font-size: 15px;
  color: var(--color-text-muted, #6c6a6c);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#drop-zone.dragover {
  background: rgba(51, 255, 51, 0.05);
  outline: 2px dashed var(--color-terminal-green, #33ff33);
  outline-offset: -16px;
}

#drop-zone input[type="file"] { display: none; }

#drop-zone-buttons {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

#drop-zone label {
  padding: 10px 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  letter-spacing: 0.04em;
  transition: opacity 0.15s;
}
#drop-zone label:hover { opacity: 0.85; }

#lbl-open-pdf { background: #4a9eff; color: #fff; }
#lbl-open-egg { background: var(--color-accent-yellow, #ffd866); color: #1a1a1a; }

#drop-zone-sub {
  font-size: 12px;
  color: #3e3b3f;
}
#drop-zone-sub code {
  color: var(--color-text-muted, #6c6a6c);
  background: #2c292d;
  padding: 1px 5px;
  border-radius: 3px;
}

/* ── Text layer (existing PDF text hit targets) ── */
#text-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 1;
}

.text-layer-item {
  position: absolute;
  pointer-events: all;
  cursor: text;
  background: transparent;
  border-bottom: 1px solid transparent;
  /* No transition — hover and disappear must be instant */
}

.text-layer-item:hover {
  background: rgba(51, 255, 51, 0.12);
  border-bottom-color: rgba(51, 255, 51, 0.6);
}

/* ── Scroll / canvas ── */
#scroll-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  display: flex;
  justify-content: center;
  padding: 20px;
}

#canvas-wrapper {
  position: relative;
  display: inline-block;
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.7);
  align-self: flex-start;
}

#pdf-canvas { display: block; }

#overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2; /* above text-layer */
}

/* ── Text-edit annotation: transparent — canvas white-out handles coverage ── */
.ann-text-edit > .item-border {
  background: transparent;
  color: #000;
  white-space: pre;      /* Never wrap — text stays on one line unless Enter is pressed */
  overflow: visible;     /* Let the box grow past its initial width */
}

.ann-text-edit.selected > .item-border,
.ann-text-edit:hover    > .item-border {
  outline: 1px dashed rgba(230, 34, 197, 0.8) !important;
  background: transparent !important;
}

.ann-text-edit.editing .item-border {
  outline: 1px solid var(--color-cyberpunk-pink, #e622c5) !important;
  background: transparent !important;
  white-space: pre !important;   /* Confirmed no-wrap while typing */
  cursor: text;
  width: auto !important;        /* Overridden by JS; ensures no stale fixed width */
}

/* ── Annotation items ── */
.ann-item {
  position: absolute;
  pointer-events: all;
  cursor: move;
  user-select: none;
}
.ann-item.selected > .item-border,
.ann-item:hover    > .item-border {
  outline: 1px dashed rgba(51, 255, 51, 0.7);
  background: rgba(51, 255, 51, 0.04);
}
.item-border {
  position: relative;
  display: inline-block;
  padding: 2px 4px;
  border-radius: 2px;
}

/* Text annotation */
.ann-text .item-border {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.35;
  font-family: Arial, Helvetica, sans-serif;
  min-width: 40px;
  min-height: 1em;
}
.ann-text.editing .item-border {
  outline: 1px solid var(--color-terminal-green, #33ff33) !important;
  background: rgba(51, 255, 51, 0.06) !important;
  cursor: text;
  white-space: pre-wrap;
}

/* Image annotation */
.ann-image img { display: block; max-width: 400px; }

/* Resize handles */
.resize-handle {
  position: absolute;
  bottom: -5px;
  right: -5px;
  width: 12px;
  height: 12px;
  background: var(--color-terminal-green, #33ff33);
  border-radius: 2px;
  cursor: se-resize;
  display: none;
  z-index: 5;
}
.resize-handle-e {
  position: absolute;
  top: 0;
  right: -5px;
  width: 10px;
  height: 100%;
  cursor: ew-resize;
  display: none;
  z-index: 5;
}
.ann-item.selected .resize-handle,
.ann-item:hover    .resize-handle,
.ann-item.selected .resize-handle-e,
.ann-item:hover    .resize-handle-e { display: block; }

/* Delete button */
.delete-btn {
  position: absolute;
  top: -9px;
  right: -9px;
  width: 17px;
  height: 17px;
  background: var(--color-accent-red, #f94646);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 10;
}
.ann-item.selected .delete-btn,
.ann-item:hover    .delete-btn { display: flex; }

/* Copy badge */
.copy-badge {
  position: absolute;
  top: -9px;
  left: -9px;
  padding: 1px 5px;
  background: #3e3b3f;
  color: #aaa;
  border-radius: 3px;
  font-size: 10px;
  display: none;
  white-space: nowrap;
}
.ann-item.selected .copy-badge { display: block; }

/* ── Generic modal ── */
.pdf-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.pdf-modal-backdrop.open { display: flex; }

.pdf-modal-box {
  background: var(--color-bg-primary, #2c292d);
  border: 1px solid #3e3b3f;
  border-radius: 8px;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.8);
  position: relative;
}
.pdf-modal-box h2 {
  font-size: 14px;
  color: var(--color-terminal-green, #33ff33);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}

.pdf-modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: var(--color-text-muted, #6c6a6c);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.pdf-modal-close:hover { color: var(--color-terminal-green, #33ff33); }

/* ── Signature modal ── */
#sig-box { width: 520px; }
#sig-canvas {
  background: #fff;
  border-radius: 4px;
  cursor: crosshair;
  touch-action: none;
  display: block;
}
#sig-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}
#sig-actions button {
  padding: 7px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
#btn-sig-clear  { background: #3e3b3f; color: #eee; }
#btn-sig-cancel { background: #2c292d; color: #eee; border: 1px solid #3e3b3f; }
#btn-sig-done   { background: var(--color-terminal-green, #33ff33); color: #1a1a1a; }

#sig-hint {
  font-size: 11px;
  color: var(--color-text-muted, #6c6a6c);
  margin-top: 4px;
}
#sig-saved-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 4px;
}
#sig-saved-label { font-size: 11px; color: var(--color-text-muted, #6c6a6c); }
.sig-thumb {
  border: 1px solid #3e3b3f;
  border-radius: 3px;
  cursor: pointer;
  background: #fff;
  height: 36px;
  width: auto;
}
.sig-thumb:hover { border-color: var(--color-terminal-green, #33ff33); }

/* ── Help modal ── */
#help-box { width: min(620px, 90vw); }

.help-section { margin-bottom: 18px; }
.help-section h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-cyberpunk-pink, #e622c5);
  margin-bottom: 8px;
  border-bottom: 1px solid #3e3b3f;
  padding-bottom: 4px;
}

.help-row {
  display: flex;
  gap: 12px;
  align-items: baseline;
  padding: 4px 0;
  border-bottom: 1px solid #2c292d;
  font-size: 13px;
}
.help-row:last-child { border-bottom: none; }
.help-key { flex-shrink: 0; min-width: 150px; color: #ddd; font-weight: 500; }
.help-desc { color: var(--color-text-muted, #6c6a6c); font-size: 12px; }

kbd {
  display: inline-block;
  padding: 1px 6px;
  background: #3e3b3f;
  border: 1px solid #575558;
  border-radius: 3px;
  font-size: 11px;
  font-family: monospace;
  color: var(--color-terminal-green, #33ff33);
  vertical-align: middle;
}

/* Help button color badges */
.hb {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 3px;
  font-size: 11px;
  color: #fff;
  vertical-align: middle;
  margin-right: 2px;
}
.hb-blue   { background: #4a9eff; }
.hb-purple { background: var(--color-accent-purple, #ac9ef2); color: #1a1a1a; }
.hb-orange { background: var(--color-accent-yellow, #ffd866); color: #1a1a1a; }
.hb-green  { background: var(--color-terminal-green, #33ff33); color: #1a1a1a; }
.hb-red    { background: var(--color-accent-red, #f94646); }
.hb-gray   { background: #3e3b3f; }

.format-note {
  margin-top: 14px;
  padding: 10px 14px;
  background: #1a1a1a;
  border: 1px solid #3e3b3f;
  border-radius: 5px;
  font-size: 12px;
  color: var(--color-text-muted, #6c6a6c);
  line-height: 1.6;
}
.format-note strong { color: var(--color-accent-yellow, #ffd866); }

/* ── mainDiv override: remove default padding so editor can fill height ── */
#mainDiv:has(#pdf-editor-wrap) {
  padding: 0;
  margin: 0;
}
