/**
 * Cassiopeia HTSprout - 單一文章頁面樣式（Mobile-First）
 *
 * 包含：
 * - 文章頁面側邊欄隱藏
 * - Page Header 區域（h1、日期列、文章圖片）
 * - 文章內文區域
 * - 附件下載區塊
 * - Gallery 輪播
 * - Lightbox
 *
 * 撰寫策略：Mobile-First
 * - Base 樣式對應手機版 414px，無 media query
 * - 桌面覆寫使用 @media (min-width: ...)
 *
 * @package     Joomla.Site
 * @subpackage  Templates.cassiopeia_htsprout
 * @copyright   Copyright (C) 2026 HTSprout. All rights reserved.
 * @license     GNU General Public License version 2 or later
 */

/* ============================================
   1. 區域性 CSS 變數
   ============================================ */
:root {
  --gallery-cols: 2; /* mobile-first: 2 欄 */
  --article-breadcrumb-inactive: #5a5a5a;
  --article-attachment-bg: #f4f9fa;
  --article-attachment-border: #efefef;
  --article-gallery-shadow: 0px 4px 24px rgba(178, 184, 199, 0.35);
}

/* ============================================
   2. 側邊欄隱藏（適用全尺寸）
   ============================================ */

/* 隱藏左右側邊欄 */
body.view-article.layout-cassiopeia_htsproutnews .container-sidebar-left,
body.view-article.layout-cassiopeia_htsproutnews .container-sidebar-right {
  display: none;
}

/* 主內容區擴展至全寬 */
body.view-article.layout-cassiopeia_htsproutnews .container-component {
  grid-column: main-start / main-end;
}

/* 標籤名稱連結關閉時，標籤為非互動元素 */
.tags-no-link .tags span.btn {
  min-height: auto;
  min-width: auto;
  cursor: default;
}

/* ============================================
   3. Page Header 區域
   ============================================ */

/* 3a. page-header-columns 內距（手機版） */
body.view-article .page-header-columns {
  padding: 20px 20px 0;
}

/* 3b. page-header__left 垂直間距 */
body.view-article .page-header__left {
  gap: 31px;
}

/* 3c. 文章標題 h1（手機版覆蓋 components.css 的 fs-56） */
body.view-article .page-header__left .page-header h1 {
  font-size: calc(2rem * var(--font-size-scale, 1));
}

/* 3d. 麵包屑字體大小（手機版覆蓋 components.css max-width:768px 設的 0.875rem） */
body.view-article .mod-breadcrumbs.breadcrumb {
  font-size: var(--htsprout-fs-16);
}

/* 3e. 麵包屑非活動連結顏色 */
body.view-article .mod-breadcrumbs__item a.pathway {
  color: var(--article-breadcrumb-inactive);
}

/* 3f. 日期列 */
body.view-article .article-info {
  display: flex;
  align-items: center;
  margin: 0;
  font-size: var(--htsprout-fs-16);
  font-weight: var(--htsprout-fw-regular);
  line-height: 26px;
  color: var(--htsprout-text-600);
  z-index: 2;
}

/* 3g. 文章圖片圓角 */
body.view-article .page-header__right .item-image img {
  border-radius: var(--htsprout-radius-btn);
}

/* ============================================
   4. 內文區域
   ============================================ */

body.view-article .com-content-article {
  margin: 40px 0 108px;
}

/* 4a. 內文容器水平內距（手機版） */
body.view-article .container-component {
  padding: 0 20px;
}

/* 4b. 內文容器（block layout 以啟用 margin collapsing） */
body.view-article .com-content-article__body {
  display: block;
  padding: 20px;
}

/* 4c. 全域 margin reset */
body.view-article .com-content-article__body > * {
  margin: 0;
}

/* 4d. 內文標題 h2 / h3 字體樣式 */
body.view-article .com-content-article__body h2,
body.view-article .com-content-article__body h3 {
  font-size: var(--htsprout-fs-20);
  font-weight: var(--htsprout-fw-medium);
  line-height: var(--htsprout-lh-150);
  color: var(--htsprout-green-800);
}

/* 4e. h2 section 間距：與前一個元素間隔 20px */
body.view-article .com-content-article__body > h2 {
  margin-top: 20px;
}

/* 第一個 h2：無頂部間距 */
body.view-article .com-content-article__body > h2:first-child {
  margin-top: 0;
}

/* 4f. h2→內容間距（精確對應 Figma） */

/* h2 + p 預設：12px（QRcode、聯絡資訊等 info 區塊） */
body.view-article .com-content-article__body > h2 + p {
  margin-top: 12px;
}

/* h2:first-child + p 例外：16px（第一個 Content 區塊） */
body.view-article .com-content-article__body > h2:first-child + p {
  margin-top: 16px;
}

/* h2 + ol：16px（含編號清單的 Content 區塊） */
body.view-article .com-content-article__body > h2 + ol {
  margin-top: 16px;
}

/* h2 + ul：12px（info 區塊） */
body.view-article .com-content-article__body > h2 + ul {
  margin-top: 12px;
}

/* 4g. hr 分隔線：上下各 20px（利用 margin collapsing 與 h2 的 20px 折疊） */
body.view-article .com-content-article__body > hr {
  border: none;
  border-top: 1px solid var(--htsprout-blue-100);
  margin: 20px 0;
  opacity: 1;
}

/* 4h. 內文本文段落、清單字體樣式 */
body.view-article .com-content-article__body > p,
body.view-article .com-content-article__body > ol,
body.view-article .com-content-article__body > ul {
  font-size: var(--htsprout-fs-16);
  font-weight: var(--htsprout-fw-regular);
  line-height: var(--htsprout-lh-150);
  color: var(--htsprout-text-1000);
}

/* 4j. ol 第一層：中文數字項目符號 (一)、(二)、(三)... */
@counter-style cjk-paren {
  system: fixed;
  symbols: '(一) ' '(二) ' '(三) ' '(四) ' '(五) ' '(六) ' '(七) ' '(八) '
    '(九) ' '(十) ';
  suffix: '';
}

body.view-article .com-content-article__body > ol {
  list-style-type: cjk-paren;
}

/* 4i. 內文圖片陰影（QRcode 等，Figma: 0px 4px 24px rgba(178,184,199,0.35)） */
body.view-article .com-content-article__body > p > img {
  box-shadow: var(--article-gallery-shadow);
}

/* 4k. 內文表格：所有儲存格加框線 */
body.view-article .com-content-article__body table {
  border-collapse: collapse;
}

body.view-article .com-content-article__body :is(td, th) {
  border: 1px solid var(--htsprout-blue-100);
  padding: 5px;
}

/* ============================================
   5. 附件下載區域
   ============================================ */

/* 5a. 附件區域內距 */
body.view-article .fields-container {
  margin: 0 20px;
  padding: 20px 0;
  border-top: 1px solid var(--htsprout-blue-100);
}

/* 5b. 附件標題 */
body.view-article #attachments-heading {
  font-size: var(--htsprout-fs-20);
  font-weight: var(--htsprout-fw-medium);
  color: var(--htsprout-green-500);
  margin: 0 0 var(--htsprout-spacing-xs);
}

/* 5b. 附件列表容器 */
body.view-article .article-attachments__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--htsprout-spacing-xs);
}

/* 5c. 附件項目行 */
body.view-article .article-attachments__list li {
  background: var(--article-attachment-bg);
  border: 1px solid var(--article-attachment-border);
  padding: 10px var(--htsprout-spacing-sm);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* 5d. 附件檔名 */
body.view-article .article-attachments__name {
  flex: 1;
  font-size: var(--htsprout-fs-16);
  font-weight: var(--htsprout-fw-regular);
  color: var(--htsprout-text-800);
}

/* 5e. 下載按鈕（參照 news.css .news-item__file-btn） */
body.view-article .article-attachments__list .news-item__file-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  min-height: auto;
  font-size: var(--htsprout-fs-16);
  font-weight: var(--htsprout-fw-regular);
  color: var(--htsprout-text-1000);
  background-color: var(--htsprout-text-50);
  border: 1px solid rgba(43, 114, 152, 0.3);
  border-radius: 0;
  text-decoration: none;
  line-height: 26px;
  transition:
    border-color var(--htsprout-transition-base),
    opacity var(--htsprout-transition-base);
}

body.view-article .article-attachments__list .news-item__file-btn:hover {
  color: var(--htsprout-text-1000);
  background-color: var(--htsprout-text-50);
  border-color: rgba(43, 114, 152, 0.6);
  text-decoration: none;
}

body.view-article .article-attachments__list .news-item__file-btn:focus {
  outline: 2px dotted var(--focus-color);
}

body.view-article .article-attachments__list .news-item__file-btn img {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ============================================
   6. Gallery 輪播（手機版 base）
   ============================================ */

/* 6a. Gallery 外層容器 */
body.view-article .article-gallery {
  margin: 0 20px;
  padding: 20px 0;
  border-top: 1px solid var(--htsprout-blue-100);
}

/* 6b. 標題列：標題 + 箭頭同一排 */
body.view-article .article-gallery__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--htsprout-spacing-xs);
}

body.view-article .article-gallery__header h2 {
  margin: 0;
  font-size: var(--htsprout-fs-20);
  font-weight: var(--htsprout-fw-medium);
  color: var(--htsprout-green-500);
}

/* 6c. 箭頭群組 */
body.view-article .article-gallery__arrows {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* 6d. 箭頭按鈕（設計稿：40×40, bg #0160A1, radius 10px, icon white） */
body.view-article .article-gallery__arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  background: var(--htsprout-blue-800);
  border: none;
  border-radius: var(--htsprout-radius-btn);
  cursor: pointer;
  color: var(--htsprout-text-50);
  font-size: var(--htsprout-fs-16);
  transition:
    background-color var(--htsprout-transition-base),
    color var(--htsprout-transition-base);
}

body.view-article .article-gallery__arrow:hover:not(:disabled) {
  background: var(--htsprout-blue-900);
  color: var(--htsprout-text-50);
}

body.view-article .article-gallery__arrow:focus {
  outline: 2px dotted var(--focus-color);
}

body.view-article .article-gallery__arrow:disabled {
  opacity: 0.35;
  cursor: default;
}

/* 6e. 滾動軌道：手機版固定 gap 20px */
body.view-article .article-gallery__track {
  display: flex;
  gap: 20px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  height: 120px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

body.view-article .article-gallery__track::-webkit-scrollbar {
  display: none;
}

/* 6f. 單一項目：固定 150×120 */
body.view-article .article-gallery__item {
  flex: 0 0 150px;
  scroll-snap-align: start;
}

/* 6g. 縮圖圖片（設計稿：150×120, radius 2px, shadow） */
body.view-article .article-gallery__item img {
  display: block;
  width: 150px;
  height: 120px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: var(--article-gallery-shadow);
  cursor: pointer;
  transition: opacity var(--htsprout-transition-base);
}

body.view-article .article-gallery__item img:hover {
  opacity: 0.8;
}

body.view-article .article-gallery__item img:focus {
  outline: 2px dotted var(--focus-color);
}

/* ============================================
   6½. container-main-area 背景色與波浪裝飾
   ============================================ */

/* 白色背景 */
body.view-article .container-main-area {
  position: relative;
  background: var(--htsprout-text-50);
}

/* page-header 文字壓在波浪裝飾（::before, z-index:1）之上，
   避免標題換行變高時被波浪遮住 */
body.view-article .container-page-header {
  position: relative;
  z-index: 2;
}

/* 波浪裝飾偽元素 */
body.view-article .container-main-area::before {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  content: '';
  width: 100%;
  height: 137px;
  background: url(../../../../../images/template/container-top-b-shape-tablet.svg)
    no-repeat;
  background-size: 1440px auto;
  background-position: 50% 0%;
  pointer-events: none;
  transform: translateY(-100%);
}

/* policy 分類：移除白色背景與波浪裝飾 */
body.view-article.category-policy .container-main-area {
  background: transparent;
  display: block;
}

body.view-article.category-policy .container-main-area::before {
  display: none;
}

/* sitemap 頁面：同 policy，移除白色背景與波浪裝飾 */
body.page-sitemap .container-main-area {
  background: transparent;
  display: block;
}

body.page-sitemap .container-main-area::before {
  display: none;
}

/* policy 分類：page-header 底部間距與水平線 */
:is(body.view-article.category-policy, body.page-sitemap) .page-header-columns {
  padding: 20px 20px 52px;
  position: relative;
  gap: 40px;
}

:is(body.view-article.category-policy, body.page-sitemap)
  .page-header-columns::after {
  content: '';
  position: absolute;
  bottom: 26px;
  left: 20px;
  right: 20px;
  height: 1px;
  background: var(--htsprout-green-300);
  pointer-events: none;
}

/* policy / sitemap：文章區域間距 */
:is(body.view-article.category-policy, body.page-sitemap) .com-content-article {
  margin: 0 0 128px;
}

:is(body.view-article.category-policy, body.page-sitemap)
  .com-content-article__body {
  padding: 0;
}

/* policy / sitemap：隱藏日期列 */
:is(body.view-article.category-policy, body.page-sitemap) .article-info {
  display: none;
}

body.view-article.category-policy .com-content-article__body > p {
  margin: 0 0 30px 0;
}

body.view-article.category-policy .com-content-article__body > p:last-child {
  margin: 0;
}

body.view-article.category-policy .com-content-article__body > h2 {
  margin: 30px 0;
}

/* 內容區域疊在波浪之上 */
body.view-article .container-component {
  position: relative;
  z-index: 2;
}

/* ============================================
   7. 響應式覆寫（Mobile-First min-width）
   ============================================ */

/* 平板（768px+）：Gallery 改為 4 欄動態 gap */
@media (min-width: 768px) {
  :root {
    --gallery-cols: 4;
  }

  body.view-article .article-gallery__track {
    gap: max(
      0px,
      calc((100% - var(--gallery-cols) * 150px) / (var(--gallery-cols) - 1))
    );
  }
}

/* 平板（768px–991.98px）：Page Header、內文區域、Gallery 調整 */
@media (min-width: 768px) and (max-width: 991.98px) {
  /* --- Page Header --- */

  /* 覆寫 components.css 的雙欄為單欄，水平內距 60px */
  body.view-article .page-header-columns {
    grid-template-columns: 1fr;
    padding: 20px 60px 0;
    gap: 34px;
  }

  /* 文章圖片限制最大寬度 */
  body.view-article .page-header__right .item-image img {
    max-width: 500px;
  }

  /* --- 內文區域 --- */

  /* 內文容器水平內距加大 */
  body.view-article .container-component {
    padding: 0 40px;
  }

  /* 內文本體：移除水平內距（由容器處理） */
  body.view-article .com-content-article__body {
    padding: 20px 0;
  }

  /* 附件區域：移除水平 margin */
  body.view-article .fields-container {
    margin: 0;
  }

  /* Gallery：移除水平 margin */
  body.view-article .article-gallery {
    margin: 0;
  }

  /* --- Gallery 箭頭 --- */

  body.view-article .article-gallery__arrows {
    gap: 8px;
  }

  /* policy / sitemap：平板版 page-header 間距 */
  :is(body.view-article.category-policy, body.page-sitemap)
    .page-header-columns {
    padding: 20px 40px 52px;
  }

  /* policy / sitemap：平板版水平線寬度限制 */
  :is(body.view-article.category-policy, body.page-sitemap)
    .page-header-columns::after {
    left: 50%;
    right: auto;
    width: calc(100% - 40px * 2);
    transform: translateX(-50%);
  }

  /* 波浪裝飾背景位置調整 */
  body.view-article .container-main-area::before {
    background-position: 23% 0%;
    height: 137px; /* was 290px：transform: translateY(-100%) 位移量綁定 height，290px 會整片往上蓋住 page-header 的 H1 標題 */
  }
}

/* 桌面（992px+）：Page Header 雙欄、內容 1104px 居中、Gallery 6 欄 */
@media (min-width: 992px) {
  :root {
    --gallery-cols: 6;
  }

  /* --- Page Header --- */

  /* 雙欄佈局 1104px 居中（覆寫 components.css 的 24px gap） */
  body.view-article .page-header-columns {
    max-width: 1144px;
    margin: 0 auto;
    padding: 20px 20px 80px;
    gap: 34px;
  }

  /* policy / sitemap：電腦版 page-header 間距 */
  :is(body.view-article.category-policy, body.page-sitemap)
    .page-header-columns {
    padding: 20px 20px 52px;
  }

  /* --- 內文區域 --- */

  /* 內文容器：移除手機版側邊內距 */
  body.view-article .container-component {
    padding: 0;
  }

  /* 文章內容區 1104px 居中 */
  body.view-article .com-content-article {
    max-width: 1144px;
    margin: -30px auto 108px;
  }

  /* policy / sitemap：移除頂部負 margin */
  :is(body.view-article.category-policy, body.page-sitemap)
    .com-content-article {
    margin: 0 auto 128px;
  }

  /* 內文本體：移除水平內距（父層 max-width 控制寬度） */
  body.view-article .com-content-article__body {
    padding: 0 20px 20px;
  }

  /* policy 分類：電腦版內文內距 */
  :is(body.view-article.category-policy, body.page-sitemap)
    .com-content-article__body {
    padding: 0 20px;
  }

  /* --- Gallery 箭頭 --- */

  body.view-article .article-gallery__arrows {
    gap: 8px;
  }

  /* 波浪裝飾背景位置調整 */
  body.view-article .container-main-area::before {
    background: url(../../../../../images/template/container-top-b-shape.svg)
      no-repeat;
    height: 127px;
    background-size: cover;
  }
}

/* ============================================
   8. Gallery Lightbox（固定覆蓋層，不受斷點影響）
   ============================================ */
.gallery-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.85);
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.gallery-lightbox.is-active {
  display: flex;
}

.gallery-lightbox__close {
  position: absolute;
  top: var(--htsprout-spacing-sm);
  right: var(--htsprout-spacing-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--htsprout-text-50);
  font-size: calc(2rem * var(--font-size-scale, 1));
  line-height: 1;
  cursor: pointer;
  transition: opacity var(--htsprout-transition-base);
}

.gallery-lightbox__close:hover {
  opacity: 0.7;
}

.gallery-lightbox__close:focus {
  outline: 2px dotted var(--focus-color);
}

.gallery-lightbox__img {
  aspect-ratio: 780 / 560;
  width: 100%;
  max-width: 780px;
  object-fit: cover;
  box-shadow: 0px 4px 24px 0px #b2b8c759;
  transition: opacity 0.2s ease;
}

.gallery-lightbox__img.is-fading {
  opacity: 0;
}

.gallery-lightbox__caption {
  color: var(--htsprout-text-50);
  text-align: center;
  margin: 1rem 0 0;
  padding: 0 var(--htsprout-spacing-md);
  font-size: calc(1.125rem * var(--font-size-scale, 1));
  line-height: 1.5;
  transition: opacity 0.2s ease;
}

.gallery-lightbox__caption.is-fading {
  opacity: 0;
}

/* Lightbox 上一頁/下一頁按鈕 */
.gallery-lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--htsprout-text-50);
  font-size: calc(2rem * var(--font-size-scale, 1));
  cursor: pointer;
  transition: opacity var(--htsprout-transition-base);
}

.gallery-lightbox__nav:hover {
  opacity: 0.7;
}

.gallery-lightbox__nav:focus {
  outline: 2px dotted var(--focus-color);
}

.gallery-lightbox__nav:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.gallery-lightbox__nav--prev {
  left: var(--htsprout-spacing-md);
}

.gallery-lightbox__nav--next {
  right: var(--htsprout-spacing-md);
}

@media (max-width: 767.98px) {
  .gallery-lightbox__nav--prev {
    left: var(--htsprout-spacing-sm);
  }
  .gallery-lightbox__nav--next {
    right: var(--htsprout-spacing-sm);
  }
}

/* Lightbox 減少動畫 */
@media (prefers-reduced-motion: reduce) {
  .gallery-lightbox,
  .gallery-lightbox__close,
  .article-gallery__item img {
    transition: none !important;
  }
}
