/* Shared org-chart styles. Tokens first.

   Theme hardening. In the standalone demo these rules came from the host page's
   own reset; a plugin lands in themes that may provide neither. Every slot
   coordinate in chart3.js is a border-box measurement, so a theme without a
   border-box reset shifts the whole poster out of alignment — this is scoped to
   the chart rather than left to the theme. The modal and the tooltip are
   appended to <body>, outside the chart root, so they are named separately. */
[data-chart-root],
[data-chart-root] *,
[data-chart-root] *::before,
[data-chart-root] *::after,
.chart-modal,
.chart-modal *,
.chart-modal *::before,
.chart-modal *::after,
.chart-tooltip,
.chart-tooltip * {
    box-sizing: border-box;
}

/* The layout was drawn against a 16px base. Themes that set a different body
   size would otherwise reflow the pills inside fixed-width panels. */
[data-chart-root],
.chart-modal,
.chart-tooltip {
    font-family: var(--chart-font, Roboto, Helvetica, Arial, sans-serif);
    font-size: 16px;
    line-height: 1.4;
}

/* Themes almost always space list items (`li { margin-bottom: … }`), and the
   mobile tiers are a <ul> whose rows are meant to sit flush against each other,
   overlapping by exactly their 1px rule. Any inherited spacing opens a visible
   gap between every row. Only the chart's own lists are named here — authored
   content in a pop-up keeps the theme's list styling, bullets included. */
[data-chart-root] .chart-tier,
[data-chart-root] .chart-tier__item,
.chart-modal__people,
.chart-modal__people > li {
    margin: 0;
    padding: 0;
    list-style: none;
}

[data-chart-root] {
    --node-w: 190px;
    --brand: #0b3b73;
    --brand-soft: #e8eef7;
    --surface: #fff;
    --ink: #0b3b73;
    --muted: #787881;
    --line: #9fb3cd;
    --rule: #ccd8e6;
    --thumb-gutter: 68px;
    --radius: 0.8rem;
    --shadow-sm: 0 0 4px rgb(0 0 0 / 10%);
    --shadow-md: 0 0 5px rgb(0 0 0 / 15%), 0 3px 10px rgb(0 0 0 / 10%);
    --shadow-lg: 0 6px 14px rgb(0 0 0 / 16%), 0 18px 36px rgb(0 0 0 / 12%);
    --sticky-h: 52px;

    position: relative;
}

/* ------------------------------------------------------------- toolbar */

.chart-toolbar {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    margin-bottom: 0.75rem;
}

.chart-toolbar button {
    font: inherit;
    font-size: 0.85rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid #dfe5ee;
    border-radius: 0.5rem;
    padding: 0.35rem 0.7rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.chart-toolbar button:hover {
    background: var(--brand);
    color: #fff;
}

.chart-hint {
    margin-left: auto;
    font-size: 0.78rem;
    color: var(--muted);
}

/* -------------------------------------------------- desktop pan/zoom canvas */

.chart-viewport {
    position: relative;
    overflow: hidden;
    height: min(68vh, 620px);
    background:
        radial-gradient(circle at 1px 1px, #dbe3ee 1px, transparent 0) 0 0 / 22px 22px,
        #f7f9fc;
    border: 1px solid #e4e8ef;
    border-radius: var(--radius);
    touch-action: none;
    cursor: grab;
}

.chart-viewport:active {
    cursor: grabbing;
}

.chart-canvas {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    /* Text selection and native image drags both cancel an in-flight pan. */
    user-select: none;
}

.chart-canvas img {
    -webkit-user-drag: none;
}

.chart-connectors {
    position: absolute;
    top: 0;
    left: 0;
    overflow: visible;
    pointer-events: none;
}

.chart-nodes {
    position: relative;
}

.chart-link {
    fill: none;
    stroke: var(--line);
    stroke-width: 2;
}

.chart-link--affiliate {
    stroke-dasharray: 6 5;
    stroke-width: 1.5;
}

/* ---------------------------------------------------------------- nodes */

.chart-node {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 0.75rem;
    text-align: center;
    color: var(--ink);
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.chart-node.is-interactive {
    cursor: pointer;
}

.chart-node:hover,
.chart-node:focus-visible {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
    outline: none;
}

.chart-node:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

.chart-node__image {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 50%;
}

.chart-node__text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.chart-node__title {
    font-weight: 600;
    line-height: 1.25;
    font-size: 0.92rem;
}

.chart-node__subtitle {
    color: var(--muted);
    font-size: 0.8rem;
}

.chart-node--main {
    background: var(--brand);
    color: #fff;
}

.chart-node--main .chart-node__title {
    font-size: 1.1rem;
}

.chart-node--main .chart-node__subtitle {
    color: #c9d8ec;
}

.chart-node--affiliate {
    background: var(--brand-soft);
    border: 1px dashed var(--line);
}

.chart-node--image {
    padding: 0.6rem;
}

.chart-node--image .chart-node__image {
    width: 96px;
    height: 96px;
    border-radius: 0.5rem;
}

.chart-node__badge {
    position: absolute;
    top: -0.5rem;
    right: -0.5rem;
    min-width: 1.4rem;
    padding: 0.1rem 0.35rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: #fff;
    background: var(--brand);
    border: 2px solid var(--surface);
    border-radius: 1rem;
}

.chart-node__link,
.chart-row__link {
    position: absolute;
    top: 0.35rem;
    left: 0.35rem;
    width: 1.5rem;
    height: 1.5rem;
    /* Without this a long title shrinks the icon into an ellipse. */
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    font-size: 0.8rem;
    text-decoration: none;
    color: var(--brand);
    background: var(--brand-soft);
    border-radius: 50%;
}

.chart-node__sr,
.chart-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* --------------------------------------------------------------- tooltip */

.chart-tooltip {
    position: fixed;
    z-index: 60;
    max-width: 260px;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    line-height: 1.35;
    color: #fff;
    background: #16233a;
    border-radius: 0.4rem;
    box-shadow: var(--shadow-md);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.chart-tooltip.is-visible {
    opacity: 1;
}

/* ----------------------------------------------------------- mobile tiers */

.chart-mobile .chart-tier {
    margin: 0;
    padding: 0;
    list-style: none;
}

.chart-mobile .chart-tier .chart-tier {
    margin-left: 0.9rem;
}

/* Rows sit flush. Each carries its own 1px rule and overlaps its neighbour by
   exactly that, so touching borders read as a single hairline, never two. */
.chart-mobile .chart-tier__item + .chart-tier__item,
.chart-mobile .chart-tier .chart-tier > .chart-tier__item:first-child {
    margin-top: -1px;
}

.chart-mobile .chart-tier__item--parent > .chart-row {
    position: sticky;
    top: calc(var(--depth) * var(--sticky-h));
    z-index: calc(50 - var(--depth));
    min-height: var(--sticky-h);
    font-weight: 700;
    background: var(--brand-soft);
}

.chart-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.75rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--rule);
}

.chart-row.is-interactive {
    cursor: pointer;
}

/* Square thumbnail slot, flush to the row's top, bottom and left edges.

   Taken out of flow deliberately: absolute top/bottom gives the slot a
   definite height to derive its 1:1 width from (as a flex item its width
   resolves before any stretch, so `aspect-ratio` collapsed it to zero), and it
   keeps slot width from feeding back into text wrapping and row height. The
   text reserves a fixed gutter instead, so left edges line up down the list
   however tall each row is. */
.chart-row__thumb {
    position: absolute;
    left: 0;
    top: 50%;
    width: var(--thumb-gutter);
    height: var(--thumb-gutter);
    transform: translateY(-50%);
    overflow: hidden;

    /* Centred by flex rather than by the image filling the slot: the near
       universal theme rule `img { height: auto }` overrides the height below,
       which would otherwise drop the logo against the top of the slot. */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Every square is the same size, whatever its row's height — tying the slot to
   the row made one-line rows visibly smaller than two-line ones. The floor
   keeps a short row from letting the square spill past its edges; on a taller
   row the square simply centres. */
.chart-row:has(.chart-row__thumb) {
    min-height: var(--thumb-gutter);
    padding-left: calc(var(--thumb-gutter) + 0.75rem);
}

/* Sticky headers set their own, shorter min-height further down; a thumbnail
   row still needs the taller floor. */
.chart-mobile .chart-tier__item--parent > .chart-row:has(.chart-row__thumb) {
    min-height: var(--thumb-gutter);
}

/* The slot is the box; the image is only contained inside it, never cropped. */
.chart-row__image {
    width: 100%;
    height: 100%;

    /* Caps a theme-forced auto height so the logo is contained either way. */
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.chart-row__text {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
}

.chart-row__title {
    line-height: 1.3;
}

.chart-row__subtitle {
    color: var(--muted);
}

.chart-row__badge {
    flex: 0 0 auto;
    padding: 0.05rem 0.45rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: #fff;
    background: var(--brand);
    border-radius: 1rem;
}

.chart-row__link {
    position: static;
}

/* Marks a row that has a description behind it. Inert — the row is the target. */
.chart-row__info {
    width: 1.5rem;
    height: 1.5rem;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    font-size: 0.75rem;
    font-style: italic;
    color: var(--brand);
    background: var(--brand-soft);
    border-radius: 50%;
}

.chart-affiliates {
    margin-top: 1.25rem;
}

.chart-affiliates__heading {
    margin-bottom: 0.5rem;
    font-size: 1rem;
    color: var(--muted);
}

.chart-affiliates .chart-tier__item + .chart-tier__item {
    margin-top: -1px;
}

/* ------------------------------------------------- renderer mode switching */

[data-chart-root][data-mode="desktop"] .chart-mobile {
    display: none;
}

[data-chart-root][data-mode="mobile"] .chart-viewport,
[data-chart-root][data-mode="mobile"] .chart-toolbar {
    display: none;
}

/* ----------------------------------------------------------------- modal */

.chart-modal {
    border: none;
    border-radius: 1.2rem;
    padding: 0;
    width: calc(100% - 2rem);
    max-width: 600px;
    background: #fff;
    box-shadow: var(--shadow-lg, 0 10px 30px rgb(0 0 0 / 20%));
}

.chart-modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid #e4e6f3;
}

.chart-modal__title {
    margin: 0;
    font-size: 1.25rem;
    color: #0b3b73;
}

.chart-modal__close {
    font-size: 1.5rem;
    line-height: 1;
    color: #787881;
    background: none;
    border: none;
    cursor: pointer;
}

.chart-modal__body {
    padding: 1rem;
}

.chart-modal__people {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.6rem;
}

.chart-modal__people li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chart-modal__people img,
.chart-modal__avatar {
    width: 48px;
    height: 48px;
    flex: 0 0 auto;
    object-fit: cover;
    background: #e8eef7;
    border-radius: 50%;
}

.chart-modal__people span {
    display: flex;
    flex-direction: column;
}

.chart-modal__people small {
    color: #787881;
}

.chart-modal::backdrop {
    background: rgb(15 23 42 / 35%);
    backdrop-filter: blur(4px);
}

/* --------------------------------------- mobile row affordances (indicators)

   These are inert marks, not controls: the whole row is the single interactive
   element, so a tap anywhere on it does the thing the icon advertises. */

.chart-row.is-link {
    text-decoration: none;
    color: var(--ink);
}

/* Match the brand focus ring the desktop nodes use, not the UA default. */
.chart-row:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: -2px;
}

.chart-row__caret {
    width: 0;
    height: 0;
    flex: 0 0 auto;
    border-left: 8px solid var(--brand);
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    transition: transform 0.2s ease;
}

.chart-row.is-open .chart-row__caret {
    transform: rotate(90deg);
}

.chart-row__open {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    fill: none;
    stroke: var(--brand);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chart-row__linkmark {
    flex: 0 0 auto;
    width: 1.5rem;
    height: 1.5rem;
    display: grid;
    place-items: center;
    font-size: 0.8rem;
    color: var(--brand);
    background: var(--brand-soft);
    border-radius: 50%;
}

/* JS skips the open/close and reflow animations when motion is reduced; the
   CSS transitions have to stand down as well. */
@media (prefers-reduced-motion: reduce) {
    [data-chart-root] *,
    [data-chart-root] *::before,
    [data-chart-root] *::after,
    .chart-modal,
    .chart-modal *,
    .chart-tooltip {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
