/**
 * Block 1 — 單卡 Swiper、等高卡片、甜甜圈 + 長條（圖例置底）+ Tooltip
 */

.chart-block {
  position: relative;
}

.chart-tooltip {
  position: fixed;
  left: 0;
  top: 0;
  max-width: 280px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.4;
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: #fff;
  background: rgba(0, 0, 0, 0.85);
  pointer-events: none;
  opacity: 0;
  z-index: 1000;
  transition: opacity 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

.chart-section {
  padding: 80px 0;
  box-sizing: border-box;
  overflow: visible;
}

.chart-section__inner.relative-container {
  position: relative;
  max-width: 920px;
  margin: 0 auto;
  padding: 0 clamp(44px, 5vw, 56px);
  box-sizing: border-box;
}

.chart-swiper-shell {
  position: relative;
  max-width: 700px;
  margin: 0 auto;
  box-sizing: border-box;
  overflow: visible;
  /* 箭頭改為絕對定位懸浮，僅留少量邊距避免貼邊裁切 */
  padding: 0 10px;
}

.chart-section__further {
  max-width: 700px;
  margin: clamp(28px, 4vw, 40px) auto 0;
  text-align: center;
}

.chart-section__further-label {
  margin: 0 0 10px;
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #0d9488;
}

.chart-section__further-link {
  display: inline;
  font-size: clamp(0.9375rem, 1.6vw, 1.0625rem);
  line-height: 1.75;
  color: #0f172a;
  text-decoration: underline;
  text-decoration-color: rgba(15, 23, 42, 0.35);
  text-underline-offset: 0.2em;
}

.chart-section__further-link:hover,
.chart-section__further-link:focus-visible {
  color: #0d9488;
  text-decoration-color: currentColor;
}

.chart-section__further-chev {
  margin-left: 0.1em;
}

.chart-swiper.swiper {
  width: 100%;
  overflow: hidden;
}

.chart-swiper .swiper-wrapper {
  align-items: stretch;
}

.chart-swiper .swiper-slide,
.jc-chart-swiper-slide {
  width: 100% !important;
  flex-shrink: 0;
  height: auto !important;
  display: flex;
  box-sizing: border-box;
  justify-content: center;
  /* 內縮留出空間，避免父層 overflow:hidden 把圓角卡片的 box-shadow 裁成直角 */
  padding: 18px 14px;
}

.chart-swiper .swiper-slide > .chart-card {
  flex: 1;
  width: 100%;
  min-height: 100%;
}

/* 卡片高度隨內容伸展，圖例置底 */
.chart-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  height: auto !important;
  min-height: 100%;
  padding-bottom: 40px !important;
  background: #ffffff;
  background-color: #ffffff;
  border-radius: 24px;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.03),
    0 6px 24px rgba(0, 0, 0, 0.055);
  padding: 40px 50px;
  text-align: center;
  box-sizing: border-box;
}

.chart-card--bars {
  text-align: center;
}

.chart-card__title {
  flex-shrink: 0;
  margin: 0 0 16px;
  font-size: clamp(1.05rem, 2.1vw, 1.35rem);
  font-weight: 800;
  color: #111;
  line-height: 1.4;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  text-align: center;
}

.chart-card__stretch {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  min-height: 0;
  width: 100%;
}

.chart-card__stretch > .chart-doughnut-block {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

.chart-card__stretch > .chart-bar-list--baronly.bar-list-wrap,
.chart-card__stretch > .bar-list-wrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

.chart-card__stretch > .chart-legend-row {
  align-self: stretch;
  width: 100%;
}

.chart-doughnut-block {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  width: 100%;
}

.chart-doughnut-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  aspect-ratio: 1;
  overflow: visible;
}

.chart-doughnut-wrap canvas#liverChart {
  position: relative;
  z-index: 1;
  display: block;
  width: 100% !important;
  height: auto !important;
  max-height: none;
}

.chart-center-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  display: none !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 0.35rem;
  opacity: 0 !important;
  visibility: hidden !important;
  z-index: 0;
}

.chart-center-text .pct {
  display: block;
  width: 100%;
  font-size: clamp(1.85rem, 4.5vw, 2.75rem);
  font-weight: 900 !important;
  line-height: 1;
  letter-spacing: -1px;
  font-family: "Montserrat", Arial, sans-serif !important;
}

.chart-center-text .pct span {
  font-size: 0.55em;
  font-weight: 900 !important;
  font-family: "Montserrat", Arial, sans-serif !important;
  letter-spacing: -1px;
}

.chart-center-text .label {
  display: block;
  width: 100%;
  max-width: 6.5em;
  margin: 0;
  font-size: clamp(0.8rem, 1.6vw, 0.92rem);
  font-weight: 700;
  line-height: 1.35;
}

@media (max-width: 768px) {
  .chart-card {
    padding: 30px 20px;
    min-height: auto !important;
  }

  .chart-doughnut-wrap {
    max-width: min(100%, 380px);
  }

  .chart-legend-row {
    grid-template-columns: 1fr;
    justify-items: start;
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
  }
}

/* 圖例：三欄網格、每格靠左；第二列與第一列欄位對齊（如附圖） */
.chart-legend-row {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  justify-items: start;
  align-content: start;
  gap: 14px 28px;
  width: 100%;
  max-width: 100%;
  margin: 30px 0 0;
  padding: 0;
  padding-top: 4px;
  box-sizing: border-box;
  text-align: left;
}

.jc-legend-item,
.legend-item,
.chart-legend-row .legend-item {
  display: flex;
  align-items: flex-start !important;
  justify-content: flex-start;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #333;
  text-align: left;
  box-sizing: border-box;
  white-space: normal !important;
  word-break: break-word !important;
  line-height: 1.4 !important;
}

.chart-legend-row .legend-item--max {
  color: #ff4013;
  font-weight: 800;
}

.jc-legend-color,
.legend-color,
.chart-legend-row .dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  margin-top: 4px;
}

/* 長條外層：與圓餅區等高撐滿，垂直間距平均分配 */
.chart-bar-list--baronly.bar-list-wrap,
.bar-list-wrap.chart-bar-list--baronly {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  gap: 16px;
  flex: 1 1 auto;
  min-height: 0;
  max-width: 100%;
  margin: 0 auto;
  width: 100%;
  align-items: stretch;
}

.chart-bar-row--baronly {
  margin: 0;
  width: 100%;
}

/* 長條過窄時由 JS 加上 --pct-outside，百分比改畫在色塊右側軌道外 */
.chart-bar-row--baronly.chart-bar-row--pct-outside .bar-track {
  overflow: visible;
}

.chart-bar-row--baronly.chart-bar-row--pct-outside .bar-fill {
  position: relative;
  justify-content: flex-start;
  padding-right: 0;
  overflow: visible;
}

.chart-bar-row--baronly.chart-bar-row--pct-outside .bar-fill__pct {
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
}

.bar-track {
  height: 40px;
  border-radius: 8px;
  background-color: #f1f5f9;
  overflow: hidden;
  box-sizing: border-box;
  width: 100%;
}

.bar-fill {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 0%;
  height: 100%;
  min-width: 0;
  border-radius: 8px;
  padding: 0 15px;
  box-sizing: border-box;
  transition: width 1s ease-out;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.bar-fill__pct {
  font-size: 0.875rem;
  font-weight: 800;
  white-space: nowrap;
  line-height: 1;
}

.bar-fill__pct--max {
  font-size: 1.1rem;
  font-weight: 900;
}

.bar-fill__pct--on-dark {
  color: #fff;
}

.bar-fill__pct--on-light {
  color: #1a1a1a;
}

/* Swiper 導覽：極簡箭頭（無圓框／無背景） */
.chart-swiper-shell .chart-nav-prev,
.chart-swiper-shell .chart-nav-next {
  position: absolute;
  top: 50% !important;
  margin-top: 0 !important;
  z-index: 20;
  width: 48px !important;
  height: 48px !important;
  border-radius: 0 !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: #a0aec0 !important;
  transform: translateY(-50%) scale(0.85);
  transition: color 0.2s ease, opacity 0.2s ease;
}

.chart-swiper-shell .chart-nav-prev:hover,
.chart-swiper-shell .chart-nav-next:hover {
  background: transparent !important;
  box-shadow: none !important;
  color: #718096 !important;
  transform: translateY(-50%) scale(0.85);
}

.chart-swiper-shell .chart-nav-prev:focus,
.chart-swiper-shell .chart-nav-next:focus,
.chart-swiper-shell .chart-nav-prev:focus-visible,
.chart-swiper-shell .chart-nav-next:focus-visible,
.chart-swiper-shell .chart-nav-prev:active,
.chart-swiper-shell .chart-nav-next:active {
  background: transparent !important;
  box-shadow: none !important;
  transform: translateY(-50%) scale(0.85);
}

.chart-swiper-shell .chart-nav-prev::after,
.chart-swiper-shell .chart-nav-next::after {
  font-size: 40px !important;
  font-weight: 700 !important;
}

.chart-swiper-shell .chart-nav-prev {
  left: -5px !important;
  right: auto !important;
}

.chart-swiper-shell .chart-nav-next {
  right: -5px !important;
  left: auto !important;
}

@media (max-width: 480px) {
  .chart-swiper-shell {
    padding: 0 6px;
  }

  .chart-swiper-shell .chart-nav-prev,
  .chart-swiper-shell .chart-nav-next {
    width: 44px !important;
    height: 44px !important;
  }

  .chart-swiper-shell .chart-nav-prev::after,
  .chart-swiper-shell .chart-nav-next::after {
    font-size: 36px !important;
  }
}

.chart-swiper-shell .chart-nav-prev.swiper-button-disabled,
.chart-swiper-shell .chart-nav-next.swiper-button-disabled {
  opacity: 0.35;
}

.chart-swiper__pagination {
  position: static !important;
  margin-top: 18px;
  text-align: center;
}

.chart-swiper__pagination .swiper-pagination-bullet {
  width: 9px;
  height: 9px;
  margin: 0 5px !important;
  background: #cfd4db;
  opacity: 1;
}

.chart-swiper__pagination .swiper-pagination-bullet-active {
  background: #64748b;
}

/* ≤768：圖表區 RWD（須置於箭頭等規則之後，才能正確覆蓋） */
@media (max-width: 768px) {
  .chart-swiper-shell {
    padding: 0 !important;
  }

  .chart-nav-prev,
  .chart-nav-next,
  .chart-swiper-shell .chart-nav-prev,
  .chart-swiper-shell .chart-nav-next {
    position: absolute !important;
    top: 50% !important;
    margin-top: 0 !important;
    transform: translateY(-50%) !important;
    z-index: 100 !important;
    width: 30px !important;
    height: 48px !important;
  }

  .chart-nav-prev,
  .chart-swiper-shell .chart-nav-prev {
    left: 0 !important;
    right: auto !important;
  }

  .chart-nav-next,
  .chart-swiper-shell .chart-nav-next {
    right: 0 !important;
    left: auto !important;
  }

  .chart-section .container,
  .chart-section__inner.relative-container {
    padding: 0 25px !important;
  }

  .chart-card {
    padding: 25px 15px !important;
    min-height: auto !important;
    height: auto !important;
    justify-content: flex-start !important;
  }

  .chart-doughnut-wrap {
    max-width: 240px !important;
    margin: 0 auto 15px !important;
  }

  .chart-bar-list--baronly.bar-list-wrap,
  .bar-list-wrap.chart-bar-list--baronly {
    gap: 10px !important;
  }

  .bar-track {
    height: 28px !important;
  }

  .jc-legend,
  .chart-legend-row {
    margin-top: 15px !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    justify-items: start !important;
    gap: 12px !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 20px !important;
    box-sizing: border-box !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .jc-legend-item,
  .legend-item,
  .chart-legend-row .legend-item {
    width: 100% !important;
    max-width: 100% !important;
    white-space: normal !important;
    word-break: break-word !important;
    line-height: 1.4 !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    text-align: left !important;
  }

  .jc-legend-color,
  .legend-color,
  .chart-legend-row .dot {
    margin-top: 3px !important;
    flex-shrink: 0 !important;
  }
}

/*
 * Block 1–10 最外層 <section> 共用底（index.html 加上 .global-section-bg；勿用於卡片／浮層）
 * 置於本檔末尾，載入順序在其它 block CSS 之後，並以 !important 蓋過區塊內既有的 section 底色／漸層
 */
section.global-section-bg {
  background-color: #f5f5f0 !important;
  background-image: none !important;
}

/* Block 1 — 圓餅圖層級：畫布高於 HTML 中心數字，Tooltip 可蓋過數字 */
.chart-doughnut-wrap canvas#liverChart {
  position: relative !important;
  z-index: 20 !important;
  pointer-events: auto !important;
}

.chart-center-text.is-visible,
.chart-center-text {
  position: absolute !important;
  z-index: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  opacity: 1 !important;
  visibility: visible !important;
}

@media (max-width: 768px) {
  .chart-card__stretch .chart-legend-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    justify-items: start !important;
    width: 100% !important;
    padding: 0 10px !important;
    margin-top: 20px !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .chart-card__stretch .chart-legend-row .legend-item {
    display: flex !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-bottom: 0 !important;
    white-space: normal !important;
    word-break: break-word !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    text-align: left !important;
  }

  .chart-card__stretch .chart-legend-row .dot,
  .chart-card__stretch .chart-legend-row .jc-legend-color {
    flex-shrink: 0 !important;
    margin-top: 4px !important;
  }
}
