/* ปรับโครงหน้า Dashboard (โหลดหลัง responsive.css): ส่วนหัวบางลงโดยคงขนาดตัวอักษรเดิม แผงข้อมูลด้านขวากว้างขึ้น
   และจัดข้อความทุกปุ่ม/ป้ายให้อยู่กึ่งกลางแนวตั้ง */

/* ---- ข้อความในปุ่ม ป้าย และชิป: กึ่งกลางเสมอ ---- */
.btn-home-back, .level-btn, .tab-btn, .toggle-btn, .btn-monthly-entry, .year-type-badge,
.btn-combined-regions, .btn-back-national, .btn-toggle-12m-table, .btn-download-graph,
.modal-chip, .modal-stats-pill, .hcode-pill, .category-badge {
  display: inline-flex; align-items: center; justify-content: center; line-height: 1.3; text-align: center;
}
.btn-back-national span, .btn-combined-regions span, .btn-download-graph span, .btn-monthly-entry span { line-height: 1.3; }
.year-display { display: inline-flex; align-items: center; justify-content: center; line-height: 1.3; }
.summary-card-label, .summary-card-val, .section-perf-title, .sidebar-main-title, .active-group-title, .modal-title, .modal-subtitle { line-height: 1.35; }
.region-table th, .region-table td { vertical-align: middle; }
.leaflet-control-zoom a { display: flex; align-items: center; justify-content: center; }

/* ---- จอกว้าง: ลดเฉพาะระยะห่าง/ความสูงของแถบ ตัวอักษรขนาดเท่าเดิม ---- */
@media (min-width: 1181px) {
  .app-header { padding: 6px 20px 6px; }
  .header-top-bar { gap: 6px 16px; }
  .brand-section { gap: 12px; }
  .brand-logo { height: clamp(40px, 3.6vw, 52px); }
  .brand-title { line-height: 1.22; gap: 0; }
  .header-top-right { gap: 6px; }
  .btn-home-back { padding: 4px 12px 4px 8px; }
  .level-switch { padding: 2px 3px; }
  .level-btn { padding: 3px 12px; }
  .header-divider { margin: 4px 0; }
  .header-nav-rows { gap: 4px; }
  .header-nav-rows .group-tabs { min-height: 0; padding: 3px; gap: 3px; border-radius: 10px; }
  .header-nav-rows .tab-btn, .header-nav-rows .tab-btn.active { min-height: 34px; padding: 4px 10px; line-height: 1.25; border-radius: 7px; }
  .header-nav-rows .tab-btn[data-group="ip_sum"],
  .header-nav-rows .tab-btn[data-group="ucep_sum"] { padding-inline: 12px; justify-content: center; text-align: center; }

  .sub-header { --sub-pad-x: 20px; padding: 5px var(--sub-pad-x); gap: 6px 14px; border-bottom-width: 1px; }
  .active-group-desc { min-height: 0; }
  .active-group-title { line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .controls-toolbar { gap: 12px; }
  .timeline-card { gap: 10px; }
  .year-display { min-width: 0; }
  .year-type-badge { padding: 3px 12px; }
  .btn-monthly-entry { padding: 4px 13px; }
  .view-mode-toggles { padding: 2px; }
  .toggle-btn { padding: 4px 14px; }

  /* แผงข้อมูลด้านขวากว้างขึ้น (เดิม 43vw) */
  #sidebar { width: clamp(600px, 58vw, 1120px); }
  #sidebar-content { padding: 14px 20px; }
  .sidebar-header-row { margin-bottom: 10px; }
  .summary-kpi-card { padding: 10px 18px; margin-bottom: 14px; }
  .summary-card-val { font-size: 1.9rem; margin-top: 4px; }
}
@media (min-width: 1500px) {
  /* จอกว้างพอ: ปุ่มกลับหน้าแรกกับมุมมองข้อมูลอยู่แถวเดียวกัน */
  .header-top-right { flex-direction: row; align-items: center; gap: 10px; }
}

/* ---- ชื่อหัวข้อชิดซ้าย ---- */
.active-group-desc { justify-content: flex-start; }
.active-group-title { text-align: left; }

/* ---- เมนูเลือกหัวข้อบริการ (header-toggle.js): ชี้/แตะที่ชื่อหัวข้อเพื่อเปิดแผง ---- */
.sub-header { position: relative; }
body.group-menu-ready .header-divider { display: none; }
.group-menu-trigger {
  display: inline-flex; align-items: center; gap: 12px; max-width: 100%; min-width: 0;
  padding: 4px 6px 4px 12px; margin-left: -12px; border-radius: 10px; cursor: pointer; text-align: left;
  background: transparent; border: 1px solid transparent; color: #ffffff; font-family: inherit;
  transition: background 0.16s ease, border-color 0.16s ease;
}
.group-menu-trigger .active-group-title { min-width: 0; }
.group-menu-hint {
  display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0; padding: 3px 8px 3px 11px; border-radius: 9999px;
  background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.28);
  font-size: 0.74rem; font-weight: 700; line-height: 1.3; white-space: nowrap; color: #e2e8f0;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}
.group-menu-hint svg { width: 15px; height: 15px; transition: transform 0.2s ease; }
.group-menu-trigger:hover, .group-menu-open .group-menu-trigger { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.16); }
body.group-menu-pinned .group-menu-trigger { cursor: default; }
.group-menu-trigger:hover .group-menu-hint, .group-menu-open .group-menu-hint { background: #FF8C0B; border-color: #FF8C0B; color: #ffffff; }
body:not(.group-menu-pinned) .group-menu-open .group-menu-hint svg { transform: rotate(180deg); }
.sub-header { flex-wrap: wrap; }
.group-menu-panel {
  position: relative; z-index: 1001; order: 99; flex: 0 0 auto;
  /* ยืดเต็มความกว้างของแถบ (ชดเชย padding ของ .sub-header) */
  width: calc(100% + 2 * var(--sub-pad-x, 20px)); margin: 6px calc(-1 * var(--sub-pad-x, 20px)) -5px;
  padding: 8px clamp(12px, 1.6vw, 22px) 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(90deg, #162554 0%, #1A2C68 50%, #263F8F 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 6px 16px rgba(19, 30, 66, 0.25);
}
.group-menu-panel .header-nav-wrap { padding-right: 76px; }
.group-menu-panel.is-floating {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 1100; width: auto; margin: 0;
  background: linear-gradient(135deg, #131E42 0%, #1A2C68 55%, #263F8F 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 18px 36px rgba(19, 30, 66, 0.45);
  max-height: calc(100dvh - 160px); overflow-y: auto;
  animation: groupMenuIn 0.16s ease;
}
.group-menu-panel.is-floating .header-nav-wrap { padding-right: 76px; }
.group-menu-close {
  position: absolute; top: 10px; right: clamp(12px, 1.6vw, 22px); z-index: 2;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 4px 11px 4px 8px; min-height: 28px; border-radius: 9999px; cursor: pointer;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.28); color: #ffffff;
  font-family: inherit; font-weight: 700; font-size: 0.74rem; line-height: 1.3; white-space: nowrap;
  transition: background 0.16s ease, border-color 0.16s ease;
}
.group-menu-close svg { width: 14px; height: 14px; flex-shrink: 0; }
.group-menu-close:hover { background: #FF8C0B; border-color: #FF8C0B; }
.group-menu-close[hidden] { display: none; }
body.group-menu-pinned .group-menu-hint svg { transform: rotate(180deg); }
.group-menu-panel[hidden] { display: none; }
@keyframes groupMenuIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .group-menu-panel { animation: none; } .group-menu-hint svg { transition: none; } }
@media (max-width: 640px) {
  .group-menu-trigger { width: calc(100% + 12px); justify-content: space-between; min-height: 44px; }
  .active-group-desc { min-height: 0; }
}
@media (min-width: 1181px) {
  /* ชื่อหัวข้อยาว: ขึ้นบรรทัดใหม่แทนการตัดด้วย … */
  .group-menu-trigger .active-group-title { white-space: normal; overflow: visible; text-overflow: clip; line-height: 1.25; text-wrap: wrap; }
}
/* กล่องชื่อหัวข้อ: ชิดขอบซ้ายของจอทุกขนาดจอ */
.sub-header .active-group-desc { justify-content: flex-start !important; align-items: center; text-align: left; margin: 0; padding-left: 0; }
.sub-header .group-menu-trigger { margin-right: auto; }

/* ชื่อ Dashboard สองบรรทัดขนาดเท่ากัน */
.brand-title-line1, .brand-title-line2 { font-size: clamp(17px, 1.2vw, 21px); font-weight: 700; line-height: 1.4; }
@media (max-width: 1180px) and (min-width: 641px) { .brand-title-line1, .brand-title-line2 { font-size: 17px; } }
@media (max-width: 640px) {
  .brand-title-line1, .brand-title-line2 { font-size: clamp(14px, 3.8vw, 16px); }
  .group-menu-panel .header-nav-wrap { padding-right: 0; padding-top: 34px; }
}
@media (max-width: 1180px) { .sub-header { --sub-pad-x: clamp(12px, 1.8vw, 28px); } }
@media (max-width: 640px) { .sub-header { --sub-pad-x: 12px; } .group-menu-panel { margin-bottom: -12px; } }

/* ---- แถบชื่อหัวข้อ: ไม่มีกรอบ จัดกึ่งกลางแนวตั้ง ขนาดตัวอักษรสมดุล ---- */
.sub-header { row-gap: 0; align-items: center; }
.group-menu-panel { margin-top: 5px; }
.group-menu-trigger,
.group-menu-trigger:hover,
.group-menu-open .group-menu-trigger { background: transparent; border-color: transparent; padding: 0; margin-left: 0; }
.group-menu-trigger { gap: 12px; }
.group-menu-trigger:focus-visible { outline: 2px solid #FF8C0B; outline-offset: 4px; border-radius: 8px; }
@media (min-width: 1181px) {
  .active-group-title { font-size: clamp(17px, 1.1vw, 21px); font-weight: 700; }
  .year-display { font-size: clamp(16px, 1vw, 19px); font-weight: 800; }
  .group-menu-hint { font-size: 12.5px; min-height: 26px; padding: 0 9px 0 12px; }
  .year-type-badge, .btn-monthly-entry, .toggle-btn { font-size: 13px; min-height: 28px; padding-top: 0; padding-bottom: 0; }
  .year-type-badge { padding-inline: 12px; }
  .btn-monthly-entry { padding-inline: 14px; }
  .toggle-btn { padding-inline: 14px; }
  .view-mode-toggles { padding: 2px; align-items: center; }
  .controls-toolbar, .timeline-card { align-items: center; }
}
/* ชื่อหัวข้อบริการเป็นข้อความรอง: เล็กกว่าชื่อ Dashboard ด้านบน */
@media (min-width: 1181px) {
  .active-group-title { font-size: clamp(15px, 0.9vw, 17px); font-weight: 600; color: #e2e8f0; }
}

/* ---- แบบ A: เพิ่มช่องไฟให้ส่วนหัวโปร่งขึ้น และขยายตัวอักษรเล็กน้อย (คงลำดับชั้น: ชื่อเว็บ > ชื่อหัวข้อ) ---- */
@media (min-width: 1181px) {
  .app-header { padding: 14px 24px 12px; }
  .brand-section { gap: 18px; }
  .brand-logo { height: clamp(50px, 3.8vw, 58px); }
  .brand-title { gap: 4px; }
  .brand-title-line1, .brand-title-line2 { font-size: clamp(18px, 1.3vw, 23px); line-height: 1.45; }
  .header-top-right { gap: 10px; }
  .btn-home-back { font-size: 0.8rem; padding: 5px 13px 5px 9px; }
  .level-btn, .level-switch-label { font-size: 0.8rem; }
  .level-btn { padding: 4px 13px; }

  .sub-header { --sub-pad-x: 24px; padding: 11px var(--sub-pad-x); }
  .group-menu-panel { margin-top: 11px; }
  .group-menu-trigger { gap: 16px; }
  .active-group-title { font-size: clamp(16px, 1vw, 18.5px); }
  .year-display { font-size: clamp(17px, 1.1vw, 20px); }
  .group-menu-hint { font-size: 13px; min-height: 28px; }
  .year-type-badge, .btn-monthly-entry, .toggle-btn { font-size: 13.5px; min-height: 30px; }

  .header-nav-rows .tab-btn, .header-nav-rows .tab-btn.active { font-size: 12.5px; min-height: 36px; text-wrap: balance; }
}
