/* Organigramme — AngularJS 1.8.3 + AngularJS Material 1.2.5
 *
 * Responsive :
 *  - écrans ≥ 960 px : arbre horizontal classique (défilement horizontal si très large) ;
 *  - écrans < 960 px (tablette, mobile) : arbre vertical indenté, qui tient toujours en largeur.
 */

.org {
  --org-line: #9e9e9e;
  --org-primary: #0b3b2a;
  --org-accent: #c9a54c;
  --org-card-bg: #ffffff;
  --org-text: #1b1b1b;
  --org-muted: #555555;
  --org-avatar-bg: #e8efe9;
  display: block;
  width: 100%;
  box-sizing: border-box;
}

.org *,
.org *::before,
.org *::after {
  box-sizing: border-box;
}

/* ---------- Barre d'outils ---------- */

.org-toolbar .md-toolbar-tools {
  flex-wrap: wrap;
  gap: 8px;
  height: auto;
  min-height: 64px;
  max-height: none;
  padding-top: 8px;
  padding-bottom: 8px;
}

.org-title {
  margin: 0;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.3;
  white-space: normal;
}

.org-toolbar .md-button {
  margin: 0;
}

.org-toolbar .md-button md-icon {
  margin-right: 4px;
}

/* ---------- Zone de l'arbre ---------- */

.org-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 32px 16px 48px;
}

.org-tree,
.org-tree ul {
  margin: 0;
  padding: 0;
  list-style: none;
  position: relative;
}

.org-tree li {
  position: relative;
}

/* ---------- Case (commun) ---------- */

md-card.org-card {
  position: relative;
  display: flex;
  margin: 0;
  background: var(--org-card-bg);
  color: var(--org-text);
  border-top: 4px solid var(--org-accent);
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 1px 1px rgba(0, 0, 0, 0.14);
}

md-card.org-card--highlight {
  background: var(--org-primary);
  color: #ffffff;
}

.org-avatar {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--org-avatar-bg);
  color: var(--org-primary);
  font-weight: 600;
  font-size: 18px;
  border: 2px solid var(--org-accent);
}

.org-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.org-text {
  min-width: 0;
}

.org-role {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--org-muted);
  overflow-wrap: anywhere;
}

.org-card--highlight .org-role {
  color: var(--org-accent);
}

.org-name {
  margin-top: 4px;
  font-size: 16px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.md-button.md-fab.md-mini.org-toggle {
  position: absolute;
  margin: 0;
  z-index: 2;
}

/* =========================================================
   Grands écrans : arbre horizontal
   ========================================================= */
@media (min-width: 960px) {
  .org-tree,
  .org-tree ul {
    display: flex;
    justify-content: center;
    padding-top: 24px;
  }

  .org-tree {
    padding-top: 0;
    min-width: max-content;
  }

  .org-tree li {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 8px 0;
  }

  /* Trait horizontal au-dessus de chaque case + trait vertical vers la case */
  .org-tree li::before,
  .org-tree li::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    width: 50%;
    height: 24px;
    border-top: 2px solid var(--org-line);
  }

  .org-tree li::after {
    right: auto;
    left: 50%;
    border-left: 2px solid var(--org-line);
  }

  .org-tree li:first-child::before,
  .org-tree li:last-child::after {
    border: 0 none;
  }

  .org-tree li:last-child::before {
    border-right: 2px solid var(--org-line);
    border-radius: 0 8px 0 0;
  }

  .org-tree li:first-child::after {
    border-radius: 8px 0 0 0;
  }

  /* Enfant unique : simple trait vertical */
  .org-tree li:only-child {
    padding-top: 0;
  }

  .org-tree li:only-child::before,
  .org-tree li:only-child::after {
    display: none;
  }

  /* Racine : pas de trait au-dessus */
  .org-tree > li {
    padding-top: 0;
  }

  .org-tree > li::before,
  .org-tree > li::after {
    display: none;
  }

  /* Trait vertical qui descend d'une case vers ses enfants */
  .org-tree ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    height: 24px;
    border-left: 2px solid var(--org-line);
  }

  org-node {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  md-card.org-card {
    flex-direction: column;
    align-items: center;
    width: clamp(150px, 13vw, 200px);
    padding: 16px 12px 24px;
    text-align: center;
  }

  .org-avatar {
    margin-bottom: 10px;
  }

  /* Postes de dernier niveau : empilés sous le parent (gain de largeur) */
  .org-tree ul.org-leaves {
    flex-direction: column;
    align-items: center;
    padding-top: 8px;
  }

  .org-tree ul.org-leaves::before {
    height: 8px;
  }

  .org-tree ul.org-leaves > li {
    padding: 16px 0 0;
  }

  .org-tree ul.org-leaves > li::before {
    display: block;
    content: '';
    top: 0;
    left: 50%;
    right: auto;
    width: 0;
    height: 16px;
    border: 0 none;
    border-left: 2px solid var(--org-line);
    border-radius: 0;
  }

  .org-tree ul.org-leaves > li::after {
    display: none;
  }

  /* Bouton à cheval sur le bas de la case */
  .md-button.md-fab.md-mini.org-toggle {
    left: 50%;
    bottom: -20px;
    margin-left: -20px;
  }
}

/* Écrans moyens : un peu plus serré */
@media (min-width: 960px) and (max-width: 1279.98px) {
  .org-tree li {
    padding-left: 4px;
    padding-right: 4px;
  }

  .org-avatar {
    width: 48px;
    height: 48px;
    font-size: 16px;
  }

  .org-name {
    font-size: 15px;
  }
}

/* =========================================================
   Tablettes et mobiles : arbre vertical indenté
   ========================================================= */
@media (max-width: 959.98px) {
  .org-scroll {
    overflow-x: visible;
    padding: 20px 12px 32px;
  }

  .org-tree {
    max-width: 640px;
    margin: 0 auto;
  }

  /* Les enfants sont décalés sous l'avatar du parent */
  .org-tree ul {
    margin-left: 33px;
  }

  .org-tree li {
    padding: 12px 0 0 22px;
  }

  .org-tree > li {
    padding: 0;
  }

  /* Coude qui relie la ligne verticale à la case */
  .org-tree ul > li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 18px;
    height: 44px;
    border-left: 2px solid var(--org-line);
    border-bottom: 2px solid var(--org-line);
    border-bottom-left-radius: 8px;
  }

  /* Ligne verticale qui continue vers les cases suivantes */
  .org-tree ul > li::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    border-left: 2px solid var(--org-line);
  }

  .org-tree ul > li:last-child::after {
    display: none;
  }

  org-node {
    display: block;
  }

  md-card.org-card {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 64px;
    padding: 10px 60px 10px 12px;
    text-align: left;
    border-top: 0;
    border-left: 4px solid var(--org-accent);
  }

  .org-avatar {
    width: 44px;
    height: 44px;
    font-size: 15px;
  }

  .org-role {
    font-size: 11px;
  }

  .org-name {
    margin-top: 2px;
    font-size: 15px;
  }

  /* Bouton à droite, centré verticalement */
  .md-button.md-fab.md-mini.org-toggle {
    right: 10px;
    top: 50%;
    margin-top: -20px;
  }
}

/* Petits mobiles : boutons de la barre réduits à leur icône */
@media (max-width: 599.98px) {
  .org-title {
    font-size: 17px;
    flex: 1 1 100%;
  }

  .org-btn-label {
    display: none;
  }

  .org-toolbar .md-button md-icon {
    margin-right: 0;
  }

  .org-tree ul {
    margin-left: 20px;
  }

  .org-tree li {
    padding-left: 16px;
  }

  .org-tree ul > li::before {
    width: 12px;
  }
}

/* =========================================================
   Onglets + Historique (frise chronologique)
   ========================================================= */

md-tabs.org-tabs {
  background: transparent;
}

md-tabs.org-tabs md-tab-item md-icon,
md-tabs.org-tabs .md-tab md-icon {
  margin-right: 6px;
  vertical-align: middle;
}

.org-history {
  --org-line: #9e9e9e;
  --org-primary: #0b3b2a;
  --org-accent: #c9a54c;
  display: block;
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 16px 48px;
  box-sizing: border-box;
}

.org-history *,
.org-history *::before,
.org-history *::after {
  box-sizing: border-box;
}

.org-history-empty {
  text-align: center;
  color: #555555;
}

.org-timeline {
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Ligne verticale de la frise (d'un repère au suivant) */
.org-timeline-item:not(:last-child)::before {
  content: '';
  position: absolute;
  top: 24px;
  bottom: 0;
  left: 23px;
  border-left: 2px solid var(--org-line);
}

.org-timeline-item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 20px;
}

.org-timeline-item:last-child {
  padding-bottom: 0;
}

.org-timeline-marker {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--org-primary);
  color: var(--org-accent);
  border: 3px solid var(--org-accent);
}

.org-timeline-marker md-icon {
  color: var(--org-accent);
  margin: 0;
}

md-card.org-timeline-card {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 14px 18px;
  background: #ffffff;
  border-left: 4px solid var(--org-accent);
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 1px 1px rgba(0, 0, 0, 0.14);
}

.org-timeline-date {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8a6d1f;
}

.org-timeline-title {
  margin: 4px 0 0;
  font-size: 18px;
  font-weight: 500;
  color: var(--org-primary);
  overflow-wrap: anywhere;
}

.org-timeline-desc {
  margin: 8px 0 0;
  font-size: 15px;
  line-height: 1.5;
  color: #333333;
}

.org-timeline-people {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.org-timeline-people li {
  padding: 4px 10px;
  border-radius: 16px;
  background: #e8efe9;
  color: var(--org-primary);
  font-size: 13px;
}

/* Grands écrans : date à gauche de la ligne, carte à droite */
@media (min-width: 960px) {
  .org-timeline-item:not(:last-child)::before {
    left: 163px;
  }

  .org-timeline-item {
    padding-left: 140px;
  }

  .org-timeline-date {
    position: absolute;
    left: 0;
    top: 14px;
    width: 124px;
    text-align: right;
  }

  .org-timeline-item md-card.org-timeline-card {
    position: static;
  }
}

/* Petits mobiles */
@media (max-width: 599.98px) {
  .org-history {
    padding: 20px 12px 32px;
  }

  .org-timeline-item:not(:last-child)::before {
    top: 18px;
    left: 17px;
  }

  .org-timeline-item {
    gap: 10px;
  }

  .org-timeline-marker {
    width: 36px;
    height: 36px;
    border-width: 2px;
  }

  .org-timeline-marker md-icon {
    font-size: 18px;
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
  }

  md-card.org-timeline-card {
    padding: 12px 14px;
  }

  .org-timeline-title {
    font-size: 16px;
  }
}
