/* =========================================================
   PROJET GORDES — zzz_visualisation.css
   ---------------------------------------------------------
   Feuille dédiée à l'espace de visualisation D3.js :
   1) page d'introduction à la visualisation
   2) barre de modes (tomes, dates, lieux, auteurs)
   3) treemap principal
   4) panneau latéral de détails
   5) état de chargement / spinner
   ---------------------------------------------------------
   Principes :
   - limiter les redéfinitions
   - fusionner layout, canevas et panneau latéral
   - préserver un rendu sobre orienté recherche documentaire
   ========================================================= */


/* =========================================================
   1. PAGE DE VISUALISATION — GABARIT GLOBAL
   ---------------------------------------------------------
   Largeur utile, introduction et respiration générale.
   ========================================================= */

/* =========================================================
   FORMULAIRE DE SAISIE D’UNE LETTRE
   ========================================================= */

#postForm,
.lettre-form {
  max-width: 1180px;
  margin: 28px auto 40px auto;
  padding: 0 12px;
  box-sizing: border-box;
}

#postForm table,
.lettre-form table {
  width: 100%;
  margin: 0;
  border: 1px solid #ddd6cb;
  border-radius: 18px;
  overflow: hidden;
  background: #fcfbf9;
  box-shadow: 0 4px 16px rgba(0,0,0,.05);
  border-collapse: separate;
  border-spacing: 0;
  font-family: "Source Sans Pro", Arial, sans-serif;
  font-size: 15px;
  color: #3f3a34;
  text-shadow: none;
}

#postForm tr,
.lettre-form tr {
  text-align: left;
}

#postForm td,
.lettre-form td,
#postForm th,
.lettre-form th {
  padding: 16px 18px;
  vertical-align: middle;
  border-top: 1px solid #ece6dc;
  border-left: 1px solid #ece6dc;
  background: #fcfbf9;
}

#postForm tr:first-child td,
.lettre-form tr:first-child td,
#postForm tr:first-child th,
.lettre-form tr:first-child th {
  border-top: 0;
}

#postForm td:first-child,
.lettre-form td:first-child,
#postForm th:first-child,
.lettre-form th:first-child {
  border-left: 0;
}

#postForm th,
.lettre-form th {
  font-size: 1.05rem;
  font-weight: 700;
  color: #8b2d2b;
  background: #f7f2ec;
}

#postForm label,
.lettre-form label,
#postForm td:first-child,
.lettre-form td:first-child {
  font-weight: 600;
  color: #5a534a;
}

#postForm input[type="text"],
#postForm input[type="date"],
#postForm input[type="search"],
#postForm select,
#postForm textarea,
.lettre-form input[type="text"],
.lettre-form input[type="date"],
.lettre-form input[type="search"],
.lettre-form select,
.lettre-form textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid #d7d0c4;
  border-radius: 10px;
  background: #fff;
  color: #2f2a22;
  font-size: 1rem;
  font-family: "Source Sans Pro", Arial, sans-serif;
  box-sizing: border-box;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.03);
}

#postForm textarea,
.lettre-form textarea {
  min-height: 96px;
  resize: vertical;
}

#postForm input:focus,
#postForm select:focus,
#postForm textarea:focus,
.lettre-form input:focus,
.lettre-form select:focus,
.lettre-form textarea:focus {
  outline: none;
  border-color: #9e8770;
  box-shadow: 0 0 0 3px rgba(158,135,112,.12);
}

#postForm .submit-row,
.lettre-form .submit-row {
  text-align: center;
  padding-top: 22px;
}

#postForm input[type="submit"],
.lettre-form input[type="submit"],
#postForm button,
.lettre-form button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 220px;
  min-height: 52px;
  padding: 0 24px;
  border: none;
  border-radius: 14px;
  background: #9a2f2a;
  color: #fff;
  font-family: "Source Sans Pro", Arial, sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.10);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

#postForm input[type="submit"]:hover,
.lettre-form input[type="submit"]:hover,
#postForm button:hover,
.lettre-form button:hover {
  background: #842723;
  box-shadow: 0 6px 16px rgba(0,0,0,.14);
  transform: translateY(-1px);
}

@media (max-width: 900px) {
  #postForm table,
  .lettre-form table,
  #postForm tbody,
  .lettre-form tbody,
  #postForm tr,
  .lettre-form tr,
  #postForm td,
  .lettre-form td,
  #postForm th,
  .lettre-form th {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }

  #postForm tr,
  .lettre-form tr {
    border-top: 1px solid #ece6dc;
    padding: 8px 0;
  }

  #postForm tr:first-child,
  .lettre-form tr:first-child {
    border-top: 0;
  }

  #postForm td,
  .lettre-form td,
  #postForm th,
  .lettre-form th {
    border: 0;
    padding: 8px 14px;
  }

  #postForm td:first-child,
  .lettre-form td:first-child {
    padding-top: 14px;
    font-size: .96rem;
  }
}



.viz-page {
  max-width: 1200px;
}

.viz-header h1 {
  margin-bottom: 10px;
}

.viz-intro {
  max-width: 900px;
  color: #5f5a53;
  line-height: 1.6;
}


/* =========================================================
   2. BARRE DE MODES
   ---------------------------------------------------------
   Accès aux vues Tomes / Dates / Lieux / Auteurs.
   ========================================================= */

.viz-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 22px 0 26px 0;
}

.viz-toolbar a {
  display: inline-block;
  padding: 10px 14px;
  border: 1px solid #d8d2c8;
  border-radius: 999px;
  background: #fff;
  color: #2f2f2f;
  text-decoration: none;
}

.viz-toolbar a.active {
  background: #8b2d2b;
  border-color: #8b2d2b;
  color: #fff;
}


/* =========================================================
   3. LAYOUT PRINCIPAL
   ---------------------------------------------------------
   Répartition entre le treemap principal et le panneau de
   détails. Variante "wide" pour donner davantage d'espace
   au treemap.
   ========================================================= */

.viz-layout {
  display: flex;
  align-items: flex-start;
  gap: 24px;
}

.viz-layout--wide {
  width: 100%;
  max-width: none;
  margin-left: 0;
}

.viz-main {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
}


/* =========================================================
   4. PANNEAU LATÉRAL
   ---------------------------------------------------------
   Zone de commentaire et de métadonnées contextuelles.
   ========================================================= */

.viz-sidepanel {
  width: 280px;
  padding: 12px 18px 18px 18px;
  overflow-y: auto;
  background: #f5f5f5;
  border: 1px solid #ddd6cb;
  border-left: 1px solid #ddd6cb;
  border-radius: 14px;
}

.viz-sidepanel h3 {
  margin-top: 0;
  margin-bottom: 14px;
  font-size: 1.2em;
}

#viz-detail-content {
  color: #4b453d;
  font-size: 0.98em;
  line-height: 1.6;
}

#viz-detail-content .viz-detail-title {
  margin: 0 0 10px 0;
  color: #2f2a22;
  font-size: 1.08em;
  font-weight: 700;
}

#viz-detail-content .viz-detail-meta {
  margin: 6px 0;
}

#viz-detail-content .viz-detail-link {
  display: inline-block;
  margin-top: 14px;
  padding: 8px 12px;
  border-radius: 10px;
  background: #8b2d2b;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}

#viz-detail-content .viz-detail-link:hover {
  background: #742320;
}


/* =========================================================
   5. CANEVAS DE VISUALISATION
   ---------------------------------------------------------
   Conteneur visuel du treemap, dimensionnement et rendu
   du SVG D3.js.
   ========================================================= */

.viz-canvas {
  position: relative;
  min-height: 620px;
  padding: 24px;
  background: #fff;
  border: 1px solid #ddd6cb;
  border-radius: 16px;
  box-shadow: 0 3px 10px rgba(0,0,0,.04);
}

.viz-canvas--tome {
  width: 100%;
  min-height: 620px;
  box-sizing: border-box;
}

.viz-placeholder h2 {
  margin-top: 0;
}

#gordes-treemap {
  width: 100%;
  height: 100%;
}

#gordes-treemap svg {
  display: block;
  width: 100%;
  height: auto;
}


/* =========================================================
   6. ÉTAT DE CHARGEMENT
   ---------------------------------------------------------
   Superposition affichée pendant la récupération du JSON et
   le rendu de la visualisation.
   ========================================================= */

.viz-loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(255,255,255,.88);
  border-radius: 16px;
}

.viz-loading p {
  margin: 0;
  color: #6a6258;
  font-size: 0.98em;
}

.viz-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #e6ddd1;
  border-top-color: #8b2d2b;
  border-radius: 50%;
  animation: viz-spin .85s linear infinite;
}

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


/* =========================================================
   7. RESPONSIVE
   ---------------------------------------------------------
   Repli du panneau latéral sous le treemap sur les écrans
   plus étroits.
   ========================================================= */

@media (max-width: 1100px) {
  .viz-layout,
  .viz-layout--wide {
    flex-direction: column;
  }

  .viz-sidepanel {
    position: static;
    width: auto;
  }

  .viz-canvas,
  .viz-canvas--tome {
    min-height: 620px;
  }
}

@media (max-width: 1000px) {
  .viz-layout {
    flex-direction: column;
  }

  .viz-sidepanel {
    width: auto;
  }
}

.consult-group-header {
  cursor: pointer;
}

.consult-group-header h3 {
  position: relative;
  padding-right: 28px !important;
}

.consult-group-header h3::after {
  content: "▸";
  position: absolute;
  right: 0;
  top: 0;
  color: #8b2d2b;
}

.consult-group-header.open h3::after {
  content: "▾";
}

.consult-group-body {
  margin-top: 12px;
}


/* =========================================================
   BARRE DES ANNÉES — réseau de correspondance
   ========================================================= */

.viz-toolbar-years {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 18px 0 24px 0;
}

.viz-toolbar-years a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid #d8d2c8;
  border-radius: 999px;
  background: #fff;
  color: #2f2f2f;
  font-family: "Source Sans Pro", Arial, sans-serif;
  font-size: 1em;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  transition: border-color .15s ease, background .15s ease, color .15s ease, box-shadow .15s ease;
}

.viz-toolbar-years a:hover {
  border-color: #b89c99;
  background: #faf7f5;
  color: #8b2d2b;
  text-decoration: none;
}

.viz-toolbar-years a.active {
  border-color: #8b2d2b;
  background: #8b2d2b;
  color: #fff;
  box-shadow: 0 3px 10px rgba(139, 45, 43, .14);
}


/* =========================================================
   ACCUEIL / VISUALISATIONS — mise en page responsive
   À coller en bas de zzz_visualisation.css
   ========================================================= */

/* Structure générale */
.wrapper {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  width: min(1500px, calc(100% - 28px));
  margin: 0 auto;
  box-sizing: border-box;
}

#menugauche {
  flex: 0 0 240px;
  min-width: 220px;
  box-sizing: border-box;
}

#texteAccueil,
#texteAccueil2 {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* vrai conteneur central */
#texteAccueil .accueil-page,
#texteAccueil .viz-page,
#texteAccueil .reseau-page,
#texteAccueil2 .viz-pagei,
#texteAccueil2 .reseau-page {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 0 48px;
  box-sizing: border-box;
}

/* en-tête de la page */
.viz-header {
  margin-bottom: 18px;
}

.viz-header h1 {
  margin: 0 0 14px 0;
  font-size: clamp(2rem, 3.2vw, 3rem);
  line-height: 1.08;
}

.viz-intro {
  max-width: 920px;
  margin: 0;
  line-height: 1.7;
  font-size: 1.05rem;
}

/* barre d’années */
.viz-toolbar-years {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 18px 0 24px 0;
}

.viz-toolbar-years a {
  flex: 0 0 auto;
}

/* réseau : zone centrale + panneau latéral */
.viz-layout,
.viz-layout--wide {
  display: flex;
  align-items: flex-start;
  gap: 22px;
  width: 100%;
  box-sizing: border-box;
}

.viz-main {
  flex: 1 1 auto;
  min-width: 0;
}

.viz-sidepanel {
  flex: 0 0 290px;
  max-width: 290px;
  box-sizing: border-box;
}

/* le canvas ne déborde pas */
.viz-canvas,
.reseau-canvas,
#gordes-network {
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

/* stats */
.consult-overview {
  width: 100% !important;
  margin: 0 !important;
  padding-top: 40px;
  box-sizing: border-box;
}

.consult-overview h2 {
  margin: 0 0 16px 0;
}

/* toutes les cartes : on neutralise les vieux inline-block */
.consult-summary-card,
.consult-entry-card {
  display: block !important;
  width: auto !important;
  min-width: 0 !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

/* grille des cartes de stats :
   prend les 6 premières cartes du bloc */
.consult-overview {
  display: block;
}

.consult-overview > .consult-summary-card {
  display: inline-block !important;
  vertical-align: top;
}

/* si tu peux plus tard ajouter <div class="consult-stats-grid">, ce sera encore mieux.
   En attendant, on force une grille moderne par flex */
.consult-overview {
  --card-gap: 18px;
}

.consult-overview > .consult-summary-card {
  width: calc(25% - 14px) !important;
  margin: 0 18px 18px 0 !important;
}

.consult-overview > .consult-summary-card:nth-of-type(4n) {
  margin-right: 0 !important;
}

/* modes de consultation */
#modesConsultation {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
  align-items: stretch;
}

#modesConsultation h2 {
  grid-column: 1 / -1;
  margin: 10px 0 2px 0;
}

#modesConsultation .consult-entry-card {
  min-height: 180px;
}

/* images, svg, tableaux : sécurité responsive */
img,
svg,
iframe,
table {
  max-width: 100%;
}

table {
  display: block;
  overflow-x: auto;
}

#texteAccueil * {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* =========================================================
   TABLETTES / ÉCRANS MOYENS
   ========================================================= */
@media (max-width: 1180px) {
  .wrapper {
    width: min(100%, calc(100% - 20px));
    gap: 18px;
  }

  #menugauche {
    flex-basis: 220px;
    min-width: 200px;
  }

  .viz-sidepanel {
    flex-basis: 260px;
    max-width: 260px;
  }

  .consult-overview > .consult-summary-card {
    width: calc(33.333% - 12px) !important;
  }

  .consult-overview > .consult-summary-card:nth-of-type(4n) {
    margin-right: 18px !important;
  }

  .consult-overview > .consult-summary-card:nth-of-type(3n) {
    margin-right: 0 !important;
  }
}

/* =========================================================
   MOBILE / PETITS ÉCRANS
   ========================================================= */
@media (max-width: 980px) {
  .wrapper {
    flex-direction: column;
    gap: 18px;
    width: min(100%, calc(100% - 16px));
  }

  #menugauche {
    flex: none;
    width: 100%;
    min-width: 0;
  }

  #texteAccueil,
  #texteAccueil2 {
    width: 100%;
  }

  #texteAccueil .accueil-page,
  #texteAccueil .viz-page,
  #texteAccueil .reseau-page,
  #texteAccueil2 .viz-pagei,
  #texteAccueil2 .reseau-page {
    max-width: 100%;
    padding: 10px 0 28px;
  }

  .viz-layout,
  .viz-layout--wide {
    flex-direction: column;
    gap: 18px;
  }

  .viz-sidepanel {
    flex: none;
    width: 100%;
    max-width: 100%;
  }

  .consult-overview > .consult-summary-card {
    width: calc(50% - 9px) !important;
  }

  .consult-overview > .consult-summary-card:nth-of-type(3n) {
    margin-right: 18px !important;
  }

  .consult-overview > .consult-summary-card:nth-of-type(2n) {
    margin-right: 0 !important;
  }
}

@media (max-width: 680px) {
  .viz-header h1 {
    font-size: 1.9rem;
    line-height: 1.12;
  }

  .viz-intro {
    font-size: 1rem;
    line-height: 1.6;
  }

  .viz-toolbar-years {
    gap: 8px;
  }

  .viz-toolbar-years a {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }

  .consult-overview > .consult-summary-card {
    width: 100% !important;
    margin-right: 0 !important;
  }

  #modesConsultation {
    grid-template-columns: 1fr;
  }
}

/* ========================================================
 *
 * ========================================================*/

#texteTranscription {
  display: block;
}

#texteTranscription [type="texte"] {
  display: grid;
  grid-template-columns: 42px 1fr;
  column-gap: 22px;
  align-items: start;
  margin: 0 0 10px 0;
}

#texteTranscription [type="texte"] > span:first-child {
  float: none !important;
  display: block;
  padding-right: 0 !important;
  font-size: 0.95rem !important;
  line-height: 1.9;
  text-align: right;
  color: #333;
}

.transcription-line {
  display: grid;
  grid-template-columns: 42px 1fr;
  column-gap: 22px;
  align-items: start;
  margin: 0 0 10px 0;
}

.transcription-line .line-number {
  text-align: right;
  line-height: 1.9;
  color: #333;
}

.transcription-line .line-text {
  margin: 0;
  text-align: justify;
  text-justify: inter-word;
  line-height: 1.9;
  hyphens: auto;
  display:inline;
}

.transcription-line .line-text match,
.transcription-line .line-text non-match,
.transcription-line .line-text group {
  display: inline;
}

/* =========================================================
   BURGER MOBILE
   ========================================================= */

.menu-toggle {
  display: none;
}

@media (max-width: 980px) {
  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 86px;
    left: 12px;
    z-index: 1200;
    width: 46px;
    height: 46px;
    border: 1px solid #d8d2c8;
    border-radius: 10px;
    background: #fff;
    color: #8b2d2b;
    font-size: 1.5rem;
    line-height: 1;
    box-shadow: 0 4px 14px rgba(0,0,0,.08);
    cursor: pointer;
  }

  #menugauche {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1100;
    width: min(86vw, 320px);
    max-width: 320px;
    height: 100vh;
    overflow-y: auto;
    background: #f7f5f2;
    box-shadow: 8px 0 24px rgba(0,0,0,.14);
    transform: translateX(-104%);
    transition: transform .22s ease;
    padding-top: 78px;
  }

  body.menu-open #menugauche {
    transform: translateX(0);
  }

  body.menu-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 1050;
    background: rgba(0,0,0,.22);
  }

  .wrapper {
    display: block;
    width: min(100%, calc(100% - 16px));
  }

  #texteAccueil,
  #texteAccueil2 {
    width: 100%;
  }
}



