/* 手機優先；斷點 600px（平板）、1024px（電腦） */
.wrap { width: 100%; max-width: calc(var(--wrap) + 2 * var(--gutter)); margin: 0 auto; padding-left: var(--gutter); padding-right: var(--gutter); }

/* ==================== 頁首 ==================== */
.site-head { position: relative; z-index: 40; background: var(--bg); border-bottom: 3px solid var(--line-accent);
             padding-top: var(--safe-top); }
.head-row { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--fg); text-decoration: none; font-weight: 700;
         margin-right: auto; min-height: var(--tap); }
.brand img { width: 104px; height: auto; display: block; }
.brand { margin-right: auto; }
.cart-btn { padding: 6px 12px; }

/* ==================== 檢索頁 ==================== */
.page-title { margin: 16px 0 8px; color: var(--fg); }
.search-layout { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "search" "side" "main"; column-gap: 28px; }
.searchbar { grid-area: search; position: sticky; top: 0; z-index: 30; background: var(--bg);
             margin: 0 calc(-1 * var(--gutter)); padding: 8px var(--gutter); transition: box-shadow .15s; }
.searchbar.stuck { box-shadow: 0 4px 12px rgba(0,0,0,.08); }
.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; min-width: 0; }
/* 提示字依寬度縮放（最小 14px），手機也能完整顯示；輸入文字本身維持 16px，避免 iOS 放大畫面 */
#q::placeholder { font-size: clamp(14px, calc((100vw - 136px) / 17), 16px); }
/* Chrome 會替搜尋框右側的清除鈕預留空間，導致提示字被截斷 */
#q::-webkit-search-cancel-button, #q::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
.search-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.filter-toggle { display: inline-flex; align-items: center; gap: 4px; min-height: var(--tap); padding: 0 14px; background: #fff;
                 border: 1px solid var(--line); border-radius: var(--radius); font: inherit; font-size: 15px; color: var(--fg); cursor: pointer; }
.filter-toggle .count:not(:empty) { color: var(--accent); font-weight: 700; }
.filter-toggle .chev { color: var(--muted); }

.sidebar { grid-area: side; display: none; }   /* 手機版篩選條件移到底部抽屜 */
.results-col { grid-area: main; min-width: 0; }
.sidebar-title { display: none; font-size: 16px; margin: 0 0 12px; color: var(--fg); }

.toolbar { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 12px; flex-wrap: wrap; margin: 12px 0 8px; }
.summary { color: var(--fg); font-size: var(--fs-small); font-weight: 600; }
.data-info { color: var(--muted); font-size: 12px; }
.contact-note { font-size: var(--fs-small); color: var(--muted); margin: 6px 0 0; }
.contact-note.center { text-align: center; }

/* 篩選條件（抽屜／側欄共用：直向排列） */
.filters { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-small); color: var(--muted); }
.field select { width: 100%; }
.field-years .years { display: flex; align-items: center; gap: 8px; }
.field-years input { width: 0; flex: 1; }
.field-years legend { padding: 0; margin-bottom: 4px; }
.filters-actions { display: flex; justify-content: flex-start; }

/* ==================== 結果清單 ==================== */
.results { min-height: 200px; }
.item { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.item:first-child { border-top: 1px solid var(--line); }
.item-body { flex: 1; min-width: 0; }
.item-h { margin: -8px 0 0; font-size: var(--fs-item); color: var(--title); }
.item-title { display: block; min-height: var(--tap); background: none; border: 0; padding: 8px 0; text-align: left;
              font: inherit; font-weight: 700; color: inherit; cursor: pointer; line-height: 1.5; }
.item-title:hover { text-decoration: underline; }
/* 四行欄位：識別碼、專案、資料類型、出版日期（所有寬度相同） */
.item .meta { font-size: 13px; gap: 0; }
.item .meta > div { grid-template-columns: 4.6em 1fr; }
.item-actions { flex: none; }
@media (min-width: 600px) {
  .item { gap: 16px; }
  .item .meta { font-size: 14px; gap: 2px; }
  .item .meta > div { grid-template-columns: 5.2em 1fr; }
}
.empty { padding: 40px 0; text-align: center; color: var(--muted); }

/* ==================== 分頁 ==================== */
.pager { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 6px; margin: 20px 0 0; }
/* 分頁列與頁尾之間只留頁尾的 margin-top（24px）；分頁置中，不會被右下角「回到最上方」擋住 */
.pager button { min-width: var(--tap); min-height: var(--tap); padding: 0 10px; border: 1px solid var(--line); background: #fff;
                color: var(--fg); border-radius: var(--radius); cursor: pointer; font: inherit; font-size: 15px; }
.pager button.current { background: var(--accent); color: #fff; border-color: var(--accent); }
.pager button:disabled { opacity: .4; cursor: default; }
.pager .gap { padding: 0 2px; color: var(--muted); }
.pager .pos { padding: 0 10px; color: var(--muted); font-size: 15px; }

/* ==================== 浮動按鈕 ==================== */
.to-top { position: fixed; z-index: 34; right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(16px + var(--safe-bottom));
          min-width: var(--tap); min-height: var(--tap); border: 1px solid var(--accent); border-radius: 22px; background: #fff;
          color: var(--accent); cursor: pointer; font: inherit; font-size: 14px; padding: 0 12px; box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.to-top:hover { background: var(--add-bg); }
.to-top .label { display: none; }

/* ==================== 一般內容頁、頁尾 ==================== */
.home { padding: 8px 0 32px; max-width: 880px; }
.home h1 { color: var(--title); margin: 24px 0 16px; }
.home p { line-height: 1.9; }
.home-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin: 24px 0; }
.notice-page { padding: 8px 0 32px; max-width: 880px; line-height: 1.9; }
.notice-page h1 { margin: 24px 0 16px; }
.site-foot { border-top: 1px solid var(--line); margin-top: 24px; padding: 16px 0 calc(16px + var(--safe-bottom));
             color: var(--muted); font-size: 16px; text-align: center; background: var(--soft); }
.site-foot p { margin: 4px 0; }
/* 手機：「回到最上方」固定在右下角（高 44px、距底 16px），頁尾多留底部空間，避免蓋住版權文字 */
@media (max-width: 599.98px) { .site-foot { padding-bottom: calc(76px + var(--safe-bottom)); } }

/* ==================== 平板 600px 以上 ==================== */
@media (min-width: 600px) {
  .brand img { width: 120px; }
  .cart-btn { padding: 8px 16px; }
  .to-top { right: 24px; bottom: calc(24px + var(--safe-bottom)); }
  .to-top .label { display: inline; }

  .sidebar { display: block; }
  .searchbar { padding-bottom: 10px; }
  /* 平板：篩選排成兩列，可收合 */
  .sidebar .filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 16px; align-items: end;
                      background: var(--soft); border-radius: 8px; padding: 12px 14px; margin-bottom: 4px; }
  .sidebar .filters.collapsed { display: none; }
  .sidebar .filters-actions { align-self: center; }

}

/* ==================== 電腦 1024px 以上 ==================== */
@media (min-width: 1024px) {
  .head-row { min-height: 68px; }
  .search-layout { grid-template-columns: 280px minmax(0, 1fr); grid-template-areas: "side search" "side main"; align-items: start; }
  .searchbar { position: static; margin: 0; padding: 0; box-shadow: none !important; }
  .search-tools { display: none; }
  .sidebar { position: sticky; top: 16px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto;
             background: var(--soft); border-radius: 10px; padding: 16px; }
  .sidebar .filters { display: flex; flex-direction: column; align-items: stretch; gap: 14px; background: none; padding: 0; margin: 0; }
  .sidebar .check-list { max-height: none; }       /* 側欄本身會捲動，不要再有內層捲軸 */
  .sidebar .filters.collapsed { display: flex; }
  .sidebar-title { display: block; }
  .page-title { margin: 20px 0 12px; }
}
