/* OPEC Fund organisational chart. Colours, fonts and text sizes live here; box dimensions in js/metrics.js. */

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --page-bg: #ffffff;
  --dark: #1d1d1b;
  --primary: #0b4f9c;
  --department: #1f6fc0;
  --unit-bg: #cfe0ec;
  --unit-text: #1a5ea8;
  --committee-border: #a9cbe6;
  --line: #2a6fbf;
  --line-width: 1.5px;
  --callout-bg: #1f6fc0;
  --callout-text: #ffffff;
  --initials-bg: #5b93d6;
  --focus: #f5a623;

  --size-governance: 17px;
  --size-department: 15px;
  --size-staff: 15px;
  --size-unit: 14px;
  --size-committee: 14px;
}

html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--unit-text);
  background: var(--page-bg);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

/* Viewport: the scrollable/zoomable window onto the stage */
.viewport {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--page-bg);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.viewport--embedded { touch-action: pan-y; } /* one finger scrolls the host page; two fingers pan and zoom */
.viewport--pannable { cursor: grab; }
.viewport--pannable:active { cursor: grabbing; }
.viewport:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.viewport:fullscreen { background: var(--page-bg); }

.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

/* Connectors */
.edges { position: absolute; left: 0; top: 0; overflow: visible; }
.edges path { fill: none; stroke: var(--line); stroke-width: var(--line-width); }

/* Boxes: nested lists for semantics, absolute positions from the layout */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }

.box {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 4px 6px;
  border: 0;
  border-radius: 0;
  font: inherit;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  overflow-wrap: break-word;
}
.box--governance {
  background: var(--dark);
  color: #fff;
  font-size: var(--size-governance);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.box--primary { background: var(--primary); }
.box--committee {
  background: #fff;
  color: var(--unit-text);
  border: 1px solid var(--committee-border);
  font-size: var(--size-committee);
}
.box--staff { background: var(--unit-bg); color: var(--unit-text); font-size: var(--size-staff); }
.box--department { background: var(--department); color: #fff; font-size: var(--size-department); font-weight: 500; }
.box--staff-child, .box--subunit, .box--unit { background: var(--unit-bg); color: var(--unit-text); font-size: var(--size-unit); }
.box--person { cursor: pointer; }
.box[href]:hover .box__label, .box[href]:focus-visible .box__label { text-decoration: underline; }
.box:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; z-index: 1; }

.measure { visibility: hidden; pointer-events: none; height: auto !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Person callout: portrait straddling the top edge of a blue panel with a pointer to the box */
.callout {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 250px;
  pointer-events: none;
}
.callout[hidden] { display: none; }
.callout__photo, .callout__initials {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  width: 96px;
  height: 96px;
  margin-bottom: -48px; /* half of the portrait overlaps the panel */
  border: 4px solid #fff;
  border-radius: 50%;
  background: #fff;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.callout__initials {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--initials-bg);
  color: #fff;
  font-size: 32px;
  font-weight: 700;
}
.callout__panel {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  padding: 60px 16px 18px;
  border-radius: 22px;
  background: var(--callout-bg);
  color: var(--callout-text);
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.callout__panel::after { /* pointer: a 17px square rotated 45° reaches 12px beyond the edge (POINTER in callouts.js) */
  content: "";
  position: absolute;
  left: var(--pointer-x, 50%);
  bottom: -8.5px;
  width: 17px;
  height: 17px;
  border-radius: 3px;
  background: inherit;
  transform: translateX(-50%) rotate(45deg);
}
.callout__name { display: block; font-size: 17px; font-weight: 600; line-height: 1.3; }
.callout__title { display: block; margin-top: 2px; font-size: 16px; line-height: 1.3; }

/* Fallback when there is no room above the box: panel on top, portrait overlapping its bottom edge */
.callout--below { flex-direction: column-reverse; }
.callout--below .callout__photo, .callout--below .callout__initials { margin-bottom: 0; margin-top: -48px; }
.callout--below .callout__panel { padding: 18px 16px 60px; }
.callout--below .callout__panel::after { bottom: auto; top: -8.5px; }

/* Toolbar */
.toolbar { position: absolute; right: 12px; bottom: 12px; z-index: 3; display: flex; gap: 6px; }
.toolbar__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}
.toolbar__button:hover { background: #fff; border-color: var(--primary); }
.toolbar__button:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.toolbar__button svg, .viewport__open svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Preview mode: thumbnail plus a single call to action, no gestures */
.viewport__open {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transform: translate(-50%, -50%);
  cursor: pointer;
}
.viewport__open:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.viewport[data-mode="preview"] .viewport__open { display: inline-flex; }
.viewport[data-mode="preview"] .toolbar { display: none; }
.viewport[data-mode="preview"] .stage { pointer-events: none; }

/* Error panel */
.error {
  margin: 16px;
  padding: 16px 20px;
  border-left: 4px solid #c0392b;
  background: #fdf2f1;
  color: var(--dark);
  font-size: 15px;
}
.error pre { margin: 8px 0 0; font-size: 13px; white-space: pre-wrap; }

@media print {
  .toolbar { display: none; }
}
