/* ===================================================================
   Organization Chart  —  styles  (Brandworks orange / white theme)
   =================================================================== */

:root {
  /* brand */
  --brand:        #f26522;   /* Brandworks orange       */
  --brand-dark:   #d4521a;
  --brand-light:  #fb8c4e;
  --brand-soft:   #fff1e8;   /* very light orange tint  */

  --charcoal:     #3a3d42;   /* logo dark text          */
  --charcoal-dk:  #25272b;

  /* node types — original chart scheme (unchanged) */
  --exec:        #e02516;    /* red    — top execs */
  --exec-dk:     #b51d10;
  --position:    #3258c4;    /* blue   — roles     */
  --position-dk: #24429a;
  --support:     #c4641d;    /* orange — support   */
  --support-dk:  #9e4f14;

  --line:        #9aa6bf;    /* connector lines    */
  --bg1:         #fffaf6;
  --bg2:         #fdeee3;
  --panel:       #ffffff;
  --ink:         #2f3338;
  --muted:       #9a8b7f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  font-family: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: #f8fafc;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: row;
}

/* ---------- Collapsible Sidebar ---------- */
.app-sidebar {
  width: 280px;
  height: 100%;
  background: #ffffff;
  border-right: 1px solid rgba(242, 101, 34, 0.08);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.02);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10;
  flex-shrink: 0;
}

.app-sidebar.collapsed {
  width: 78px;
}

/* Brand header in sidebar */
.sidebar-brand {
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  height: 80px;
  flex-shrink: 0;
}

.sidebar-brand .brand-logo {
  height: 38px;
  width: auto;
  flex-shrink: 0;
  display: block;
}

.app-sidebar.collapsed .sidebar-brand {
  padding: 20px 10px;
  justify-content: center;
}

.app-sidebar.collapsed .brand-logo {
  display: none;
}

/* Search wrap in sidebar */
.sidebar-search {
  padding: 16px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrapper .search-icon {
  position: absolute;
  left: 12px;
  font-size: 14px;
  color: #94a3b8;
  pointer-events: none;
}

.sidebar-search input {
  width: 100%;
  padding: 10px 12px 10px 34px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 13.5px;
  outline: none;
  background: #f8fafc;
  transition: all 0.2s ease;
  color: var(--ink);
}

.sidebar-search input:focus {
  border-color: var(--brand);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(242, 101, 34, 0.12);
}

.app-sidebar.collapsed .sidebar-search {
  padding: 16px 12px;
}

.app-sidebar.collapsed .sidebar-search input {
  padding: 10px 0;
  text-align: center;
  text-indent: -9999px; /* Hide text but keep functional */
  background: #f8fafc url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'/%3E%3C/svg%3E") no-repeat center center;
  background-size: 18px;
}

.app-sidebar.collapsed .search-icon {
  display: none;
}

/* Nav links in sidebar */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Custom Scrollbar for navigation */
.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}
.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
}

.dept-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border: none;
  background: transparent;
  color: #64748b;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
  position: relative;
}

.dept-nav-item:hover {
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.dept-nav-item.active {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(242, 101, 34, 0.2);
}

.dept-icon {
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  flex-shrink: 0;
}

.dept-label-text {
  flex: 1;
  transition: opacity 0.2s ease, width 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar.collapsed .dept-label-text {
  opacity: 0;
  pointer-events: none;
  width: 0;
}

.dept-badge {
  font-size: 10px;
  background: #f1f5f9;
  color: #475569;
  padding: 2px 6px;
  border-radius: 20px;
  font-weight: 700;
  transition: all 0.2s ease;
}

.dept-nav-item.active .dept-badge {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.app-sidebar.collapsed .dept-badge {
  display: none;
}

.dept-nav-item.empty {
  opacity: 0.55;
  font-weight: 500;
  font-style: italic;
}

.app-sidebar.collapsed .dept-nav-item {
  padding: 11px 0;
  justify-content: center;
}

/* Sidebar brand layout helper */

/* Hamburger button styling */
.hamburger-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: #64748b;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.hamburger-btn:hover {
  background: #f1f5f9;
  color: var(--brand);
}

.hamburger-btn svg {
  display: block;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 16px 14px;
  border-top: 1px solid rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #475569;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  transition: all 0.2s ease;
}

.admin-link:hover {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-dark);
}

.admin-icon {
  font-size: 15px;
}

.admin-text {
  transition: opacity 0.2s ease;
}

.sidebar-credit {
  font-size: 10.5px;
  color: #94a3b8;
  text-align: center;
  margin-top: 4px;
}

.app-sidebar.collapsed .sidebar-footer {
  padding: 16px 0;
  align-items: center;
}

.app-sidebar.collapsed .admin-link {
  border: none;
  padding: 8px 0;
  width: 100%;
  justify-content: center;
}

.app-sidebar.collapsed .admin-text,
.app-sidebar.collapsed .sidebar-credit {
  display: none;
}

/* ---------- Main Content Wrapper ---------- */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  overflow: hidden;
}

/* ---------- Top Bar ---------- */
.top-bar {
  height: 70px;
  background: #ffffff;
  border-bottom: 1px solid rgba(242, 101, 34, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  flex-shrink: 0;
  z-index: 8;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.01);
}

.top-bar-title-group {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.active-dept-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--charcoal);
  margin: 0;
  letter-spacing: -0.3px;
}

.active-dept-subtitle {
  font-size: 11.5px;
  color: var(--brand);
  font-weight: 600;
  letter-spacing: 0.3px;
  margin-top: 1px;
}

.top-bar-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 8px;
}

.zoom-controls button {
  border: none;
  background: transparent;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: #475569;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.zoom-controls button:hover {
  background: #ffffff;
  color: var(--brand-dark);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

#zoomLabel {
  font-size: 12.5px;
  font-weight: 700;
  color: #475569;
  min-width: 42px;
  text-align: center;
}

#printBtn {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(242, 101, 34, 0.2);
  transition: all 0.2s ease;
}

#printBtn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(242, 101, 34, 0.3);
  filter: brightness(1.05);
}

/* ---------- Content row: chart + side panel ---------- */
.content {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---------- Chart viewport ---------- */
.chart-viewport {
  flex: 1;
  overflow: auto;
  padding: 30px 24px 50px;
  cursor: grab;
  user-select: none;            /* avoid text-selection while dragging */
  background-image: 
    radial-gradient(rgba(242, 101, 34, 0.09) 1px, transparent 1px);
  background-size: 24px 24px;
}
.chart-viewport.grabbing { cursor: grabbing; }

/* ---------- Side "scale" summary panel ---------- */
.stats-panel {
  width: 230px;
  flex-shrink: 0;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-left: 1px solid rgba(242, 101, 34, 0.12);
  padding: 14px 14px 20px;
}
.stats-head {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--charcoal);
  margin: 0 0 2px;
}
.stats-sub {
  font-size: 10.5px;
  color: var(--muted);
  margin: 0 0 12px;
  letter-spacing: .3px;
  text-transform: uppercase;
}

/* KPI cards */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.kpi {
  background: linear-gradient(180deg, #fff, #fff7f1);
  border: 1px solid #f1e0d2;
  border-radius: 10px;
  padding: 8px 10px 7px;
  text-align: left;
}
.kpi-num {
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  color: var(--charcoal);
}
.kpi-label {
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
  font-weight: 600;
}
.kpi.accent  .kpi-num { color: var(--brand-dark); }
.kpi.vacant  { border-color: #f4c4bf; }
.kpi.vacant  .kpi-num { color: #d0392b; }
.kpi.newpos  { border-color: #c2d4f7; }
.kpi.newpos  .kpi-num { color: #2f6fe0; }

/* status breakdown ("scale" bars) */
.bd-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--charcoal);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 0 0 8px;
}
.bd-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.bd-dot { width: 9px; height: 9px; border-radius: 3px; }
.bd-name { font-size: 11px; color: var(--ink); }
.bd-count { font-size: 11px; font-weight: 700; color: var(--charcoal); }
.bd-bar {
  grid-column: 2 / 4;
  height: 5px;
  background: #f0eae4;
  border-radius: 5px;
  overflow: hidden;
}
.bd-fill { height: 100%; border-radius: 5px; transition: width .4s ease; }

.bd-total {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #ecdccd;
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
}
.bd-total b { color: var(--charcoal); }
.chart-stage {
  position: relative;
  transform-origin: top center;
  transition: transform .15s ease;
  display: flex;
  justify-content: center;
  min-width: min-content;
  margin: 0 auto;
}

/* a small root (e.g. ECO) tucked next to the main root box */
.org-tree.satellite {
  position: absolute;
  top: 0;
  left: 0;
}

/* ---------- The tree (classic CSS connector technique) ---------- */
.org-tree, .org-tree ul {
  display: flex;
  justify-content: center;
  padding: 0;
  margin: 0;
  list-style: none;
}
.org-tree li {
  position: relative;
  padding: 20px 4px 0 4px;
  text-align: center;
}

/* vertical line going UP from each node to the horizontal connector */
.org-tree li::before,
.org-tree li::after {
  content: "";
  position: absolute;
  top: 0;
  right: 50%;
  width: 50%;
  height: 20px;
  border-top: 2px solid var(--line);
}
.org-tree li::after {
  right: auto;
  left: 50%;
  border-left: 2px solid var(--line);
}
/* sole child: hide the horizontal ::before; ::after handled below */
.org-tree li:only-child::before { display: none; }
.org-tree li:only-child { padding-top: 20px; }

.org-tree li:first-child::before,
.org-tree li:last-child::after { border: 0 none; }
.org-tree li:last-child::before {
  border-right: 2px solid var(--line);
  border-radius: 0 7px 0 0;
}
.org-tree li:first-child::after {
  border-radius: 7px 0 0 0;
}

/* sole child WITH a parent (i.e. inside a nested <ul>): draw a single
   continuous vertical line. Scoped to ".org-tree ul li" so it does NOT
   apply to the top-level roots (ECO / DIRECTOR), which must have no line. */
.org-tree ul li:only-child::after {
  display: block;
  top: -2px;
  right: auto;
  left: 50%;
  width: 0;
  height: 24px;
  border: 0 none;
  border-left: 2px solid var(--line);
  border-radius: 0;
}

/* vertical line coming DOWN from a parent into its children's row */
.org-tree ul::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 0;
  height: 22px;
  border-left: 2px solid var(--line);
}
.org-tree ul { position: relative; padding-top: 20px; }

/* ---------- Vertical branches for space optimization ---------- */
.org-tree ul.vertical-branch {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-left: 50%;
  padding-top: 20px;
  list-style: none;
}
.org-tree ul.vertical-branch::before {
  left: 0;
  height: 20px;
}
.org-tree ul.vertical-branch::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 40px;
  width: 0;
  border-left: 2px solid var(--line);
}
.org-tree ul.vertical-branch li {
  display: block;
  padding: 6px 0 6px 20px;
  text-align: left;
}
.org-tree ul.vertical-branch li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 40px;
  width: 24px;
  height: 0;
  border-top: 2px solid var(--line);
  border-radius: 0;
}
.org-tree ul.vertical-branch li::after {
  display: none !important;
}
.org-tree ul.vertical-branch li:only-child::after {
  display: none !important;
}

/* ---------- Node boxes (designation card + name plate) ---------- */
.node {
  display: inline-block;
  width: 126px;                 /* standardized box size */
  vertical-align: top;
  border-radius: 10px;
  overflow: hidden;
  text-align: center;
  cursor: inherit;
  box-shadow: 0 3px 9px rgba(20,30,50,.18);
  border: 1px solid rgba(0,0,0,.10);
  transition: transform .14s, box-shadow .14s, filter .14s;
}
.node:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 24px rgba(20,30,50,.30);
}

/* top: designation */
.node .role-name {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.3em;
  padding: 6px 7px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.18;
}

/* bottom: name plate */
.node .role-person {
  display: block;
  background: #ffffff;
  color: #34373d;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.18;
  padding: 4px 6px;
  border-top: 1px solid rgba(0,0,0,.08);
}
.node .role-person.is-empty  { color: #b9a89b; font-weight: 500; }
.node .role-person.is-vacant { color: #d0392b; font-weight: 700; }
.node .role-person.is-new    { color: #2f6fe0; font-weight: 700; }

.node.exec .role-name     { background: linear-gradient(180deg, var(--exec), var(--exec-dk)); }
.node.position .role-name { background: linear-gradient(180deg, var(--position), var(--position-dk)); }
.node.support .role-name  { background: linear-gradient(180deg, var(--support), var(--support-dk)); }

/* compact grid: a large group of leaf positions wraps into rows instead of
   one very wide row. The whole grid connects to the parent as one unit. */
.org-tree li.grid-group { padding-top: 22px; }
.leaf-grid {
  display: grid;
  grid-template-columns: repeat(5, max-content);
  gap: 10px;
  justify-content: center;
  align-items: start;
}
.leaf-grid .node { margin: 0; }

/* search highlight */
.node.dimmed { filter: grayscale(.6) opacity(.32); }
.node.match {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(242, 101, 34, 0.25), 0 8px 24px rgba(242, 101, 34, 0.15);
  transform: translateY(-2px) scale(1.02);
}

/* empty department message */
.empty-state {
  margin: 70px auto;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  max-width: 440px;
  background: #fff;
  padding: 34px 30px;
  border-radius: 14px;
  border: 1.5px dashed #cbd5e1;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.02);
}
.empty-state strong { color: var(--brand-dark); }
.empty-state code { background: #f1f5f9; padding: 1px 6px; border-radius: 5px; color: var(--charcoal); }

/* ---------- Footer ---------- */
.app-footer {
  padding: 12px 26px;
  font-size: 12.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(242, 101, 34, 0.12);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.app-footer .brand-credit { color: var(--brand-dark); font-weight: 600; }
.app-footer .footer-right { display: flex; align-items: center; gap: 18px; }
.app-footer .admin-link {
  color: var(--charcoal);
  text-decoration: none;
  font-weight: 600;
  padding: 4px 12px;
  border: 1px solid #e6d3c3;
  border-radius: 7px;
}
.app-footer .admin-link:hover { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); }

/* ---------- Print  (A3 landscape, centred) ---------- */
.print-header { display: none; }
.print-signatures { display: none; }
@page { size: A3 landscape; margin: 5mm; }

@media print {
  .app-sidebar, .top-bar, .app-footer { display: none !important; }
  
  html {
    height: 100% !important;
  }

  body {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    min-height: 100vh !important;
    background: #f8f6f2 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .main-wrapper {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    height: auto !important;
    width: 100% !important;
    overflow: visible !important;
    order: 2 !important;
  }

  /* print header: company logo on the left, title centered */
  .print-header {
    order: 1 !important;
    position: relative;
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    margin: 0 0 3mm;
    padding-bottom: 2mm;
    border-bottom: 2px solid var(--brand);
  }

  .print-title {
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: #1f2733;
    margin: 0;
  }

  .print-logo {
    position: absolute;
    left: 0;
    top: 0;
    height: 42px;
    width: auto;
    object-fit: contain;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* chart (left) + summary (right) — stretch to fill remaining page height */
  .content {
    display: flex;
    align-items: stretch;
    flex: 1 !important;
    gap: 4mm;
  }

  .chart-viewport {
    flex: 1;
    overflow: visible;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4mm;
    border: 1px solid #dcd1c4;
    border-radius: 6px;
    background: #ffffff !important;
    background-image: none !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .chart-stage {
    transform: none !important;
    margin: 0 auto;
  }

  .stats-panel {
    display: block;
    width: 200px;
    flex-shrink: 0;
    overflow: visible;
    padding: 4mm;
    border: 1px solid #dcd1c4;
    border-radius: 6px;
    background: #ffffff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .node { box-shadow: none; }
  .node, .kpi, .bd-fill, .bd-dot, .swatch {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* signature blocks across the bottom */
  .print-signatures {
    order: 3 !important;
    display: flex !important;
    justify-content: space-between;
    gap: 10mm;
    margin-top: 8mm;
    padding: 0 4mm;
  }
  .print-signatures .sig { flex: 1; text-align: center; }
  .print-signatures .sig-space { height: 15mm; border-bottom: 1.5px solid #333; }
  .print-signatures .sig-label {
    margin-top: 5px;
    font-size: 12px;
    font-weight: 600;
    color: #000;
  }
}
