/* ============================================================
   OpenDocTools — style.css
   Aesthetic: Technical-Refined Dark UI with Teal Accents
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&family=Sora:wght@400;500;600;700&display=swap');

/* ---- Variables ---- */
:root {
  --bg-base:      #0d0f14;
  --bg-surface:   #13161e;
  --bg-raised:    #1c2030;
  --bg-hover:     #242840;
  --border:       rgba(255,255,255,0.07);
  --border-focus: rgba(0, 212, 170, 0.5);

  --text-primary:   #eef0f6;
  --text-secondary: #8892a4;
  --text-muted:     #4a5468;

  --accent:         #00d4aa;
  --accent-dim:     rgba(0, 212, 170, 0.15);
  --accent-glow:    0 0 20px rgba(0, 212, 170, 0.25);

  --danger:         #ff4d6a;
  --danger-dim:     rgba(255, 77, 106, 0.15);
  --warn:           #f0b429;

  --sidebar-w:      220px;
  --toolbar-h:      56px;
  --radius:         8px;
  --radius-sm:      5px;
  --radius-lg:      12px;
  --shadow-md:      0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg:      0 8px 48px rgba(0,0,0,0.6);

  --font-ui:   'Sora', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --transition: 0.18s cubic-bezier(0.4,0,0.2,1);
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; height: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   INSTALL BANNER
   ============================================================ */
.install-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  background: linear-gradient(90deg, var(--accent-dim), transparent);
  border-bottom: 1px solid var(--border-focus);
  font-size: 0.85rem;
  color: var(--text-secondary);
  animation: slideDown 0.3s ease;
}
.install-banner span { flex: 1; }

@keyframes slideDown { from { transform: translateY(-100%); opacity:0; } to { transform: none; opacity:1; } }

/* ============================================================
   TOOLBAR
   ============================================================ */
.toolbar {
  height: var(--toolbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  margin-right: 8px;
}
.brand-icon { width: 28px; height: 28px; }
.brand-name {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  white-space: nowrap;
}
.brand-badge {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  padding: 2px 7px;
  border-radius: 99px;
  border: 1px solid var(--accent);
  color: var(--accent);
  opacity: 0.8;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.toolbar-actions::-webkit-scrollbar { display: none; }

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

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

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 8px;
  border-left: 1px solid var(--border);
  padding-left: 12px;
}
.zoom-label {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  min-width: 40px;
  text-align: center;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition), opacity var(--transition);
  outline: none;
  position: relative;
}
.btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.8; flex-shrink: 0; }

.btn:focus-visible { box-shadow: 0 0 0 2px var(--accent); }

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  color: #0a0f0d;
  font-weight: 600;
}
.btn-primary:hover { background: #00f0c0; box-shadow: var(--accent-glow); }

.btn-accent {
  background: var(--accent);
  color: #0a0f0d;
  font-weight: 600;
}
.btn-accent:hover { background: #00f0c0; box-shadow: var(--accent-glow); }

.btn-secondary {
  background: var(--bg-raised);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-focus); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-raised); color: var(--text-primary); }

.btn-icon {
  padding: 6px 9px;
  font-size: 1rem;
  line-height: 1;
}
.btn-sm { padding: 4px 10px; font-size: 0.75rem; }
.btn-full { width: 100%; justify-content: center; }

.btn.tool-toggle.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
  border: 1px solid;
  box-shadow: var(--accent-glow);
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

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

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-title { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
.sidebar-count { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); }

.thumbnails {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.empty-sidebar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
}
.empty-sidebar svg { width: 48px; opacity: 0.3; }
.empty-sidebar p { font-size: 0.8rem; line-height: 1.6; }

/* Thumbnail Item */
.thumb-item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
  background: var(--bg-raised);
  flex-shrink: 0;
}
.thumb-item:hover { border-color: var(--border-focus); transform: scale(1.01); }
.thumb-item.active { border-color: var(--accent); box-shadow: var(--accent-glow); }
.thumb-item canvas { display: block; width: 100%; height: auto; }
.thumb-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  padding: 3px;
  background: rgba(13,15,20,0.7);
}

/* Merge Queue */
.merge-queue {
  border-top: 1px solid var(--border);
  padding: 10px 10px 12px;
  flex-shrink: 0;
  background: var(--bg-base);
}
.merge-queue-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.merge-count { color: var(--accent); font-family: var(--font-mono); }
.merge-file-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; max-height: 120px; overflow-y: auto; }
.merge-file-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding: 4px 6px;
  background: var(--bg-raised);
  border-radius: var(--radius-sm);
}
.merge-file-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.merge-file-item .remove-merge { cursor: pointer; color: var(--danger); font-size: 0.85rem; flex-shrink: 0; }
.merge-queue-actions { display: flex; flex-direction: column; gap: 4px; }

/* ============================================================
   VIEWER AREA
   ============================================================ */
.viewer-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: #080a0f;
  background-image:
    radial-gradient(circle at 20% 20%, rgba(0,212,170,0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(0,100,200,0.03) 0%, transparent 50%);
}

/* Drop Zone */
.drop-zone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background var(--transition);
}
.drop-zone.drag-over { background: rgba(0,212,170,0.05); }
.drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 40px;
  border: 2px dashed rgba(0,212,170,0.2);
  border-radius: 24px;
  text-align: center;
  max-width: 400px;
  transition: border-color var(--transition);
}
.drop-zone.drag-over .drop-zone-content { border-color: var(--accent); }
.drop-zone-content svg { width: 64px; height: 64px; }
.drop-zone-content h2 { font-size: 1.3rem; font-weight: 600; color: var(--text-primary); }
.drop-zone-content p { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5; }
.drop-note { font-size: 0.72rem !important; color: var(--text-muted) !important; font-family: var(--font-mono); }

/* Canvas Container */
.canvas-container {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  position: relative;
}

/* ============================================================
   CANVAS WRAPPER — KEY FIX
   Both pdf-canvas and fabric-canvas live inside this wrapper.
   The wrapper sizes to match the PDF canvas exactly, and
   fabric-canvas overlays it precisely using position:absolute.
   ============================================================ */
.canvas-wrapper {
  position: relative;
  display: inline-block;
  line-height: 0; /* removes phantom space under canvas */
  flex-shrink: 0;
}

#pdf-canvas {
  display: block;
  border-radius: 4px;
  box-shadow: 0 8px 48px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.05);
  position: relative;
  z-index: 1;
}

/* Fabric canvas container (generated by fabric.js) */
.canvas-wrapper .canvas-container,
#fabric-canvas,
.canvas-wrapper > canvas:nth-child(2) {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  z-index: 2;
  pointer-events: none;
  border-radius: 4px;
}

/* fabric.js wraps canvas in a div.canvas-container — override its inline styles */
.canvas-wrapper .upper-canvas {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  pointer-events: none;
  border-radius: 4px;
}

/* When annotation tool is active, enable pointer events on fabric overlay */
.canvas-wrapper.active .upper-canvas,
.canvas-wrapper.active .canvas-container {
  pointer-events: all !important;
  cursor: crosshair;
}

/* For signature mode (drag), use default cursor */
.canvas-wrapper.active.sign-mode .upper-canvas {
  cursor: default;
}

/* Page Navigation */
.page-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.page-indicator {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.page-sep { color: var(--text-muted); }

/* Status Bar */
.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
  background: var(--bg-base);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  flex-shrink: 0;
}
#tool-status { flex: 1; }

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8,10,15,0.85);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s cubic-bezier(0.34,1.56,0.64,1);
  overflow: hidden;
}
.modal-wide { max-width: 760px; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1rem; font-weight: 600; }

.modal-hint { padding: 10px 20px; font-size: 0.8rem; color: var(--text-secondary); }

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-btn-row { display: flex; justify-content: flex-end; gap: 8px; }
.modal-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; }
.modal-label { font-size: 0.78rem; color: var(--text-secondary); white-space: nowrap; }

/* Modal Tabs */
.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
  border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; padding: 16px 20px; }
.tab-content.active { display: block; }

/* Signature Canvas */
#sig-canvas {
  display: block;
  background: #f8f8f0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: crosshair;
  width: 100%;
  max-width: 480px;
  touch-action: none;
}

/* Typed Signature */
.type-sig-preview {
  background: #f8f8f0;
  border-radius: var(--radius-sm);
  padding: 24px;
  text-align: center;
  font-size: 2rem;
  color: #111;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Dancing Script', cursive;
  margin-bottom: 12px;
}
.sig-text-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  outline: none;
  margin-bottom: 10px;
}
.sig-text-input:focus { border-color: var(--border-focus); }
.sig-font-row { display: flex; gap: 6px; }
.sig-font-btn {
  flex: 1;
  padding: 6px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
}
.sig-font-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* Signer Row */
.signer-row { display: flex; align-items: center; gap: 8px; }
.input-sm {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  outline: none;
}
.input-sm:focus { border-color: var(--border-focus); }

/* Split Options */
.split-options { display: flex; align-items: center; gap: 10px; padding: 0 20px 12px; }
.split-total { color: var(--text-muted); font-size: 0.8rem; }
.split-preview { padding: 0 20px 16px; font-size: 0.82rem; color: var(--accent); font-family: var(--font-mono); }

/* Reorder Grid */
.reorder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  padding: 0 20px 16px;
  max-height: 400px;
  overflow-y: auto;
}
.reorder-item {
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: grab;
  transition: border-color var(--transition), transform var(--transition);
  background: var(--bg-raised);
  user-select: none;
}
.reorder-item:hover { border-color: var(--accent); transform: scale(1.02); }
.reorder-item.dragging { opacity: 0.5; cursor: grabbing; }
.reorder-item.drag-over { border-color: var(--accent); box-shadow: var(--accent-glow); }
.reorder-item canvas { display: block; width: 100%; }
.reorder-label { font-size: 0.65rem; font-family: var(--font-mono); text-align: center; padding: 3px; color: var(--text-muted); }

/* ============================================================
   TOAST
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.82rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: all;
  min-width: 220px;
  max-width: 340px;
}
.toast.success { border-left: 3px solid var(--accent); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--warn); }
.toast.fade-out { animation: toastOut 0.25s ease forwards; }
@keyframes toastIn  { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateX(20px); } }
.toast-icon { font-size: 1rem; }

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8,10,15,0.75);
  backdrop-filter: blur(4px);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--bg-raised);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

input[type="color"] {
  width: 32px; height: 28px;
  padding: 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  cursor: pointer;
}
input[type="range"] { accent-color: var(--accent); }
input[type="number"].input-sm {
  width: 72px;
  -moz-appearance: textfield;
  text-align: center;
}
input[type="number"].input-sm::-webkit-inner-spin-button { opacity: 0.5; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  :root { --sidebar-w: 160px; }
  .toolbar { overflow-x: auto; }
  .brand-badge { display: none; }
}
@media (max-width: 640px) {
  .sidebar { width: 120px; }
  .toolbar-actions .btn span { display: none; }
  .toolbar-actions .btn svg { margin: 0; }
}
