/* ===================================================================
   DESIGN SYSTEM — CV ATS Studio (v3 : tokens partagés avec l'accueil,
   cartes, responsive mobile-first)
   Tokens identiques à cv-generator/public/index.html — toute modification
   de palette/typo doit être répercutée des deux côtés.
=================================================================== */

:root {
  --bg: #ffffff;
  --bg-page: #ffffff;
  --bg-input: #f5f6f8;
  --bg-input-focus: #eef0f4;
  --ink: #1b2230;
  --title-gray: #4d5566;
  --muted: #6a7180;
  --faint: #9aa1ad;
  --border-tag: #c7cbd4;
  --border-light: #e6e8ee;
  --line: #e6e8ee;
  --accent: #3652f6;
  --accent-ink: #2540e0;
  --accent-soft: #eaefff;

  --success: #17a34a;
  --success-soft: #e9f8ef;
  --danger: #dc2626;
  --danger-soft: #fdecec;

  --font-display: 'Fraunces', Georgia, serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', monospace;
  --font-body: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --font-section: 'Fraunces', Georgia, serif;

  --radius-sm: 6px;
  --radius-md: 9px;
  --radius-lg: 12px;
  --radius-pill: 999px;

  --shadow-card: 0 10px 28px -20px rgba(27,34,48,.28);
  --shadow-card-open: 0 16px 36px -22px rgba(27,34,48,.22);
  --shadow-accent: 0 14px 30px -18px rgba(54,82,246,.45);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg-page);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  /* Même trame technique très discrète que la page d'accueil. */
  background-image: radial-gradient(var(--line) 1px, transparent 1px);
  background-size: 22px 22px;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Barre de marque ---------- */

.app-topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  padding: 0 24px;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand-link {
  display: flex;
  align-items: center;
  gap: 9px;
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  margin: 0 0 0 -6px;
  transition: background .15s ease;
}
.brand-link:hover { background: var(--bg-input); }
.brand-logo { flex-shrink: 0; }
.brand-text {
  font-family: 'Aptos', 'Aptos Display', 'Segoe UI', var(--font-body);
  font-weight: 600;
  font-size: 18px;
  color: var(--ink);
  letter-spacing: 0.01em;
}
.app-topbar .back-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
}

.app {
  display: flex;
  min-height: calc(100vh - 56px);
}

/* ---------- Panneau formulaire ---------- */

.form-panel {
  width: 44%;
  overflow-y: auto;
  padding: 28px 32px 40px;
  background: transparent;
}

/* ---------- Bloc import de CV ---------- */

.import-block {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}
.import-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow .15s ease;
}
.import-label:hover { background: var(--accent-ink); box-shadow: var(--shadow-accent); }
.import-label:active { transform: translateY(1px); }
#import-cv-input { display: none; }
.import-hint {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 10px;
}
.import-status { font-size: 12.5px; margin-top: 8px; min-height: 16px; font-weight: 500; }
.import-status.loading { color: var(--accent-ink); }
.import-status.success { color: var(--success); }
.import-status.error { color: var(--danger); }

.progress-track {
  display: none;
  height: 6px;
  background: var(--bg-input);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-top: 12px;
}
.progress-track.visible { display: block; }
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: var(--radius-pill);
  transition: width 0.2s ease;
}
.progress-track.indeterminate .progress-fill {
  width: 40% !important;
  animation: progress-indeterminate 1.1s ease-in-out infinite;
}
@keyframes progress-indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

/* ---------- Sélecteur de thème ---------- */

.theme-switcher {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}
.theme-label {
  display: block;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 9px;
}
.theme-switcher select {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid transparent;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.theme-switcher select:hover { background: var(--bg-input-focus); }
.theme-switcher select:focus {
  outline: none;
  background: var(--bg-input-focus);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- Sections (cartes, ouverture unique) ---------- */

.sections-container { margin-top: 4px; display: flex; flex-direction: column; gap: 12px; }

.form-section {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 0 20px;
  transition: box-shadow .18s ease, border-color .18s ease, opacity 0.15s ease;
  box-shadow: var(--shadow-card);
}
.form-section:not(.collapsed) {
  border-color: #d7deff;
  box-shadow: var(--shadow-card-open);
}
.form-section.dragging { opacity: 0.4; }

.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 0 16px;
  cursor: pointer;
}

.section-drag-handle {
  flex-shrink: 0;
  color: var(--faint);
  font-size: 15px;
  letter-spacing: -2px;
  cursor: grab;
  user-select: none;
  padding: 4px 2px;
}
.section-drag-handle:active { cursor: grabbing; }

.section-title {
  flex: 1;
  font-family: var(--font-section);
  font-weight: 600;
  font-size: 19px;
  color: var(--title-gray);
  letter-spacing: -0.01em;
  transition: color 0.15s ease;
}
.form-section:not(.collapsed) .section-title { color: var(--ink); }

.form-section.collapsed .section-body { display: none; }

.section-add {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: #ffffff;
  border: 1px solid var(--border-tag);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, color .15s ease;
}
.section-add:hover { background: var(--bg-input); border-color: var(--faint); }
.form-section:not(.collapsed) .section-add {
  transform: rotate(45deg);
  color: var(--accent-ink);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.section-body { padding-bottom: 22px; }

.subsection-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 14px 0 8px;
}

/* ---------- Champs ---------- */

input[type="text"], input[type="email"], input[type="tel"], input[type="date"], select, textarea {
  width: 100%;
  padding: 12px 13px;
  margin-bottom: 10px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-family: var(--font-body);
  font-size: 14.5px;
  color: var(--ink);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:hover, select:hover, textarea:hover {
  border-color: var(--border-tag);
  background: var(--bg-input-focus);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 78px; resize: vertical; line-height: 1.5; }

.field-row { display: flex; gap: 10px; }
.field-row input, .field-row select { flex: 1; min-width: 0; }

.char-counter {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--faint);
  text-align: right;
  margin-top: -6px;
}

/* ---------- Photo (cercle 120x120 avec icône SVG) ---------- */

.photo-upload { margin-bottom: 18px; }

.identity-photo-row {
  display: flex;
  align-items: stretch;
  gap: 16px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.identity-photo-row .photo-upload { margin-bottom: 0; flex-shrink: 0; }
.identity-name-fields {
  flex: 1;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}
.identity-name-fields input { margin-bottom: 10px; }
.identity-name-fields input:last-child { margin-bottom: 0; }

#identite-photo {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.photo-circle {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 1.5px dashed var(--border-tag);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  color: var(--faint);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.photo-circle:hover {
  background: var(--bg-input-focus);
  border-color: var(--accent);
  color: var(--accent);
}
#identite-photo:focus-visible + .photo-circle {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.photo-preview-img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-preview-img.has-photo { display: block; }
.photo-circle.has-photo { border-style: solid; }
.photo-circle.has-photo .photo-icon { display: none; }

.photo-hover-label {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(16, 22, 36, 0.55);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
}
.photo-circle.has-photo:hover .photo-hover-label { display: flex; }

/* ---------- Champs personnalisés ---------- */

.custom-field-row { align-items: center; }

/* ---------- Cartes de listes dynamiques (Terminé + glisser-déposer) ------- */

.entry-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  background: var(--bg-input);
  transition: box-shadow 0.15s ease, opacity 0.15s ease, border-color .15s ease;
}
.entry-card:not(.is-collapsed) { border-color: #d7deff; background: #ffffff; }

.entry-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
}

.entry-summary {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-card-actions { display: flex; gap: 6px; flex-shrink: 0; }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: #ffffff;
  border: 1px solid var(--border-tag);
  color: var(--muted);
  font-size: 14.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { background: var(--bg-input); border-color: var(--faint); }
.btn-toggle-entry { color: var(--success); border-color: #a9dcbb; }
.btn-toggle-entry:hover { background: var(--success-soft); }
.btn-delete-entry:hover { background: var(--danger-soft); border-color: #f3b9b9; color: var(--danger); }

.entry-card-body {
  padding: 4px 17px 18px;
  border-top: 1px solid var(--line);
}
.entry-card.is-collapsed .entry-card-body { display: none; }

.entry-card .field-row { margin-bottom: 8px; }

.date-label {
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 5px;
}
.date-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0 5px;
  flex-wrap: wrap;
  gap: 8px;
}
.date-label-row .date-label { margin: 0; }

/* ---------- Interrupteur (toggle switch) ---------- */

.toggle-switch { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.toggle-switch input { display: none; }
.toggle-slider {
  width: 32px; height: 18px;
  background: var(--border-tag);
  border-radius: var(--radius-pill);
  position: relative;
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  background: white;
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: transform 0.15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(14px); }
.toggle-text { font-size: 11.5px; color: var(--muted); }

.mission-item { display: flex; gap: 6px; margin-bottom: 6px; }
.mission-item input { flex: 1; margin-bottom: 0; }
.mission-item button, .btn-remove-inline {
  background: none; border: none; color: var(--danger); cursor: pointer;
  font-size: 15px; padding: 0 6px; border-radius: var(--radius-sm);
}
.mission-item button:hover, .btn-remove-inline:hover { background: var(--danger-soft); }

.checkbox-row { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink); margin-bottom: 10px; }
.checkbox-row input { width: auto; margin: 0; }

/* ---------- Boutons "tags" (style étiquette cliquable) ---------- */

.btn-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #ffffff;
  color: var(--title-gray);
  border: 1px solid var(--border-tag);
  border-radius: var(--radius-pill);
  padding: 8px 15px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color .15s ease;
}
.btn-tag:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }

.btn-remove {
  display: block;
  margin-top: 6px;
  background: none;
  border: none;
  color: var(--danger);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
}
.btn-remove:hover { text-decoration: underline; }

/* ---------- Compétences (chips) ---------- */

.chips-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  background: var(--bg-input);
  color: var(--title-gray);
  border: 1px solid var(--border-tag);
  padding: 7px 9px 7px 14px;
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 7px;
}
.chip button {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-weight: bold; font-size: 13px; line-height: 1;
}

/* ---------- Langues : zone de saisie plus grande ---------- */

#langues-list .field-row input[type="text"] {
  flex: 2.2;
  padding: 13px 14px;
  font-size: 15.5px;
}
#langues-list .field-row select {
  flex: 1;
  padding: 13px 12px;
  border: 1.5px solid var(--line);
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  color: var(--ink);
}

/* ---------- Actions (bas de formulaire) ---------- */

.actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg-page) 78%, transparent);
  padding: 18px 0 6px;
}
.actions button {
  flex: 1;
  padding: 13px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, box-shadow .15s ease;
}
.actions button:active { transform: translateY(1px); }
#btn-save { background: #ffffff; color: var(--ink); border: 1.5px solid var(--line) !important; }
#btn-save:hover { background: var(--bg-input); border-color: var(--border-tag) !important; }
#btn-download-pdf { background: var(--accent); color: white; }
#btn-download-pdf:hover { background: var(--accent-ink); box-shadow: var(--shadow-accent); }

.status-message {
  font-size: 11.5px;
  margin-top: 8px;
  min-height: 16px;
  color: var(--success);
}
.status-message.error { color: var(--danger); }

/* ---------- Panneau de prévisualisation ---------- */

.preview-panel {
  width: 56%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 24px;
  overflow-y: auto;
  background: #f4f5f7;
  border-left: 1px solid var(--line);
}
.preview-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 14px;
}

/* Le CV interne (rendu dans l'iframe) n'est jamais touché : on ne redimensionne
   que le CONTENEUR de l'aperçu, jamais son contenu, via transform: scale()
   sur l'iframe entière. */
.preview-scale-wrap {
  width: 210mm;
  flex-shrink: 0;
}
#preview-frame {
  width: 210mm;
  height: 297mm;
  border: none;
  background: white;
  box-shadow: var(--shadow-card-open);
  border-radius: 3px;
  display: block;
  transform-origin: top center;
}

/* ---------- Responsive (mobile-first) ---------- */

@media (max-width: 980px) {
  .form-panel { width: 50%; padding: 24px 22px 36px; }
  .preview-panel { width: 50%; padding: 24px 16px; }
}

@media (max-width: 760px) {
  .app { flex-direction: column; min-height: auto; }
  .form-panel, .preview-panel {
    width: 100%;
    overflow-y: visible;
  }
  .form-panel { padding: 20px 18px 28px; order: 1; }
  .preview-panel {
    order: 2;
    border-left: none;
    border-top: 1px solid var(--line);
    padding: 22px 16px 32px;
  }
  .app-topbar { padding: 0 16px; }

  /* L'iframe garde ses dimensions A4 internes (le CV n'est jamais modifié) ;
     seul son affichage est réduit via scale(), dans un conteneur dont la
     hauteur est recalculée pour ne rien rogner. */
  .preview-scale-wrap {
    width: 100%;
    max-width: 420px;
    height: calc(297mm * 0.55);
  }
  #preview-frame { transform: scale(0.55); }
}

@media (max-width: 480px) {
  .app-topbar { height: 52px; }
  .brand-text { font-size: 16px; }
  .form-panel { padding: 16px 14px 24px; }
  .preview-panel { padding: 18px 10px 28px; }

  .field-row { flex-direction: column; gap: 0; }
  .field-row input, .field-row select { width: 100%; }

  #langues-list .field-row { flex-direction: row; }

  .identity-photo-row { flex-direction: column; align-items: flex-start; }

  .section-title { font-size: 17px; }
  .actions { flex-direction: column; }

  .preview-scale-wrap { max-width: 300px; height: calc(297mm * 0.39); }
  #preview-frame { transform: scale(0.39); }
}

@media (prefers-reduced-motion: reduce) {
  .import-label, .section-add, .btn-tag, .icon-btn, .actions button, input, select, textarea {
    transition: none;
  }
}
