/* ============================================================
   PDF CANVAS — Premium Dark Theme
   ============================================================ */

/* ── Reset & Base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:        #0c0c12;
  --bg-surface:     #14141e;
  --bg-elevated:    #1c1c2a;
  --bg-hover:       #22223a;
  --border:         rgba(255,255,255,0.07);
  --border-bright:  rgba(255,255,255,0.14);

  --accent:         #6366f1;
  --accent-light:   #818cf8;
  --accent-dark:    #4f52d4;
  --accent-glow:    rgba(99,102,241,0.35);

  --text-primary:   #f0f0f8;
  --text-secondary: #9090b0;
  --text-muted:     #555575;

  --danger:         #ef4444;
  --success:        #22c55e;
  --warning:        #f59e0b;

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  24px;

  --shadow-sm:  0 2px 8px rgba(0,0,0,0.3);
  --shadow-md:  0 4px 20px rgba(0,0,0,0.5);
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.6);
  --shadow-accent: 0 0 32px rgba(99,102,241,0.25);

  --transition: 0.18s ease;
  --font: 'Inter', system-ui, sans-serif;

  --header-h: 58px;
  --sidebar-w: 180px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: var(--font); cursor: pointer; border: none; }
input  { font-family: var(--font); }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar              { width: 6px; height: 6px; }
::-webkit-scrollbar-track        { background: transparent; }
::-webkit-scrollbar-thumb        { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover  { background: rgba(255,255,255,0.2); }

/* ============================================================
   UPLOAD SCREEN
   ============================================================ */
#upload-screen {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}

.upload-gradient-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(99,102,241,0.22) 0%, transparent 70%),
    radial-gradient(ellipse 50% 40% at 80% 80%,  rgba(139,92,246,0.12) 0%, transparent 60%),
    var(--bg-base);
  z-index: 0;
}

.upload-noise-overlay {
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  z-index: 0; pointer-events: none; opacity: 0.6;
}

/* Nav */
.landing-nav {
  position: relative; z-index: 2;
  width: 100%; max-width: 1100px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 24px 32px;
}

.nav-logo {
  display: flex; align-items: center; gap: 10px;
}

.logo-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #a855f7);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: white;
  box-shadow: var(--shadow-accent);
}

.logo-text {
  font-size: 18px; font-weight: 600; color: var(--text-primary);
  letter-spacing: -0.3px;
}
.logo-text strong { color: var(--accent-light); }

.nav-badge {
  font-size: 11.5px; font-weight: 500;
  color: var(--text-secondary);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px 12px;
  letter-spacing: 0.2px;
}

/* Hero */
.upload-hero {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  padding: 40px 24px 60px;
  max-width: 680px; width: 100%;
}

.hero-tag {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 500; color: var(--accent-light);
  background: rgba(99,102,241,0.12);
  border: 1px solid rgba(99,102,241,0.25);
  border-radius: 100px; padding: 6px 14px;
  margin-bottom: 28px;
  animation: fadeDown 0.5s ease both;
}

.hero-title {
  font-size: clamp(42px, 8vw, 72px);
  font-weight: 800; letter-spacing: -2.5px; line-height: 1.05;
  margin-bottom: 16px;
  animation: fadeDown 0.5s 0.08s ease both;
}

.gradient-text {
  background: linear-gradient(135deg, var(--accent-light), #a78bfa, #c084fc);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-subtitle {
  font-size: 17px; font-weight: 400; color: var(--text-secondary);
  line-height: 1.65; margin-bottom: 36px;
  animation: fadeDown 0.5s 0.16s ease both;
}

/* Drop Zone */
.drop-zone {
  position: relative; width: 100%; max-width: 520px;
  background: rgba(255,255,255,0.025);
  border: 2px dashed rgba(99,102,241,0.35);
  border-radius: var(--radius-xl);
  padding: 48px 24px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform 0.2s;
  animation: fadeDown 0.5s 0.24s ease both;
  overflow: hidden;
  margin-bottom: 32px;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(99,102,241,0.06);
  transform: translateY(-2px);
}
.drop-zone.drag-over {
  border-style: solid;
  background: rgba(99,102,241,0.1);
}

.drop-zone-glow {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse 60% 40% at 50% 50%, rgba(99,102,241,0.08), transparent);
  pointer-events: none;
}

.drop-zone-inner {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  position: relative; z-index: 1;
}

.drop-icon-wrap {
  position: relative;
  margin-bottom: 8px;
}
.drop-icon-main {
  font-size: 64px; color: var(--accent); opacity: 0.85;
  filter: drop-shadow(0 0 20px var(--accent-glow));
}
.drop-icon-plus {
  position: absolute; bottom: 2px; right: -12px;
  font-size: 20px; color: var(--accent-light);
  background: var(--bg-elevated); border-radius: 50%;
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
}

.drop-title {
  font-size: 20px; font-weight: 600; color: var(--text-primary); letter-spacing: -0.3px;
}

.drop-sub { font-size: 13px; color: var(--text-muted); }

.btn-choose-file {
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: white; font-size: 14.5px; font-weight: 600;
  padding: 11px 28px; border-radius: var(--radius-md);
  border: none; cursor: pointer;
  box-shadow: 0 4px 20px rgba(99,102,241,0.4);
  transition: transform var(--transition), box-shadow var(--transition);
  margin-top: 6px;
}
.btn-choose-file:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 28px rgba(99,102,241,0.55);
}

.drop-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

/* Feature pills */
.feature-pills {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  animation: fadeDown 0.5s 0.32s ease both;
}
.feature-pill {
  display: flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
  border-radius: 100px; padding: 7px 16px;
  font-size: 13px; font-weight: 500; color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}
.feature-pill i { color: var(--accent-light); font-size: 12px; }
.feature-pill:hover { background: rgba(99,102,241,0.1); color: var(--text-primary); }

/* ============================================================
   EDITOR SCREEN
   ============================================================ */
#editor-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────── */
#app-header {
  height: var(--header-h);
  min-height: var(--header-h);
  background: rgba(20, 20, 30, 0.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 10px 0 6px;
  gap: 8px;
  position: relative; z-index: 100;
  flex-shrink: 0;
}

.header-left {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0; min-width: 0;
}

.logo-small {
  display: flex; align-items: center; gap: 7px;
  font-size: 15px; font-weight: 600; color: var(--text-primary);
  padding: 0 4px;
  white-space: nowrap;
}
.logo-small i { color: var(--accent); font-size: 17px; }
.logo-small strong { color: var(--accent-light); }

.file-badge {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 12.5px; color: var(--text-secondary);
  max-width: 200px; overflow: hidden;
}
.file-badge i { color: var(--accent); font-size: 13px; flex-shrink: 0; }
.file-badge span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Main toolbar */
.main-toolbar {
  display: flex; align-items: center; gap: 3px;
  background: rgba(255,255,255,0.03); border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  flex: 1; justify-content: center;
  overflow-x: auto; min-width: 0;
}

.tool-group { display: flex; align-items: center; gap: 2px; }

.toolbar-sep {
  width: 1px; height: 24px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 4px;
}

/* Tool buttons */
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 10px; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-secondary);
  font-size: 11px; font-weight: 500; line-height: 1;
  border: 1px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
  min-width: 44px;
}
.tool-btn i { font-size: 14px; margin-bottom: 1px; }
.tool-btn:hover {
  background: rgba(255,255,255,0.06); color: var(--text-primary);
}
.tool-btn.active {
  background: rgba(99,102,241,0.18);
  color: var(--accent-light);
  border-color: rgba(99,102,241,0.3);
}

/* Icon buttons (generic) */
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-secondary);
  font-size: 14px; border: 1px solid transparent;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }
.icon-btn.sm { width: 30px; height: 30px; font-size: 12px; }

/* Header right */
.header-right {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0; margin-left: auto;
}

/* Tool options panel */
.tool-options {
  display: flex; align-items: center; gap: 6px;
  min-width: 0;
}
.opt-label { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }

/* Color swatch */
.color-swatch-wrap { position: relative; }
.color-swatch {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  border: 2px solid rgba(255,255,255,0.15);
  cursor: pointer; padding: 0;
  transition: transform var(--transition);
}
.color-swatch:hover { transform: scale(1.1); }

/* Size slider */
.opt-slider {
  -webkit-appearance: none;
  width: 80px; height: 4px;
  background: var(--bg-hover); border-radius: 2px; cursor: pointer;
  outline: none;
}
.opt-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-elevated);
}

/* Font size input */
.opt-number {
  width: 48px; height: 28px;
  background: var(--bg-hover); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  text-align: center; font-size: 12.5px; font-weight: 500;
  outline: none;
}
.opt-number:focus { border-color: var(--accent); }

/* Highlight color buttons */
.hl-colors { display: flex; gap: 4px; }
.hl-color-btn {
  width: 20px; height: 20px; border-radius: 4px;
  border: 2px solid transparent; cursor: pointer;
  transition: transform var(--transition), border-color var(--transition);
  padding: 0;
}
.hl-color-btn:hover { transform: scale(1.15); }
.hl-color-btn.active { border-color: white; transform: scale(1.15); }

/* Download button */
.btn-download {
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: white; font-size: 13.5px; font-weight: 600;
  padding: 8px 18px; border-radius: var(--radius-md);
  border: none; cursor: pointer;
  box-shadow: 0 2px 12px rgba(99,102,241,0.4);
  transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
  white-space: nowrap; flex-shrink: 0;
}
.btn-download:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(99,102,241,0.55);
}
.btn-download:active { transform: translateY(0); }
.btn-download.loading { opacity: 0.6; pointer-events: none; }

/* Donation button */
.btn-donate {
  display: flex; align-items: center; gap: 6px;
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  font-size: 13.5px; font-weight: 600;
  padding: 8px 18px; border-radius: var(--radius-md);
  text-decoration: none;
  border: 1px solid rgba(245, 158, 11, 0.3);
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition), border-color var(--transition);
  white-space: nowrap; flex-shrink: 0;
}
.btn-donate:hover {
  background: rgba(245, 158, 11, 0.25);
  border-color: rgba(245, 158, 11, 0.5);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(245, 158, 11, 0.2);
}

/* ── Main Area ───────────────────────────────────────────── */
#main-area {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.badge {
  background: rgba(99,102,241,0.2); color: var(--accent-light);
  font-size: 11px; font-weight: 700; padding: 2px 7px;
  border-radius: 100px;
}

#pages-list {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 10px 8px;
  display: flex; flex-direction: column; gap: 6px;
}

/* Thumbnail items */
.thumb-item {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  cursor: pointer; padding: 6px;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  transition: background var(--transition), border-color var(--transition);
  position: relative;
}
.thumb-item:hover { background: rgba(255,255,255,0.04); }
.thumb-item.active {
  background: rgba(99,102,241,0.1);
  border-color: rgba(99,102,241,0.5);
}
.thumb-item.thumb-deleted {
  opacity: 0; transform: scale(0.9);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}

.thumb-canvas-wrapper {
  position: relative; width: 100%;
  background: white; border-radius: 4px;
  overflow: hidden; box-shadow: var(--shadow-sm);
  min-height: 60px;
  display: flex; align-items: center; justify-content: center;
}

.thumb-canvas {
  display: block; width: 100%; height: auto;
}

.thumb-delete-btn {
  position: absolute; top: 4px; right: 4px;
  width: 20px; height: 20px; border-radius: 4px;
  background: rgba(239,68,68,0.85); color: white;
  font-size: 10px; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity var(--transition);
}
.thumb-item:hover .thumb-delete-btn { opacity: 1; }
.thumb-delete-btn:hover { background: var(--danger); }

.thumb-label {
  font-size: 11px; color: var(--text-muted); font-weight: 500;
}
.thumb-item.active .thumb-label { color: var(--accent-light); }

/* ── Canvas Area ─────────────────────────────────────────── */
#canvas-area {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; background: var(--bg-base);
  min-width: 0;
}

/* Top bar (zoom) */
.canvas-topbar {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 12px;
  background: rgba(20,20,30,0.6); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.zoom-level-btn {
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 4px 12px;
  color: var(--text-secondary); font-size: 12.5px; font-weight: 500;
  cursor: pointer; min-width: 58px; text-align: center;
  transition: background var(--transition), color var(--transition);
}
.zoom-level-btn:hover { background: rgba(255,255,255,0.09); color: var(--text-primary); }

/* Scrollable canvas viewport */
#canvas-scroll {
  flex: 1; overflow: auto;
  display: flex; align-items: flex-start; justify-content: center;
}

#canvas-outer {
  display: flex; align-items: flex-start; justify-content: center;
  padding: 32px;
  min-width: max-content;
  min-height: max-content;
}

#canvas-container {
  position: relative;
  box-shadow: 0 8px 48px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.06);
  border-radius: 2px;
  display: inline-block;
}

#pdf-canvas {
  display: block;
  background: white;
}

#fabric-canvas {
  position: absolute !important;
  top: 0 !important; left: 0 !important;
  pointer-events: auto;
}

/* Fabric.js canvas wrapper override */
.canvas-container {
  position: absolute !important;
  top: 0 !important; left: 0 !important;
}

/* Bottom bar (page nav) */
.canvas-bottombar {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 12px;
  background: rgba(20,20,30,0.6); border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.page-nav-wrap {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-secondary);
}
.page-nav-wrap input {
  width: 44px; height: 28px; text-align: center;
  background: var(--bg-hover); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-size: 13px; font-weight: 500; outline: none;
}
.page-nav-wrap input:focus { border-color: var(--accent); }
.page-sep { color: var(--text-muted); }
#page-count { font-weight: 600; color: var(--text-secondary); }

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
#loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(12,12,18,0.75);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}

.loading-box {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 32px 40px;
  box-shadow: var(--shadow-lg);
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(99,102,241,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

#loading-text {
  font-size: 14px; font-weight: 500; color: var(--text-secondary);
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 9998;
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elevated); border: 1px solid var(--border-bright);
  border-radius: var(--radius-md); padding: 12px 20px;
  font-size: 13.5px; font-weight: 500; color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease;
  white-space: nowrap;
}
.toast.error { border-color: rgba(239,68,68,0.4); }
.toast.error i { color: var(--danger); }
.toast.success i { color: var(--success); }

/* ============================================================
   UTILITIES
   ============================================================ */
.hidden { display: none !important; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes thumbFadeIn {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

.thumb-item { animation: thumbFadeIn 0.2s ease both; }

/* ── Misc small pieces ───────────────────────────────────── */
.opt-divider { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; margin: 0 2px; }

.opt-select {
  background: var(--bg-hover); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-family: var(--font); font-size: 12px;
  padding: 4px 8px; outline: none; cursor: pointer;
}
.opt-select:focus { border-color: var(--accent); }
