:root {
  --color-primary: #5d3a1a;
  --color-primary-dark: #3d2410;
  --color-secondary: #8b5e3c;
  --color-accent: #c19a6b;
  --color-bg: #f8f5f0;
  --color-surface: #ffffff;
  --color-text: #3a322b;
  --color-text-muted: #6e655d;
  --color-border: #d9cfc3;
  --color-link: #7a4e2e;
  --color-link-hover: #3d2410;
  --nav-height: 48px;
  --max-width: 1100px;
  --radius: 6px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  font-size: 16px;
  line-height: 1.7;
  color: var(--color-text);
  background-color: #978478;
}

a { color: var(--color-link); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--color-link-hover); text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

/* 外層容器 */
.site-wrapper {
  max-width: var(--max-width);
  margin: 0 auto;
  background-color: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 20px rgba(0,0,0,0.15);
}

/* 頁首橫幅 */
.site-header {
  background: linear-gradient(90deg, #f4efe8 0%, #e9e0d3 100%);
  border-bottom: 3px solid var(--color-primary);
}

.header-inner {
  position: relative;
  padding: 0;
}

.logo-link {
  display: block;
  width: 100%;
}
.logo-img {
  width: 100%;
  height: auto;
  max-height: none;
  object-fit: cover;
  display: block;
}

.header-actions {
  position: absolute;
  top: 0.75rem;
  right: 1.25rem;
  z-index: 10;
}

.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius);
  background-color: var(--color-surface);
  color: var(--color-primary);
  font-weight: 600;
  font-size: 0.9rem;
}
.lang-toggle:hover {
  background-color: var(--color-primary);
  color: #fff;
  text-decoration: none;
}
.lang-toggle::before { content: "🌐"; font-size: 0.9em; }

/* 主導覽 */
.main-nav {
  background-color: var(--color-primary);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.nav-menu-toggle {
  display: none;
  width: 100%;
  padding: 0.75rem 1.25rem;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  align-items: center;
  gap: 0.5rem;
}

.menu-icon {
  display: inline-block;
  width: 20px;
  height: 14px;
  position: relative;
}
.menu-icon::before,
.menu-icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: #fff;
  transition: transform 0.2s;
}
.menu-icon::before { top: 0; }
.menu-icon::after { bottom: 0; }

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

.nav-list li { flex: 1 1 auto; text-align: center; }

.nav-list a {
  display: block;
  padding: 0.85rem 0.6rem;
  color: #fff;
  font-weight: 500;
  font-size: 1.05rem;
  border-bottom: 4px solid transparent;
  transition: background-color 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.nav-list a:hover,
.nav-list a.active {
  background-color: var(--color-primary-dark);
  border-bottom-color: var(--color-accent);
  text-decoration: none;
}

/* 主要內容 */
.site-main {
  flex: 1;
  padding: 1.5rem 1.25rem;
}

.content-container {
  max-width: var(--max-width);
  margin: 0 auto;
  background-color: var(--color-surface);
  padding: 2rem 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 400px;
  min-width: 0;
}

.page-content { min-width: 0; }
.page-content pre,
.page-content code {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.loading {
  text-align: center;
  color: var(--color-text-muted);
  padding: 3rem 0;
}

/* 首頁三欄 */
.home-grid {
  display: grid;
  grid-template-columns: 220px 1fr 240px;
  gap: 1.5rem;
}

.home-sidebar,
.home-links {
  background-color: #faf8f5;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  align-self: start;
}

.home-sidebar h2,
.home-links h2,
.home-news h2 {
  font-size: 1.1rem;
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-accent);
  padding-bottom: 0.4rem;
  margin-top: 0;
}

.promo-button {
  display: block;
  margin-bottom: 0.75rem;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  transition: transform 0.2s;
}
.promo-button:hover { transform: translateY(-2px); }
.promo-button img { width: 100%; }

.home-sidebar img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

.news-list img {
  max-width: 100%;
  height: auto;
  display: inline-block;
  vertical-align: middle;
}

.news-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.news-list li {
  padding: 0.7rem 0;
  border-bottom: 1px dashed var(--color-border);
}
.news-list li:last-child { border-bottom: none; }
.news-date { color: var(--color-text-muted); font-size: 0.85rem; margin-left: 0.25rem; }
.new-tag { color: #c0392b; font-size: 0.75rem; font-weight: bold; margin-left: 0.25rem; }

.more-link { text-align: right; margin-top: 0.75rem; font-style: italic; }

.link-list a {
  display: block;
  padding: 0.35rem 0;
  border-bottom: 1px dotted var(--color-border);
  font-size: 0.95rem;
}
.link-list a:last-child { border-bottom: none; }

/* 內頁通用排版 */
.page-content h1 {
  color: var(--color-primary);
  font-size: 1.6rem;
  margin-top: 0;
  border-bottom: 2px solid var(--color-accent);
  padding-bottom: 0.5rem;
}

.page-content h2,
.page-content h3 {
  color: var(--color-secondary);
  margin-top: 1.5rem;
}

.page-content table {
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.95rem;
  max-width: 100%;
}
.page-content table:not([border^="0"]) {
  width: 100%;
}
.page-content {
  word-break: break-word;
  overflow-wrap: break-word;
}
.page-content td,
.page-content th {
  overflow-wrap: break-word;
}

.page-content .history-president-table th,
.page-content .history-president-table td {
  white-space: nowrap;
}

@media (min-width: 641px) {
  .page-content table[border="1"] td:nth-child(2),
  .page-content table[border="1"] th:nth-child(2) {
    white-space: nowrap;
    min-width: 120px;
  }
}
.page-content table table {
  width: auto;
  min-width: unset;
  margin: 0;
}
.page-content table[align="center"] {
  margin-left: auto;
  margin-right: auto;
}
.page-content .member-table td {
  vertical-align: middle;
}
.page-content .member-logo {
  max-width: 80px;
  max-height: 60px;
  width: auto;
  height: auto;
  display: inline-block;
}

/* 表格內容溢出時可橫向捲動（不破壞原排版） */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* 辦法頁面目錄清單：不讓條目在手機版斷行 */
.table-responsive li {
  white-space: nowrap;
  overflow-wrap: normal;
}

.page-content th,
.page-content td {
  padding: 0.6rem 0.75rem;
  vertical-align: top;
}
.page-content table:not([border^="0"]) th,
.page-content table:not([border^="0"]) td {
  border: 1px solid var(--color-border);
  text-align: left;
}
.page-content th {
  background-color: #f0e9df;
  color: var(--color-primary-dark);
  font-weight: 600;
}
.page-content tr:nth-child(even) { background-color: #faf8f5; }

/* 舊版無框線版面表格（border=0 或 0.5）：不顯示格線 */
.page-content table[border^="0"],
.page-content table[border^="0"] th,
.page-content table[border^="0"] td {
  border: none !important;
  background: transparent !important;
}
.page-content table[border^="0"] th {
  font-weight: 600;
}

.page-content ul,
.page-content ol { padding-left: 1.5rem; }

.page-content iframe {
  max-width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  background-color: var(--color-primary);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 500;
}
.btn:hover { background-color: var(--color-primary-dark); color: #fff; text-decoration: none; }

/* 頁尾 */
.site-footer {
  background-color: var(--color-primary-dark);
  color: #e0d8cc;
  text-align: center;
  padding: 1.25rem 1rem;
  font-size: 0.9rem;
}
.site-footer p {
  margin: 0.35rem 0;
  line-height: 1.6;
}
.site-footer .contact-info {
  color: #fff;
  font-size: 0.95rem;
  font-weight: 500;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* 響應式 */
@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr 1fr; }
  .home-news { grid-column: 1 / -1; order: -1; }
}

@media (max-width: 640px) {
  .header-inner { flex-direction: column; align-items: flex-start; }
  .logo-img { max-height: 85px; }

  .nav-menu-toggle { display: flex; }
  .nav-list {
    display: none;
    flex-direction: column;
    background-color: var(--color-primary-dark);
  }
  .nav-list.open { display: flex; }
  .nav-list li { text-align: left; }
  .nav-list a { border-bottom: none; border-left: 4px solid transparent; padding: 0.85rem 1.25rem; }
  .nav-list a.active { border-left-color: var(--color-accent); border-bottom-color: transparent; }

  .site-main { padding: 1rem 0.75rem; min-width: 0; }
  .content-container { padding: 1rem 0.75rem; min-width: 0; }
  .home-grid { grid-template-columns: 1fr; }
  .home-news { order: unset; grid-column: auto; }

  .page-content table,
  .page-content table table {
    width: 100% !important;
    max-width: 100% !important;
    table-layout: fixed;
    font-size: 0.85rem;
  }
  .page-content table[align="center"] { margin-left: auto; margin-right: auto; }
  .page-content th,
  .page-content td {
    padding: 0.35rem 0.4rem;
    max-width: 100%;
    word-break: break-word;
    overflow-wrap: anywhere;
    min-width: 0;
  }

  /* 組織名單兩欄表格（border="0.5"）：手機版改為 flex 佈局 */
  .page-content table[border="0.5"] tr {
    display: flex;
    gap: 0.5rem;
  }
  .page-content table[border="0.5"] th,
  .page-content table[border="0.5"] td {
    display: block;
  }
  .page-content table[border="0.5"] td:first-child {
    flex: 0 0 auto;
    white-space: nowrap;
    min-width: 5rem;
  }
  .page-content table[border="0.5"] td:nth-child(2) {
    flex: 1 1 auto;
  }
  .page-content table[border="0.5"] th[colspan],
  .page-content table[border="0.5"] td[colspan] {
    flex: 1 1 100%;
    text-align: center;
  }

  .page-content td > div[align="center"] { text-align: center; }
  .page-content img { max-width: 100%; height: auto; display: inline-block; }

  .home-sidebar img { width: 100%; height: auto; }

  /* 沿革頁面外層巢狀表格：手機版強制撐滿並讓文字換行 */
  .page-content .history-intro,
  .page-content .history-intro table,
  .page-content .history-intro td,
  .page-content .history-intro th {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed;
  }
  .page-content .history-intro p {
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  .page-content .history-intro img,
  .page-content .history-president-table img {
    max-width: 100% !important;
    height: auto !important;
  }

  /* 歷屆理事長表格手機版：左文右圖 */
  .page-content .history-president-table tbody,
  .page-content .history-president-table tr {
    display: block;
  }
  .page-content .history-president-table tr:first-child {
    display: none;
  }
  .page-content .history-president-table tr {
    display: grid;
    grid-template-columns: 1fr 110px;
    gap: 0.25rem 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed var(--color-border);
  }
  .page-content .history-president-table tr:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
  }
  .page-content .history-president-table th {
    padding: 0;
    text-align: left;
    word-break: normal;
    overflow-wrap: normal;
    white-space: normal;
  }
  .page-content .history-president-table th:nth-child(1) { grid-column: 1; grid-row: 1; }
  .page-content .history-president-table th:nth-child(2) { grid-column: 1; grid-row: 2; }
  .page-content .history-president-table th:nth-child(3) { grid-column: 1; grid-row: 3; }
  .page-content .history-president-table th:nth-child(4) {
    grid-column: 2;
    grid-row: 1 / span 3;
    align-self: center;
    padding: 0;
  }
  .page-content .history-president-table th:nth-child(4) img {
    max-width: 100%;
    width: auto;
    height: auto;
    display: block;
    margin: 0 auto;
  }
  .page-content .history-president-table th:nth-child(1)::before { content: "屆數："; font-weight: bold; color: var(--color-primary); }
  .page-content .history-president-table th:nth-child(2)::before { content: "任期："; font-weight: bold; color: var(--color-primary); }
  .page-content .history-president-table th:nth-child(3)::before { content: "姓名："; font-weight: bold; color: var(--color-primary); }

  /* 辦法頁面條文表格（width=600）：手機版改為左條號、右內容，拉大內容欄寬度 */
  .regulations-page .page-content table[width="600"] tr {
    display: flex;
    gap: 0.35rem;
    min-width: 0;
  }
  .regulations-page .page-content table[width="600"] td,
  .regulations-page .page-content table[width="600"] th {
    display: block;
    width: auto !important;
    min-width: 0 !important;
    white-space: normal;
  }
  .regulations-page .page-content table[width="600"] td:first-child,
  .regulations-page .page-content table[width="600"] th:first-child {
    flex: 0 0 auto;
    white-space: nowrap;
    min-width: 3.5rem;
    text-align: center;
    padding-right: 0.25rem;
  }
  .regulations-page .page-content table[width="600"] td:nth-child(2),
  .regulations-page .page-content table[width="600"] th:nth-child(2) {
    flex: 0 0 0.25rem;
    text-align: center;
    padding-left: 0;
    padding-right: 0;
  }
  .regulations-page .page-content table[width="600"] td:nth-child(3),
  .regulations-page .page-content table[width="600"] th:nth-child(3) {
    flex: 1 1 auto;
    min-width: 0 !important;
    word-break: normal;
    overflow-wrap: break-word;
  }
  .regulations-page .page-content table[width="600"] td:nth-child(3) *,
  .regulations-page .page-content table[width="600"] th:nth-child(3) * {
    word-break: normal;
    overflow-wrap: break-word;
    white-space: normal;
  }
  .regulations-page .page-content table[width="600"] td[colspan],
  .regulations-page .page-content table[width="600"] th[colspan] {
    flex: 1 1 100%;
    width: 100% !important;
    min-width: 0 !important;
    text-align: left;
    word-break: normal;
    overflow-wrap: break-word;
  }
  .regulations-page .page-content table[width="600"] td[colspan] *,
  .regulations-page .page-content table[width="600"] th[colspan] * {
    word-break: normal;
    overflow-wrap: break-word;
    white-space: normal;
  }
}

/* 會刊目錄樣式 */
.journal-section h1 {
  font-size: 1.5rem;
  color: var(--color-primary);
  text-align: center;
  margin: 0.5rem 0 1rem;
}
.issue-nav { text-align: center; margin: 1rem 0; }
.issue-nav a {
  display: inline-block;
  padding: 3px 8px;
  margin: 2px;
  background: #f0e9df;
  color: var(--color-link);
  font-size: 0.85rem;
  border-radius: 3px;
}
.issue-nav a:hover { background: var(--color-accent); color: #fff; }
.issue-info { font-size: 0.85rem; color: var(--color-text-muted); margin-bottom: 0.5rem; }
.entry { margin: 0.5rem 0; padding: 0.4rem 0; border-bottom: 1px dotted var(--color-border); }
.entry-zh { font-size: 0.95rem; font-weight: bold; }
.entry-en { font-size: 0.85rem; color: var(--color-text-muted); }
.entry-authors { font-size: 0.85rem; color: var(--color-secondary); }
.entry-pages { font-size: 0.8rem; color: var(--color-text-muted); float: right; }
.top-link { text-align: right; font-size: 0.85rem; margin: 0.3rem 0; }

@media (max-width: 400px) {
  .logo-img { max-height: 70px; }
  .content-container { padding: 1rem; }
}
