/* =========================================================
   Cut — Feuille de style principale
   Layout : 2 colonnes (fiches | visionneuse PDF)
   Design : sobre, ergonomique, lisible
   ========================================================= */

/* --- Variables de design --- */
:root {
  --color-bg:          #f1f5f9;   /* Gris-bleu plus doux, inspiré de la palette Merge */
  --color-surface:     #ffffff;
  --color-border:      #e2e8f0;   /* Bordure plus claire et plus bleue */
  --color-primary:     #2563eb;
  --color-primary-h:   #1d4ed8;
  --color-danger:      #dc2626;
  --color-danger-h:    #b91c1c;
  --color-success:     #16a34a;
  --color-warning:     #d97706;   /* Couleur d'avertissement ajoutée */
  --color-muted:       #94a3b8;   /* Gris ardoise pour éléments atténués */
  --color-text:        #1e293b;
  --color-text-muted:  #64748b;
  --color-thumb-bg:    #e8edf5;
  --color-thumb-hover: #d1daea;
  --color-assigned:    #2563eb;
  --color-multi:       #7c3aed;
  --color-dropzone:    #dbeafe;
  --color-dropzone-b:  #2563eb;
  --color-highlight:   #eff6ff;   /* Fond bleu très léger, inspiré de Merge */
  --color-highlight-b: #dbeafe;   /* Bordure bleutée pour éléments actifs */
  --radius:            10px;      /* Coins plus arrondis, plus modernes */
  --radius-sm:         6px;
  /* Double ombre pour une profondeur plus subtile et élégante */
  --shadow:            0 1px 4px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04);
  --shadow-md:         0 4px 16px rgba(0,0,0,.10), 0 0 0 1px rgba(0,0,0,.04);
  --transition:        .18s ease; /* Légèrement plus lente pour plus de fluidité */
  --col-fiches-w:      320px;
}

/* --- Reset minimal --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* Garantir que l'attribut HTML `hidden` est toujours respecté,
   même quand une règle CSS fixe display sur l'élément. */
[hidden] { display: none !important; }
body {
  /* Ajout de -apple-system pour Safari/macOS + line-height confortable */
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* =========================================================
   HEADER
   ========================================================= */
.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  z-index: 10;
}
.app-header h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: -.6px; /* Chasse resserrée comme les titres Merge */
}
.app-header .mallette-name {
  font-size: 13px;
  color: var(--color-text-muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-load-pdf {
  flex-shrink: 0;
}

/* =========================================================
   LAYOUT PRINCIPAL — 2 colonnes
   ========================================================= */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* =========================================================
   COLONNE GAUCHE — Fiches
   ========================================================= */
.col-fiches {
  width: var(--col-fiches-w);
  min-width: 240px;
  max-width: 420px;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.col-fiches-header {
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.col-fiches-header h2 {
  font-size: 11px;  /* Réduit pour correspondre au style "label de section" de l'exemple */
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px; /* Espacement plus aéré, comme les sidebar-label de l'exemple */
  color: var(--color-muted);
}

.fiches-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

/* --- Carte fiche --- */
.fiche-card {
  margin: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  transition: box-shadow var(--transition), border-color var(--transition);
  overflow: hidden;
}
/* Ombre au survol avec le double effet de l'exemple */
.fiche-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04); }
.fiche-card.active { border-color: var(--color-primary); }

.fiche-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  cursor: pointer;
  user-select: none;
  background: #f8fafc;
}
/* Survol bleuté plutôt que gris, cohérent avec la palette Merge */
.fiche-header:hover { background: var(--color-highlight); }

.fiche-toggle {
  font-size: 11px;
  color: var(--color-text-muted);
  transition: transform var(--transition);
  flex-shrink: 0;
}
.fiche-card.open .fiche-toggle { transform: rotate(90deg); }

.fiche-name-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -.1px; /* Légère compression pour les noms de fiches */
  color: var(--color-text);
  outline: none;
  min-width: 0;
  cursor: text;
}
.fiche-name-input:focus {
  background: #fff;
  border-bottom: 1px solid var(--color-primary);
}

.fiche-count {
  font-size: 11px;
  color: var(--color-text-muted);
  background: var(--color-thumb-bg);
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}

.fiche-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.btn-icon {
  width: 24px; height: 24px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition);
}
/* Survol bleuté comme dans Merge, sauf pour les actions dangereuses */
.btn-icon:hover { background: var(--color-highlight); color: var(--color-primary); }
.btn-icon.danger:hover { background: #fee2e2; color: var(--color-danger); }

/* --- Pages dans la fiche (liste déroulante) --- */
.fiche-pages {
  display: none;
  padding: 6px 8px 8px;
  border-top: 1px solid var(--color-border);
}
.fiche-card.open .fiche-pages { display: block; }

.fiche-pages-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 36px;
  padding: 6px;
  border-radius: var(--radius-sm);
  border: 2px dashed var(--color-border);
  transition: border-color var(--transition), background var(--transition);
}
.fiche-pages-grid.drag-over {
  border-color: var(--color-dropzone-b);
  background: var(--color-dropzone);
}

/* Vignette de page dans la fiche */
.fiche-page-chip {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--color-thumb-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px 5px 2px 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: grab;
  user-select: none;
  transition: background var(--transition);
}
.fiche-page-chip:hover { background: var(--color-thumb-hover); }
.fiche-page-chip .chip-remove {
  width: 14px; height: 14px;
  border: none; background: transparent;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 11px;
  line-height: 1;
  padding: 0;
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
}
.fiche-page-chip .chip-remove:hover { background: #fee2e2; color: var(--color-danger); }

.fiche-empty-hint {
  font-size: 11px;
  color: var(--color-text-muted);
  text-align: center;
  padding: 4px 0;
  width: 100%;
}

/* --- Bouton "Nouvelle fiche" (icône dans le header) --- */
.btn-add-fiche {
  width: 26px;
  height: 26px;
  font-size: 18px;
  color: var(--color-primary);
  flex-shrink: 0;
}
.btn-add-fiche:hover {
  /* Fond bleuté cohérent avec le reste des survols */
  background: var(--color-highlight);
  color: var(--color-primary-h);
}

/* =========================================================
   COLONNE DROITE — Visionneuse PDF
   ========================================================= */
.col-viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Dégradé subtil inspiré de la palette Merge pour donner de la profondeur */
  background: linear-gradient(175deg, var(--color-bg) 55%, #e4ecf7 100%);
}

/* --- Visionneuse principale (page courante) --- */
.pdf-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  padding: 16px;
}

.pdf-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  max-width: 420px;
  padding: 48px 40px;
  /* Bordure bleutée et fond dégradé léger comme les cartes Merge */
  /*
  border: 2.5px dashed var(--color-highlight-b);
  background: linear-gradient(135deg, var(--color-surface) 0%, var(--color-highlight) 100%);
  box-shadow: var(--shadow);
  */
  border-radius: 16px;
  text-align: center;
  transition: border-color var(--transition), background var(--transition);
  cursor: default;
}
.pdf-placeholder.drag-over {
  border-color: var(--color-primary);
  background: var(--color-dropzone);
}
.drop-zone-icon {
  font-size: 56px;
  line-height: 1;
  opacity: .55;
}
.drop-zone-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.5px; /* Chasse Merge : titres plus percutants */
  color: var(--color-text);
}
.drop-zone-or {
  font-size: 13px;
  color: var(--color-text-muted);
  margin: -4px 0;
}
.drop-zone-btn {
  font-size: 14px;
  padding: 9px 22px;
}
.drop-zone-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: -4px;
}

#pdf-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius);
  /* Ombre plus profonde et légèrement bleutée pour le document au premier plan */
  box-shadow: 0 8px 32px rgba(37,99,235,.10), 0 2px 8px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04);
  background: #fff;
  display: block;
}

/* --- Contrôles navigation page --- */
.pdf-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 16px;
  /* Fond légèrement bleuté comme les zones stats de Merge */
  background: #f8fafc;
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}
.pdf-nav-info {
  font-size: 13px;
  font-weight: 600;       /* Plus affirmé, comme les valeurs chiffrées Merge */
  letter-spacing: -.2px;
  color: var(--color-text-muted);
  min-width: 90px;
  text-align: center;
}

/* --- Bandeau vignettes --- */
.pdf-thumbs-bar {
  flex-shrink: 0;
  height: 130px;
  /* Fond légèrement différencié du blanc pur, cohérent avec la nav */
  background: #f8fafc;
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  overflow-x: auto;
  overflow-y: hidden;
}

.pdf-thumb {
  position: relative;
  flex-shrink: 0;
  width: 70px;
  cursor: grab;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  background: var(--color-thumb-bg);
  transition: border-color var(--transition), transform var(--transition);
  user-select: none;
}
/* Survol : ombre bleutée inspirée des cartes Merge */
.pdf-thumb:hover {
  border-color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(37,99,235,.14), 0 0 0 1px rgba(37,99,235,.08);
}
.pdf-thumb.active-page { border-color: var(--color-primary); }
.pdf-thumb.selected {
  border-color: var(--color-primary);
  background: var(--color-highlight);
  /* Double anneau bleu, comme les cartes sélectionnées dans Merge */
  box-shadow: 0 0 0 3px rgba(37,99,235,.22), 0 4px 12px rgba(37,99,235,.12);
}
.pdf-thumb.dragging { opacity: .4; transform: scale(.93); }

.pdf-thumb canvas {
  display: block;
  width: 100%;
  border-radius: 3px;
}

/* Numéro de page sous la vignette */
.thumb-label {
  text-align: center;
  font-size: 10px;
  font-weight: 600;       /* Plus lisible, comme les labels de section Merge */
  letter-spacing: .3px;
  color: var(--color-text-muted);
  padding: 3px 0 2px;
}

/* Badge d'assignation sur la vignette */
.thumb-badge {
  position: absolute;
  top: 3px;
  right: 3px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .2px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  pointer-events: none;
  line-height: 1;
  /* Contour blanc discret pour lisibilité sur tout fond de vignette */
  box-shadow: 0 0 0 1.5px rgba(255,255,255,.7);
}
.thumb-badge.assigned-1 {
  background: var(--color-assigned);
  color: #fff;
}
.thumb-badge.assigned-multi {
  background: var(--color-multi);
  color: #fff;
}

/* =========================================================
   BARRE D'ACTIONS — bas de page
   ========================================================= */
.app-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 8px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 10px;
}

/* =========================================================
   BOUTONS génériques
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--color-primary-h); }

.btn-secondary {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-secondary:hover:not(:disabled) { background: var(--color-thumb-bg); }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--color-danger-h); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-muted);
}
.btn-ghost:hover:not(:disabled) { background: var(--color-thumb-bg); color: var(--color-text); }

/* =========================================================
   TOOLTIP
   ========================================================= */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s;
  z-index: 100;
  max-width: 240px;
  white-space: normal;
  text-align: center;
}
[data-tooltip]:hover::after { opacity: 1; }

/* =========================================================
   ÉTAT VIDE (aucun PDF chargé)
   ========================================================= */
.state-no-pdf .col-fiches,
.state-no-pdf .pdf-nav,
.state-no-pdf .pdf-thumbs-bar,
.state-no-pdf .btn-save,
.state-no-pdf .btn-add-fiche,
.state-no-pdf .btn-load-spec { opacity: .4; pointer-events: none; }

/* =========================================================
   SCROLLBAR personnalisée (Webkit)
   ========================================================= */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
/* Couleur de la poignée alignée avec la nouvelle palette bleutée */
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
