/* Kalpasar Department website: organisation chart (About > Organisation Structure), all three options, light, dark and high contrast.
   Markup (pages-about.js, K.ui.orgChartHtml): nested lists, so a screen reader reads it level by level.
   Wide container: a top-down chart with connector lines, the four field units as columns with their posts below.
   Narrow container (phones, large text): an indented tree with a left spine. Colours come only from the design tokens. */

.oc { container-type: inline-size; --oc-line: var(--color-border-ui); --oc-w: 2px; --oc-g: 1.1em; --oc-x: 1.3em; margin-top: 0.6em; }
.oc :where(ul, li) { list-style: none; margin: 0; padding: 0; }

/* Boxes */
.oc-box { display: block; box-sizing: border-box; padding: 0.55em 0.75em; border: 1px solid var(--color-border-ui); border-radius: var(--radius-md);
  background: var(--color-card); color: var(--color-text); font-weight: 600; line-height: 1.35; text-align: center; overflow-wrap: break-word; }
.oc-gog { background: var(--color-surface-alt); color: var(--color-primary-text); border: var(--oc-w) solid var(--color-primary-text); font-weight: 700; letter-spacing: 0.02em; }
.oc-head { background: var(--color-primary); color: var(--color-on-primary); border-color: var(--color-primary); font-weight: 700; font-size: 1.05em; }
.oc-ce { border-top: 4px solid var(--color-secondary); }
.oc-mid { border-top: 4px solid var(--color-accent); font-size: 0.95em; }
.oc-leaf { background: var(--color-surface-alt); font-weight: 500; font-size: 0.9em; padding: 0.4em 0.6em; }

/* Wide: centred top-down chart */
.oc-tree > li, .oc-down:not(.oc-row) > li { display: flex; flex-direction: column; align-items: center; }
.oc-gog, .oc-head { width: min(100%, 24em); }
.oc-down { position: relative; padding-top: var(--oc-g); width: 100%; }
.oc-down::before { content: ''; position: absolute; top: 0; left: calc(50% - var(--oc-w) / 2); height: var(--oc-g); border-left: var(--oc-w) solid var(--oc-line); }
.oc-pair { width: 100%; }

/* Rows with a bar: each child draws half of the bar on each side and its own drop line */
.oc-row { display: flex; justify-content: center; }
.oc-row > li { position: relative; flex: 1 1 0; min-width: 0; padding: var(--oc-g) 0.3em 0; display: flex; flex-direction: column; }
.oc-row > li::before, .oc-row > li::after { content: ''; position: absolute; top: 0; width: 50%; height: var(--oc-g); border-top: var(--oc-w) solid var(--oc-line); }
.oc-row > li::before { left: 0; }
.oc-row > li::after { left: calc(50% - var(--oc-w) / 2); width: calc(50% + var(--oc-w) / 2); border-left: var(--oc-w) solid var(--oc-line); }
.oc-row > li:first-child::before { border-top: 0; }
.oc-row > li:last-child::after { width: 0; }
.oc-row > li:last-child::before { width: calc(50% + var(--oc-w) / 2); }
.oc-row > li > .oc-box { flex: 1 0 auto; }

/* The two Chief Engineers, joined below by one bracket that leads to the field units */
.oc-ces { position: relative; width: min(100%, 40em); margin: 0 auto; padding-bottom: var(--oc-g); }
.oc-ces::after { content: ''; position: absolute; bottom: 0; left: calc(25% - var(--oc-w) / 2); right: calc(25% - var(--oc-w) / 2); height: var(--oc-g);
  border: var(--oc-w) solid var(--oc-line); border-top: 0; }

/* Field units as equal columns; the unit boxes share one height */
.oc-units { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: auto auto; }
.oc-units > li { display: grid; grid-row: span 2; grid-template-rows: subgrid; row-gap: 0; }
.oc-units > li > .oc-box { flex: none; }

/* Posts under a unit: a spine on the left with a tick to each post (same in both layouts) */
.oc-posts { margin-left: 0.9em; }
.oc-posts > li { position: relative; padding: 0.4em 0 0 1em; }
.oc-posts > li::before { content: ''; position: absolute; left: 0; top: calc(0.4em + 1.05em); width: 0.85em; border-top: var(--oc-w) solid var(--oc-line); }
.oc-posts > li::after { content: ''; position: absolute; left: 0; top: 0; bottom: 0; border-left: var(--oc-w) solid var(--oc-line); }
.oc-posts > li:last-child::after { bottom: auto; height: calc(0.4em + 1.05em + var(--oc-w)); }
.oc-posts .oc-leaf { text-align: left; }

/* Narrow: indented tree */
@container (max-width: 38em) {
  .oc-tree > li, .oc-down:not(.oc-row) > li { align-items: stretch; }
  .oc-gog, .oc-head { width: 100%; }
  .oc-box, .oc-posts .oc-leaf { text-align: left; }
  .oc-down { padding-top: 0.75em; }
  .oc-down::before { left: var(--oc-x); height: 0.75em; }

  /* The two Chief Engineers as one group, both above the field units */
  .oc-ces { display: grid; gap: 0.5em; width: 100%; padding: 0.5em; border: var(--oc-w) solid var(--oc-line); border-radius: var(--radius-md); box-sizing: border-box; }
  .oc-ces::after { content: none; }
  .oc-ces > li { padding: 0; }
  .oc-ces > li::before, .oc-ces > li::after { content: none; }

  /* Field units: a spine from the group down the left, a tick to each unit, posts indented under their unit */
  .oc-units { display: block; width: auto; padding-top: 0; margin-left: var(--oc-x); }
  .oc-units::before { content: none; }
  .oc-units > li { display: block; padding: 0.75em 0 0 1.1em; }
  .oc-units > li::before { left: 0; top: calc(0.75em + 1.15em); width: 0.95em; height: 0; border-left: 0; border-top: var(--oc-w) solid var(--oc-line); }
  .oc-units > li::after { left: 0; top: 0; bottom: 0; width: 0; height: auto; border-top: 0; border-left: var(--oc-w) solid var(--oc-line); }
  .oc-units > li:last-child::after { bottom: auto; height: calc(0.75em + 1.15em + var(--oc-w)); }
  .oc-units > li:last-child::before { width: 0.95em; }
  .oc-units > li:first-child::before { border-top: var(--oc-w) solid var(--oc-line); }
}

@media print { .oc-box { break-inside: avoid; } .oc-head { background: none; color: #000; border: 2px solid #000; } }
