/* Shared by both dashboard entry points. */
html { -webkit-text-size-adjust: 100%; }
*, *::before, *::after { box-sizing: border-box; }
body { height: 100dvh; }
.app-header, .header-top-bar, .header-top-right, .header-nav-wrap,
.header-nav-rows, .nav-row, .controls-toolbar, .timeline-card,
#main, #map-container, #sidebar, #sidebar-content { min-width: 0; }
.active-group-title { white-space: normal; overflow-wrap: anywhere; }
.brand-title-line1, .brand-title-line2 { overflow-wrap: anywhere; }
.region-table-wrapper { max-width: 100%; overscroll-behavior-x: contain; }
.region-table.table-12m { min-width: 1120px; }
.modal-card { width: min(1320px, 100%); max-height: calc(100dvh - 32px); }
.modal-body { min-height: 0; overflow: auto; }
.modal-graph-image { max-width: 100%; height: auto; object-fit: contain; }
.modal-close-btn { flex: 0 0 44px; width: 44px; height: 44px; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 3px; }

/* Tablets, including landscape iPads and split-screen desktop windows. */
@media (max-width: 1180px) {
  body { height: auto; min-height: 100dvh; overflow: auto; }
  .app-header { position: relative; padding: 14px 18px; }
  .header-top-bar { flex-wrap: wrap; gap: 12px; }
  .header-top-right { flex-wrap: wrap; max-width: 100%; }
  .header-nav-rows .group-tabs { flex-wrap: wrap; overflow: visible; border-radius: 16px; }
  .header-nav-rows .tab-btn { white-space: normal; justify-content: center; }
  .sub-header { position: relative; flex-wrap: wrap; }
  .active-group-desc { flex-basis: 100%; }
  .controls-toolbar { width: 100%; justify-content: space-between; }
  #main { display: flex; flex-direction: column; flex: none; height: auto; overflow: visible; }
  #map-container { flex: none; width: 100%; height: clamp(340px, 48svh, 600px); min-height: 0; }
  #sidebar { width: 100%; height: auto; overflow: visible; border-left: 0; border-top: 1px solid #e2e8f0; }
  #sidebar-content { height: auto; overflow: visible; }
  .sidebar-header-row { flex-wrap: wrap; }
  .region-table:not(.table-12m) th { white-space: normal; }
}

@media (min-width: 641px) and (max-width: 900px) {
  .brand-section { flex-basis: 100%; }
  .header-top-right { width: 100%; flex-direction: row; justify-content: space-between; align-items: center; }
  .brand-title-line1, .brand-title-line2 { font-size: 17px; line-height: 1.45; }
}

@media (max-width: 640px) {
  .app-header { padding: 12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left)); }
  .brand-section { width: 100%; align-items: flex-start; }
  .brand-logo { height: 42px; flex-shrink: 0; }
  .brand-title-line1, .brand-title-line2 { font-size: clamp(14px, 3.8vw, 18px); line-height: 1.5; }
  .header-top-right, .level-switch { width: 100%; }
  .level-switch { margin-left: 0; border-radius: 14px; }
  .level-btn { white-space: normal; line-height: 1.4; min-height: 44px; }
  .header-nav-rows .group-tabs { display: flex; width: 100%; gap: 4px; padding: 4px; }
  .header-nav-rows .tab-btn { min-height: 44px; flex: 1 1 auto; font-size: 12px; padding: 7px 10px; line-height: 1.4; }
  .header-nav-rows .tab-btn[data-group="ip_sum"],
  .header-nav-rows .tab-btn[data-group="ucep_sum"] { flex-basis: 100%; }
  .sub-header { padding: 12px; }
  .controls-toolbar { display: flex; flex-direction: column; align-items: stretch; gap: 10px; }
  .timeline-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; flex: none; width: 100%; min-width: 0; gap: 8px; }
  .timeline-card .year-display { grid-column: 1; }
  .timeline-card .year-type-badge { grid-column: 2; grid-row: 1; }
  .timeline-card .year-slider { grid-column: 1 / -1; width: 100%; }
  .timeline-card .btn-monthly-entry { grid-column: 1 / -1; width: 100%; margin: 0; justify-content: center; }
  .year-display { white-space: normal; }
  .year-slider { width: auto; min-width: 80px; flex: 1 1 100px; min-height: 36px; }
  .view-mode-toggles { width: 100%; }
  .toggle-btn, .btn-monthly-entry, .btn-combined-regions,
  .btn-back-national, .btn-toggle-12m-table, .modal-chip { min-height: 44px; }
  .view-mode-toggles .toggle-btn { white-space: normal; line-height: 1.4; }
  #map-container { height: clamp(300px, 48svh, 460px); }
  #sidebar-content { padding: 16px 12px max(20px, env(safe-area-inset-bottom)); }
  .region-table:not(.table-12m) { table-layout: fixed; }
  .region-table:not(.table-12m) th:first-child { width: 38%; }
  .region-table:not(.table-12m) th#thColShare { width: 27% !important; }
  .region-table:not(.table-12m) td { overflow-wrap: anywhere; padding: 10px 6px; }
  .region-val-text { white-space: normal; }
  .hosp-name-text { white-space: normal; overflow-wrap: anywhere; }
  .modal-overlay { padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .modal-card { max-width: 100%; max-height: calc(100dvh - 32px); border-radius: 14px; }
  .modal-header { align-items: flex-start; }
  .modal-title { overflow-wrap: anywhere; }
  .modal-filter-bar { flex-wrap: wrap; overflow: visible; }
  .modal-chip { flex: 1 1 auto; white-space: normal; }
  .modal-img-container { max-height: none; padding: 0; }
  .modal-graph-image { max-height: none; width: 100%; }
  .leaflet-tooltip { max-width: min(280px, calc(100vw - 32px)); white-space: normal; }
}

@media (max-height: 540px) and (max-width: 1180px) and (orientation: landscape) {
  #map-container { height: 70svh; min-height: 260px; }
  .modal-overlay { padding: 6px; }
  .modal-card { max-height: calc(100dvh - 12px); }
}
@media (pointer: coarse) {
  .leaflet-control-zoom a { width: 44px; height: 44px; line-height: 44px; }
}

/* Predictable navigation: each category has its own aligned, full-width row. */
.header-nav-rows { gap: 8px; align-items: stretch; }
.header-nav-rows .nav-row { width: 100%; }
.header-nav-rows .group-tabs {
  display: flex; width: 100%; max-width: none; margin: 0;
  padding: 5px; gap: 4px; align-items: stretch; flex-wrap: nowrap;
  overflow: visible; border-radius: 14px;
  background: rgba(255,255,255,.055);
  border: 1px solid rgba(255,255,255,.14);
}
.header-nav-rows .tab-btn,
.header-nav-rows .tab-btn.active {
  display: flex; align-items: center; justify-content: center;
  min-width: 0; min-height: 42px; flex: 1 1 0;
  padding: 8px 10px; border-radius: 9px; font-size: 12px;
  font-weight: 700 !important; line-height: 1.45;
  white-space: normal; overflow-wrap: anywhere; text-align: center;
  transform: none; transition: background-color .15s ease, color .15s ease;
}
.header-nav-rows .tab-btn[data-group="ip_sum"],
.header-nav-rows .tab-btn[data-group="ucep_sum"] {
  flex: 0 0 clamp(250px, 24vw, 350px);
  justify-content: flex-start; text-align: left; padding-inline: 14px;
  background: rgba(255,255,255,.06);
}
.header-nav-rows .tab-btn.active { box-shadow: 0 2px 6px rgba(255,140,11,.2) !important; }
.level-btn, .level-btn.active { font-weight: 700; }
.active-group-desc { display: flex; align-items: center; min-height: 56px; }
.active-group-title { line-height: 1.45; }
#sidebar-content { scrollbar-gutter: stable; }
.summary-card-val, .year-display { font-variant-numeric: tabular-nums; }

@media (min-width: 1181px) {
  .header-nav-rows .group-tabs { min-height: 64px; }
  .header-nav-rows .tab-btn { min-height: 52px; }
}

@media (min-width: 641px) and (max-width: 1180px) {
  .header-nav-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .header-nav-rows .group-tabs {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    height: 100%; align-content: start;
  }
  .header-nav-rows .tab-btn { min-height: 48px; padding: 7px; }
  .header-nav-rows .tab-btn[data-group="ip_sum"],
  .header-nav-rows .tab-btn[data-group="ucep_sum"] {
    grid-column: 1 / -1; min-height: 56px;
    justify-content: center; text-align: center;
  }
}
@media (max-width: 640px) {
  .header-nav-rows { display: grid; grid-template-columns: 1fr; gap: 10px; }
  .header-nav-rows .group-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .header-nav-rows .tab-btn { min-height: 48px; padding: 6px; font-size: 12px; }
  .header-nav-rows .tab-btn[data-group="ip_sum"],
  .header-nav-rows .tab-btn[data-group="ucep_sum"] {
    grid-column: 1 / -1; min-height: 48px;
    justify-content: center; text-align: center;
  }
  .active-group-desc { min-height: 72px; }
}

/* Typography: consistent hierarchy, readable Thai, stable label metrics. */
body { font-size: 16px; line-height: 1.55; }
.brand-title-line1 { font-size: clamp(17px, 1.2vw, 21px); line-height: 1.45; font-weight: 700; letter-spacing: 0; }
.brand-title-line2 { font-size: clamp(15px, 1.05vw, 18px); line-height: 1.5; font-weight: 600; letter-spacing: 0; }
.header-nav-rows .tab-btn,
.header-nav-rows .tab-btn.active { font-size: clamp(13px, .95vw, 15px); line-height: 1.5; letter-spacing: 0; }
.level-btn, .level-switch-label, .btn-home-back { font-size: 13px; line-height: 1.5; }
.active-group-title { font-size: clamp(18px, 1.35vw, 23px); line-height: 1.5; font-weight: 700; letter-spacing: 0; }
.year-display { font-size: clamp(17px, 1.3vw, 22px); line-height: 1.4; }
.year-type-badge, .btn-monthly-entry, .toggle-btn { font-size: 13px; line-height: 1.5; }
.sidebar-main-title { font-size: clamp(20px, 1.5vw, 25px); line-height: 1.5; font-weight: 700; letter-spacing: 0; }
.summary-card-label { font-size: 14px; line-height: 1.6; font-weight: 600; }
.summary-card-val { font-size: clamp(30px, 2.4vw, 44px); line-height: 1.25; font-weight: 700; letter-spacing: -.02em; }
.perf-section-header h3 { font-size: 18px; line-height: 1.5; font-weight: 700; }
.region-table th { font-size: 13px; line-height: 1.55; font-weight: 700; }
.region-table td, .region-val-text { font-size: 15px; line-height: 1.6; }
.hosp-name-text { font-size: 14px; line-height: 1.6; }
.hcode-pill, .inline-error { font-size: 12px; line-height: 1.5; }
.btn-combined-regions, .btn-back-national, .btn-toggle-12m-table { font-size: 13px; line-height: 1.5; }
.modal-title { font-size: clamp(18px, 1.4vw, 24px); line-height: 1.5; font-weight: 700; }
.modal-subtitle { font-size: 13px; line-height: 1.6; }
.modal-chip { font-size: 13px; line-height: 1.5; }
.region-table.table-12m th, .region-table.table-12m td { font-size: 13px; }
@media (max-width: 640px) {
  .brand-title-line1 { font-size: 15px; }
  .brand-title-line2 { font-size: 14px; }
  .header-nav-rows .tab-btn, .header-nav-rows .tab-btn.active { font-size: 13px; }
  .level-btn { font-size: 12px; }
  .active-group-title { font-size: 18px; }
  .sidebar-main-title { font-size: 21px; }
  .summary-card-val { font-size: 32px; }
  .region-table:not(.table-12m) th { font-size: 12px; line-height: 1.6; }
  .region-table:not(.table-12m) td, .region-table:not(.table-12m) .region-val-text { font-size: 14px; line-height: 1.6; }
  .hosp-name-text { font-size: 13px; }
}
