/* ============ 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;
  overflow-y: auto;
}
.sidebar .brand {
  padding: 4px 8px;
}
.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.side-nav a {
  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 {
  background: var(--bg-elev);
  color: var(--text);
}
.side-nav a.active {
  background: var(--primary-soft);
  color: var(--primary);
}
.side-nav a.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:not(.side-nav-divided) {
  padding-left: 15px;
}

.usage-card {
  margin-top: auto;
  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); }

/* 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; }

/* ============ 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;
}

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

@media (max-width: 880px) {
  #view-app { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    padding: 12px;
    align-items: center;
  }
  .side-nav { flex-direction: row; }
  .side-nav a { white-space: nowrap; }
  .side-nav-section { display: none; }
  .usage-card { 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, #0e7490, #0c4a6e);
  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;
  }
}
