/* 317767.com 新聞快讀 — 前台樣式
   build: 2026-07-29 v4-root-public-front
   設計目標：專業新聞網站風、響應式、無廣告 */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1e3a8a;       /* 信賴藍 */
  --primary-2: #1e40af;
  --primary-soft: #eff6ff;
  --accent: #dc2626;         /* 強調紅 */
  --accent-soft: #fef2f2;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #94a3b8;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --warn: #f59e0b;
  --ok: #10b981;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 1px 3px rgba(15,23,42,.06);
  --shadow-md: 0 4px 6px -1px rgba(15,23,42,.1), 0 2px 4px -2px rgba(15,23,42,.1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Hiragino Sans", system-ui, sans-serif;
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color .15s; }
a:hover { color: var(--primary-2); text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* === Topbar === */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto;
  padding: 14px 20px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 20px; align-items: center;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; box-shadow: var(--shadow);
}
.brand-text { line-height: 1.2; }
.brand-title { font-size: 18px; font-weight: 800; display: block; color: var(--text); }
.brand-subtitle { font-size: 11px; color: var(--muted); }

.topnav { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; justify-content: center; }
.topnav a {
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
}
.topnav a:hover { background: var(--bg); color: var(--primary); text-decoration: none; }
.topnav a.active { background: var(--primary); color: white; }

.search { display: flex; gap: 6px; }
.search input {
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 14px;
  width: 180px;
  outline: none;
  transition: border .15s;
}
.search input:focus { border-color: var(--primary); }
.search button {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.search button:hover { background: var(--primary-2); }

/* === Container === */
.container { max-width: 1280px; margin: 0 auto; padding: 24px 20px 60px; }
.container-narrow { max-width: 760px; }

/* === Hero === */
.hero {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
  margin-bottom: 32px;
}
.hero-main {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--card);
  box-shadow: var(--shadow);
  display: block;
  color: inherit;
  min-height: 420px;
}
.hero-main:hover { text-decoration: none; }
.hero-main img {
  width: 100%; height: 320px; object-fit: cover; display: block;
  background: var(--border);
}
.hero-main-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 20px 24px;
  background: linear-gradient(to top, rgba(0,0,0,.85) 0%, rgba(0,0,0,.5) 60%, transparent 100%);
  color: white;
}
.hero-main-body .badge { background: var(--accent); color: white; }
.hero-main-body h2 {
  font-size: 26px; font-weight: 800; line-height: 1.3;
  margin: 8px 0 6px;
  color: white;
}
.hero-main-body p { color: rgba(255,255,255,.85); font-size: 14px; margin-bottom: 8px; }
.hero-main-body .muted { color: rgba(255,255,255,.7); }

.hero-side { display: flex; flex-direction: column; gap: 12px; }
.hero-card {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  color: inherit;
  flex: 1;
}
.hero-card:hover { box-shadow: var(--shadow-md); text-decoration: none; }
.hero-card img { width: 130px; height: 100%; object-fit: cover; background: var(--border); }
.hero-card > div { padding: 12px 12px 12px 0; display: flex; flex-direction: column; justify-content: space-between; }
.hero-card h3 { font-size: 15px; line-height: 1.4; font-weight: 700; margin: 4px 0 6px; }
.badge-mini { display: inline-block; background: var(--bg); color: var(--text-2); font-size: 11px; padding: 2px 6px; border-radius: 4px; font-weight: 500; }

/* === Section === */
.section { margin-bottom: 40px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary);
}
.section-head h2 { font-size: 22px; font-weight: 800; }
.more { font-size: 14px; font-weight: 500; }

/* === Card grid === */
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
.card-grid-5 { grid-template-columns: repeat(5, 1fr); }
.card {
  display: flex; flex-direction: column;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  color: inherit;
  transition: all .2s;
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); text-decoration: none; }
.card-img { position: relative; aspect-ratio: 16/9; background: var(--border); overflow: hidden; }
.card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-noimg {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary-soft), var(--accent-soft));
  font-size: 56px;
  color: var(--primary);
}
.card-badge {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,.75); color: white;
  font-size: 11px; padding: 3px 8px; border-radius: 4px;
  font-weight: 600;
}
.card-important { border: 2px solid var(--accent); }
.card-important .card-badge { background: var(--accent); }
.card-body { padding: 12px 14px 14px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.card-title {
  font-size: 15px; font-weight: 700; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  color: var(--text);
}
.card-excerpt {
  color: var(--text-2); font-size: 13px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  flex: 1;
}
.card-meta { display: flex; gap: 6px; align-items: center; font-size: 12px; flex-wrap: wrap; }

/* === Region page === */
.region-head { margin-bottom: 24px; }
.region-head h1 { font-size: 28px; font-weight: 800; margin-bottom: 16px; }
.chip-bar { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 6px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 100px;
  font-size: 13px;
  color: var(--text-2);
  background: var(--card);
}
.chip:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.chip.active { background: var(--primary); color: white; border-color: var(--primary); }

.pagination {
  display: flex; gap: 12px; justify-content: center; align-items: center;
  margin-top: 32px; padding: 16px;
  background: var(--card); border-radius: var(--radius);
}
.page-link { padding: 6px 14px; border: 1px solid var(--border-strong); border-radius: 6px; font-size: 14px; }
.page-link:hover { background: var(--primary); color: white; border-color: var(--primary); text-decoration: none; }
.page-info { color: var(--text-2); font-size: 14px; }

/* === Article page === */
.breadcrumb { font-size: 13px; color: var(--text-2); margin-bottom: 16px; }
.breadcrumb a { color: var(--text-2); }
.breadcrumb a:hover { color: var(--primary); }
.article { background: var(--card); border-radius: var(--radius-lg); padding: 32px 40px; box-shadow: var(--shadow); }
.article-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; font-size: 13px; }
.badge { display: inline-block; background: var(--primary-soft); color: var(--primary); font-size: 12px; padding: 3px 10px; border-radius: 4px; font-weight: 600; }
.article-title { font-size: 30px; font-weight: 800; line-height: 1.3; margin-bottom: 20px; color: var(--text); }
.article-cover { width: 100%; max-height: 480px; object-fit: cover; border-radius: var(--radius); margin-bottom: 24px; }
.article-body { font-size: 17px; line-height: 1.85; color: var(--text); }
.article-body p { margin: 0 0 1.4em; text-align: justify; }
.article-body img { max-width: 100%; height: auto; border-radius: var(--radius); margin: 12px 0; }
.article-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-top: 32px; padding-top: 20px;
  border-top: 1px solid var(--border);
}
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-2); border-color: var(--primary-2); color: white; }
.btn-ghost { background: transparent; border-color: var(--border); }

.related { margin-top: 40px; }
.related h2 { font-size: 18px; font-weight: 700; margin-bottom: 14px; }
.related-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.related-list li { padding: 12px 14px; background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.related-list li a { font-weight: 600; font-size: 15px; }

/* === Search === */
.search-head { margin-bottom: 28px; }
.search-head h1 { font-size: 28px; font-weight: 800; margin-bottom: 16px; }
.search-large { display: flex; gap: 8px; }
.search-large input { flex: 1; padding: 12px 16px; font-size: 16px; border: 1px solid var(--border-strong); border-radius: 6px; outline: none; }
.search-large input:focus { border-color: var(--primary); }
.search-list { display: flex; flex-direction: column; gap: 14px; }
.search-item { display: grid; grid-template-columns: 180px 1fr; gap: 16px; padding: 16px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); color: inherit; }
.search-item:hover { box-shadow: var(--shadow-md); text-decoration: none; }
.search-thumb { width: 180px; height: 110px; object-fit: cover; border-radius: 6px; }
.search-item h3 { font-size: 17px; font-weight: 700; margin: 6px 0; line-height: 1.4; }
.search-item p { margin: 4px 0 8px; font-size: 14px; }

.empty { text-align: center; padding: 40px; color: var(--muted); font-size: 15px; background: var(--card); border-radius: var(--radius); }

/* === Article page (v5 兩欄 layout + sidebar) === */
.article-page { max-width: 1280px; }
.article-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas: "main side";
  gap: 32px;
  align-items: start;
}
.article-main {
  grid-area: main;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}
.article-main img { max-width: 100%; height: auto; }
.article-main pre, .article-main table, .article-main figure { max-width: 100%; }
.article-sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  min-width: 0;
}
.article-body-page .container { padding-top: 16px; }
.breadcrumb { font-size: 13px; color: var(--text-2); margin-bottom: 16px; }
.breadcrumb a { color: var(--text-2); }
.breadcrumb a:hover { color: var(--primary); }
.article { background: var(--card); border-radius: var(--radius-lg); padding: 32px 40px; box-shadow: var(--shadow); }
.article-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; font-size: 13px; }
.badge { display: inline-block; background: var(--primary-soft); color: var(--primary); font-size: 12px; padding: 3px 10px; border-radius: 4px; font-weight: 600; }
.article-title { font-size: 30px; font-weight: 800; line-height: 1.3; margin-bottom: 20px; color: var(--text); }
.article-cover { width: 100%; max-height: 480px; object-fit: cover; border-radius: var(--radius); margin-bottom: 24px; }
.article-body { font-size: 17px; line-height: 1.85; color: var(--text); }
.article-body p { margin: 0 0 1.4em; text-align: justify; }
.article-body img { max-width: 100%; height: auto; border-radius: var(--radius); margin: 12px 0; }
.article-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--border); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--card); color: var(--text); font-size: 14px; font-weight: 500; cursor: pointer; transition: all .15s; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-2); border-color: var(--primary-2); color: white; }
.btn-ghost { background: transparent; border-color: var(--border); }
.related { margin-top: 40px; }
.related h2 { font-size: 18px; font-weight: 700; margin-bottom: 14px; }
.related-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.related-list li { padding: 12px 14px; background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.related-list li a { font-weight: 600; font-size: 15px; }

/* sidebar cards */
.sidebar-card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.sidebar-card h3 { font-size: 14px; font-weight: 700; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 2px solid var(--primary); }
.region-switch { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.region-switch li a { display: block; padding: 8px 12px; border-radius: 6px; font-size: 14px; color: var(--text-2); font-weight: 500; transition: all .15s; }
.region-switch li a:hover { background: var(--bg); color: var(--primary); text-decoration: none; }
.region-switch li a.active { background: var(--primary); color: white; }
.sidebar-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.sidebar-list li a { font-size: 14px; line-height: 1.5; color: var(--text); font-weight: 500; }
.sidebar-list li a:hover { color: var(--primary); }

/* === Ads (v5 / v5.1 img-size guard) === */
.ad-slot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* 防止廣告圖撐開 grid/flex 父容器 */
  min-width: 0;
}
.ad-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  /* 防止圖片撐開 */
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
}
.ad-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  /* 防止 flex 項目被圖片撐大 */
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
.ad-link:hover { text-decoration: none; opacity: 0.85; }
.ad-link img {
  /* ★ v5.1：嚴格限制圖片大小，避免原始大圖撐開版面 */
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: 250px;
  object-fit: contain;
  border-radius: 4px;
}
/* 各位置個別 max-width（依建議尺寸） */
.ad-hero_below img       { max-width: 1200px; max-height: 200px; object-fit: cover; }
.ad-between_sections img { max-width: 800px;  max-height: 150px; object-fit: cover; }
.ad-footer_top img       { max-width: 1200px; max-height: 80px;  object-fit: cover; }
.ad-region_top img       { max-width: 1200px; max-height: 150px; object-fit: cover; }
.ad-sidebar_top img,
.ad-sidebar_inline img   { max-width: 320px;  max-height: 250px; object-fit: cover; }
.ad-title { font-weight: 600; font-size: 12px; }
.ad-pill { display: inline-block; background: #fef3c7; color: #92400e; font-size: 10px; padding: 1px 6px; border-radius: 3px; font-weight: 700; }
.ad-text { padding: 8px 12px; background: var(--bg); border-radius: 4px; }

/* Position-specific */
.ad-hero_below { margin-bottom: 24px; }
.ad-between_sections { margin: 32px 0; }
.ad-footer_top { margin: 40px 0 0; }
.ad-region_top { margin: 16px 0 24px; }
.ad-sidebar_top, .ad-sidebar_inline { background: transparent; border: none; padding: 0; }
.ad-sidebar_top .ad-item, .ad-sidebar_inline .ad-item { background: var(--card); box-shadow: var(--shadow); }

/* 響應式：小螢幕圖片自適應 */
@media (max-width: 640px) {
  .ad-hero_below img,
  .ad-between_sections img,
  .ad-footer_top img,
  .ad-region_top img { max-width: 100%; }
}

/* === Empty / unavailable page === */
.empty-page {
  text-align: center;
  padding: 80px 20px;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin: 32px 0;
}
.empty-icon {
  font-size: 72px;
  margin-bottom: 20px;
  line-height: 1;
}
.empty-page h1 { font-size: 28px; font-weight: 700; margin-bottom: 12px; justify-content: center; }
.empty-page p { color: var(--text-2); margin-bottom: 8px; }

/* === Footer === */
.footer {
  background: var(--card);
  border-top: 1px solid var(--border);
  margin-top: 60px;
  padding: 32px 20px 16px;
  font-size: 13px;
  color: var(--text-2);
}
.footer-inner { max-width: 1280px; margin: 0 auto; }
.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 32px;
  text-align: left;
  margin-bottom: 24px;
}
.footer-grid > div { min-width: 0; }
.footer-brand { display: block; font-size: 16px; color: var(--text, #222); margin-bottom: 8px; }
.footer-tagline { margin: 0 0 8px; }
.footer-grid ul.footer-links { list-style: none; padding: 0; margin: 8px 0 0; }
.footer-grid ul.footer-links li { margin: 4px 0; }
.footer-grid ul.footer-links a { color: var(--text-2); text-decoration: none; }
.footer-grid ul.footer-links a:hover { color: var(--text, #222); text-decoration: underline; }
.footer-grid strong { display: block; margin-bottom: 4px; color: var(--text, #222); }
.footer-grid p { line-height: 1.5; margin: 0 0 6px; }
.footer-meta {
  max-width: 1280px;
  margin: 0 auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  text-align: center;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.footer-meta span { display: inline-block; }

/* === Responsive === */
@media (max-width: 960px) {
  .topbar-inner { grid-template-columns: 1fr; gap: 12px; }
  .topnav { justify-content: flex-start; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .topnav a { white-space: nowrap; }
  .search { width: 100%; }
  .search input { flex: 1; }
  .hero { grid-template-columns: 1fr; }
  .hero-main { min-height: 280px; }
  .hero-main img { height: 220px; }
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  .card-grid-5 { grid-template-columns: repeat(2, 1fr); }
  .article { padding: 20px 18px; }
  .article-title { font-size: 22px; }
  .article-body { font-size: 16px; }
  .search-item { grid-template-columns: 1fr; }
  .search-thumb { width: 100%; height: 180px; }
  .article-layout { display: block; }
  .article-main { max-width: 100%; }
  .article-sidebar { width: 100%; margin-top: 24px; }
  .article-sidebar { position: static; max-height: none; }
  .article-main { grid-area: main; }
}
@media (max-width: 600px) {
  .card-grid, .card-grid-5 { grid-template-columns: 1fr; }
  .hero-side { flex-direction: row; }
  .hero-card { grid-template-columns: 100px 1fr; }
  .hero-card img { width: 100px; }
  .section-head h2 { font-size: 18px; }
  .article { padding: 16px 14px; }
  .article-title { font-size: 19px; }
  /* v5.2 mobile UX fix：CJK 標題/標籤不擠壓、封面圖不過高 */
  .article-title { word-wrap: break-word; overflow-wrap: anywhere; }
  .article-body p { word-wrap: break-word; overflow-wrap: break-word; }
  .article-body figure { margin: 16px 0; }
  .article-body figcaption { font-size: 13px; line-height: 1.5; padding: 6px 4px; }
  .article-body figure img { max-width: 100%; height: auto; }
  .article-cover { max-height: 220px; }
  .article-meta { gap: 6px; }
  .article-meta .badge,
  .article-meta .chip,
  .breadcrumb .chip { white-space: nowrap; flex-shrink: 0; }
  .breadcrumb { font-size: 12px; overflow-x: auto; white-space: nowrap; padding-bottom: 4px; }
  /* 卡片標題不超出 */
  .card-title, .hero-card .card-title, .news-card .card-title,
  .search-item .card-title { word-wrap: break-word; overflow-wrap: anywhere; }
  /* Hero 主圖文字 mobile 縮減 */
  .hero-title { font-size: 20px !important; line-height: 1.3; }
  .hero-desc { font-size: 14px !important; -webkit-line-clamp: 3; line-clamp: 3; }
  /* chip 群組 wrap */
  .chip-bar { flex-wrap: wrap; }
  .chip { white-space: nowrap; flex-shrink: 0; }
  /* 頂部導航避免擠壓 */
  .topbar-inner { padding: 0 12px; }
  .topnav { padding: 0 12px; }
  /* 搜尋框 mobile 全寬 */
  .search form { flex-direction: column; }
  .search form button { width: 100%; }
  /* footer */
  .footer { padding: 24px 14px 16px; font-size: 13px; }
  .footer-grid { grid-template-columns: 1fr; gap: 20px; }
  .footer-meta { font-size: 11px; gap: 4px; }
  /* 廣告 slot 圖片全寬（已在 v5.1 修，這裡保險） */
  .ad-item img { max-width: 100%; }
  /* article sidebar 廣告（被擠到下面） */
  .article-sidebar { padding: 0 4px; }
  .article-sidebar .ad-item { margin-bottom: 12px; }
}
