/* ============ App layout ============ */
#view-app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* ============ Sidebar ============ */
.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  /* The nav scrolls internally; the sidebar itself stays a fixed shell so
     the usage card stays pinned at the bottom even with many tools listed. */
  overflow: hidden;
}
.sidebar .brand {
  padding: 4px 8px;
  flex-shrink: 0;
}
.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  /* Small inner padding so focus rings on the last item aren't clipped by
     the overflow:hidden parent. */
  padding-bottom: 4px;
}
.side-nav a,
.side-nav-pinned {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.side-nav a:hover,
.side-nav-pinned:hover {
  background: var(--bg-elev);
  color: var(--text);
}
.side-nav a.active,
.side-nav-pinned.active {
  background: var(--primary-soft);
  color: var(--primary);
}
.side-nav a.active svg,
.side-nav-pinned.active svg { color: var(--primary); }
.side-nav-section {
  margin: 12px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted, var(--text-soft));
  opacity: 0.7;
}
.side-nav-section:first-of-type { margin-top: 14px; }
/* Subtle indent of items under section headers (skip the divided History) */
.side-nav .side-nav-section ~ a {
  padding-left: 15px;
}

/* History link + usage card form the pinned footer cluster, kept outside the
   scrolling .side-nav so History is always reachable without scrolling. */
.sidebar-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.usage-card {
  flex-shrink: 0;
  padding: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.usage-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-soft);
}
.usage-head span:last-child {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.usage-bar {
  height: 6px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
}
.usage-bar-fill {
  height: 100%;
  background: var(--grad);
  width: 0%;
  transition: width .3s;
}
.usage-bar-fill.warn { background: linear-gradient(90deg, #f59e0b, #ef4444); }

/* Soft nudge for anon users with 2+ used — gives them a path to a
   personal quota so a coworker on the same IP doesn't burn theirs. */
.usage-nudge {
  display: block;
  font-size: 12px;
  color: var(--text-soft);
  text-align: center;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: color .15s, background .15s;
}
.usage-nudge:hover { color: var(--primary); background: var(--primary-soft); }
.usage-nudge[hidden] { display: none; }

/* Pro plan: no daily limit, so the bar + upgrade button are noise. */
.usage-card.is-pro .usage-bar { display: none; }
.usage-card.is-pro [data-action="open-upgrade"] { display: none; }
.usage-card.is-pro .usage-nudge { display: none; }

/* ============ Main ============ */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* The sticky .topbar (and the landing nav) overlay the top of the scrollport, so every
   scrollIntoView({block:'start'}) and anchor jump must land *below* it — otherwise the
   section's top (first download button, Auto-redact CTA, tool editors) hides behind the bar.
   Setting scroll-padding-top on the document scroller offsets all of them from one place. */
html { scroll-padding-top: 88px; }

.tool-content {
  flex: 1;
  padding: 32px;
  max-width: 920px;
  width: 100%;
}

/* ============ Page transitions (rise + fade) ============ */
/* js/app.js wraps tool→tool swaps in document.startViewTransition() where supported,
   scoping the motion to #tool-content so the sidebar/topbar stay put. The view switch
   (landing/app/signin) and browsers without View Transitions use the .kp-enter
   fallback. Reduced-motion is honored in JS and by the global block in main.css.
   kpRise/kpFadeDown are defined in main.css (shared with the standalone pages). */
#tool-content { view-transition-name: kp-content; }

/* Only the named content region animates — keep the whole-page root crossfade off. */
:root::view-transition-old(root),
:root::view-transition-new(root) { animation: none; }

::view-transition-old(kp-content) { animation: kpFadeDown .26s cubic-bezier(.2, .7, .3, 1) both; }
::view-transition-new(kp-content) { animation: kpRise .26s cubic-bezier(.2, .7, .3, 1) both; }

.kp-enter { animation: kpRise .26s cubic-bezier(.2, .7, .3, 1) both; }

/* Mobile-only chrome — hidden on desktop, where the h1, the persistent sidebar,
   and the text "Back to site" already do these jobs. */
.tools-trigger { display: none; }
.back-to-site-icon { display: none; }

@media (max-width: 880px) {
  /* The persistent sidebar becomes a fixed dropdown overlay opened by the
     .tools-trigger in the topbar, so #view-app collapses to a single flowing
     column (just .main). One header row, and no grid track left to stretch —
     the height-doubling the old strip suffered structurally can't happen. */
  #view-app { display: block; }

  /* The topbar IS the whole mobile header — one row: [page ▾] ...... [actions].
     The h1 duplicates the trigger label (and each tool's own heading), so it's
     hidden; the trigger carries the current page name (kept in sync by app.js). */
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar h1 { display: none; }

  .tools-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 1 auto;
    min-width: 0;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elev);
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
  }
  .tools-trigger:hover { background: var(--bg-soft); border-color: var(--border-strong); }
  .tools-trigger:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
  .tools-trigger:active { transform: translateY(1px); }
  .tools-trigger-icon, .tools-trigger-chevron { flex-shrink: 0; }
  .tools-trigger-chevron { color: var(--text-soft); transition: transform .15s; }
  /* Long names (e.g. "Bates Numbering") ellipsis instead of shoving actions off-row. */
  .tools-trigger-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-actions { flex-shrink: 0; }
  #view-app.tools-open .tools-trigger { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
  #view-app.tools-open .tools-trigger-chevron { transform: rotate(180deg); color: var(--primary); }

  /* The sidebar overlay: a fixed dropdown sitting just under the sticky header.
     top matches the topbar height (verified); fixed keeps it under the header
     even after the page scrolls (the trigger lives in the sticky topbar). */
  .sidebar {
    position: fixed;
    top: 60px;
    left: 8px;
    right: 8px;
    z-index: 50;
    display: none;
    flex-direction: column;
    gap: 6px;
    height: auto;
    max-height: calc(100vh - 68px);
    overflow-y: auto;
    padding: 10px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
  }
  #view-app.tools-open .sidebar { display: flex; }
  .sidebar .brand { display: none; }

  /* History pinned to the TOP of the overlay (its footer normally sits last). */
  .sidebar-footer { order: -1; flex-direction: column; gap: 6px; }
  .usage-card { display: none; }
  .side-nav-pinned { white-space: nowrap; padding: 11px 10px; border-radius: var(--radius); }

  /* Tools as a 2-column grid below History. */
  .side-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; flex: 0 0 auto; overflow: visible; }
  .side-nav a { white-space: nowrap; padding: 11px 10px; }
  .side-nav .side-nav-section ~ a { padding-left: 10px; }
  .side-nav-section { display: none; }

  /* Keep the header on one line: Back-to-site shows only its icon, and the
     account chip drops the email when signed in. */
  .back-to-site-icon { display: inline-block; }
  .back-to-site span { display: none; }
  .account-email { display: none; }

  .tool-content { padding: 20px; }
}

/* ============ Tool common ============ */
.tool-header {
  margin-bottom: 24px;
}
.tool-header h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.tool-header p {
  color: var(--text-soft);
  font-size: 15px;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* ============ Drop zone ============ */
.dropzone {
  position: relative;
  display: block;
  padding: 40px 24px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  text-align: center;
  cursor: pointer;
  background: var(--bg-soft);
  color: var(--text-soft);
  transition: border-color .15s, background .15s, color .15s;
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}
.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.dropzone-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dropzone strong {
  display: block;
  color: var(--text);
  font-size: 15px;
  margin-bottom: 4px;
}
.dropzone-hint { font-size: 13px; }

/* ============ File list ============ */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.file-item .file-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.file-item .file-meta {
  flex: 1;
  min-width: 0;
}
.file-item .file-name {
  font-size: 14px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.file-item .file-size {
  font-size: 12px;
  color: var(--text-mute);
}
.file-item .file-actions {
  display: flex;
  gap: 4px;
}
.icon-action {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-mute);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.icon-action:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.icon-action.danger:hover { color: var(--danger); }

/* ============ Action bar ============ */
.action-bar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ============ Empty state ============ */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-mute);
  font-size: 14px;
}

/* ============ Result panel ============ */
.result-panel {
  padding: 20px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 8%, var(--bg-elev)), var(--bg-elev));
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}
.result-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--success);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.result-text { flex: 1; }
.result-text strong { display: block; font-size: 15px; margin-bottom: 2px; }
.result-text span { font-size: 13px; color: var(--text-soft); }

/* ============ Spinner ============ */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Dashboard ============ */
.dash-greeting {
  margin-bottom: 32px;
}
.dash-greeting h2 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.dash-greeting p { color: var(--text-soft); }

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.dash-tile {
  display: block;
  padding: 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.dash-tile:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow);
}
.dash-tile .tool-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: block;
  object-fit: cover;
  margin-bottom: 12px;
  box-shadow: 0 3px 10px -3px rgba(0, 0, 0, 0.16), 0 1px 2px rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] .dash-tile .tool-icon {
  box-shadow: 0 3px 12px -3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.35);
}
.dash-tile h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.dash-tile p { font-size: 13px; color: var(--text-soft); }

/* ============ Page picker (for split/rotate) ============ */
.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.page-thumb {
  position: relative;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
  aspect-ratio: 3/4;
  display: flex;
  align-items: center;
  justify-content: center;
}
.page-thumb:hover { border-color: var(--primary-hover); transform: translateY(-1px); }
.page-thumb.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.page-thumb canvas { width: 100%; height: 100%; object-fit: contain; }
.page-thumb .page-num {
  position: absolute;
  bottom: 4px;
  left: 4px;
  font-size: 11px;
  background: rgba(0,0,0,.7);
  color: white;
  padding: 1px 6px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.page-thumb .rot-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 10px;
  font-weight: 600;
  background: var(--primary);
  color: white;
  padding: 2px 6px;
  border-radius: 999px;
}

/* ============ Account chip (top-bar) ============ */
.account-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text);
  max-width: 260px;
}
.account-chip[hidden] { display: none; }
.account-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}
.account-plan {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
}
.account-plan.plan-free { background: var(--bg-soft); color: var(--text-soft); }
.account-plan.plan-pro {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  color: #fff;
}
.account-menu-btn {
  background: transparent;
  border: none;
  color: var(--text-soft);
  padding: 4px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
}
.account-menu-btn:hover { background: var(--bg-soft); color: var(--text); }

.account-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  padding: 4px;
  z-index: 50;
}
.account-menu[hidden] { display: none; }
.account-menu button {
  width: 100%;
  background: transparent;
  border: none;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--radius-sm, 6px);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.account-menu button:hover { background: var(--bg-soft); }

/* ============ Watermark editor ============ */
.wm-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  gap: 24px;
  margin-top: 16px;
  align-items: start;
}
.wm-preview-pane {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.wm-preview-frame {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
}
.wm-preview-empty {
  color: var(--text-mute);
  font-size: 13px;
}
.wm-preview-stage {
  position: relative;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  border-radius: 4px;
  overflow: hidden;
  /* Background is the rendered page; force white so dark mode doesn't bleed through transparent PDF areas. */
  background: #fff;
  max-width: 100%;
}
.wm-preview-canvas {
  display: block;
  width: 100%;
  height: auto;
}
.wm-preview-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.wm-stamp {
  position: absolute;
  font-family: Helvetica, Arial, sans-serif;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  letter-spacing: 0;
  /* Overlay sets pointer-events:none so the canvas shows through — re-enable on the stamp itself. */
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
}
/* Hide the cursor mid-drag — the stamp follows the mouse 1:1, so the cursor
 * glyph is just covering the text the user is aligning with page content
 * underneath. Same rationale as .pf-placement.dragging in sign.css. */
.wm-stamp.dragging { cursor: none; }
.wm-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-soft);
}
.wm-pager .btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.wm-pager-label {
  font-variant-numeric: tabular-nums;
  min-width: 110px;
  text-align: center;
}
.wm-preview-note {
  font-size: 12px;
  text-align: center;
}
.wm-controls-pane {
  display: flex;
  flex-direction: column;
}
.wm-controls-pane .field:last-child {
  margin-bottom: 0;
}

.wm-pos-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.wm-chip {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-soft);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.wm-chip:hover:not(:disabled) {
  background: var(--bg-soft);
  color: var(--text);
}
.wm-chip.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}
.wm-chip:disabled {
  opacity: 0.45;
  cursor: default;
}
.wm-chip-custom { font-style: italic; }

@media (max-width: 880px) {
  .wm-editor {
    grid-template-columns: 1fr;
  }
}
