/* ตั้งค่าพื้นฐาน */
body { font-family: 'Sarabun', sans-serif; margin: 0; background-color: #f4f6fa; color: #333; }

/* แถบ Header สีน้ำเงิน */
.topbar { background: linear-gradient(90deg, #1a56b0, #2b6fd4); color: white; padding: 20px 30px; display: flex; justify-content: space-between; align-items: center; }
.btn-staff { background: white; color: #1a56b0; border: none; padding: 8px 16px; border-radius: 5px; cursor: pointer; font-weight: bold; }

/* แถบตัวกรอง */
.filters { display: flex; gap: 15px; padding: 20px 30px; background: white; border-bottom: 1px solid #ddd; }
select { padding: 8px; border-radius: 5px; border: 1px solid #ccc; }

/* แถวการ์ด KPI */
.kpi-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 15px; padding: 20px 30px; }
.kpi-card { background: white; padding: 15px; border-radius: 10px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); text-align: center; }
.kpi-card p { font-size: 0.85em; color: #666; margin-bottom: 5px; }
.kpi-card h3 { font-size: 1.2em; margin: 0; color: #1a56b0; }
#resetFilters {
  padding: 8px 18px;
  border: 1px solid #1a56b0;
  border-radius: 5px;
  background-color: #ffffff;
  color: #1a56b0;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
}

#resetFilters:hover {
  background-color: #1a56b0;
  color: #ffffff;
}

#resetFilters:active {
  transform: scale(0.97);
}
/* ตารางสรุปงบประมาณแยกตามหน่วยงาน */
.summary-section {
  margin: 30px;
  padding: 24px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.summary-section h2 {
  margin: 0 0 20px;
  color: #1a56b0;
  font-size: 22px;
}

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

#summaryTable {
  width: 100%;
  min-width: 1000px;
  border-collapse: collapse;
  font-size: 14px;
}

#summaryTable th,
#summaryTable td {
  padding: 14px 16px;
  border-bottom: 1px solid #e2e8f0;
  text-align: right;
  white-space: nowrap;
}

#summaryTable th {
  background: #1a56b0;
  color: #ffffff;
}

#summaryTable th:first-child,
#summaryTable td:first-child {
  text-align: left;
}

#summaryTable tbody tr:nth-child(even) {
  background: #f4f7fc;
}

#summaryTable tbody tr:hover {
  background: #eaf2ff;
}

#summaryTable td[colspan] {
  text-align: center;
  color: #666666;
}

@media (max-width: 600px) {
  .summary-section {
    margin: 16px;
    padding: 16px;
  }
}/* แท็บเลือกประเภทงบประมาณ */
.budget-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 30px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
}

.budget-tab {
  padding: 10px 20px;
  border: 1px solid #ccd8eb;
  border-radius: 8px;
  background: #ffffff;
  color: #1a56b0;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
}

.budget-tab:hover {
  background: #eaf2ff;
}

.budget-tab.active {
  background: #1a56b0;
  border-color: #1a56b0;
  color: #ffffff;
  font-weight: bold;
}

.budget-tab:focus-visible {
  outline: 3px solid #faa43a;
  outline-offset: 3px;
}.report-context {
  margin: 0 0 16px;
  padding: 12px 16px;
  background: #eef4ff;
  border-left: 4px solid #1a56b0;
  border-radius: 6px;
  color: #334155;
  font-size: 14px;
  line-height: 1.7;
}.print-button {
  margin-bottom: 16px;
  padding: 10px 18px;
  background: #1a56b0;
  color: white;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}

.print-button:hover {
  background: #14438a;
}

/* รูปแบบสำหรับพิมพ์รายงาน */
@media print {
  @page {
    size: A4 landscape;
    margin: 12mm;
  }

  body {
    background: white;
    color: black;
  }

  .topbar,
  .budget-tabs,
  .filters,
  .kpi-row,
  .chart-container,
  .print-button {
    display: none !important;
  }

  .summary-section {
    margin: 0;
    padding: 0;
    box-shadow: none;
    border: none;
  }

  .table-scroll {
    overflow: visible;
  }

  #summaryTable {
    width: 100%;
    min-width: 0;
    font-size: 10pt;
  }

  #summaryTable th,
  #summaryTable td {
    padding: 8px 6px;
    white-space: normal;
    border: 1px solid #cccccc;
  }

  #summaryTable th {
    background: #eeeeee !important;
    color: black !important;
  }

  #summaryTable thead {
    display: table-header-group;
  }

  #summaryTable tr {
    break-inside: avoid;
  }

  .report-context {
    background: white;
    border: 1px solid #cccccc;
    color: black;
  }
}#projectSearch {
  display: block;
  width: 100%;
  max-width: 500px;
  box-sizing: border-box;
  margin-top: 8px;
  padding: 12px;
  border: 1px solid #ccd8eb;
  border-radius: 6px;
  font: inherit;
}

#projectCount {
  color: #555;
  font-size: 14px;
}

#projectTable {
  width: 100%;
  min-width: 1200px;
  border-collapse: collapse;
  font-size: 14px;
}

#projectTable th,
#projectTable td {
  padding: 12px;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
  vertical-align: top;
}

#projectTable th {
  background: #1a56b0;
  color: white;
  white-space: nowrap;
}

#projectTable td:nth-child(3) {
  min-width: 260px;
  overflow-wrap: anywhere;
}

#projectTable td:nth-child(4) {
  min-width: 180px;
}

#projectTable td:nth-child(5),
#projectTable td:nth-child(6),
#projectTable td:nth-child(7) {
  text-align: right;
  white-space: nowrap;
}

#projectTable tbody tr:nth-child(even) {
  background: #f4f7fc;
}

/* ปุ่มพิมพ์เดิมยังพิมพ์เฉพาะรายงานสรุป */
@media print {
  .project-section {
    display: none !important;
  }
}#projectPagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 20px;
}

#projectPagination button {
  padding: 10px 18px;
  border: 1px solid #1a56b0;
  border-radius: 6px;
  background: white;
  color: #1a56b0;
  font: inherit;
  cursor: pointer;
}

#projectPagination button:disabled {
  opacity: 0.4;
  cursor: default;
}.data-note {
  margin: 12px 0 16px;
  padding: 12px 16px;
  border: 1px solid #d6b66b;
  border-radius: 6px;
  background: #fff8e6;
  color: #664d03;
  font-size: 14px;
  line-height: 1.7;
}label[for="projectStatus"] {
  display: block;
  margin-top: 16px;
  margin-bottom: 8px;
}

#projectStatus {
  width: 100%;
  max-width: 500px;
  padding: 10px 12px;
  font: inherit;
  border: 1px solid #ccd8eb;
  border-radius: 6px;
  background: white;
}.clear-project-button {
  display: block;
  margin-top: 16px;
  padding: 10px 18px;
  border: 1px solid #1a56b0;
  border-radius: 6px;
  background: white;
  color: #1a56b0;
  font: inherit;
  cursor: pointer;
}

.clear-project-button:hover {
  background: #eaf2ff;
}@media screen {
  .filters {
    flex-wrap: wrap;
  }

  .filters select {
    max-width: 100%;
  }

  .kpi-card {
    min-width: 0;
  }

  .kpi-card h3 {
    overflow-wrap: anywhere;
  }

  .chart-container {
    max-width: calc(100% - 32px);
  }
}

@media screen and (max-width: 1100px) {
  .kpi-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media screen and (max-width: 600px) {
  .topbar {
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px;
  }

  .filters,
  .budget-tabs {
    padding: 16px;
  }

  .kpi-row {
    grid-template-columns: minmax(0, 1fr);
    padding: 16px;
  }

  #projectStatus {
    box-sizing: border-box;
  }
}@media print {
  .year-section {
    break-before: page;
    page-break-before: always;
  }

  .year-section h2,
  .year-section p {
    break-after: avoid;
    page-break-after: avoid;
  }

  .year-section .table-scroll {
    overflow: visible;
  }

  #yearComparisonTable {
    width: 100%;
    min-width: 0;
  }

  #yearComparisonTable tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
#exportProjectCsv:disabled { opacity: .5; cursor: not-allowed; }
.csv-help { font-size: 14px; line-height: 1.6; }
@media print { #exportProjectCsv, #exportCsvStatus, .csv-help { display: none !important; } }
.year-chart-container {
  position: relative;
  width: 100%;
  height: 360px;
  margin: 24px 0;
}

/* พิมพ์เฉพาะตาราง เพื่อคงรูปแบบรายงานเดิม */
@media print {
  .year-chart-container {
    display: none !important;
  }
}#backToTop {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1000;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: #1e56b3;
  color: white;
  font: inherit;
  cursor: pointer;
  box-shadow: 0 2px 8px #0003;
}

#backToTop:hover {
  background: #16428c;
}

@media print {
  #backToTop {
    display: none !important;
  }
}@media screen and (max-width: 600px) {
  /* ให้ยอดเงินอยู่ครบในบรรทัดเดียว */
  .kpi-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .kpi-card h3 {
    white-space: nowrap;
    overflow-wrap: normal;
    font-size: 22px;
  }

  /* จัดตัวกรองให้กดสะดวก */
  .filters {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .filters select,
  .filters button {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-height: 44px;
  }

  /* ให้ตารางเลื่อนภายในกรอบ */
  .table-scroll {
    max-width: 100%;
    overflow-x: auto;
  }

  /* ย้ายปุ่มไปท้ายหน้า เพื่อไม่บังเนื้อหา */
  #backToTop {
    position: static;
    display: block;
    width: fit-content;
    margin: 16px 16px 24px auto;
  }
}
/* จำกัดกรอบหน้ามือถือ โดยไม่ซ่อนเนื้อหาที่ล้น */
@media screen and (max-width: 600px) {
  *, *::before, *::after {
    box-sizing: border-box;
  }

  html, body {
    width: 100%;
    min-width: 0;
    margin: 0;
  }

  .topbar, .budget-tabs, .filters, .kpi-row {
    width: 100%;
    min-width: 0;
  }

  .topbar h2 {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .filters select, .filters button,
  #projectSearch, #projectStatus {
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }

  .summary-section {
    width: calc(100% - 32px);
    min-width: 0;
    max-width: calc(100% - 32px);
    margin: 16px;
    padding: 16px;
  }

  .summary-section h2, .summary-section p,
  .summary-section label {
    overflow-wrap: anywhere;
  }

  .table-scroll, .year-chart-container {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

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

  #projectPagination {
    flex-wrap: wrap;
    gap: 10px;
  }

  .clear-project-button, .print-button, #backToTop {
    max-width: 100%;
    white-space: normal;
  }

  #backToTop {
    max-width: calc(100% - 32px);
    position: static;
    margin: 16px 16px 24px auto;
  }
}
