/* ==========================================================================
   HTMS Organization Chart — three structurally distinct designs.

   All three share the same DOM (a nested <ul> tree built by js/org-chart.js)
   and differ through CSS alone via a design class on the root:
     .oc-corporate-hierarchy — classic top-down connector tree
     .oc-modern-organization — horizontal swimlane cards, left-to-right flow
     .oc-compact-site        — dense indented list, built for a site office printout
   ========================================================================== */

.org-chart-root { overflow-x: auto; padding: 8px 4px 20px; }

.oc-node-card {
  display: inline-flex; flex-direction: column; gap: 2px;
  background: var(--surface-card); border: 1px solid var(--border-default);
  border-radius: 10px; padding: 10px 14px; min-width: 150px;
  box-shadow: var(--shadow-xs); cursor: pointer;
  transition: box-shadow .15s, border-color .15s, transform .15s;
}
.oc-node-card:hover { box-shadow: var(--shadow-md); border-color: var(--accent-300, var(--accent-400)); transform: translateY(-1px); }
.oc-node-card.oc-vacant { border-style: dashed; opacity: 0.75; }
.oc-node-title { font-size: 12.5px; font-weight: 700; color: var(--text-primary); }
.oc-node-role { font-size: 10.5px; color: var(--text-tertiary); }
.oc-node-employee { font-size: 11.5px; color: var(--accent-600); font-weight: 600; margin-top: 3px; }
.oc-node-type-badge { font-size: 8.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-tertiary); }
.oc-node-card.oc-highlight { border-color: var(--accent-500); box-shadow: 0 0 0 3px var(--accent-100); }

/* ---- 1. Corporate Hierarchy: classic top-down tree with connectors ---- */
.oc-corporate-hierarchy ul { display: flex; padding-top: 24px; position: relative; }
.oc-corporate-hierarchy ul ul { padding-top: 24px; }
.oc-corporate-hierarchy li {
  list-style: none; text-align: center; position: relative;
  padding: 0 14px; display: flex; flex-direction: column; align-items: center;
}
.oc-corporate-hierarchy li::before {
  content: ''; position: absolute; top: 0; left: 50%; width: 1px; height: 24px;
  background: var(--border-strong);
}
.oc-corporate-hierarchy li:first-child ul::before,
.oc-corporate-hierarchy ul > li:only-child::before { display: none; }
.oc-corporate-hierarchy > li::before { display: none; }
.oc-corporate-hierarchy ul li ul { display: flex; }
.oc-corporate-hierarchy ul ul::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: var(--border-strong); margin: 0 auto; width: calc(100% - 28px);
}

/* ---- 2. Modern Organization: horizontal swimlanes, left-to-right depth ---- */
.oc-modern-organization .org-chart-root { display: flex; gap: 28px; align-items: flex-start; }
.oc-modern-organization .oc-lane { display: flex; flex-direction: column; gap: 12px; min-width: 200px; }
.oc-modern-organization .oc-lane-label {
  font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-tertiary); border-bottom: 2px solid var(--accent-200); padding-bottom: 6px;
}
.oc-modern-organization .oc-node-card { width: 100%; border-left: 3px solid var(--accent-500); }

/* ---- 3. Compact Site: dense indented list, built for a printed office sheet ---- */
.oc-compact-site .org-chart-root { display: block; }
.oc-compact-site ul { list-style: none; margin: 0; padding-left: 22px; border-left: 1px dashed var(--border-default); }
.oc-compact-site > ul { padding-left: 0; border-left: 0; }
.oc-compact-site li { margin: 4px 0; }
.oc-compact-site .oc-node-card {
  display: flex; flex-direction: row; align-items: center; gap: 8px;
  min-width: 0; padding: 5px 10px; border-radius: 7px;
}
.oc-compact-site .oc-node-title { font-size: 11.5px; }
.oc-compact-site .oc-node-role,
.oc-compact-site .oc-node-employee { font-size: 10.5px; margin: 0; }
.oc-compact-site .oc-node-employee::before { content: '— '; }

@media print {
  .org-chart-root { overflow: visible; }
  .oc-node-card { box-shadow: none; }
}

/* ==========================================================================
   Premium organization workspace
   ========================================================================== */
.org-page-hero { align-items: center; margin-bottom: 18px; }
.org-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
  min-width: min(100%, 520px);
}
.org-summary-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: var(--shadow-xs);
}
.org-summary-item > span:last-child { min-width: 0; }
.org-summary-item strong { display: block; font-family: var(--font-display); font-size: 19px; line-height: 1; color: var(--text-primary); }
.org-summary-item small { display: block; margin-top: 5px; color: var(--text-tertiary); font-size: 10px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; white-space: nowrap; }
.org-summary-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  color: var(--accent-600);
  background: var(--accent-50);
  border-radius: 9px;
}
.org-summary-icon.is-filled { color: var(--emerald-600); background: var(--emerald-50); }
.org-summary-icon.is-vacant { color: var(--amber-600); background: var(--amber-50); }

.org-command-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: 13px;
  box-shadow: var(--shadow-xs);
}
.org-view-control, .org-command-actions { display: flex; align-items: center; gap: 9px; min-width: 0; }
.org-command-actions { justify-content: flex-end; }
.org-control-label { padding-left: 3px; color: var(--text-tertiary); font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.org-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(290px, 34vw);
  min-width: 190px;
  height: 36px;
  padding: 0 10px;
  color: var(--text-tertiary);
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.org-search:focus-within { background: var(--surface-card); border-color: var(--accent-400); box-shadow: 0 0 0 3px var(--accent-100); }
.org-search input { width: 100%; min-width: 0; height: auto; padding: 0; background: transparent; border: 0; box-shadow: none; outline: 0; font-size: 12px; }
.org-search-count { color: var(--accent-600); font-size: 10px; font-weight: 700; white-space: nowrap; }

.org-chart-panel { overflow: hidden; }
.org-chart-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  background: linear-gradient(180deg, var(--surface-card), var(--surface-muted));
  border-bottom: 1px solid var(--border-subtle);
}
.org-legend { display: flex; align-items: center; gap: 14px; color: var(--text-tertiary); font-size: 11px; font-weight: 650; white-space: nowrap; }
.org-legend span { display: inline-flex; align-items: center; gap: 6px; }
.org-legend-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--emerald-500); box-shadow: 0 0 0 3px var(--emerald-50); }
.org-legend-dot.is-vacant { background: var(--amber-500); box-shadow: 0 0 0 3px var(--amber-50); }
.org-chart-stage {
  position: relative;
  min-height: 510px;
  padding: 30px 24px 36px;
  overflow: hidden;
  background-color: #f8fafc;
  background-image: radial-gradient(circle, rgba(148, 163, 184, .24) 1px, transparent 1px);
  background-size: 22px 22px;
}
.org-chart-root { max-width: 100%; padding: 6px 4px 24px; scrollbar-color: var(--slate-300) transparent; }

.oc-node-card {
  position: relative;
  gap: 0;
  min-width: 210px;
  max-width: 240px;
  padding: 14px;
  text-align: left;
  border-color: rgba(148, 163, 184, .42);
  border-radius: 13px;
  box-shadow: 0 8px 22px rgba(15, 23, 42, .07), 0 1px 2px rgba(15, 23, 42, .06);
}
.oc-node-card::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent-500); border-radius: 13px 0 0 13px; }
.oc-node-card.oc-type-organization { color: #fff; background: linear-gradient(145deg, #153a66, #1d4f83); border-color: #2f679d; box-shadow: 0 12px 28px rgba(19, 58, 100, .24); }
.oc-node-card.oc-type-organization::before { background: #62b5e5; }
.oc-node-card.oc-type-organization .oc-node-title,
.oc-node-card.oc-type-organization .oc-node-person strong { color: #fff; }
.oc-node-card.oc-type-organization .oc-node-kicker,
.oc-node-card.oc-type-organization .oc-node-role,
.oc-node-card.oc-type-organization .oc-node-person small { color: rgba(255, 255, 255, .7); }
.oc-node-card.oc-type-department::before { background: var(--emerald-500); }
.oc-node-card.oc-vacant { opacity: 1; background: rgba(255, 255, 255, .88); border-color: var(--amber-300); border-style: dashed; box-shadow: 0 6px 18px rgba(15, 23, 42, .05); }
/* A vacant organization-type node otherwise inherits the near-white
   .oc-vacant background while its title/kicker stay white (set above for
   the navy-gradient organization card), leaving the label invisible.
   Keep the navy gradient so the white text stays readable; the dashed
   amber border from .oc-vacant already communicates the vacant state. */
.oc-node-card.oc-type-organization.oc-vacant { background: linear-gradient(145deg, #153a66, #1d4f83); border-color: var(--amber-300); }
.oc-node-kicker { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; color: var(--accent-600); font-size: 9px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.oc-node-kicker i { font-size: 9px; }
.oc-node-title { font-size: 13px; line-height: 1.3; }
.oc-node-role { min-height: 14px; margin-top: 3px; font-size: 10px; }
.oc-node-person { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid rgba(148, 163, 184, .22); }
.oc-node-avatar { display: grid; place-items: center; width: 29px; height: 29px; flex: 0 0 29px; border-radius: 8px; color: var(--accent-700); background: var(--accent-50); font-size: 9px; font-weight: 800; }
.oc-vacant .oc-node-avatar { color: var(--amber-700); background: var(--amber-50); }
.oc-node-person > span:last-child { min-width: 0; }
.oc-node-person strong, .oc-node-person small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.oc-node-person strong { color: var(--text-primary); font-size: 10.5px; }
.oc-node-person small { margin-top: 2px; color: var(--text-tertiary); font-size: 8.5px; }
.oc-node-card:focus-visible { outline: 0; border-color: var(--accent-500); box-shadow: 0 0 0 4px var(--accent-100), 0 8px 22px rgba(15, 23, 42, .08); }
.oc-node-card.oc-highlight { border-color: var(--accent-500); box-shadow: 0 0 0 4px var(--accent-100), 0 12px 26px rgba(15, 23, 42, .12); transform: translateY(-2px); }

.oc-corporate-hierarchy ul { justify-content: center; }
.oc-corporate-hierarchy li { padding-inline: 10px; }
.oc-corporate-hierarchy li::before,
.oc-corporate-hierarchy ul ul::before { background: #b9c7d7; }
.oc-modern-organization { display: flex; align-items: flex-start; gap: 18px; }
.oc-modern-organization .oc-lane { min-width: 230px; padding: 10px; background: rgba(255, 255, 255, .66); border: 1px solid rgba(148, 163, 184, .28); border-radius: 13px; }
.oc-modern-organization .oc-lane-label { padding: 2px 3px 9px; color: var(--accent-700); border-bottom-color: var(--accent-200); }
.oc-modern-organization .oc-node-card { width: 100%; max-width: none; }
.oc-compact-site ul { border-left-color: #b9c7d7; }
.oc-compact-site .oc-node-card { max-width: none; min-height: 50px; padding: 8px 10px; }
.oc-compact-site .oc-node-kicker { width: 88px; margin: 0; }
.oc-compact-site .oc-node-person { margin: 0 0 0 auto; padding: 0 0 0 12px; border-top: 0; border-left: 1px solid var(--border-subtle); }

@media (max-width: 1100px) {
  .org-page-hero { align-items: flex-start; }
  .org-summary { width: 100%; }
  .org-command-bar { align-items: stretch; flex-direction: column; }
  .org-command-actions { justify-content: flex-start; flex-wrap: wrap; }
  .org-search { flex: 1 1 260px; width: auto; }
}
@media (max-width: 700px) {
  .org-summary { grid-template-columns: 1fr; }
  .org-summary-item { padding: 10px 12px; }
  .org-command-actions .btn { flex: 1 1 auto; }
  .org-view-control { align-items: stretch; flex-direction: column; }
  .org-view-control .segmented { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
  .org-search { flex-basis: 100%; min-width: 0; }
  .org-chart-panel-head { align-items: flex-start; flex-direction: column; }
  .org-chart-stage { min-height: 420px; padding: 20px 12px 28px; }
}

@media print {
  @page { size: A4 landscape; margin: 12mm; }
  .sidebar, .app-header, .org-command-bar, .org-summary, .org-legend { display: none !important; }
  .main-col, .main-content { margin: 0 !important; padding: 0 !important; }
  .org-page-hero { margin-bottom: 12px; }
  .org-chart-panel { border: 0; }
  .org-chart-stage { min-height: 0; padding: 10px 0; background: #fff; overflow: visible; }
  .org-chart-root { overflow: visible !important; }
  /* Wide layouts (many siblings / swimlanes) must wrap onto additional
     printed rows instead of running off the right edge of the page —
     a printer can't offer a horizontal scrollbar the way the screen does. */
  .oc-corporate-hierarchy ul { flex-wrap: wrap; row-gap: 24px; }
  .oc-modern-organization,
  .oc-modern-organization .org-chart-root { flex-wrap: wrap; }
  .oc-node-card { break-inside: avoid; box-shadow: none; }
  .oc-node-card::before { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .oc-node-card.oc-type-organization { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
