/* ============================================================
   PDFMend — modern SaaS light theme
   ============================================================ */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-50: #eef2ff;
  --danger: #dc2626;
  --danger-50: #fef2f2;
  --success: #16a34a;
  --warn: #d97706;
  --ring: 0 0 0 3px rgba(79, 70, 229, .25);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 4px 16px rgba(15, 23, 42, .08);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, .14);
  --radius: 10px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
/* author display:flex/inline-flex etc. ko [hidden] ke against jeetne se rok do */
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ============ NAV ============ */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); }
.brand-logo {
  font-size: 22px;
  background: var(--primary-50);
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 10px;
}
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: -.02em; }
.brand-name span { color: var(--primary); }
.brand-pill {
  font-size: 10px; font-weight: 700;
  background: var(--primary-50);
  color: var(--primary);
  padding: 3px 7px;
  border-radius: 999px;
  margin-left: 2px;
}
.nav-right { display: flex; align-items: center; gap: 18px; }
.nav-tag { font-size: 13px; color: var(--text-muted); }
.nav-link { font-size: 13px; color: var(--text); text-decoration: none; font-weight: 600; }
.nav-link:hover { color: var(--primary); }

/* ============ Upload screen ============ */
.upload-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 56px 24px 80px;
  max-width: 1080px;
  margin: 0 auto;
  width: 100%;
}
.hero { text-align: center; max-width: 720px; }
.hero h1 {
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.1;
}
.grad {
  background: linear-gradient(90deg, var(--primary), #9333ea);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero .sub {
  margin-top: 14px;
  font-size: 16px;
  color: var(--text-muted);
  line-height: 1.6;
}

.drop-zone {
  width: 100%;
  max-width: 640px;
  background: var(--surface);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  text-align: center;
  transition: border-color .2s, background .2s, transform .2s, box-shadow .2s;
  box-shadow: var(--shadow);
}
.drop-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-50);
  transform: scale(1.01);
}
.dz-icon { font-size: 40px; }
.dz-title { font-size: 20px; font-weight: 700; margin-top: 10px; }
.dz-or { color: var(--text-faint); font-size: 13px; margin: 8px 0; }
.dz-note { margin-top: 18px; font-size: 13px; color: var(--text-faint); }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  width: 100%;
}
.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .15s;
}
.feature-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.fc-icon { font-size: 26px; }
.feature-card h3 { font-size: 16px; margin: 10px 0 6px; }
.feature-card p { font-size: 13.5px; color: var(--text-muted); line-height: 1.55; }

/* ============ Buttons ============ */
.btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger-50); border-color: #fecaca; color: var(--danger); }
.btn.danger:hover { background: #fee2e2; }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.btn.lg { padding: 12px 22px; font-size: 15px; }
.btn.icon { padding: 8px 10px; }
.btn.tool { padding: 8px 12px; }
.btn.tool .ic { font-size: 15px; }
.btn.tool .lbl { font-size: 13.5px; }
.btn.tool.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, .3);
}

/* ============ Editor ============ */
.editor-screen { flex: 1; display: flex; flex-direction: row; min-height: 0; }

/* ============ Sidebar ============ */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.sb-section { display: flex; flex-direction: column; gap: 8px; }
.sb-head { display: flex; align-items: center; justify-content: space-between; }
.sb-section h4 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }
.sb-count { font-size: 11px; background: var(--surface-2); color: var(--text-muted); padding: 1px 8px; border-radius: 999px; }
.thumbs { display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow-y: auto; padding-right: 2px; }
.thumb {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: grab;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.thumb.active { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }
.thumb.dragging { opacity: .4; }
.thumb.drag-over { border-style: dashed; border-color: var(--primary); transform: translateY(2px); }
.thumb canvas { display: block; width: 100%; }
.thumb-num { position: absolute; top: 3px; left: 4px; font-size: 10px; background: rgba(15,23,42,.7); color: #fff; padding: 1px 5px; border-radius: 4px; }
.thumb-rot { position: absolute; bottom: 3px; right: 4px; font-size: 10px; background: var(--primary); color: #fff; padding: 1px 5px; border-radius: 4px; }
.thumb-del { position: absolute; top: 3px; right: 4px; font-size: 10px; background: var(--danger); color: #fff; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; border: none; cursor: pointer; line-height: 1; }
.sb-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.sb-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s;
  line-height: 1.2;
}
.sb-btn:hover { background: var(--primary-50); border-color: var(--primary); color: var(--primary); }
.sb-btn.danger { color: var(--danger); }
.sb-btn.danger:hover { background: var(--danger-50); border-color: var(--danger); color: var(--danger); }
.sb-btn.stamp { font-size: 11px; font-weight: 700; letter-spacing: .04em; padding: 7px 4px; background: #fff; }
.sb-btn.stamp:hover { transform: rotate(-2deg); transition: transform .15s; }
.thumb.selected { border-color: var(--primary); background: var(--primary-50); }
.sb-label { font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.sb-select { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px; font-size: 12px; }

.editor-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 64px;
  z-index: 20;
}
.toolbar .group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.toolbar .tools .btn.tool .ic { margin-right: 1px; }
.toolbar .sep { width: 1px; height: 28px; background: var(--border); }
.toolbar .spacer { flex: 1; }
.toolbar .opt {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--text-muted);
}
.toolbar input[type="number"] {
  width: 56px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
}
.toolbar input[type="color"] {
  width: 34px; height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 2px;
  cursor: pointer;
}
.page-info {
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  min-width: 64px; text-align: center;
}

.status-bar {
  padding: 8px 20px;
  font-size: 13px;
  background: var(--primary-50);
  color: var(--primary-600);
  min-height: 36px;
  display: flex; align-items: center;
  border-bottom: 1px solid var(--border);
}
.status-bar.locked { background: #fffbeb; color: var(--warn); }

.canvas-wrap {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 32px;
  background:
    radial-gradient(circle at 20% 10%, rgba(79,70,229,.04), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(147,51,234,.04), transparent 40%),
    var(--bg);
}
.page-container {
  position: relative;
  box-shadow: var(--shadow-lg);
  background: #fff;
  border-radius: 2px;
  height: fit-content;
}
.page-container canvas { display: block; }
#editCanvas {
  position: absolute;
  top: 0; left: 0;
  touch-action: none;
  border-radius: 2px;
}
#editCanvas.tool-text,
#editCanvas.tool-edittext { cursor: text; }
#editCanvas.tool-draw,
#editCanvas.tool-highlight,
#editCanvas.tool-whiteout { cursor: crosshair; }
#editCanvas.tool-image { cursor: copy; }

/* ============ Text popup ============ */
.text-popup {
  position: fixed;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.text-popup[hidden] { display: none; }
.text-popup textarea {
  width: 280px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 15px;
  color: var(--text);
  resize: vertical;
  font-family: inherit;
}
.text-popup textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.text-popup div { display: flex; gap: 8px; justify-content: flex-end; }

/* ============ Responsive ============ */
@media (max-width: 720px) {
  .nav-tag { display: none; }
  .nav { padding: 12px 16px; }
  .sidebar { width: 160px; padding: 10px; }
  .toolbar { padding: 10px 12px; gap: 8px; }
  .btn.tool .lbl { display: none; }
  .btn.tool { padding: 9px 11px; }
  .toolbar .sep { display: none; }
  .canvas-wrap { padding: 12px; }
}

/* ============ Dark theme ============ */
:root[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1c25;
  --surface-2: #232732;
  --border: #2d313e;
  --border-strong: #3a3f4d;
  --text: #e7e9ee;
  --text-muted: #9aa0b0;
  --text-faint: #6b7080;
  --primary: #818cf8;
  --primary-600: #6366f1;
  --primary-50: rgba(129, 140, 248, .15);
  --danger: #f87171;
  --danger-50: rgba(248, 113, 113, .15);
  --success: #4ade80;
  --warn: #fbbf24;
  --shadow: 0 4px 16px rgba(0,0,0,.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.6);
}
:root[data-theme="dark"] body { background: var(--bg); color: var(--text); }
:root[data-theme="dark"] .nav,
:root[data-theme="dark"] .sidebar,
:root[data-theme="dark"] .modal-card,
:root[data-theme="dark"] .drop-zone,
:root[data-theme="dark"] .feature-card,
:root[data-theme="dark"] .toolbar,
:root[data-theme="dark"] .status-bar,
:root[data-theme="dark"] .canvas-wrap,
:root[data-theme="dark"] .find-bar,
:root[data-theme="dark"] .recent-dropdown { background-color: var(--surface); color: var(--text); }
:root[data-theme="dark"] .btn { background: var(--surface-2); border-color: var(--border); color: var(--text); }
:root[data-theme="dark"] .btn:hover { background: var(--surface); border-color: var(--border-strong); }
:root[data-theme="dark"] .btn.primary { background: var(--primary); color: #fff; }
:root[data-theme="dark"] .btn.ghost { background: transparent; }
:root[data-theme="dark"] .btn.danger { background: var(--danger-50); color: var(--danger); border-color: var(--danger); }
:root[data-theme="dark"] .thumb { background: #fff; }
:root[data-theme="dark"] .field input,
:root[data-theme="dark"] .field select,
:root[data-theme="dark"] .field textarea { background: var(--surface-2); color: var(--text); border-color: var(--border); }
:root[data-theme="dark"] .modal { background: rgba(0,0,0,.7); }
:root[data-theme="dark"] .modal-card code { background: var(--surface-2); }
:root[data-theme="dark"] .dz-note { color: var(--text-faint); }
:root[data-theme="dark"] .dz-icon { filter: invert(.9); }
:root[data-theme="dark"] .feature-card { background: var(--surface); border-color: var(--border); }

/* ============ Toasts ============ */
.toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 200;
  display: flex; flex-direction: column-reverse; gap: 10px;
  pointer-events: none;
}
.toast {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  min-width: 220px; max-width: 360px;
  pointer-events: auto;
  animation: toast-in .25s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.toast.fade-out { opacity: 0; transform: translateY(10px); transition: all .25s; }

/* ============ Recent files dropdown ============ */
.recent-dropdown {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  margin-top: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; min-width: 260px; z-index: 50;
  box-shadow: var(--shadow-lg);
}
.recent-dropdown[hidden] { display: none; }
.rd-head { font-size: 12px; font-weight: 700; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
#recentList { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.recent-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border-radius: 8px;
  cursor: pointer; font-size: 13px;
}
.recent-item:hover { background: var(--surface-2); }
.recent-item .ri-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item .ri-date { font-size: 11px; color: var(--text-faint); }

/* ============ Footer section ============ */
.sb-footer { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-top: 10px; border-top: 1px solid var(--border); }

/* ============ Onboarding tour ============ */
.tour-mask {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(15, 23, 42, .45);
  display: grid; place-items: center;
}
.tour-card {
  background: var(--surface); border-radius: 14px;
  padding: 22px; width: min(440px, 92vw);
  box-shadow: var(--shadow-lg);
}
.tour-card h3 { font-size: 16px; margin-bottom: 8px; }
.tour-card p { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin-bottom: 16px; }
.tour-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ============ Inspect diff highlight ============ */
.diff-add { background: rgba(34, 197, 94, .15); color: #16a34a; padding: 1px 3px; border-radius: 3px; }
.diff-del { background: rgba(239, 68, 68, .15); color: #dc2626; text-decoration: line-through; padding: 1px 3px; border-radius: 3px; }
kbd {
  display: inline-block;
  background: var(--surface-2); border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px; font-size: 11px; font-family: monospace;
  color: var(--text);
}

/* ============ Modals ============ */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, .45);
  display: grid; place-items: center;
  backdrop-filter: blur(2px);
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 22px;
  width: min(560px, 92vw);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 12px;
}
.modal-card h3 { font-size: 17px; }
.modal-card .muted { font-size: 13px; color: var(--text-muted); }
.modal-card code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.modal-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--text-muted); flex: 1; min-width: 120px; }
.field input[type="text"], .field input[type="number"] {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px; color: var(--text); font-size: 14px; font-weight: 500;
}
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

/* ============ Crop overlay ============ */
.crop-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(15,23,42,.6);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 20px;
}
.crop-overlay[hidden] { display: none; }
.crop-hint { color: #fff; font-weight: 600; }
#cropCanvas { background: #fff; box-shadow: var(--shadow-lg); cursor: crosshair; max-width: 90vw; max-height: 70vh; }
.crop-actions { display: flex; gap: 10px; }

/* ============ Find bar ============ */
.find-bar {
  position: fixed; top: 120px; right: 24px; z-index: 40;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 6px;
}
.find-bar[hidden] { display: none; }
.find-bar input { border: none; outline: none; font-size: 14px; padding: 4px 8px; width: 200px; background: transparent; }
.find-count { font-size: 12px; color: var(--text-muted); min-width: 50px; }
