*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #5b5fc7;
  --primary-hover: #4a4eb8;
  --primary-light: #eef0fd;
  --sidebar-bg: #1e1e2e;
  --sidebar-width: 72px;
  --header-height: 52px;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --bg-viewer: #525659;
  --bg-page: #ffffff;
  --radius: 8px;
  --shadow-card: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-page: 0 4px 24px rgba(0,0,0,0.35);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #f8f9fb;
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ─── Screens ─────────────────────────────────────────── */
.screen { display: none; height: 100vh; }
.screen.active { display: flex; }

/* ─── Upload Screen ───────────────────────────────────── */
#upload-screen {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: linear-gradient(160deg, #f0f2ff 0%, #fafafa 60%);
  overflow-y: auto;
  padding: 48px 24px;
}

.upload-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 520px;
  width: 100%;
}

.upload-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.brand-icon { display: flex; }

.brand-name {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.upload-heading {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  text-align: center;
  line-height: 1.2;
  letter-spacing: -0.5px;
}

.upload-sub {
  color: var(--text-secondary);
  font-size: 1rem;
  text-align: center;
  line-height: 1.5;
}

/* ─── Recent Files ────────────────────────────────────── */
.recent-files {
  width: 100%;
}

.recent-files.hidden { display: none; }

.recent-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.recent-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.recent-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  transition: border-color 0.15s;
}

.recent-card:hover { border-color: #c7caee; }

.recent-card-icon { flex-shrink: 0; }

.recent-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.recent-card-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-card-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.recent-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.resume-btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 5px 14px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.resume-btn-primary:hover { background: var(--primary-hover); }

.recent-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.recent-delete-btn:hover { background: #fef2f2; color: #ef4444; }

.recent-show-all {
  width: 100%;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  margin-top: 2px;
}

.recent-show-all:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

.drop-zone {
  width: 100%;
  border: 2px dashed #d1d5f0;
  border-radius: 16px;
  background: white;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 4px;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 24px;
}

.drop-icon { margin-bottom: 4px; }

.drop-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.drop-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.upload-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 9px 22px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.upload-btn:hover { background: var(--primary-hover); }

.drop-types {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.upload-features {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 4px;
}

.feature-pill {
  background: white;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 100px;
}

/* ─── Editor Screen ───────────────────────────────────── */
#editor-screen { flex-direction: column; }

/* ─── Header ──────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  height: var(--header-height);
  padding: 0 16px;
  background: white;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
  z-index: 10;
}

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

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

.header-brand-name {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.3px;
}

.header-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}

.header-doc-name {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #f3f4f6;
  border-radius: var(--radius);
  padding: 4px 6px;
  flex-shrink: 0;
}

.zoom-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.zoom-btn:hover {
  background: white;
  color: var(--text-primary);
  box-shadow: var(--shadow-card);
}

.zoom-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 40px;
  text-align: center;
}

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

.header-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  background: white;
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.header-btn:hover {
  background: #f9fafb;
  border-color: #d1d5db;
}

.header-btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.header-btn.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

/* ─── Editor Body ─────────────────────────────────────── */
.editor-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Tool Sidebar ────────────────────────────────────── */
.tool-sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 4px;
  flex-shrink: 0;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 52px;
  padding: 10px 4px;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: #8b8fa8;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.tool-btn span {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.tool-btn:hover {
  background: rgba(255,255,255,0.08);
  color: #c5c8e0;
}

.tool-btn.active {
  background: rgba(91, 95, 199, 0.25);
  color: #a8aaff;
  border: 1px solid rgba(91, 95, 199, 0.4);
}

.tool-danger {
  color: #f87171 !important;
  margin-top: auto;
}

.tool-danger:hover {
  background: rgba(248, 113, 113, 0.1) !important;
  color: #fca5a5 !important;
}

.sidebar-sep {
  width: 32px;
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 4px 0;
}

/* ─── PDF Viewer ──────────────────────────────────────── */
.pages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  background: var(--bg-viewer);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  scroll-behavior: smooth;
}

.page-wrapper {
  position: relative;
  background: white;
  box-shadow: var(--shadow-page);
  border-radius: 2px;
  flex-shrink: 0;
}

.page-wrapper canvas { display: block; }

.annotation-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

.annotation-layer.interactive { pointer-events: all; cursor: crosshair; }

/* ─── Modals ──────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
}

.modal-box {
  position: relative;
  z-index: 1;
  background: white;
  border-radius: 14px;
  width: 540px;
  max-width: 95vw;
  box-shadow: 0 24px 48px rgba(0,0,0,0.2);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.modal-close:hover { background: #f3f4f6; color: var(--text-primary); }

.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
}

.tab-btn {
  padding: 10px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  margin-bottom: -1px;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content { padding: 20px; }
.tab-content.hidden { display: none; }

.sig-canvas-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fafafa;
}

#sig-canvas {
  display: block;
  background: white;
  cursor: crosshair;
  width: 100%;
  touch-action: none;
}

.sig-actions {
  margin-top: 10px;
  display: flex;
}

.ghost-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 5px;
  font-family: inherit;
  transition: all 0.15s;
}

.ghost-btn:hover { background: #f3f4f6; color: var(--text-primary); }

.sig-type-wrap { display: flex; flex-direction: column; gap: 10px; }

.field-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.4;
}

.sig-text-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.sig-text-input:focus { border-color: var(--primary); }

.sig-preview {
  font-family: 'Brush Script MT', 'Dancing Script', cursive;
  font-size: 2.5rem;
  color: #111;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-height: 72px;
  display: flex;
  align-items: center;
}

.modal-body { padding: 20px; }

textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text-primary);
  font-family: inherit;
  resize: vertical;
  outline: none;
  margin-top: 6px;
  transition: border-color 0.15s;
}

textarea:focus { border-color: var(--primary); }

.send-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 500;
  margin-top: 12px;
  line-height: 1.4;
}

.send-notice svg { flex-shrink: 0; margin-top: 1px; }

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--primary);
  color: white;
  border: none;
  padding: 9px 20px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--primary-hover); }

/* ─── Text Format Bar ─────────────────────────────────────── */
.text-format-bar {
  position: fixed;
  display: flex;
  align-items: center;
  gap: 2px;
  background: #1e1e2e;
  border-radius: 8px;
  padding: 4px 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  z-index: 300;
}

.text-format-bar.hidden { display: none; }

.fmt-btn {
  background: transparent;
  border: none;
  color: #c5c8e0;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 5px;
  font-family: inherit;
  transition: all 0.15s;
}

.fmt-btn:hover { background: rgba(255,255,255,0.1); color: white; }

.fmt-size {
  font-size: 0.78rem;
  font-weight: 600;
  color: #8b8fa8;
  min-width: 24px;
  text-align: center;
}

/* ─── Placed Annotations ──────────────────────────────── */
.text-annotation {
  position: absolute;
  background: transparent;
  border: 1.5px dashed var(--primary);
  color: #000;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  padding: 2px 5px;
  cursor: text;
  min-width: 80px;
  min-height: 26px;
  outline: none;
  z-index: 10;
  border-radius: 2px;
  transition: background 0.1s;
}

.text-annotation:focus {
  border-style: solid;
  background: rgba(255,255,255,0.96);
  box-shadow: 0 2px 8px rgba(91,95,199,0.15);
}

.sig-annotation {
  position: absolute;
  cursor: move;
  z-index: 10;
}

.sig-annotation img {
  display: block;
  user-select: none;
  pointer-events: none;
}

/* ─── AcroForm Field Inputs ───────────────────────────── */
.form-field-input {
  position: absolute;
  z-index: 8;
  background: rgba(91, 95, 199, 0.07);
  border: 1.5px solid rgba(91, 95, 199, 0.35);
  border-radius: 2px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: #000;
  padding: 0 4px;
  outline: none;
  cursor: text;
  box-sizing: border-box;
}

.form-field-input:focus {
  background: rgba(91, 95, 199, 0.12);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(91, 95, 199, 0.15);
}

/* ─── Form Detect Toast ───────────────────────────────── */
.form-detect-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e1e2e;
  color: #c5c8e0;
  border-radius: 100px;
  padding: 8px 18px;
  font-size: 0.82rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  animation: fadeInUp 0.3s ease;
}

.form-detect-toast.hidden { display: none; }

/* Signature field boxes (editor) */
.sigfield-box {
  position: absolute;
  border: 2px dashed #5b5fc7;
  background: rgba(91,95,199,0.08);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  z-index: 15;
  pointer-events: all;
}
.sigfield-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #5b5fc7;
  pointer-events: none;
  user-select: none;
}
.sigfield-del {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  border: none;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}
.sigfield-type {
  position: absolute;
  top: -10px;
  left: -10px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #5b5fc7;
  color: #fff;
  border: none;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.sigfield-resize {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 12px;
  color: #5b5fc7;
  cursor: se-resize;
  line-height: 1;
  user-select: none;
}

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

.sig-annotation:hover::after {
  content: '';
  position: absolute;
  inset: -2px;
  border: 1.5px dashed var(--primary);
  border-radius: 2px;
  pointer-events: none;
}
