/* ═══════════════════════════════════════════════════════════════════
   ORG CHART — dotted-canvas visualisation of the company hierarchy.
   - Canvas: CSS dot-grid background, SVG connectors, HTML cards.
   - Pan with click-drag, zoom with mouse wheel.
   - Mobile fallback (<=768px): plain nested tree, no canvas.
   =================================================================== */

/* ── Canvas wrapper ───────────────────────────────────────── */
.org-canvas-wrap {
  position: relative;
  width: 100%;
  height: 640px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background-color: var(--surface);
  /* Dotted grid background — 20px pitch, small dots. Uses border
     color for subtle contrast in both light and dark themes. */
  background-image: radial-gradient(circle, var(--border) 1px, transparent 1.5px);
  background-size: 20px 20px;
  background-position: 0 0;
  cursor: grab;
  touch-action: none;      /* prevent browser native pan/zoom on mobile; we handle it */
}

.org-canvas-wrap.is-panning { cursor: grabbing; }

/* The transformed root — one element moves + scales for pan/zoom
   instead of every card being individually positioned. Kids live
   inside (SVG layer + HTML card layer), sharing coordinates. */
.org-canvas-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  width: 0;           /* content is absolutely positioned; width is decorative */
  height: 0;
  will-change: transform;
}

.org-canvas-svg {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;       /* lets elbow paths draw past the origin */
  pointer-events: none;    /* clicks pass through to cards */
}

/* Connector paths. Primary = solid teal, dotted = dashed muted. */
.org-canvas-svg .link-primary {
  stroke: var(--teal, #0e5a78);
  stroke-width: 2;
  fill: none;
}
.org-canvas-svg .link-dotted {
  stroke: var(--muted, #6b7280);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
  fill: none;
}

/* ── Employee card ────────────────────────────────────────── */
.org-node {
  position: absolute;
  width: 200px;
  height: 110px;
  padding: 12px;
  padding-top: 16px;              /* room for level chip in the corner */
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left-width: 4px;         /* level-tier accent stripe on the left */
  border-left-color: var(--muted);
  border-radius: 10px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Level chip — small, absolutely-positioned badge in the top-right
   corner of the card. Color-coded by tier so levels are visible at a
   glance while panning the canvas. Matches the left accent stripe. */
.org-node-level {
  position: absolute;
  top: -8px;
  right: 12px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--muted);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  line-height: 1;
  pointer-events: none;
}

.org-node.level-tier-0 { border-left-color: #0a4a64; }
.org-node.level-tier-0 .org-node-level { background: #0a4a64; }

.org-node.level-tier-1 { border-left-color: #0e5a78; }
.org-node.level-tier-1 .org-node-level { background: #0e5a78; }

.org-node.level-tier-2 { border-left-color: #2d8fb5; }
.org-node.level-tier-2 .org-node-level { background: #2d8fb5; }

.org-node.level-tier-3 { border-left-color: #6ba8c2; }
.org-node.level-tier-3 .org-node-level { background: #6ba8c2; color: #0f1419; }

.org-node.level-tier-4 { border-left-color: #9cb5c0; }
.org-node.level-tier-4 .org-node-level { background: #9cb5c0; color: #0f1419; }

.org-node.level-tier-5 { border-left-color: #7a8793; }
.org-node.level-tier-5 .org-node-level { background: #7a8793; }

.org-node.level-tier-none { border-left-color: var(--border); }
.org-node.level-tier-none .org-node-level {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--border);
  font-weight: 500;
}

.org-node:hover {
  transform: translateY(-2px);
  border-color: var(--teal, #0e5a78);
  box-shadow: var(--shadow-sm);
  z-index: 2;
}

.org-node.is-self {
  border-color: var(--teal, #0e5a78);
  border-width: 2px;
}

.org-node-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.org-node-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface3);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.org-node-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.org-node-designation {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.org-node-meta {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.org-node-chip {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  background: var(--surface3);
  color: var(--muted);
}

.org-node-chip.role-admin { background: rgba(14, 90, 120, 0.18); color: var(--teal, #0e5a78); }

/* ── Toolbar ──────────────────────────────────────────────── */
.org-toolbar {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: var(--surface-elevated, var(--surface2));
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-xs);
  backdrop-filter: blur(6px);
  z-index: 5;
}

.org-toolbar button {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 6px;
  line-height: 1;
}

.org-toolbar button:hover { background: var(--surface3); }
.org-toolbar .tb-zoom { font-variant-numeric: tabular-nums; font-family: 'DM Mono', monospace; color: var(--muted); }

/* ── Legend ───────────────────────────────────────────────── */
.org-legend {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
}
.org-legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.org-legend-line {
  width: 24px;
  height: 2px;
  background: var(--teal, #0e5a78);
}
.org-legend-line.dotted {
  background: transparent;
  border-top: 2px dashed var(--muted);
}

/* ── Side drawer (opens when a card is clicked) ───────────── */
.org-drawer {
  position: fixed;
  top: 0;
  right: -380px;
  width: 360px;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.25);
  z-index: 120;
  padding: 20px;
  overflow-y: auto;
  transition: right 0.22s ease;
}
.org-drawer.open { right: 0; }

.org-drawer-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}
.org-drawer-close:hover { color: var(--text); }

.org-drawer-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.org-drawer-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface3);
  color: var(--text);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.org-drawer-name { font-size: 16px; font-weight: 600; color: var(--text); }
.org-drawer-sub  { font-size: 13px; color: var(--muted); }

.org-drawer-kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  font-size: 13px;
  margin-bottom: 14px;
}
.org-drawer-kv dt {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
  align-self: center;
}
.org-drawer-kv dd { color: var(--text); margin: 0; }

.org-drawer-list {
  font-size: 13px;
  color: var(--text);
  list-style: none;
  padding: 0;
  margin: 6px 0 14px 0;
}
.org-drawer-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.org-drawer-list li:last-child { border-bottom: 0; }

/* ── Mobile fallback — no canvas, just a nested vertical tree ── */
@media (max-width: 768px) {
  .org-canvas-wrap { display: none; }
  .org-fallback-tree { display: block !important; }

  /* Full-screen sheet on phones. The drawer is now a body-level
     sibling of #app, so position:fixed is viewport-relative again —
     box-sizing:border-box + width:100% means right:-100% parks it
     exactly off-screen (no sliver) and .open (right:0 from the base
     rule) is an exact full-screen sheet with no overflow. */
  .org-drawer {
    box-sizing: border-box;
    width: 100%;
    right: -100%;
    padding: 16px;
    padding-top: 48px; /* space for the close button */
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .org-drawer-close { font-size: 28px; padding: 6px 12px; }
  .org-toolbar {
    /* Above the canvas on very narrow screens so it never overlaps cards */
    position: static;
    margin-bottom: 10px;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .org-legend {
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    background: var(--surface2);
    border-radius: 8px;
  }
}

@media (max-width: 480px) {
  /* Mobile fallback tree: tighter padding, larger tap area */
  .org-fallback-tree li { padding: 8px 0 8px 14px; }
  .org-fallback-tree li::after { top: 20px; width: 10px; }
  .org-fallback-card {
    padding: 10px 12px;
    min-height: 44px; /* accessibility tap target */
    flex-wrap: wrap;
  }
  .org-fallback-card .org-node-name,
  .org-fallback-card .org-node-designation {
    white-space: normal;
    word-break: break-word;
  }
}

.org-fallback-tree { display: none; }
.org-fallback-tree ul {
  list-style: none;
  padding-left: 18px;
  margin: 0;
  position: relative;
}
.org-fallback-tree > ul { padding-left: 0; }
.org-fallback-tree li {
  position: relative;
  padding: 6px 0 6px 18px;
}
.org-fallback-tree li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-left: 1px solid var(--border);
}
.org-fallback-tree li::after {
  content: '';
  position: absolute;
  left: 0;
  top: 18px;
  width: 14px;
  border-top: 1px solid var(--border);
}
.org-fallback-tree > ul > li::before { display: none; } /* top row has no parent line */
.org-fallback-tree > ul > li::after  { display: none; }

.org-fallback-card {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-left-color: var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.org-fallback-card .org-node-avatar { width: 26px; height: 26px; font-size: 11px; }
.org-fallback-card .org-node-name { font-size: 13px; }
.org-fallback-card .org-node-designation { font-size: 11px; }
/* Inline level chip for the mobile fallback card — not absolutely
   positioned, just a small pill at the start of the card. */
.org-fallback-card .org-node-level {
  position: static;
  font-size: 10px;
  padding: 2px 6px;
  box-shadow: none;
  margin-right: 2px;
  flex-shrink: 0;
}

.org-empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
