/* ═══════════════════════════════════════════════
   CSS CUSTOM PROPERTIES — LIGHT THEME (default)
   ═══════════════════════════════════════════════ */
:root {
  --bg:           #f3f4f8;
  --surface:      #ffffff;
  --surface-2:    #f8f9fc;
  --border:       #e2e5ee;
  --border-focus: #4f46e5;
  --text:         #111827;
  --text-muted:   #6b7280;
  --text-subtle:  #9ca3af;
  --accent:       #4f46e5;
  --accent-hover: #4338ca;
  --accent-light: #eef2ff;
  --accent-ghost: rgba(79,70,229,.08);
  --danger:       #ef4444;
  --danger-light: #fef2f2;
  --drop-active:  #e9edfc;
  --shadow-xs:    0 1px 2px rgba(0,0,0,.06);
  --shadow-sm:    0 2px 6px rgba(0,0,0,.08);
  --shadow-md:    0 4px 16px rgba(0,0,0,.10);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.12);
  --shadow-card:  0 0 0 1px var(--border), 0 2px 8px rgba(0,0,0,.06);
  --radius:       14px;
  --radius-sm:    8px;
  --radius-xs:    5px;
  --transition:   .18s ease;
}

/* ═══════════════════════════════════════════════
   DARK THEME
   ═══════════════════════════════════════════════ */
body.dark {
  --bg:           #0d0e14;
  --surface:      #161720;
  --surface-2:    #1d1e2c;
  --border:       #2a2b3d;
  --border-focus: #6366f1;
  --text:         #e4e6f1;
  --text-muted:   #8b8fa8;
  --text-subtle:  #555870;
  --accent:       #6366f1;
  --accent-hover: #7c80f5;
  --accent-light: #1a1b2e;
  --accent-ghost: rgba(99,102,241,.12);
  --danger:       #f87171;
  --danger-light: #2c1a1a;
  --drop-active:  #1b1d2f;
  --shadow-xs:    0 1px 2px rgba(0,0,0,.3);
  --shadow-sm:    0 2px 6px rgba(0,0,0,.35);
  --shadow-md:    0 4px 16px rgba(0,0,0,.4);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.5);
  --shadow-card:  0 0 0 1px var(--border), 0 2px 8px rgba(0,0,0,.3);
}

/* ═══════════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════════ */
header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  transition: background var(--transition), border-color var(--transition);
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
  user-select: none;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  transition: color var(--transition), background var(--transition);
  white-space: nowrap;
}
.back-btn:hover { color: var(--text); background: var(--surface-2); }
.back-btn.hidden { visibility: hidden; pointer-events: none; }

.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.theme-toggle:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.snap-toggle {
  height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.snap-toggle:hover { background: var(--surface-2); }
.snap-toggle.snap-on {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* ═══════════════════════════════════════════════
   VIEWS
   ═══════════════════════════════════════════════ */
.view {
  max-width: 760px;
  margin: 0 auto;
  padding: 52px 24px 80px;
}
.view.hidden { display: none; }
.view.active { animation: fadeUp .22s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════
   LANDING
   ═══════════════════════════════════════════════ */
.hero {
  text-align: center;
  margin-bottom: 52px;
}

.hero h1 {
  font-size: clamp(2.2rem, 6vw, 3.2rem);
  font-weight: 900;
  letter-spacing: -1.5px;
  line-height: 1.1;
  margin-bottom: 14px;
  background: linear-gradient(135deg, var(--accent) 0%, #a855f7 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub {
  font-size: 1rem;
  color: var(--text-muted);
  max-width: 440px;
  margin: 0 auto;
  line-height: 1.6;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 28px 24px;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  box-shadow: var(--shadow-xs);
}
.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}
.feature-card:active { transform: translateY(-2px); }

.card-icon {
  width: 54px;
  height: 54px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.card-text h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}
.card-text p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.card-cta {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
  margin-top: 4px;
}

/* ═══════════════════════════════════════════════
   SECTION HEADER
   ═══════════════════════════════════════════════ */
.section-header {
  margin-bottom: 28px;
}
.section-header h2 {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.6px;
  margin-bottom: 4px;
}
.section-header p {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════
   DROPZONE
   ═══════════════════════════════════════════════ */
.dropzone {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 44px 32px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: border-color var(--transition), background var(--transition);
}
.dropzone:hover, .dropzone.dz-hover {
  border-color: var(--accent);
  background: var(--drop-active);
}
.dropzone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.dz-icon { color: var(--text-subtle); margin-bottom: 4px; }
.dz-title { font-size: 1rem; font-weight: 600; color: var(--text); }
.dz-sub { font-size: 0.82rem; color: var(--text-muted); }

/* Hide the real file input */
input[type="file"] { display: none; }

/* ═══════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition), color var(--transition), border-color var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79,70,229,.3);
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 4px 14px rgba(79,70,229,.4); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.btn-outline:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
.btn-remove:hover { background: var(--danger-light); color: var(--danger); }

/* Coming-soon disabled state with tooltip */
.coming-soon {
  opacity: 0.45;
  cursor: not-allowed !important;
}
.coming-soon:hover {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}

.tooltip-wrap { position: relative; display: inline-block; }
.tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-xs);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  z-index: 10;
}
.tooltip-wrap:hover .tooltip { opacity: 1; }

/* ═══════════════════════════════════════════════
   FILE LIST (COMBINE)
   ═══════════════════════════════════════════════ */
.file-list {
  list-style: none;
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  cursor: grab;
  user-select: none;
  transition: border-color var(--transition), box-shadow var(--transition), opacity var(--transition), background var(--transition);
}
.file-item:active { cursor: grabbing; }

.file-item.is-dragging {
  opacity: 0.35;
}
.file-item.drop-target {
  border-color: var(--accent);
  background: var(--accent-ghost);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.drag-handle {
  color: var(--text-subtle);
  cursor: grab;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 2px;
}
.drag-handle:active { cursor: grabbing; }

.pdf-icon { color: var(--accent); flex-shrink: 0; }

.item-name {
  flex: 1;
  font-size: 0.88rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-size {
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════
   COMBINE FOOTER
   ═══════════════════════════════════════════════ */
.footer-bar {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.footer-bar.hidden { display: none; }

.outname-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 220px;
}
.outname-row label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.outname-row input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.88rem;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.outname-row input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-ghost);
}

/* ═══════════════════════════════════════════════
   SPLIT — FILE BAR
   ═══════════════════════════════════════════════ */
.file-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-top: 16px;
}
.file-bar.hidden { display: none; }

.file-bar-info {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.file-bar-name {
  font-size: 0.9rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-bar-meta { font-size: 0.78rem; color: var(--text-muted); }

/* ═══════════════════════════════════════════════
   SPLIT EDITOR
   ═══════════════════════════════════════════════ */
.split-editor {
  margin-top: 24px;
}
.split-editor.hidden { display: none; }

.split-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.split-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  display: grid;
  grid-template-columns: 28px 1fr 1fr 2fr 30px;
  align-items: end;
  gap: 14px;
}

.split-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 1px;
}

.split-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.split-field label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.split-card input[type="number"],
.split-card input[type="text"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  font-size: 0.875rem;
  color: var(--text);
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.split-card input[type="number"] { width: 80px; }
.split-card input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-ghost);
}

/* Remove number input spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type="number"] { -moz-appearance: textfield; }

.split-btn-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
}
.split-run-row { display: flex; justify-content: flex-start; }

/* ═══════════════════════════════════════════════
   LOADING OVERLAY
   ═══════════════════════════════════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.overlay.hidden { display: none; }

.overlay-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 44px;
  text-align: center;
  max-width: 340px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: fadeUp .2s ease;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loader-title { font-size: 1.05rem; font-weight: 700; }
.loader-sub   { font-size: 0.82rem; color: var(--text-muted); min-height: 1.2em; }

.progress-track {
  width: 100%;
  height: 5px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #a855f7);
  border-radius: 99px;
  transition: width .25s ease;
  width: 0%;
}
.progress-pct {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════ */
@media (max-width: 600px) {
  .view { padding: 32px 16px 60px; }
  .header-inner { padding: 0 16px; }

  .split-card {
    grid-template-columns: 28px 1fr 1fr 30px;
    grid-template-rows: auto auto;
  }
  .split-card .split-field:nth-child(4) { /* filename field */
    grid-column: 2 / 5;
  }
  .split-card .btn-icon { align-self: start; margin-top: 22px; }

  .footer-bar { flex-direction: column; align-items: stretch; }
  .outname-row { width: 100%; }
}

/* ═══════════════════════════════════════════════
   SHARED: SMALL BUTTON VARIANT
   ═══════════════════════════════════════════════ */
.btn-sm {
  padding: 7px 13px;
  font-size: 0.82rem;
}

/* ═══════════════════════════════════════════════
   WIDE VIEW (Repaginate / Form Editor)
   ═══════════════════════════════════════════════ */
.view--wide {
  max-width: 100%;
  padding: 0;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px); /* fill below header */
  overflow: hidden;
}

/* ═══════════════════════════════════════════════
   SHARED TOOLBAR DROPZONE (inline, compact)
   ═══════════════════════════════════════════════ */
.toolbar-dz-wrap {
  flex: 1;
  min-width: 0;
}
.toolbar-dz-wrap.hidden {
	display: none;
}
.toolbar-dropzone {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-muted);
  transition: border-color var(--transition), background var(--transition);
}
.toolbar-dropzone:hover, .toolbar-dropzone.dz-hover {
  border-color: var(--accent);
  background: var(--drop-active);
}

/* ═══════════════════════════════════════════════
   REPAGINATE — TOOLBAR
   ═══════════════════════════════════════════════ */
.repag-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.repag-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}
.repag-controls.hidden { display: none; }

.repag-file-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px 5px 10px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  max-width: 200px;
}
.repag-file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.repag-ctrl-group {
  display: flex;
  align-items: center;
  gap: 5px;
}
.repag-ctrl-group label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.repag-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 6px 8px;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition);
}
.repag-select:focus { outline: none; border-color: var(--border-focus); }

.repag-num-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 6px 7px;
  font-size: 0.82rem;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.repag-num-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--accent-ghost);
}

.repag-unit {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════
   REPAGINATE — WORKSPACE
   ═══════════════════════════════════════════════ */
.repag-workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.repag-workspace.hidden { display: none; }

.repag-thumbs {
  width: 200px;
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.repag-thumbs-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
  padding: 0 4px;
}

.repag-thumb {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-xs);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: border-color var(--transition);
}
.repag-thumb:hover { border-color: var(--accent); }
.repag-thumb.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ghost); }
.repag-thumb img { display: block; width: 100%; height: auto; }
.repag-thumb-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 6px;
  text-align: center;
}

.repag-canvas-wrap {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
}

/* Tight wrapper: canvas + SVG overlay aligned perfectly */
.repag-canvas-inner {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
}
.repag-canvas-inner canvas { display: block; }
.repag-canvas-inner svg {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: all;
  overflow: visible;
  cursor: default;
}

/* ═══════════════════════════════════════════════
   REPAGINATE — SVG OVERLAY ELEMENTS
   ═══════════════════════════════════════════════ */
.repag-rect {
  fill: rgba(79, 70, 229, 0.10);
  stroke: var(--accent);
  stroke-width: 2;
  cursor: move;
  transition: fill 0.1s;
}
.repag-rect:hover { fill: rgba(79, 70, 229, 0.18); }
.repag-rect.selected { stroke-width: 3; fill: rgba(79, 70, 229, 0.22); stroke: var(--accent); }

.repag-gutter-rect {
  fill: none;
  stroke: rgba(245, 158, 11, 0.8);
  stroke-width: 1.5;
  stroke-dasharray: 5 3;
  pointer-events: none;
}

/* Placement rect (shown in Preview Output mode) */
.repag-placement-rect {
  fill: rgba(245, 158, 11, 0.06);
  stroke: rgba(245, 158, 11, 0.9);
  stroke-width: 2;
  stroke-dasharray: 7 3;
  cursor: move;
}
.repag-placement-rect:hover { fill: rgba(245, 158, 11, 0.15); }

.repag-rect-label {
  font-size: 18px;
  font-weight: 800;
  fill: var(--accent);
  pointer-events: none;
  user-select: none;
  dominant-baseline: hanging;
}

.repag-handle {
  fill: white;
  stroke: var(--accent);
  stroke-width: 2;
  r: 6;
}
.repag-handle:hover { fill: var(--accent); }

/* ═══════════════════════════════════════════════
   FORMS EDITOR — TOOLBAR
   ═══════════════════════════════════════════════ */
.forms-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.forms-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}
.forms-controls.hidden { display: none; }

.forms-file-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px 5px 10px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  max-width: 200px;
  flex-shrink: 0;
}
.forms-file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.forms-tool-group {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}
.forms-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 11px;
  font-size: 0.78rem;
  font-weight: 600;
  transition: background var(--transition), color var(--transition);
  border-right: 1px solid var(--border);
  white-space: nowrap;
}
.forms-tool-btn:last-child { border-right: none; }
.forms-tool-btn:hover { background: var(--accent-light); color: var(--accent); }
.forms-tool-btn.active { background: var(--accent); color: #fff; }

.forms-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════
   FORMS EDITOR — WORKSPACE
   ═══════════════════════════════════════════════ */
.forms-workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.forms-workspace.hidden { display: none; }

.forms-pages-strip {
  width: 120px;
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.forms-page-thumb {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-xs);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: border-color var(--transition);
}
.forms-page-thumb:hover { border-color: var(--accent); }
.forms-page-thumb.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-ghost); }
.forms-page-thumb canvas { display: block; width: 100%; height: auto; }
.forms-page-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 4px;
  text-align: center;
}

.forms-editor-area {
  flex: 1;
  overflow: auto;
  position: relative;
  background: var(--bg);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
}

.forms-page-wrap {
  position: relative;
  display: none;
  flex-shrink: 0;
}
.forms-page-wrap.active { display: block; }
.forms-page-wrap canvas { display: block; box-shadow: var(--shadow-md); }
.forms-page-wrap svg {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: all;
  overflow: visible;
}

/* ═══════════════════════════════════════════════
   FORMS EDITOR — SVG FIELD ELEMENTS
   ═══════════════════════════════════════════════ */
.forms-field-rect {
  fill: rgba(99, 102, 241, 0.08);
  stroke: #6366f1;
  stroke-width: 1.5;
  cursor: move;
}
.forms-field-rect:hover { fill: rgba(99, 102, 241, 0.16); }
.forms-field-rect.selected { stroke-width: 2.5; fill: rgba(99, 102, 241, 0.2); }

.forms-field-label {
  font-size: 9px;
  fill: #6366f1;
  pointer-events: none;
  user-select: none;
  dominant-baseline: hanging;
}

.forms-handle {
  fill: white;
  stroke: #6366f1;
  stroke-width: 1.5;
  r: 5;
}
.forms-handle:hover { fill: #6366f1; }

/* New-item neon glow (clears on first move) */
.forms-field-new .forms-field-body {
  filter: drop-shadow(0 0 5px rgba(255, 100, 0, 0.9));
  stroke: rgba(255, 100, 0, 0.9) !important;
}
.forms-field-placeholder {
  fill: var(--text-muted, #aaa);
  font-size: 9px;
  pointer-events: none;
  user-select: none;
  dominant-baseline: hanging;
}
.forms-field-highlight-rect {
  stroke: none;
  cursor: move;
}
.forms-field-highlight-rect.selected {
  stroke: rgba(255, 235, 59, 0.9);
  stroke-width: 1.5;
  stroke-dasharray: 4 2;
}
.forms-field-label-text {
  pointer-events: none;
  user-select: none;
  dominant-baseline: hanging;
  cursor: move;
}
.forms-child-connector {
  stroke: rgba(150, 150, 150, 0.5);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  pointer-events: none;
}
.forms-snap-guide {
  stroke: rgba(59, 130, 246, 0.7);
  stroke-width: 1;
  pointer-events: none;
}
.popup-row {
  display: flex;
  gap: 12px;
  margin-bottom: 0;
}
.popup-row .popup-field {
  flex: 1;
  margin-bottom: 14px;
}

/* ═══════════════════════════════════════════════
   FORMS EDITOR — TAB ORDER PANEL
   ═══════════════════════════════════════════════ */
.forms-tab-order-panel {
  position: fixed;
  right: 0;
  top: 60px; /* below header */
  bottom: 0;
  width: 280px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  z-index: 300;
  transform: translateX(0);
  transition: transform 0.25s ease;
}
.forms-tab-order-panel.hidden { transform: translateX(100%); display: flex; visibility: hidden; }

.forms-tab-order-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.forms-tab-order-header h3 { font-size: 0.95rem; font-weight: 700; }

.forms-tab-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 8px 16px 4px;
}

.tab-order-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.tab-order-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: grab;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  user-select: none;
  transition: background var(--transition);
}
.tab-order-item:active { cursor: grabbing; }
.tab-order-item:hover { background: var(--surface-2); }
.tab-order-item.drag-over { border-top: 2px solid var(--accent); }
.tab-order-item.is-dragging { opacity: 0.4; }
.tab-order-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tab-order-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-type-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
  background: var(--accent-light);
  color: var(--accent);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════
   FORMS EDITOR — FIELD SETTINGS POPUP
   ═══════════════════════════════════════════════ */
.forms-field-popup {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
.forms-field-popup.hidden { display: none; }

.forms-popup-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 420px;
  max-width: 95vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: fadeUp .18s ease;
}

.popup-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 18px;
  color: var(--text);
}

.popup-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}
.popup-field label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.popup-field input[type="text"],
.popup-field input[type="number"],
.popup-field select,
.popup-field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  font-size: 0.875rem;
  color: var(--text);
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}
.popup-field input:focus,
.popup-field select:focus,
.popup-field textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-ghost);
}

.popup-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
}
.popup-check-row input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }

.popup-options-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}
.popup-option-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.popup-option-row input[type="text"] {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 6px 8px;
  font-size: 0.82rem;
  color: var(--text);
}
.popup-option-row input:focus { outline: none; border-color: var(--border-focus); }

.popup-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.popup-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-subtle);
  margin: 14px 0 8px;
}
.popup-divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}
