/* ============================================================
   CopyPaste Any PDF — style.css
   Scandinavian minimal design: clean, functional, generous space
   ============================================================ */

/* ── CSS Custom Properties ─────────────────────────────────── */
:root {
  --bg:          #F9F9F7;
  --surface:     #FFFFFF;
  --border:      #E4E4E0;
  --border-hover:#C8C8C2;
  --text:        #18181B;
  --text-muted:  #71717A;
  --text-light:  #A1A1AA;
  --accent:      #2563EB;
  --accent-hover:#1D4ED8;
  --accent-light:#EFF6FF;
  --success:     #059669;
  --success-bg:  #ECFDF5;
  --error:       #DC2626;
  --error-bg:    #FEF2F2;
  --warn-bg:     #FFFBEB;
  --warn:        #D97706;
  --shadow-sm:   0 1px 2px rgba(0,0,0,.04), 0 1px 6px rgba(0,0,0,.04);
  --shadow-md:   0 4px 12px rgba(0,0,0,.06), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg:   0 20px 40px rgba(0,0,0,.10), 0 4px 12px rgba(0,0,0,.06);
  --radius:      12px;
  --radius-sm:   8px;
  --radius-xs:   6px;
  --transition:  150ms ease;
  --max-w:       760px;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Utilities ─────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.text-muted { color: var(--text-muted); }
.container { width: 100%; max-width: var(--max-w); margin: 0 auto; padding: 0 24px; }

/* ── Header ─────────────────────────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.logo-mark { flex-shrink: 0; }

.logo-text {
  font-size: 16px;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--text);
}

.logo-text strong {
  font-weight: 600;
}

.btn-support {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-support:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--bg);
}

/* ── Main ────────────────────────────────────────────────────── */
.main {
  flex: 1;
  padding: 64px 0 80px;
}

/* ── Hero ─────────────────────────────────────────────────── */
.hero {
  text-align: center;
  margin-bottom: 40px;
}

.hero h1 {
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text);
  margin-bottom: 12px;
}

.hero-sub {
  font-size: 16px;
  color: var(--text-muted);
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.65;
}

/* ── Dropzone ─────────────────────────────────────────────── */
.dropzone {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 56px 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  outline: none;
  position: relative;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-light);
}

.dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: scale(1.005);
}

.dropzone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

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

.drop-title {
  font-size: 17px;
  font-weight: 500;
  color: var(--text);
}

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

.file-link {
  color: var(--accent);
  cursor: pointer;
  font-weight: 500;
  pointer-events: all;
  text-decoration: none;
}

.file-link:hover { text-decoration: underline; }

.drop-hint {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 2px;
}

/* ── Error Message ─────────────────────────────────────────── */
.error-message {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--error-bg);
  border: 1px solid #FECACA;
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}

/* ── How It Works ─────────────────────────────────────────── */
.how-it-works {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 40px;
  flex-wrap: wrap;
}

.step {
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--text);
  color: white;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.step-arrow {
  color: var(--border-hover);
  font-size: 18px;
  line-height: 1;
}

/* ── Privacy Note ─────────────────────────────────────────── */
/* ── Trust Badges ────────────────────────────────────────── */
.trust-badges {
  display: flex;
  justify-content: center;
  gap: 0;
  margin-top: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.trust-badge {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 12px;
  text-align: center;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.trust-badge:last-child {
  border-right: none;
}

.trust-badge svg {
  color: var(--text-muted);
  flex-shrink: 0;
  margin-bottom: 2px;
}

.trust-badge strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.trust-badge span {
  font-size: 12px;
  color: var(--text-light);
  line-height: 1.3;
}

@media (max-width: 600px) {
  .trust-badges {
    flex-direction: column;
    border-radius: var(--radius-sm);
  }
  .trust-badge {
    flex-direction: row;
    text-align: left;
    gap: 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
  }
  .trust-badge:last-child { border-bottom: none; }
  .trust-badge svg { margin-bottom: 0; }
  .trust-badge > div { display: flex; flex-direction: column; gap: 2px; }
}

/* ── OCR Language Selector ───────────────────────────────── */
.ocr-lang-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}

.ocr-lang-row svg {
  color: var(--text-light);
  flex-shrink: 0;
}

.ocr-lang-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: default;
}

.ocr-lang-select {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}

.ocr-lang-select:focus {
  border-color: var(--accent);
}

.ocr-lang-hint {
  font-size: 12px;
  color: var(--text-light);
  margin-left: auto;
}

@media (max-width: 600px) {
  .ocr-lang-hint { display: none; }
  .ocr-lang-row  { gap: 10px; }
}

/* ── OCR Result Badge ────────────────────────────────────── */
.ocr-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  background: #EFF6FF;
  color: var(--accent);
  border: 1px solid #BFDBFE;
  width: fit-content;
  margin-bottom: 4px;
}

.ocr-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* ── OCR Region Select ───────────────────────────────────── */

/* Crosshair cursor + blocked text-selection while drawing */
.viewer-container.ocr-region-mode .pdf-page-wrapper {
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

.viewer-container.ocr-region-mode .textLayer {
  pointer-events: none; /* don't intercept drag while in region mode */
}

/* Dashed selection rectangle drawn over the canvas */
.ocr-selection-rect {
  position: absolute;
  border: 2px dashed var(--accent);
  background: rgba(37, 99, 235, 0.08);
  border-radius: 2px;
  pointer-events: none;
  z-index: 10;
  width: 0;
  height: 0;
}

.ocr-selection-rect.processing {
  border-color: var(--accent);
  animation: ocr-rect-pulse 1s ease-in-out infinite;
}

@keyframes ocr-rect-pulse {
  0%, 100% { background: rgba(37, 99, 235, 0.08); }
  50%       { background: rgba(37, 99, 235, 0.22); }
}

/* Spinner shown inside the rect while OCR is running */
.ocr-region-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border: 2.5px solid rgba(37, 99, 235, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  background: rgba(255,255,255,0.7);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

/* Hide spinner when rect is too small to show it */
.ocr-selection-rect:not(.processing) .ocr-region-spinner {
  display: none;
}

/* Hint bar below viewer */
.ocr-region-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--accent-light);
  border: 1px solid #BFDBFE;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}

.ocr-region-hint svg { flex-shrink: 0; }

.ocr-region-cancel {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color var(--transition);
}
.ocr-region-cancel:hover { text-decoration-color: currentColor; }

/* Active state for the toggle button */
.btn.active,
.btn-outline.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── OCR Result Panel ────────────────────────────────────── */
.ocr-result-panel {
  position: fixed;
  z-index: 250;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ocr-result-panel.hidden { display: none !important; }

.ocr-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.ocr-result-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ocr-result-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ocr-result-copy {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--text);
  color: white;
  border: none;
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.ocr-result-copy:hover { background: #333; }

.ocr-result-close {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all var(--transition);
}
.ocr-result-close:hover { background: var(--border); color: var(--text); }

.ocr-result-textarea {
  width: 100%;
  min-height: 120px;
  max-height: 280px;
  padding: 12px 14px;
  border: none;
  outline: none;
  resize: vertical;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--surface);
}

/* ── Processing Card ─────────────────────────────────────── */
.processing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 64px 32px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.processing-card h2 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.processing-card p {
  font-size: 14px;
  margin-bottom: 28px;
}

/* Spinner */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 24px;
}

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

/* Progress bar */
.progress-track {
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  max-width: 280px;
  margin: 0 auto;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  width: 0%;
  transition: width 250ms ease;
}

/* ── Result Header ───────────────────────────────────────── */
.result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.result-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #A7F3D0;
  width: fit-content;
  margin-bottom: 4px;
}

.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.status-badge.warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: #FDE68A;
}

.result-filename {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  word-break: break-all;
}

.result-info {
  font-size: 13px;
}

.result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
}

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

.btn-primary:hover {
  background: #333;
  border-color: #333;
}

.btn-outline {
  background: white;
  color: var(--text);
  border-color: var(--border);
}

.btn-outline:hover {
  border-color: var(--border-hover);
  background: var(--bg);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

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

/* ── PDF Viewer ──────────────────────────────────────────── */
.viewer-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  width: 100%;
  overflow-x: auto;
}

.pdf-page-wrapper {
  position: relative;
  background: white;
  box-shadow: var(--shadow-md);
  border-radius: 4px;
  overflow: hidden;
  user-select: text;
  max-width: 100%;
}

.pdf-page-wrapper canvas {
  display: block;
  /* No CSS scaling — scale is computed precisely in JS so canvas
     and text-layer always share the same pixel dimensions. */
}

.pdf-page-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  min-width: 400px;
  background: #F4F4F2;
  color: var(--text-light);
  font-size: 13px;
}

/* ── PDF Text Layer ──────────────────────────────────────── */
.textLayer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: visible; /* do NOT clip — spans must not be cut off */
  line-height: 1;
  z-index: 2;
  user-select: text;
  -webkit-user-select: text;
}

.textLayer > span,
.textLayer > div {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  user-select: text;
  -webkit-user-select: text;
}

.textLayer ::selection {
  background: rgba(37, 99, 235, 0.25);
  color: transparent;
}

.textLayer ::-moz-selection {
  background: rgba(37, 99, 235, 0.25);
  color: transparent;
}

/* ── Donation Modal ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 200ms ease;
}

.modal-overlay.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  position: relative;
  animation: slideUp 250ms ease;
}

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

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--bg);
  color: var(--text);
}

.modal-body {
  padding: 36px 32px 28px;
  text-align: center;
}

.modal-coffee {
  font-size: 36px;
  margin-bottom: 12px;
  display: block;
}

.modal-body h3 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.modal-body > .text-muted {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 24px;
}

/* Donation amount grid */
.amount-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.amount-btn {
  padding: 10px 0;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
}

.amount-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.amount-btn.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.custom-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  margin-bottom: 16px;
  transition: border-color var(--transition);
  outline: none;
}

.custom-input:focus {
  border-color: var(--accent);
}

.custom-input.hidden { display: none !important; }

/* Ko-fi button */
.btn-kofi {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 13px 20px;
  background: #29ABE0;
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), transform var(--transition);
  margin-top: 8px;
  margin-bottom: 12px;
}

.btn-kofi:hover {
  background: #22A0D5;
  transform: translateY(-1px);
}

.btn-kofi:active {
  transform: translateY(0);
}

.modal-note {
  font-size: 12px;
  opacity: 0.8;
}

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--text);
  color: white;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 250ms ease, transform 250ms ease;
  z-index: 300;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Footer ──────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  margin-top: auto;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
}

.footer-copy {
  font-size: 13px;
  text-align: center;
}

.footer-support-link {
  background: none;
  border: none;
  font-family: inherit;
  font-size: inherit;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  transition: color var(--transition);
  text-decoration: underline;
  text-decoration-color: transparent;
}

.footer-support-link:hover {
  color: var(--text);
  text-decoration-color: currentColor;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 600px) {
  .main { padding: 40px 0 60px; }

  .hero h1 { font-size: 26px; }
  .hero-sub { font-size: 15px; }

  .dropzone { padding: 40px 20px; }

  .how-it-works {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
    padding: 0 4px;
  }

  .step-arrow { display: none; }

  .result-header { flex-direction: column; }

  .result-actions { width: 100%; }

  .btn { width: 100%; justify-content: center; }

  .amount-grid { grid-template-columns: repeat(2, 1fr); }

  .modal-body { padding: 28px 20px 24px; }
}

@media (max-width: 400px) {
  .container { padding: 0 16px; }
}
