/* =====================================================================
   GDOH Provincial Referral Pathways Toolkit
   styles/organogram.css — public EMS District Organograms feature

   Two layers, both built by components/organogram.js:
     .og-overlay   district picker (five cards)
     .og-viewer    the interactive organisational chart
   ===================================================================== */

:root {
  --og-blue:       #0b4da2;
  --og-blue-dark:  #08356f;
  --og-navy:       #0b2545;
  --og-gold:       #f2a900;
  --og-teal:       #12a3a3;
  --og-ink:        #1f2a3a;
  --og-muted:      #6b7a90;
  --og-line:       #e2e8f0;
  --og-ease:       cubic-bezier(.22, .61, .36, 1);
  --og-dur:        380ms;
}

/* ---------------------------------------------------------------------
   Shared overlay behaviour
   --------------------------------------------------------------------- */
.og-overlay,
.og-viewer {
  position: fixed;
  inset: 0;
  z-index: 9200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3vh 3vw;
  opacity: 0;
  visibility: hidden;
  background: radial-gradient(120% 120% at 50% 0%, rgba(11,37,69,.62) 0%, rgba(3,12,26,.82) 100%);
  backdrop-filter: blur(7px) saturate(1.1);
  -webkit-backdrop-filter: blur(7px) saturate(1.1);
  transition: opacity var(--og-dur) var(--og-ease), visibility 0s linear var(--og-dur);
}
.og-overlay.is-open,
.og-viewer.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--og-dur) var(--og-ease), visibility 0s;
}
.og-viewer { z-index: 9300; padding: 0; }

/* ---------------------------------------------------------------------
   District picker
   --------------------------------------------------------------------- */
.og-panel {
  position: relative;
  width: min(1080px, 96vw);
  max-height: 92vh;
  overflow: auto;
  border-radius: 22px;
  padding: 30px 32px 34px;
  background: linear-gradient(165deg, rgba(255,255,255,.97) 0%, rgba(238,244,251,.96) 100%);
  box-shadow: 0 40px 100px rgba(3,12,26,.55), 0 0 0 1px rgba(255,255,255,.35);
  transform: scale(.94) translateY(20px);
  opacity: 0;
  transition: opacity var(--og-dur) var(--og-ease), transform var(--og-dur) var(--og-ease);
}
.og-overlay.is-open .og-panel { transform: scale(1) translateY(0); opacity: 1; }

.og-panel__head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 6px; }
.og-panel__head img { height: 46px; width: auto; flex: none; }
.og-panel__titles { flex: 1; min-width: 0; }
.og-panel h2 {
  margin: 0;
  font: 700 22px/1.25 'Segoe UI', system-ui, sans-serif;
  color: var(--og-navy);
  letter-spacing: .2px;
}
.og-panel__sub { margin: 3px 0 0; font: 400 13px/1.5 'Segoe UI', system-ui, sans-serif; color: var(--og-muted); }

.og-x {
  flex: none;
  width: 40px; height: 40px;
  border: 0; border-radius: 12px;
  background: rgba(11,77,162,.08);
  color: var(--og-blue-dark);
  cursor: pointer;
  display: grid; place-items: center;
  transition: background var(--og-dur) var(--og-ease), transform var(--og-dur) var(--og-ease);
}
.og-x:hover { background: rgba(11,77,162,.18); transform: rotate(90deg); }
.og-x:focus-visible { outline: 3px solid var(--og-blue); outline-offset: 2px; }

.og-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

/* District card — glass, lifts on hover */
.og-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px 20px 20px;
  border: 0;
  border-radius: 18px;
  text-align: left;
  cursor: pointer;
  background: linear-gradient(160deg, #ffffff 0%, #f2f7fd 100%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.9),
    inset 0 0 0 1px rgba(11,77,162,.14),
    0 4px 0 #d5e0ee,
    0 10px 24px rgba(8,53,111,.14);
  transition: transform var(--og-dur) var(--og-ease), box-shadow var(--og-dur) var(--og-ease);
  animation: og-rise var(--og-dur) var(--og-ease) backwards;
}
.og-card:nth-child(1){animation-delay:.02s} .og-card:nth-child(2){animation-delay:.06s}
.og-card:nth-child(3){animation-delay:.10s} .og-card:nth-child(4){animation-delay:.14s}
.og-card:nth-child(5){animation-delay:.18s}
@keyframes og-rise { from { opacity:0; transform: translateY(14px); } to { opacity:1; transform:none; } }

.og-card:hover, .og-card:focus-visible {
  transform: translateY(-5px) scale(1.02);
  box-shadow:
    inset 0 0 0 1px rgba(11,77,162,.34),
    0 8px 0 #d5e0ee,
    0 20px 40px rgba(8,53,111,.24),
    0 0 26px rgba(17,96,189,.26);
}
.og-card:active { transform: translateY(1px) scale(.99); transition-duration: 90ms; }
.og-card:focus-visible { outline: 3px solid var(--og-blue); outline-offset: 3px; }

.og-card__icon {
  width: 46px; height: 46px;
  border-radius: 14px;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(160deg, #1160bd, var(--og-blue-dark));
  box-shadow: 0 6px 14px rgba(8,53,111,.28);
}
.og-card__name { font: 700 16px/1.25 'Segoe UI', system-ui, sans-serif; color: var(--og-navy); }
.og-card__meta { font: 400 11.5px/1.5 'Segoe UI', system-ui, sans-serif; color: var(--og-muted); }
.og-card__go {
  margin-top: 4px;
  font: 700 12px/1 'Segoe UI', system-ui, sans-serif;
  color: var(--og-blue);
  display: inline-flex; align-items: center; gap: 6px;
}
.og-card:hover .og-card__go { gap: 10px; }
.og-card__go span { transition: gap var(--og-dur) var(--og-ease); }

.og-note {
  margin-top: 22px;
  padding: 12px 15px;
  border-radius: 12px;
  background: rgba(11,77,162,.06);
  font: 400 11.5px/1.6 'Segoe UI', system-ui, sans-serif;
  color: var(--og-muted);
}

/* Loading skeletons -------------------------------------------------- */
.og-skel {
  height: 132px;
  border-radius: 18px;
  background: linear-gradient(90deg, #eef3f9 0%, #f7fafd 50%, #eef3f9 100%);
  background-size: 220% 100%;
  animation: og-shimmer 1.4s var(--og-ease) infinite;
}
@keyframes og-shimmer { 0%{background-position:120% 0} 100%{background-position:-120% 0} }

/* ---------------------------------------------------------------------
   Organogram viewer
   --------------------------------------------------------------------- */
.og-viewer__shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100vw; height: 100vh;
  background: #f4f7fb;
  opacity: 0;
  transform: scale(.97);
  transition: opacity var(--og-dur) var(--og-ease), transform var(--og-dur) var(--og-ease);
}
.og-viewer.is-open .og-viewer__shell { opacity: 1; transform: none; }

.og-bar {
  position: sticky; top: 0; z-index: 4;
  flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  color: #fff;
  background: linear-gradient(160deg, #0f5ab6 0%, var(--og-blue) 42%, var(--og-blue-dark) 100%);
  border-bottom: 3px solid var(--og-gold);
  box-shadow: 0 6px 20px rgba(8,53,111,.3);
  flex-wrap: wrap;
}
.og-bar__title { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.og-bar__title b { font: 700 15px/1.25 'Segoe UI', system-ui, sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.og-bar__title span { font-size: 11px; opacity: .85; }

.og-search { position: relative; flex: none; }
.og-search input {
  width: 260px; max-width: 46vw;
  padding: 9px 34px 9px 34px;
  border: 0; border-radius: 10px;
  font: 400 13px 'Segoe UI', system-ui, sans-serif;
  color: #fff;
  background: rgba(255,255,255,.16);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.24);
  transition: background var(--og-dur) var(--og-ease), box-shadow var(--og-dur) var(--og-ease);
}
.og-search input::placeholder { color: rgba(255,255,255,.72); }
.og-search input:focus {
  outline: none;
  background: rgba(255,255,255,.26);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.6);
}
.og-search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); opacity: .8; pointer-events: none; }
.og-search__count {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font: 700 10.5px 'Segoe UI', system-ui, sans-serif; opacity: .85; pointer-events: none;
}

.og-tools { display: flex; align-items: center; gap: 7px; flex: none; }
.og-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 8px 11px;
  border: 0; border-radius: 10px;
  font: 700 12px 'Segoe UI', system-ui, sans-serif;
  color: #fff; cursor: pointer;
  background: rgba(255,255,255,.14);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.24), inset 0 0 0 1px rgba(255,255,255,.18),
              0 3px 0 rgba(0,0,0,.2), 0 5px 12px rgba(0,0,0,.2);
  transition: transform var(--og-dur) var(--og-ease), background var(--og-dur) var(--og-ease),
              box-shadow var(--og-dur) var(--og-ease);
}
.og-btn:hover, .og-btn:focus-visible {
  transform: translateY(-2px);
  background: rgba(255,255,255,.25);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.32), 0 5px 0 rgba(0,0,0,.2),
              0 12px 22px rgba(0,0,0,.28), 0 0 18px rgba(255,255,255,.2);
}
.og-btn:active { transform: translateY(1px); transition-duration: 90ms;
  box-shadow: inset 0 2px 5px rgba(0,0,0,.3), 0 1px 0 rgba(0,0,0,.2); }
.og-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.og-btn--close { background: rgba(224,75,58,.32); box-shadow: inset 0 0 0 1px rgba(255,160,150,.42), 0 3px 0 rgba(90,16,10,.4), 0 5px 12px rgba(0,0,0,.24); }
.og-btn--close:hover { background: rgba(224,75,58,.55); }
.og-btn__label { display: inline; }

/* Canvas ------------------------------------------------------------- */
.og-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  background:
    radial-gradient(circle at 1px 1px, rgba(11,37,69,.10) 1px, transparent 0) 0 0 / 26px 26px,
    #f4f7fb;
  cursor: grab;
  scroll-behavior: smooth;
}
.og-stage.is-panning { cursor: grabbing; scroll-behavior: auto; user-select: none; }

.og-canvas {
  transform-origin: 50% 0;
  transition: transform 260ms var(--og-ease);
  padding: 34px 40px 60px;
  width: max-content;
  min-width: 100%;
  margin: 0 auto;
}
.og-canvas.is-zooming { transition: none; }

/* Tree ---------------------------------------------------------------
   Geometry, top to bottom:
     parent card
       │  24px descender      (ul::before)
       ├──────────────────    horizontal rail at y=24 (ul::after)
       │  24px ascender       (li::before)
     child card
   --------------------------------------------------------------------- */
.og-tree, .og-tree ul { list-style: none; margin: 0; padding: 0; }

.og-tree ul {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 26px;
  padding-top: 48px;
}

.og-tree li {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* descender from the parent card down to the rail */
.og-tree li > ul::before {
  content: "";
  position: absolute; top: 0; left: 50%;
  width: 2px; height: 24px;
  margin-left: -1px;
  background: #b9c9dd;
  animation: og-grow-v 380ms var(--og-ease) backwards;
}

/* horizontal rail joining the children */
.og-tree li > ul::after {
  content: "";
  position: absolute; top: 24px; height: 2px;
  left: var(--rail-left, 50%);
  right: var(--rail-right, 50%);
  background: #b9c9dd;
  border-radius: 2px;
  animation: og-grow-h 380ms var(--og-ease) backwards;
}

/* ascender from the rail down to each child card */
.og-tree ul > li::before {
  content: "";
  position: absolute; top: -24px; left: 50%;
  width: 2px; height: 24px;
  margin-left: -1px;
  background: #b9c9dd;
}

@keyframes og-grow-v { from { height: 0; opacity: 0; } }
@keyframes og-grow-h { from { transform: scaleX(.2); opacity: 0; } }

.og-tree li.is-collapsed > ul { display: none; }

/* Node ---------------------------------------------------------------- */
.og-nodewrap { position: relative; display: flex; flex-direction: column; align-items: center; }

.og-node {
  position: relative;
  width: 222px;
  padding: 13px 14px 12px;
  border: 0;
  border-radius: 14px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  box-shadow:
    inset 0 0 0 1px rgba(11,37,69,.10),
    0 2px 0 rgba(11,37,69,.05),
    0 6px 16px rgba(8,53,111,.10);
  transition: transform var(--og-dur) var(--og-ease), box-shadow var(--og-dur) var(--og-ease);
  animation: og-pop 340ms var(--og-ease) backwards;
}
@keyframes og-pop { from { opacity: 0; transform: translateY(8px) scale(.97); } }

.og-node:hover, .og-node:focus-visible {
  transform: translateY(-3px);
  box-shadow:
    inset 0 0 0 1px rgba(11,77,162,.32),
    0 5px 0 rgba(11,37,69,.05),
    0 14px 30px rgba(8,53,111,.18);
}
.og-node:focus-visible { outline: 3px solid var(--og-blue); outline-offset: 3px; }

/* coloured band across the top, matching the workbook legend */
.og-node::before {
  content: "";
  position: absolute; left: 0; right: 0; top: 0;
  height: 4px; border-radius: 14px 14px 0 0;
}
.og-node--district::before    { background: var(--og-navy); }
.og-node--subdistrict::before { background: var(--og-blue); }
.og-node--station::before     { background: #5b9bd5; }
.og-node--shift::before       { background: #9aa7b8; }

.og-node__top { display: flex; align-items: center; gap: 11px; margin-top: 4px; }

.og-avatar {
  width: 40px; height: 40px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  font: 700 13.5px 'Segoe UI', system-ui, sans-serif;
  color: #fff;
  background: linear-gradient(160deg, #1160bd, var(--og-blue-dark));
  box-shadow: 0 3px 8px rgba(8,53,111,.26);
}
.og-node--district .og-avatar { background: linear-gradient(160deg, #244a7a, var(--og-navy)); }
.og-node--station  .og-avatar { background: linear-gradient(160deg, #79b0e0, #4a86c4); }
.og-node--shift    .og-avatar { background: linear-gradient(160deg, #aab6c6, #8593a5); }
.og-avatar--empty {
  background: #eef2f7 !important;
  color: #94a3b5;
  box-shadow: inset 0 0 0 1px #dde5ee;
}

.og-node__id { min-width: 0; flex: 1; }

/* name, then designation directly beneath it */
.og-node__name {
  font: 700 13.5px/1.3 'Segoe UI', system-ui, sans-serif;
  color: var(--og-navy);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.og-node__name.is-empty { color: var(--og-blue-dark); }
.og-node__role {
  display: block;
  margin-top: 2px;
  font: 400 11.5px/1.35 'Segoe UI', system-ui, sans-serif;
  color: var(--og-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.og-node--district .og-node__role,
.og-node--subdistrict .og-node__role { color: var(--og-blue); font-weight: 600; }

.og-node__meta {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid #eef2f7;
  display: flex; flex-direction: column; gap: 5px;
}
.og-node__line {
  display: flex; align-items: center; gap: 7px;
  font: 400 11.5px/1.35 'Segoe UI', system-ui, sans-serif;
  color: var(--og-muted);
  min-width: 0;
}
.og-node__line svg { flex: none; opacity: .7; }
.og-node__line > span,
.og-node__line > a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.og-node__line a { color: var(--og-blue); text-decoration: none; font-weight: 600; }
.og-node__line a:hover { text-decoration: underline; }

/* One person covering more than one post — explains a repeated name */
.og-node__also {
  display: block;
  margin-top: 9px;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(242,169,0,.13);
  color: #8a5a12;
  font: 600 10.5px/1.4 'Segoe UI', system-ui, sans-serif;
}

/* expand / collapse pip, straddling the descender */
.og-toggle {
  position: absolute; left: 50%; bottom: -12px;
  transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 4px;
  height: 24px; padding: 0 9px;
  border: 0; border-radius: 12px;
  cursor: pointer;
  background: #fff;
  color: var(--og-blue-dark);
  font: 700 11px/1 'Segoe UI', system-ui, sans-serif;
  box-shadow: inset 0 0 0 1px rgba(11,77,162,.28), 0 2px 6px rgba(8,53,111,.16);
  transition: transform var(--og-dur) var(--og-ease), background var(--og-dur) var(--og-ease),
              color var(--og-dur) var(--og-ease);
  z-index: 3;
}
.og-toggle__sign { font-size: 13px; line-height: 1; }
.og-toggle__n { opacity: .7; font-size: 10px; }
.og-toggle:hover {
  background: var(--og-blue); color: #fff;
  transform: translateX(-50%) scale(1.08);
  box-shadow: 0 4px 12px rgba(8,53,111,.32);
}
.og-toggle:hover .og-toggle__n { opacity: .9; }

/* Search highlighting ------------------------------------------------ */
.og-canvas.is-searching .og-node { opacity: .26; filter: saturate(.4); }
.og-canvas.is-searching .og-node.is-match {
  opacity: 1; filter: none;
  box-shadow: inset 0 0 0 2px var(--og-gold), 0 8px 22px rgba(154,106,8,.34), 0 0 24px rgba(242,169,0,.45);
  animation: og-flash 1.1s var(--og-ease);
}
@keyframes og-flash { 0%,100%{box-shadow: inset 0 0 0 2px var(--og-gold), 0 8px 22px rgba(154,106,8,.34);} 50%{box-shadow: inset 0 0 0 3px var(--og-gold), 0 8px 30px rgba(242,169,0,.6);} }

/* Empty state -------------------------------------------------------- */
.og-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 60px 24px; text-align: center;
  font-family: 'Segoe UI', system-ui, sans-serif; color: var(--og-muted);
}
.og-empty b { font-size: 15px; color: var(--og-navy); }
.og-empty p { margin: 0; font-size: 12.5px; max-width: 420px; line-height: 1.6; }

/* Legend ------------------------------------------------------------- */
.og-legend {
  position: absolute; left: 14px; bottom: 14px; z-index: 3;
  display: flex; gap: 14px; flex-wrap: wrap;
  padding: 9px 13px; border-radius: 11px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 6px 18px rgba(8,53,111,.16);
  font: 600 10.5px 'Segoe UI', system-ui, sans-serif;
  color: var(--og-muted);
}
.og-legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.og-zoomlabel {
  position: absolute; right: 14px; bottom: 14px; z-index: 3;
  padding: 8px 12px; border-radius: 10px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 6px 18px rgba(8,53,111,.16);
  font: 700 11px 'Segoe UI', system-ui, sans-serif; color: var(--og-blue-dark);
}

/* ---------------------------------------------------------------------
   Print
   --------------------------------------------------------------------- */
@media print {
  body > *:not(.og-viewer) { display: none !important; }
  .og-viewer { position: static; opacity: 1; visibility: visible; background: #fff; padding: 0; }
  .og-viewer__shell { width: auto; height: auto; box-shadow: none; }
  .og-bar, .og-legend, .og-zoomlabel, .og-toggle { display: none !important; }
  .og-stage { overflow: visible; background: #fff; }
  .og-canvas { transform: none !important; padding: 0; }
  .og-node { box-shadow: inset 0 0 0 1px #ccd6e2; break-inside: avoid; }
  .og-tree li.is-collapsed > ul { display: flex !important; }
}

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
@media (max-width: 900px) {
  .og-btn__label { display: none; }
  .og-btn { padding: 8px; width: 36px; }
  .og-btn--close { width: auto; padding: 8px 11px; }
  .og-btn--close .og-btn__label { display: inline; }
  .og-search input { width: 170px; }
}
@media (max-width: 640px) {
  .og-overlay { padding: 0; }
  .og-panel { width: 100vw; max-height: 100vh; border-radius: 0; padding: 22px 18px 28px; }
  .og-bar { padding: 9px 10px; gap: 8px; }
  .og-bar__title span { display: none; }
  .og-node { width: 200px; }
  .og-legend { display: none; }
}

/* ---------------------------------------------------------------------
   Reduced motion / forced colours
   --------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .og-overlay, .og-viewer, .og-panel, .og-viewer__shell, .og-node, .og-card,
  .og-canvas, .og-btn, .og-toggle { transition-duration: 1ms !important; animation: none !important; }
  .og-stage { scroll-behavior: auto; }
}
@media (forced-colors: active) {
  .og-node, .og-card, .og-panel { border: 1px solid ButtonText; }
  .og-btn { border: 1px solid ButtonText; }
}
