/* ── Thai Open Data Visualization Catalog — shared stylesheet ─────────────── */

:root {
  --navy: #1e3c72;
  --navy-2: #2a5298;
  --ink: #1f2430;
  --muted: #6c757d;
  --bg: #f5f7fa;
  --card: #ffffff;
  --line: #e3e8ef;
  --ac: var(--navy-2);
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-lg: 0 8px 16px rgba(16, 24, 40, .08), 0 20px 44px rgba(16, 24, 40, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Sarabun', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.page { max-width: 1180px; margin: 0 auto; padding: 28px 22px 72px; }

a { color: var(--navy-2); }

/* ── หน้า index: hero ─────────────────────────────────────────────────────── */
.site-hero {
  background: linear-gradient(135deg, #16294f 0%, var(--navy) 45%, var(--navy-2) 100%);
  color: #fff;
  padding: 64px 0 56px;
  position: relative;
  overflow: hidden;
}
.site-hero::after {
  content: '';
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 88% 15%, rgba(255,255,255,.13), transparent 42%),
    radial-gradient(circle at 12% 92%, rgba(255,255,255,.09), transparent 38%);
  pointer-events: none;
}
.site-hero .page { padding-top: 0; padding-bottom: 0; position: relative; z-index: 1; }
.site-hero h1 { margin: 0 0 10px; font-size: clamp(1.6rem, 4vw, 2.5rem); font-weight: 700; letter-spacing: -.4px; }
.site-hero p { margin: 0; opacity: .82; font-size: 1.03rem; max-width: 62ch; }

.site-stats { display: flex; gap: 40px; margin-top: 32px; flex-wrap: wrap; }
.site-stats div { display: flex; flex-direction: column; }
.site-stats b { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.site-stats span { font-size: .85rem; opacity: .72; }

/* ── หน้า index: กลุ่ม + การ์ด ─────────────────────────────────────────────── */
.group-block { margin-top: 54px; }
.group-header {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px;
  font-size: 1.32rem; font-weight: 700;
  border-left: 5px solid var(--navy-2);
  padding: 2px 0 2px 14px;
  margin: 0 0 22px;
}
.group-header .group-emoji { font-size: 1.3em; }
.group-header small { font-weight: 400; font-size: .78rem; color: var(--muted); }

.vgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 22px; }

.vcard {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 22px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  transition: transform .18s ease, box-shadow .18s ease;
}
.vcard:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.vcard-icon {
  width: 52px; height: 52px; border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-size: 25px; margin-bottom: 16px;
}
.vcard h3 { margin: 0 0 8px; font-size: 1.04rem; font-weight: 700; line-height: 1.45; }
.vcard p { margin: 0 0 16px; font-size: .89rem; color: var(--muted); }
.vcard-meta {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-size: .8rem; color: var(--muted);
  padding-bottom: 16px; margin-top: auto;
  border-bottom: 1px solid var(--line); margin-bottom: 16px;
}

.btn {
  display: inline-block; text-align: center; text-decoration: none;
  border-radius: 9px; padding: 10px 18px;
  font-weight: 600; font-size: .89rem;
  transition: background .16s ease, color .16s ease;
}
.btn-view { border: 1.5px solid var(--ac); color: var(--ac); background: transparent; }
.btn-view:hover { background: var(--ac); color: #fff; }

/* ── หน้า dashboard ───────────────────────────────────────────────────────── */
.back-link {
  display: inline-block; margin-bottom: 18px;
  font-size: .88rem; font-weight: 600; text-decoration: none; color: var(--muted);
}
.back-link:hover { color: var(--navy-2); }

.hero {
  border-radius: 18px;
  padding: 38px 44px;
  margin-bottom: 26px;
  color: #fff;
  position: relative;
  overflow: hidden;
}
.hero::before {
  position: absolute; right: 30px; top: -6px;
  font-size: 116px; opacity: .16; line-height: 1; pointer-events: none;
}
.hero-kicker { font-size: .82rem; opacity: .75; font-weight: 600; letter-spacing: .04em; }
.hero h1 { margin: 6px 0 8px; font-size: clamp(1.25rem, 3vw, 1.95rem); font-weight: 700; letter-spacing: -.3px; max-width: 40ch; }
.hero p { margin: 0; opacity: .78; font-size: .96rem; max-width: 68ch; }
.badges { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.26);
  border-radius: 20px; padding: 4px 14px; font-size: .81rem;
}

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 34px; }
.stat-card {
  background: var(--card); border-radius: 12px; padding: 18px 20px;
  box-shadow: var(--shadow); border-left: 4px solid var(--ac);
}
.stat-card .num { font-size: 1.75rem; font-weight: 700; color: var(--ac); line-height: 1.15; }
.stat-card .lbl { font-size: .82rem; color: var(--muted); margin-top: 3px; }

.section-title {
  font-size: 1.12rem; font-weight: 700;
  margin: 38px 0 18px; padding-left: 13px;
  border-left: 4px solid var(--ac);
  line-height: 1.5;
}

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
  margin-bottom: 22px; overflow: hidden;
}
.card-header {
  padding: 15px 20px 0;
  font-size: .76rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted);
}
.card-body { padding: 8px 10px 12px; }
.card-body img { max-width: 100%; height: auto; display: block; margin: 0 auto; }

/* กราฟ plotly ต้องยืดตามการ์ด ไม่ล้นออกนอกกรอบ */
.card-body .plotly-graph-div { width: 100% !important; max-width: 100%; }
.card-body > div { max-width: 100%; overflow-x: auto; }

/* ให้ข้อความไทยในกราฟใช้ฟอนต์เดียวกับเว็บ
   notebook บางเล่มเคยฝังฟอนต์เป็น base64 มาในผลลัพธ์ (ก้อนละ ~4 MB)
   ที่นี่โหลดจาก Google Fonts ครั้งเดียวแล้วบังคับผ่าน CSS แทน */
.plotly-graph-div text,
.plotly-graph-div .gtitle,
.plotly-graph-div .xtitle,
.plotly-graph-div .ytitle,
.plotly-graph-div .legendtext,
.plotly-graph-div .annotation-text {
  font-family: 'Sarabun', 'Segoe UI', system-ui, sans-serif !important;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
.grid-2 .card { margin-bottom: 0; }

.page-footer {
  margin-top: 48px; padding-top: 22px;
  border-top: 1px solid var(--line);
  font-size: .85rem; color: var(--muted);
}
.page-footer p { margin: 4px 0; }
.page-footer code { background: #eef1f6; padding: 2px 7px; border-radius: 5px; font-size: .92em; }

/* ── ปุ่มลอยมุมซ้ายล่าง ───────────────────────────────────────────────────── */
.floating {
  position: fixed; bottom: 18px; left: 18px; z-index: 9999;
  display: flex; flex-direction: column; gap: 9px;
}
.fl-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 15px; border-radius: 9px;
  text-decoration: none; font-weight: 600; font-size: .84rem;
  box-shadow: 0 4px 14px rgba(0,0,0,.22);
}
.fl-dark { background: #24292e; color: #fff; }
.fl-light { background: #fff; color: var(--ink); border: 1px solid var(--line); }

/* ── footer หน้า index ────────────────────────────────────────────────────── */
.site-footer {
  text-align: center; padding: 34px 20px 46px;
  border-top: 1px solid var(--line); background: #fff;
  font-size: .88rem;
}
.site-footer p { margin: 4px 0; }
.site-footer .muted { color: var(--muted); font-size: .82rem; }

/* ── responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .hero { padding: 28px 24px; }
  .hero::before { display: none; }
  .site-stats { gap: 26px; }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .page { padding: 20px 15px 88px; }
  .floating { flex-direction: row; bottom: 12px; left: 12px; }
  .fl-btn { padding: 8px 12px; font-size: .78rem; }
}
