/* ============================================================
   Section 4 — 職位分布圖
   ============================================================ */

#role-chart {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border-light);
  border-bottom: 1px solid var(--color-border-light);
}

.role-chart-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--space-12);
  align-items: center;
}

/* --- 圖表容器（overflow visible 讓 hoverOffset 不被裁切） --- */
.role-chart-canvas-wrap {
  position: relative;
  width: 260px;
  height: 260px;
  margin: 0 auto;
  flex-shrink: 0;
  overflow: visible;
}

/* --- Callout 卡片群：4+4 兩欄排列 --- */
.role-callouts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-flow: column;
  grid-template-rows: repeat(4, auto);
  gap: var(--space-2);
  column-gap: var(--space-3);
}

/* --- 每張卡片 --- */
.role-callout {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  cursor: default;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  overflow: visible; /* 讓頭像 tooltip 能溢出 */
  position: relative;
  /* z-index 由 JS 動態設定（倒序），第一張卡片最高 */
}

/* --- 職稱列（色點 + 名稱 + 數量） --- */
.role-callout__title-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.role-callout__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.role-callout__name {
  flex: 1;
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  line-height: 1.3;
}

/* --- 底部列（頭像 + 數量同排） --- */
.role-callout__bottom {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* --- 頭像列 --- */
.role-callout__avatars {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
  flex: 1;
}

.role-callout__count {
  font-size: 40px;
  font-weight: var(--font-weight-bold);
  line-height: 1;
  flex-shrink: 0;
}

/* --- 單顆頭像（帶 tooltip） --- */
.role-callout__avatar-wrap {
  position: relative;
}

.role-callout__avatar-wrap img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top;
  border: 2px solid var(--color-surface);
  display: block;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.role-callout__avatar-wrap:hover img {
  transform: translateY(-2px);
}

/* 頭像 tooltip（::after 實作，不需要 JS） */
.role-callout__avatar-wrap::after {
  content: attr(data-name);
  position: absolute;
  top: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text-primary);
  color: #fff;
  font-size: 11px;
  font-weight: var(--font-weight-medium);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 200;
}

.role-callout__avatar-wrap:hover::after {
  opacity: 1;
}

/* ============================================================
   RWD
   ============================================================ */

@media (max-width: 1024px) {
  .role-chart-layout {
    grid-template-columns: 260px 1fr;
    gap: var(--space-8);
  }
}

@media (max-width: 768px) {
  .role-chart-layout {
    grid-template-columns: 1fr;
  }

  .role-chart-canvas-wrap {
    width: 220px;
    height: 220px;
  }

  .role-callouts {
    grid-template-columns: 1fr;
    grid-auto-flow: row;
    grid-template-rows: unset;
  }
}
