:root {
  --primary: #2f6b46;
  --primary-dark: #1f4d33;
  --accent: #e8a33d;
  --bg: #f6f7f3;
  --card-bg: #ffffff;
  --text: #333333;
  --muted: #6b6b6b;
  --border: #e0e0e0;
  --radius: 8px;
}

* { box-sizing: border-box; }

html { font-size: 16px; }
html.font-small { font-size: 14px; }
html.font-large { font-size: 19px; }

body {
  margin: 0;
  font-family: "Noto Sans TC", "Microsoft JhengHei", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; cursor: pointer; }
button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.skip-link { position: absolute; left: -9999px; top: 0; }
.skip-link:focus { left: 8px; top: 8px; background: #fff; padding: 8px; z-index: 999; }

/* ===== Top bar ===== */
.topbar { background: var(--primary-dark); color: #fff; padding: 10px 20px; }
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-badge {
  width: 44px; height: 44px; border-radius: 50%;
  background: #fff; color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.95rem;
}
.brand-text .title { font-weight: 700; font-size: 1.05rem; }
.brand-text .subtitle { font-size: 0.75rem; opacity: 0.85; }

.topnav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; font-size: 0.85rem; }
.topnav a:hover { text-decoration: underline; }
.topmeta { display: flex; align-items: center; gap: 10px; font-size: 0.8rem; opacity: 0.9; }
.fontsize-btns button {
  background: transparent; border: 1px solid rgba(255,255,255,0.5); color: #fff;
  border-radius: 4px; padding: 2px 6px; font-size: 0.75rem; margin-left: 4px;
}
.fontsize-btns button.active { background: #fff; color: var(--primary-dark); }

/* ===== 分類導覽列（分類是動態的，不是固定清單） ===== */
.categorybar { background: var(--primary); display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; padding: 2px; }
.categorybar a { color: #fff; padding: 10px 14px; font-size: 0.82rem; font-weight: 600; text-align: center; flex: 1 1 auto; min-width: 110px; }
.categorybar a:hover, .categorybar a.active { filter: brightness(1.15); text-decoration: underline; }

/* ===== Layout ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }
.breadcrumb { font-size: 0.85rem; color: var(--muted); margin-bottom: 16px; }
.breadcrumb a:hover { text-decoration: underline; }

.page-heading { text-align: center; margin: 10px 0 30px; }
.page-heading .logo-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 90px; height: 90px; border-radius: 50%;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 1.4rem;
  margin-bottom: 12px;
}
.page-heading h1 {
  font-size: 1.6rem; color: var(--primary-dark); margin: 0;
  display: inline-block; padding-bottom: 8px; border-bottom: 4px solid var(--accent);
}

/* ===== Search / filter ===== */
.search-row { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.search-row input[type="text"] {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  width: 260px; max-width: 100%;
}
.btn { background: var(--primary); color: #fff; border: none; padding: 9px 18px; border-radius: var(--radius); font-weight: 600; font-size: 0.9rem; }
.btn:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); }
.btn-accent:hover { filter: brightness(0.95); }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }

.filter-row { display: flex; justify-content: center; margin-bottom: 24px; }
.filter-row select { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); min-width: 220px; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; background: var(--card-bg); border-radius: var(--radius); box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
thead th { background: var(--primary); color: #fff; text-align: left; padding: 12px 14px; font-size: 0.85rem; white-space: nowrap; cursor: pointer; user-select: none; }
thead th:hover { filter: brightness(1.1); }
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 0.9rem; vertical-align: middle; }
tbody tr:hover { background: #fafcf9; }
.topic-link { color: var(--primary-dark); font-weight: 600; }
.topic-link:hover { text-decoration: underline; }
.empty-row td, .loading-row td { text-align: center; color: var(--muted); padding: 40px; }

/* ===== Pagination ===== */
.pagination { display: flex; justify-content: center; gap: 6px; margin: 24px 0; flex-wrap: wrap; }
.pagination a, .pagination span {
  display: inline-block; min-width: 34px; text-align: center;
  padding: 6px 10px; border-radius: 4px; border: 1px solid var(--border); font-size: 0.85rem;
}
.pagination a:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .disabled { color: #ccc; }

.result-count { text-align: center; color: var(--muted); font-size: 0.85rem; margin-bottom: 10px; }

/* ===== Detail page ===== */
.detail-card { background: var(--card-bg); border-radius: var(--radius); box-shadow: 0 1px 4px rgba(0,0,0,0.06); padding: 30px; }
.detail-title { font-size: 1.4rem; color: var(--primary-dark); margin: 0 0 6px; }
.detail-meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 20px; display: flex; gap: 16px; flex-wrap: wrap; }
.category-tag { display: inline-block; color: #fff; padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.detail-section { margin-bottom: 22px; }
.detail-section h2 { font-size: 1rem; color: var(--primary); border-left: 4px solid var(--accent); padding-left: 10px; margin: 0 0 8px; }
.detail-section p { margin: 0; white-space: pre-wrap; color: var(--text); }
.detail-actions { display: flex; gap: 12px; justify-content: center; margin-top: 30px; flex-wrap: wrap; }

/* ===== Modal ===== */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal-overlay.open { display: flex; }
.modal-box { background: #fff; border-radius: var(--radius); padding: 26px; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; }
.modal-box h3 { margin-top: 0; color: var(--primary-dark); }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.85rem; margin-bottom: 4px; font-weight: 600; }
.form-group input, .form-group textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; }
.form-group textarea { min-height: 70px; resize: vertical; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal-msg { font-size: 0.85rem; margin-top: 10px; min-height: 1.2em; }
.modal-msg.error { color: #c62828; }
.modal-msg.success { color: var(--primary); }

/* ===== Back to top ===== */
.top-btn {
  position: fixed; right: 20px; bottom: 24px;
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.top-btn:hover { background: var(--primary-dark); }

@media (max-width: 640px) {
  .topbar-inner { flex-direction: column; align-items: flex-start; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr { border-bottom: 4px solid var(--bg); padding: 10px 0; }
  tbody td { border-bottom: none; padding: 4px 14px; }
  tbody td::before { content: attr(data-label); display: block; font-size: 0.72rem; color: var(--muted); font-weight: 600; }
}
