/* =========================
   ORGANIGRAMA (IEM)
   - SIN SCROLL (fit-to-container)
   - Conectores jerárquicos
   - Raíz centrada
   ========================= */

:root {
    --org-color: #a10085;
    --org-gap-y: 40px;
    /* separación vertical entre niveles */
    --org-gap-x: 10px;
    /* separación horizontal entre hermanos */
}

/* Contenedor exterior */
.iem-org-wrap {
    width: 100%;
    display: flex;
    justify-content: center;
    /* Centrar el scroll container si es menor al 100% */
}

/* Contenedor “viewport” SIN scroll: aquí el JS ajusta altura al scale */
.iem-org-scroll {
    width: 100%;
    overflow: visible;
    /* Permitir ver si sobrepasa un poco */
    /* 🔒 no scroll */
    text-align: center;
    /* Centrar el inline-block chart */
    padding: 20px 20px 40px;
    /* margen para que no se recorten líneas */
    border-radius: 16px;
    background: #fff;
    box-sizing: border-box;
}

/* El diagrama mantiene su tamaño natural para poder escalarse con JS */
.iem-org-chart {
    display: inline-block;
    /* Permitir text-align: center del padre actuar */
    min-width: max-content;
    transform-origin: top center;
    text-align: center;
    /* will-change: transform; */
}

/* ====== NIVELES ====== */
/* Resets básicos para ul/li */
.iem-org-chart ul {
    padding: 0;
    margin: 0;
    list-style: none;
}

.iem-org-level {
    display: flex;
    /* Flexbox para distribuir los hijos uniformemente */
    justify-content: center;
    position: relative;
    padding-top: var(--org-gap-y);
}

/* Nodo */
.iem-org-node {
    position: relative;
    padding: var(--org-gap-y) var(--org-gap-x) 0 var(--org-gap-x);
}

/* ====== CONECTORES ====== */
/* Horizontal lines and vertical drop to cards */
.iem-org-node::before,
.iem-org-node::after {
    content: "";
    position: absolute;
    top: 0;
    width: 50%;
    height: var(--org-gap-y);
    border-top: 2px solid var(--org-color);
}

.iem-org-node::before {
    right: 50%;
}

.iem-org-node::after {
    left: 50%;
    border-left: 2px solid var(--org-color);
    /* The drop down line */
}

/* Un solo hijo -> sin brazos horizontales pero SI drop vertical */
.iem-org-node:only-child::before,
.iem-org-node:only-child::after {
    display: none;
}

.iem-org-node:only-child {
    padding-top: 0;
}

/* primer y último hijo: quitar brazo exterior horizontal */
.iem-org-node:first-child::before {
    border-top: 0;
}

.iem-org-node:last-child::after {
    border-top: 0;
}

/* Caso especial si es el UNICO hijo, queremos la caida vertical, 
   pero la flecha horizontal esta oculta, asi que añadimos la caida manual.
   Mejor solucion: el before/after se apagan pero el padre dibuja la caida
*/
.iem-org-level::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    height: var(--org-gap-y);
    border-left: 2px solid var(--org-color);
    transform: translateX(-50%);
}

/* ====== NIVEL RAÍZ ====== */
.iem-org-chart>.iem-org-level {
    padding-top: 0;
}

.iem-org-chart>.iem-org-level::before {
    display: none;
}

.iem-org-chart>.iem-org-level>.iem-org-node {
    padding-top: 0;
}

.iem-org-chart>.iem-org-level>.iem-org-node::before,
.iem-org-chart>.iem-org-level>.iem-org-node::after {
    display: none;
}

/* ====== CARD ====== */
.iem-org-card {
    width: 170px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin: 0 auto;
}

.iem-org-avatar {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    border: 4px solid var(--org-color);
    overflow: hidden;
    background: #cecece;
    display: flex;
    justify-content: center;
    align-items: center;
}

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

.iem-org-text {
    text-align: center;
    line-height: 1.2;
}

.iem-org-nombre {
    font-weight: 700;
    font-size: 0.9rem;
    color: #6b6b6b;
    margin-bottom: 2px;
}

.iem-org-cargo {
    font-weight: 800;
    font-size: 0.85rem;
    color: var(--org-color);
}

.iem-org-cv {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;

    height: 26px;
    padding: 2px 2px 2px 10px;

    border-radius: 999px;
    background: var(--org-color);
    color: #fff;

    font-weight: 900;
    font-size: 0.8rem;
    text-decoration: none;
    user-select: none;
    margin-top: 6px;
    box-sizing: border-box;
}

.iem-org-cv span.cv-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: var(--org-color);
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.iem-org-cv--off {
    opacity: 0.45;
    cursor: default;
}

/* ====== ROOT CARD OVERRIDES ====== */
.iem-org-chart>.iem-org-level>.iem-org-node>.iem-org-card {
    width: 240px;
}

.iem-org-chart>.iem-org-level>.iem-org-node>.iem-org-card .iem-org-avatar {
    width: 150px;
    height: 150px;
    border-width: 6px;
}

.iem-org-chart>.iem-org-level>.iem-org-node>.iem-org-card .iem-org-nombre {
    font-size: 1rem;
}

.iem-org-chart>.iem-org-level>.iem-org-node>.iem-org-card .iem-org-cargo {
    font-size: 1rem;
}

/* ====== RESPONSIVE ====== */
@media (max-width: 768px) {
    :root {
        --org-gap-y: 30px;
        --org-gap-x: 5px;
    }

    .iem-org-card {
        width: 130px;
    }

    .iem-org-avatar {
        width: 80px;
        height: 80px;
        border-width: 3px;
    }

    .iem-org-chart>.iem-org-level>.iem-org-node>.iem-org-card {
        width: 180px;
    }

    .iem-org-chart>.iem-org-level>.iem-org-node>.iem-org-card .iem-org-avatar {
        width: 120px;
        height: 120px;
        border-width: 5px;
    }
}