/* ============================================================
   การเฝ้าระวังโรคติดต่อในสถานการณ์อุทกภัย ปี 2569
   กองระบาดวิทยา กรมควบคุมโรค | แหล่งข้อมูล DDS
   ============================================================ */

:root {
  /* น้ำลึก -> น้ำตื้น */
  --abyss:   #07203A;
  --deep:    #0A2E52;
  --navy:    #12557F;
  --tide:    #1E7BA8;
  --shallow: #00A0C6;
  --foam:    #7FD4E8;

  --paper:   #EEF4F9;
  --card:    #FFFFFF;
  --line:    #D3E1EC;
  --line-soft: #E8F0F6;

  --ink:     #0D2436;
  --ink-mid: #4A6579;
  --ink-dim: #7E96A8;

  --alert:   #C6362F;
  --warn:    #D98324;
  --calm:    #2E7D5B;

  --r-sm: 3px;
  --r-md: 6px;
  --shadow-card: 0 1px 2px rgba(10,46,82,.06), 0 4px 16px rgba(10,46,82,.05);

  --wrap: 1400px;
}

* { box-sizing: border-box; }

html {
  scroll-padding-top: calc(112px + env(safe-area-inset-top, 0px));
}

body {
  margin: 0;
  font-family: 'Kanit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-weight: 300;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-weight: 600; margin: 0; line-height: 1.3; letter-spacing: -.01em; }

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

.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ---------- ส่วนหัว ---------- */

.masthead {
  position: relative;
  background: linear-gradient(168deg, var(--abyss) 0%, var(--deep) 45%, var(--navy) 100%);
  color: #fff;
  overflow: hidden;
  padding-top: env(safe-area-inset-top, 0px);
}

.masthead__waves {
  position: absolute;
  inset: auto 0 -2px 0;
  height: 76px;
  width: 100%;
  display: block;
  opacity: .5;
  pointer-events: none;
}

.masthead__inner {
  position: relative;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 22px 24px 30px;
  display: flex;
  gap: 22px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.crest {
  width: 52px; height: 52px;
  flex: none;
  border: 1.5px solid rgba(127,212,232,.5);
  border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(127,212,232,.09);
}

.masthead__text { flex: 1 1 380px; min-width: 0; }

.masthead h1 {
  font-size: clamp(20px, 2.6vw, 30px);
  font-weight: 600;
  margin-bottom: 4px;
}

.masthead__org {
  font-size: 13.5px;
  font-weight: 300;
  color: var(--foam);
  line-height: 1.5;
}

.masthead__meta {
  flex: none;
  text-align: right;
  font-size: 13px;
  color: rgba(255,255,255,.82);
  border-left: 1px solid rgba(127,212,232,.28);
  padding-left: 20px;
}
.masthead__meta strong { display: block; font-size: 17px; font-weight: 500; color: #fff; }
.masthead__meta span { color: var(--foam); }

/* ---------- แถบนำทาง ---------- */

.nav {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 40;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.nav__inner {
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav__inner::-webkit-scrollbar { display: none; }

.nav button {
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 400;
  color: var(--ink-mid);
  background: none;
  border: none;
  border-bottom: 2.5px solid transparent;
  padding: 13px 16px 11px;
  cursor: pointer;
  white-space: nowrap;
  display: flex; align-items: center; gap: 7px;
  transition: color .15s, border-color .15s;
}
.nav button:hover { color: var(--navy); }
.nav button[aria-selected="true"] {
  color: var(--deep);
  font-weight: 500;
  border-bottom-color: var(--shallow);
}
.nav button:focus-visible { outline: 2px solid var(--shallow); outline-offset: -2px; }
.nav svg { width: 17px; height: 17px; flex: none; }

.nav__spacer { flex: 1; }

.nav__print {
  font-family: inherit; font-size: 13.5px; font-weight: 400;
  color: #fff; background: var(--navy);
  border: none; border-radius: var(--r-md);
  padding: 7px 15px; margin: 8px 0 8px 10px;
  cursor: pointer; white-space: nowrap;
  display: flex; align-items: center; gap: 7px;
}
.nav__print:hover { background: var(--deep); }

/* ---------- โครงหน้า ---------- */

main {
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 24px 24px 80px;
}

.view[hidden] { display: none; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
}

.panel__head {
  display: flex; align-items: baseline; gap: 12px;
  flex-wrap: wrap;
  padding: 15px 20px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.panel__head h2 { font-size: 16.5px; font-weight: 500; }
.panel__head h3 { font-size: 15px; font-weight: 500; }
.panel__head p { margin: 0; font-size: 13px; color: var(--ink-dim); font-weight: 300; }
.panel__head .spacer { flex: 1; }

.panel__body { padding: 18px 20px 20px; }
.panel__body--flush { padding: 0; }

/* ---------- แถบตัวเลขสำคัญ ---------- */

.kpibar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  margin-bottom: 20px;
}
.kpi {
  padding: 15px 18px 16px;
  border-right: 1px solid var(--line-soft);
  border-top: 3px solid transparent;
}
.kpi:last-child { border-right: none; }
.kpi__label { font-size: 12.5px; color: var(--ink-mid); font-weight: 300; margin-bottom: 3px; }
.kpi__value { font-size: 27px; font-weight: 500; letter-spacing: -.02em; line-height: 1.15; }
.kpi__sub { font-size: 12.5px; color: var(--ink-dim); font-weight: 300; margin-top: 2px; }
.kpi--accent { border-top-color: var(--shallow); }
.kpi--alert  { border-top-color: var(--alert); }
.kpi--alert .kpi__value { color: var(--alert); }

/* ---------- ตารางโรค ---------- */

.dtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.dtable th {
  text-align: left; font-weight: 500; font-size: 12.5px;
  color: var(--ink-mid); padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #F8FBFD; white-space: nowrap;
}
.dtable th.r, .dtable td.r { text-align: right; }
.dtable td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.dtable tbody tr:last-child td { border-bottom: none; }
.dtable tbody tr.clickable { cursor: pointer; }
.dtable tbody tr.clickable:hover { background: #F4FAFD; }
.dtable td.num, .dtable th.num { font-variant-numeric: tabular-nums; text-align: right; }

.swatch {
  display: inline-block; width: 9px; height: 9px;
  border-radius: 2px; margin-right: 8px; vertical-align: 1px;
}

.dname { font-weight: 400; }
.dgroup { font-size: 12px; color: var(--ink-dim); font-weight: 300; }

.trend { font-size: 13px; font-weight: 400; font-variant-numeric: tabular-nums; }
.trend--up   { color: var(--alert); }
.trend--down { color: var(--calm); }
.trend--flat { color: var(--ink-dim); }

.phase-tag {
  display: inline-block;
  font-size: 11.5px; font-weight: 300;
  padding: 2px 9px; border-radius: 11px;
  background: #EAF4FA; color: var(--navy);
  border: 1px solid #CFE5F0;
  white-space: nowrap;
}

/* ---------- กราฟ ---------- */

.chart-wrap { position: relative; width: 100%; }
.chart-wrap--hero { height: 340px; }
.chart-wrap--md   { height: 280px; }
.chart-wrap--sm   { height: 215px; }
.chart-wrap--tall { height: 440px; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 20px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 20px; }

/* ---------- ตัวควบคุม ---------- */

.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  background: #fff;
}
.seg button {
  font-family: inherit; font-size: 13px; font-weight: 300;
  color: var(--ink-mid); background: none; border: none;
  padding: 6px 13px; cursor: pointer;
  border-right: 1px solid var(--line-soft);
}
.seg button:last-child { border-right: none; }
.seg button[aria-pressed="true"] { background: var(--navy); color: #fff; font-weight: 400; }
.seg button:focus-visible { outline: 2px solid var(--shallow); outline-offset: -2px; }

select, .pick {
  font-family: inherit; font-size: 13.5px; font-weight: 300;
  color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 6px 11px; cursor: pointer; max-width: 100%;
}
select:focus-visible { outline: 2px solid var(--shallow); outline-offset: 1px; }

/* ---------- เส้นทางพื้นที่ (breadcrumb) ---------- */

.crumbs {
  display: flex; align-items: center; gap: 7px;
  flex-wrap: wrap; font-size: 13.5px; color: var(--ink-mid);
  margin-bottom: 14px;
}
.crumbs button {
  font-family: inherit; font-size: inherit; font-weight: 400;
  color: var(--navy); background: none; border: none;
  padding: 2px 0; cursor: pointer; text-decoration: underline;
  text-underline-offset: 3px; text-decoration-color: #B9D6E6;
}
.crumbs button:hover { text-decoration-color: var(--navy); }
.crumbs svg { width: 13px; height: 13px; color: var(--ink-dim); }
.crumbs .current { font-weight: 500; color: var(--ink); }

/* ---------- แถบเปรียบเทียบในตาราง ---------- */

.bar {
  position: relative;
  height: 20px;
  background: #F1F7FA;
  border-radius: var(--r-sm);
  display: flex; align-items: center;
  overflow: hidden;
}
.bar__fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--tide), var(--shallow));
  border-radius: var(--r-sm);
  min-width: 2px;
}
.bar__txt {
  position: relative; z-index: 1;
  font-size: 11.5px; font-variant-numeric: tabular-nums;
  padding-left: 8px; color: var(--ink-mid);
}
.bar--hi .bar__txt { color: #fff; }

.go {
  color: var(--ink-dim); font-size: 11.5px; font-weight: 300;
  margin-left: 5px; white-space: nowrap;
}
tr.clickable:hover .go { color: var(--navy); }

/* ---------- แถบสถานะข้อมูล ---------- */

.notice {
  display: flex; gap: 11px; align-items: flex-start;
  background: #FFF8EC; border: 1px solid #F0DCB8;
  border-radius: var(--r-md); padding: 12px 16px;
  font-size: 13.5px; font-weight: 300; color: #7A5418;
  margin-bottom: 20px;
}
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; color: var(--warn); }
.notice strong { font-weight: 500; }

.loading {
  padding: 40px 20px; text-align: center;
  color: var(--ink-dim); font-size: 14px; font-weight: 300;
}

/* ---------- ปฏิทินเฝ้าระวัง ---------- */

.timeline { display: flex; flex-direction: column; gap: 2px; }
.tl-row {
  display: grid;
  grid-template-columns: 210px 1fr;
  align-items: center;
  gap: 14px;
  padding: 7px 0;
}
.tl-label { font-size: 13.5px; font-weight: 400; display: flex; align-items: center; }
.tl-track {
  position: relative; height: 26px;
  background: linear-gradient(90deg, #E7F2F8 0%, #F4FAFC 100%);
  border-radius: var(--r-sm);
}
.tl-bar {
  position: absolute; top: 4px; bottom: 4px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; padding-left: 9px;
  font-size: 11.5px; color: #fff; font-weight: 300; white-space: nowrap;
}
.tl-axis {
  display: grid; grid-template-columns: 210px 1fr; gap: 14px;
  font-size: 11.5px; color: var(--ink-dim); margin-top: 6px;
}
.tl-axis__marks { display: flex; justify-content: space-between; }

/* ---------- รายงานหน้าเดียว ---------- */

.report {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow-card);
  padding: 30px 34px 34px; max-width: 900px; margin: 0 auto;
}
.report__head { border-bottom: 2.5px solid var(--navy); padding-bottom: 14px; margin-bottom: 20px; }
.report__head h2 { font-size: 20px; margin-bottom: 3px; }
.report__head p { margin: 0; font-size: 13px; color: var(--ink-mid); font-weight: 300; }

.report h3 {
  font-size: 14.5px; font-weight: 500; color: var(--deep);
  margin: 22px 0 10px; padding-left: 10px;
  border-left: 3px solid var(--shallow);
}
.report ul { margin: 0; padding-left: 20px; font-size: 14px; font-weight: 300; }
.report li { margin-bottom: 5px; }
.report__sign {
  margin-top: 26px; padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--ink-dim); font-weight: 300;
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}

footer {
  border-top: 1px solid var(--line);
  background: #fff;
  padding: 22px 24px calc(28px + env(safe-area-inset-bottom, 0px));
  font-size: 12.5px; color: var(--ink-dim); font-weight: 300;
}
.footer__inner { max-width: var(--wrap); margin: 0 auto; display: flex; gap: 18px; flex-wrap: wrap; justify-content: space-between; }

/* ---------- จอเล็ก ---------- */

@media (max-width: 760px) {
  body { font-size: 14.5px; }
  .masthead__inner { padding: 18px 16px 26px; gap: 16px; }
  .masthead__meta { border-left: none; padding-left: 0; text-align: left; }
  main { padding: 18px 14px 60px; }
  .nav__inner { padding: 0 14px; }
  .panel__head, .panel__body { padding-left: 14px; padding-right: 14px; }
  .tl-row, .tl-axis { grid-template-columns: 128px 1fr; gap: 9px; }
  .tl-label { font-size: 12.5px; }
  .kpi__value { font-size: 23px; }
  .report { padding: 20px 16px 24px; }
  .table-scroll { overflow-x: auto; }
}

.table-scroll { overflow-x: auto; }

/* ---------- พิมพ์ ---------- */

@media print {
  body { background: #fff; font-size: 11.5pt; }
  .nav, .masthead__waves, footer, .no-print { display: none !important; }
  .masthead { background: none; color: var(--ink); border-bottom: 2.5px solid var(--navy); }
  .masthead__org, .masthead__meta span { color: var(--ink-mid); }
  .masthead__meta { border-left: none; }
  .masthead__meta strong { color: var(--ink); }
  .crest { border-color: var(--navy); background: none; }
  .report { border: none; box-shadow: none; padding: 0; max-width: none; }
  .panel { break-inside: avoid; box-shadow: none; }
  main { padding: 0; }
  @page { margin: 14mm; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* หมายเหตุใต้กราฟ: ช่วงที่รายงานยังเข้าไม่ครบ */
.chart-note {
  margin: 12px 0 0; padding: 8px 12px;
  font-size: 13px; color: #7A4B00; font-weight: 300; line-height: 1.55;
  background: #FFF8EC; border: 1px solid #F0DCB8; border-radius: var(--r-md);
}
.chart-note::before {
  content: ''; display: inline-block; width: 16px; height: 11px; margin-right: 8px; vertical-align: -1px;
  border-left: 1.5px dashed #B26A00;
  background: repeating-linear-gradient(45deg, rgba(178,106,0,.35) 0 1px, #fff 1px 5px);
}
.kpi__warn { color: #B26A00; font-size: 11.5px; }

/* ---------- อัตราส่วนเพศ ---------- */
.sexbox { display: flex; align-items: center; gap: 12px; margin-top: 2px; }
.sexbox__pie { position: relative; width: 58px; height: 58px; flex: none; }
.sexrow { display: flex; gap: 12px; margin-top: 3px; flex-wrap: wrap; }
.sex { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.sex svg { width: 17px; height: 17px; }
.sex b { font-weight: 500; }
.sex--m { color: #1E7BA8; }
.sex--f { color: #C97F14; }

/* ---------- แผนที่ + ตารางรายพื้นที่ ---------- */
.area-grid {
  display: grid; grid-template-columns: minmax(300px, 400px) 1fr;
  align-items: start;
}
.area-grid--nomap { grid-template-columns: 1fr; }
.area-grid--nomap .area-map { display: none; }
.area-map {
  padding: 16px 16px 18px;
  border-right: 1px solid var(--line-soft);
  position: sticky; top: 56px;
}
.map svg { width: 100%; height: auto; max-height: 640px; display: block; transition: none; }
.map path {
  stroke: #fff; stroke-width: .8; vector-effect: non-scaling-stroke;
  cursor: pointer; transition: fill .2s;
}
.map path:hover { stroke: var(--deep); stroke-width: 1.6; }
.map path.is-off { opacity: .85; }
.map path.is-sel { stroke: var(--deep); stroke-width: 2.2; }
.map-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11.5px; color: var(--ink-mid); margin-top: 10px; }
.map-legend__title { width: 100%; font-weight: 400; color: var(--ink); }
.map-legend span { display: inline-flex; align-items: center; gap: 5px; }
.map-legend i { width: 13px; height: 11px; border-radius: 2px; display: inline-block; border: 1px solid rgba(10,46,82,.1); }
.map-tip {
  position: absolute; z-index: 5; pointer-events: none;
  background: rgba(10,46,82,.94); color: #fff; border-radius: 5px;
  padding: 7px 10px; font-size: 12.5px; line-height: 1.45; white-space: nowrap;
  display: flex; flex-direction: column;
}
.map-tip strong { font-weight: 500; }
.map-tip span { color: #CFE5F0; font-weight: 300; }

/* ---------- ตารางรายสัปดาห์ ---------- */
.table-scroll--tall { max-height: 640px; overflow: auto; }
.table-scroll--tall thead th { position: sticky; top: 0; z-index: 2; }
.wtable th, .wtable td { padding: 8px 10px; }
.wtable .wk-col { min-width: 92px; vertical-align: bottom; line-height: 1.35; }
.wk-date { font-size: 11px; color: var(--ink-dim); font-weight: 300; }
.wk-flag {
  display: inline-block; margin-top: 3px; font-size: 10.5px; font-weight: 400;
  color: #7A4B00; background: #FFF4E0; border: 1px solid #E8B36A; border-radius: 8px; padding: 0 6px;
}
.wk-cell { background: rgba(30,123,168,var(--heat)); }
.wk-cell.wk-inc, .wtable th.wk-inc {
  background-image: repeating-linear-gradient(45deg, rgba(178,106,0,.16) 0 1px, transparent 1px 6px);
}
.wtable th.wk-cur, .wtable th.wk-prev { color: var(--deep); }
.wtable th.wk-cur { box-shadow: inset 0 -3px 0 var(--shallow); }
.wtable th.wk-prev { box-shadow: inset 0 -3px 0 #A9CDE6; }
.wk-cell.wk-cur { font-weight: 500; outline: 1.5px solid var(--shallow); outline-offset: -1.5px; }
.wk-chg { white-space: nowrap; border-left: 1px solid var(--line-soft); }
.wk-name { white-space: nowrap; font-weight: 400; }
.wk-total td { background-color: #F8FBFD; border-top: 1.5px solid var(--line); }
.wk-total .wk-cell { font-weight: 500; }
.wk-note { margin: 0 16px 16px; }

@media (max-width: 900px) {
  .area-grid { grid-template-columns: 1fr; }
  .area-map { position: relative; top: 0; border-right: none; border-bottom: 1px solid var(--line-soft); }
  .map svg { max-height: 460px; }
}

/* ให้แอตทริบิวต์ hidden ชนะ display ของคลาสอื่นเสมอ */
[hidden] { display: none !important; }
