/* ═══════════════════════════════════════════
   VARIABLES ET RESET
═══════════════════════════════════════════ */
:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #22263a;
  --accent: #4f8ef7;
  --accent2: #7c3aed;
  --success: #22c55e;
  --danger: #ef4444;
  --text: #e8eaf0;
  --text2: #8892a4;
  --border: #2d3348;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ═══════════════════════════════════════════
   NAVBAR
═══════════════════════════════════════════ */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 60px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  letter-spacing: -0.5px;
}

.logo-icon {
  font-size: 1.5rem;
  color: var(--accent);
}

.nav-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text2);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text2);
  animation: pulse 2s infinite;
}

.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ═══════════════════════════════════════════
   ÉCRAN D'UPLOAD
═══════════════════════════════════════════ */
.upload-screen {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: radial-gradient(ellipse at 50% 0%, #1a2340 0%, var(--bg) 70%);
}

.upload-card {
  text-align: center;
  max-width: 560px;
  width: 100%;
}

.upload-icon { font-size: 4rem; margin-bottom: 1.5rem; }

.upload-title {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -1px;
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, #fff 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.upload-subtitle {
  color: var(--text2);
  line-height: 1.7;
  margin-bottom: 2rem;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  transition: all 0.3s;
  cursor: pointer;
  background: var(--bg2);
  margin-bottom: 1rem;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(79, 142, 247, 0.05);
}

.drop-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  color: var(--accent);
}

.drop-text {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.drop-or {
  color: var(--text2);
  margin: 0.75rem 0;
  font-size: 0.9rem;
}

.btn-upload {
  display: inline-block;
  padding: 0.7rem 2rem;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-upload:hover { background: #3a7ae0; transform: translateY(-1px); }

.upload-note {
  font-size: 0.8rem;
  color: var(--text2);
}

/* ═══════════════════════════════════════════
   ÉCRAN D'ÉDITION
═══════════════════════════════════════════ */
.editor-screen {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}

.btn-back {
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 0.4rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.btn-back:hover { border-color: var(--accent); color: var(--text); }

.file-name {
  flex: 1;
  font-size: 0.95rem;
  color: var(--text2);
  text-align: center;
}

.btn-download {
  background: var(--success);
  color: white;
  border: none;
  padding: 0.5rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.btn-download:hover:not(:disabled) {
  background: #16a34a;
  transform: translateY(-1px);
}

.btn-download:disabled {
  background: var(--bg3);
  color: var(--text2);
  cursor: not-allowed;
}

/* ─── Layout principal ─── */
.editor-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Colonne PDF ─── */
.pdf-viewer-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: auto;
  background: #080a10;
  padding: 1rem;
}

.pdf-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  background: #080a10;
  padding: 0.5rem 0;
  z-index: 10;
}

.btn-page {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-page:hover:not(:disabled) { border-color: var(--accent); }
.btn-page:disabled { opacity: 0.3; cursor: not-allowed; }

.page-info { color: var(--text2); font-size: 0.9rem; }

/* Boutons de contrôle (zoom, rotation) */
.btn-control {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-control:hover { 
  border-color: var(--accent); 
  background: var(--accent);
  color: white;
}

.controls-separator {
  color: var(--border);
  margin: 0 0.5rem;
}

.zoom-info {
  color: var(--text2);
  font-size: 0.85rem;
  min-width: 50px;
  text-align: center;
}

.canvas-wrapper {
  position: relative;
  display: inline-block;
  margin: 0 auto;
  box-shadow: var(--shadow);
  /* Permettre le scroll quand zoomé */
  min-width: fit-content;
}

#pdfCanvas {
  display: block;
  /* Le canvas ne doit pas être limité */
}

/* Calque par-dessus le canvas pour les zones cliquables */
.text-overlay {
  position: absolute;
  top: 0; 
  left: 0;
  /* Dimensions gérées dynamiquement par JS */
  pointer-events: none;
}

/* Zone de texte cliquable individuelle */
.text-zone {
  position: absolute;
  border: 1px solid rgba(79, 142, 247, 0.3);
  background: rgba(79, 142, 247, 0.05);
  border-radius: 2px;
  cursor: pointer;
  pointer-events: all;
  transition: all 0.15s;
}

.text-zone:hover {
  background: rgba(79, 142, 247, 0.2);
  border-color: var(--accent);
}

.text-zone.selected {
  background: rgba(79, 142, 247, 0.25);
  border-color: var(--accent);
  border-width: 2px;
}

/* ─── Panneau d'édition ─── */
.editor-panel {
  width: 320px;
  min-width: 320px;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1.5rem;
  gap: 1.5rem;
}

.panel-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Formulaire d'édition */
.edit-form {
  background: var(--bg3);
  border-radius: var(--radius);
  padding: 1.25rem;
  border: 1px solid var(--border);
}

.form-group { margin-bottom: 1rem; }

.form-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text2);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.original-text {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-size: 0.95rem;
  color: var(--accent);
  word-break: break-all;
}

.form-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

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

.btn-apply {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 0.5rem;
  transition: all 0.2s;
}

.btn-apply:hover { background: #3a7ae0; }

.btn-cancel {
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.btn-cancel:hover { border-color: var(--danger); color: var(--danger); }

/* Hint panneau */
.panel-hint {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.hint-icon { font-size: 2rem; margin-bottom: 0.75rem; }
.hint-sub { font-size: 0.8rem; margin-top: 0.5rem; opacity: 0.6; }

/* Liste modifications */
.modifications-list { flex: 1; }

.no-mods {
  color: var(--text2);
  font-size: 0.85rem;
  font-style: italic;
}

.mod-item {
  background: var(--bg3);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  border-left: 3px solid var(--success);
  font-size: 0.85rem;
}

.mod-old { color: var(--danger); text-decoration: line-through; }
.mod-new { color: var(--success); }
.mod-arrow { color: var(--text2); margin: 0 4px; }

/* ═══════════════════════════════════════════
   LOADING & NOTIFICATIONS
═══════════════════════════════════════════ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  gap: 1rem;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text { color: var(--text2); font-size: 0.9rem; }

.notification {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 1000;
  box-shadow: var(--shadow);
  animation: slideUp 0.3s ease;
}

.notification.success { border-color: var(--success); color: var(--success); }
.notification.error { border-color: var(--danger); color: var(--danger); }

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

/* ═══════════════════════════════════════════
   ÉCRAN DE PRÉPARATION IMAGE
═══════════════════════════════════════════ */
.prep-screen {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--bg);
}

.prep-container {
  text-align: center;
  max-width: 800px;
  width: 100%;
}

.prep-title {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.prep-subtitle {
  color: var(--text2);
  margin-bottom: 1.5rem;
}

.prep-preview {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
  max-height: 60vh;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

#prepCanvas {
  max-width: 100%;
  max-height: 55vh;
  border-radius: 4px;
}

.prep-controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.btn-control-lg {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-control-lg:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.prep-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.btn-cancel-prep {
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
}

.btn-cancel-prep:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.btn-start-ocr {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.75rem 2rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-start-ocr:hover {
  background: #3a7ae0;
  transform: translateY(-1px);
}

/* ═══════════════════════════════════════════
   OPTIMISATION MOBILE — CSS UNIQUEMENT
   (aucun changement JS ou HTML)
═══════════════════════════════════════════ */

@media (max-width: 768px) {

  /* Layout : empiler PDF et panneau verticalement */
  .editor-main {
    flex-direction: column;
  }

  /* Panneau passe en bas, hauteur fixe */
  .editor-panel {
    width: 100%;
    min-width: unset;
    height: 320px;
    min-height: 320px;
    border-left: none;
    border-top: 1px solid var(--border);
    overflow-y: auto;
  }

  /* PDF prend la place restante */
  .pdf-viewer-col {
    flex: 1;
    min-height: 0;
  }

  /* Toolbar compacte */
  .editor-toolbar {
    padding: 0 0.5rem;
    gap: 0.4rem;
  }

  .btn-back {
    font-size: 0.78rem;
    padding: 0.4rem 0.6rem;
    white-space: nowrap;
  }

  .file-name {
    font-size: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .btn-download {
    font-size: 0.75rem;
    padding: 0.4rem 0.6rem;
    white-space: nowrap;
  }

  /* Eviter le zoom auto iOS sur les inputs */
  .form-input {
    font-size: 1rem;
  }

  /* Upload : taille adaptée */
  .upload-title {
    font-size: 1.8rem;
  }

  .dropzone {
    padding: 2rem 1rem;
  }
}

@media (max-width: 480px) {
  /* Masquer le nom de fichier sur très petit écran */
  .file-name {
    display: none;
  }

  .editor-panel {
    height: 280px;
    min-height: 280px;
    padding: 1rem;
  }

  .upload-title {
    font-size: 1.5rem;
  }
}
