/* The hidden attribute's default `display: none` is a browser-stylesheet
   rule, which any of this file's own `display` declarations below silently
   overrides (author styles beat the browser default regardless of selector
   specificity) — so every element toggled via `.hidden = true/false` in JS
   needs this guard, or it stays visible/laid-out even while "hidden". */
[hidden] {
  display: none !important;
}

.pdfedit-intro {
  padding: 56px 0 8px;
  text-align: center;
  background: radial-gradient(circle at 50% 0%, var(--lighter-background), var(--background) 70%);
}

.pdfedit-intro h1 {
  color: var(--foreground);
  font-size: 2rem;
  margin-bottom: 8px;
}

.pdfedit-intro .tagline {
  color: var(--light-foreground);
  font-size: 0.95rem;
}

.pdfedit-panel {
  padding: 40px 0 80px;
}

.drop-zone {
  max-width: 560px;
  margin: 0 auto;
  border: 2px dashed var(--muted);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  color: var(--light-foreground);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.drop-zone:hover,
.drop-zone:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.drop-zone.is-dragover {
  border-color: var(--accent);
  background: var(--lighter-background);
}

.drop-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.75rem;
}

.pdfedit-status {
  max-width: 560px;
  margin: 20px auto 0;
  text-align: center;
  color: var(--light-foreground);
  font-size: 0.9rem;
}

.progress-track {
  max-width: 560px;
  margin: 12px auto 0;
  height: 6px;
  border-radius: 999px;
  background: var(--dark-background);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.15s ease;
}

.pdfedit-toolbar {
  max-width: 900px;
  margin: 0 auto 24px;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-primary,
.btn-secondary {
  border-radius: 999px;
  padding: 10px 24px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  transition: transform 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: var(--dark-background);
}

.btn-secondary {
  background: transparent;
  color: var(--light-foreground);
  border: 1px solid var(--muted);
  padding: 9px 23px; /* -1px to offset the border and match .btn-primary's box height */
}

.btn-primary:hover:not(:disabled),
.btn-secondary:hover:not(:disabled) {
  transform: scale(1.05);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.page-grid {
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.page-card {
  background: var(--lighter-background);
  border: 1px solid var(--muted);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Square on purpose: a shape inscribed in a square stays inscribed after any
   90-degree rotation, so rotating the thumbnail below can never clip or
   overflow the frame regardless of the source page's own aspect ratio. */
.thumb-frame {
  aspect-ratio: 1 / 1;
  background: #1a1a1a;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb-frame img {
  max-width: 92%;
  max-height: 92%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease;
}

.page-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.page-number {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--dark-background);
  color: var(--light-foreground);
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-card-controls {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  gap: 3px;
  flex-wrap: wrap;
}

.page-btn {
  background: var(--dark-background);
  color: var(--light-foreground);
  border: none;
  border-radius: 6px;
  width: 24px;
  height: 24px;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.page-btn:hover:not(:disabled) {
  background: var(--accent);
  color: var(--dark-background);
}

.page-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.page-btn-remove:hover:not(:disabled) {
  background: var(--red);
  color: #fff;
}

.pdfedit-empty {
  max-width: 560px;
  margin: 20px auto 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.pdfedit-result {
  max-width: 560px;
  margin: 24px auto 0;
  background: var(--lighter-background);
  border: 1px solid var(--muted);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}

.result-info {
  color: var(--foreground);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.download-btn {
  display: inline-block;
  background: var(--accent);
  color: var(--dark-background);
  border-radius: 999px;
  padding: 10px 28px;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.15s ease;
}

.download-btn:hover {
  transform: scale(1.05);
  color: var(--dark-background);
}

.page-edit-btn {
  width: 100%;
  background: var(--dark-background);
  color: var(--light-foreground);
  border: 1px solid var(--muted);
  border-radius: 6px;
  padding: 6px 0;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.page-edit-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- page editor modal --- */

.page-editor-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 18, 34, 0.9);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.page-editor {
  background: var(--panel, var(--dark-background));
  border: 1px solid var(--muted);
  border-radius: 12px;
  width: 100%;
  max-width: 900px;
  /* A definite height, not just a cap — .page-editor-stage-wrap below is
     flex:1 and needs a concrete parent height to grow into. max-height
     alone doesn't establish one (the container stays auto-sized to
     content), which silently collapsed the whole PDF view to 0 height. */
  height: min(900px, 90vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--muted);
  flex-wrap: wrap;
}

.page-editor-spacer {
  flex: 1;
}

.page-editor-stage-wrap {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: var(--dark-background);
}

.page-editor-stage {
  position: relative;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  flex-shrink: 0;
}

.page-editor-bg {
  display: block;
  max-width: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

.annot-layer {
  position: absolute;
  inset: 0;
}

.annot {
  position: absolute;
  border: 1px dashed rgba(250, 169, 104, 0.7);
  box-sizing: border-box;
}

.annot-text-area {
  width: 100%;
  height: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: #111;
  font-family: Helvetica, Arial, sans-serif;
  padding: 0;
  margin: 0;
  overflow: hidden;
  line-height: 1.2;
}

.annot-img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}

.annot-toolbar {
  position: absolute;
  left: 0;
  top: -30px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--dark-background);
  border: 1px solid var(--muted);
  border-radius: 6px;
  padding: 3px 4px;
  white-space: nowrap;
}

.annot-toolbar input[type="number"] {
  width: 42px;
  background: var(--panel, var(--lighter-background));
  color: var(--text, #fff);
  border: 1px solid var(--muted);
  border-radius: 4px;
  font-size: 0.7rem;
  padding: 2px 4px;
}

.annot-toolbar input[type="color"] {
  width: 22px;
  height: 22px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
}

.annot-bold-btn {
  background: var(--dark-background);
  border: 1px solid var(--muted);
  border-radius: 4px;
  color: var(--light-foreground);
  font-weight: 700;
  width: 22px;
  height: 22px;
  font-size: 0.7rem;
  cursor: pointer;
}

.annot-bold-btn.is-active {
  background: var(--accent);
  color: var(--dark-background);
  border-color: var(--accent);
}

.annot-handle {
  position: absolute;
  background: var(--accent);
  color: var(--dark-background);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  user-select: none;
  border-radius: 3px;
}

.annot-move {
  top: -16px;
  left: -1px;
  width: 20px;
  height: 14px;
  cursor: move;
  touch-action: none;
}

.annot-resize {
  right: -6px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  cursor: nwse-resize;
  touch-action: none;
  border-radius: 50%;
}

.annot-remove {
  position: absolute;
  top: -16px;
  right: -1px;
  width: 16px;
  height: 14px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 3px;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}

.pdfedit-note {
  max-width: 560px;
  margin: 32px auto 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}
