* {
  box-sizing: border-box;
}

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --accent: #3b82f6;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e2e8f0;
  --radius: 18px;
}

body {
  margin: 0;
  font-family: "Sarabun", sans-serif;
  color: var(--text);
  background: var(--bg);
}

img {
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

.container {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
}

.brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.site-nav {
  display: flex;
  gap: 20px;
  align-items: center;
}

.site-nav a {
  padding: 10px 0;
  color: var(--muted);
  transition: color 0.2s ease;
}

.site-nav a:hover {
  color: var(--primary);
}

.mobile-menu-toggle {
  display: none;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 10px;
}

.mobile-menu-toggle span {
  display: block;
  width: 26px;
  height: 3px;
  border-radius: 999px;
  background: var(--text);
  margin: 5px 0;
}

.hero-panel {
  background: linear-gradient(
    135deg,
    rgba(37, 99, 235, 0.12),
    rgba(59, 130, 246, 0.08)
  );
  padding: 56px 0;
}

.hero-copy {
  max-width: 680px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--primary);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.hero-copy h1 {
  margin: 0 0 16px;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.05;
}

.hero-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.8;
}

.content-section {
  padding: 48px 0;
}

.section-heading {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.65rem;
}

.section-heading p {
  margin: 0;
  color: var(--muted);
  max-width: 560px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.06);
}

.card h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--muted);
}

.stat {
  margin: 0;
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--text);
}

.subtext {
  margin: 8px 0 0;
  color: var(--muted);
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.06);
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
}

.data-table th,
.data-table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  color: var(--primary-dark);
  font-weight: 600;
  background: #f8fafc;
}

.site-footer {
  padding: 24px 0 36px;
}

.site-footer p {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 860px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }
  .site-nav {
    position: absolute;
    right: 16px;
    top: 76px;
    flex-direction: column;
    gap: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 12px 16px;
    display: none;
    width: calc(100% - 32px);
    max-width: 320px;
  }
  .site-nav.open {
    display: flex;
  }
  .site-nav a {
    padding: 10px 0;
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
  }
  .site-nav a:last-child {
    border-bottom: none;
  }
  .mobile-menu-toggle {
    display: inline-flex;
  }
}

.navbar-brand .app-brand-logo svg {
  width: 25px;
  height: auto;
}

.navbar-brand .app-brand-text {
  margin-left: 0.75rem;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.navbar-nav .nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.navbar-nav .nav-link i {
  font-size: 1.05rem;
}

.navbar-nav .nav-link.active {
  font-weight: 600;
}

.navbar-nav .badge {
  margin-left: 0.5rem;
}

.layout-page {
  transition: margin-top 0.3s ease;
}

/* Budget List Popup Styles */
.budget-list-popup .table-responsive {
  max-height: 50vh;
  overflow-y: auto;
}

.budget-list-popup .sticky-top {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: #f8f9fa !important;
}

.budget-list-popup .sticky-bottom {
  position: sticky;
  bottom: 0;
  z-index: 10;
  background-color: #e9ecef !important;
}

.budget-list-popup tbody tr:hover {
  background-color: #f0f0f0;
  cursor: pointer;
}

.budget-details-popup .table-responsive {
  max-height: 50vh;
  overflow-y: auto;
}


/* Pie Chart Year Dropdown */
#pieYearDropdown {
  font-size: 0.875rem;
  font-weight: 500;
}

#pieYearDropdown .bx {
  font-size: 1rem;
}

#pieYearDropdown:hover {
  background-color: #696cff;
  color: #fff;
  border-color: #696cff;
}

/* Sneat theme override ค่า color: #696cff ให้กับ .active ด้วย !important
   จึงต้องบังคับ color: #fff !important ด้วยเช่นกัน */
.dropdown-menu .dropdown-item.active,
.dropdown-menu .dropdown-item:active {
  background-color: #696cff !important;
  color: #fff !important;
  font-weight: 600;
}

.dropdown-menu .dropdown-item.active:hover,
.dropdown-menu .dropdown-item:active:hover {
  background-color: #5f61e6 !important;
  color: #fff !important;
}

.dropdown-menu .dropdown-item:hover:not(.active):not(:active) {
  background-color: rgba(105, 108, 255, 0.08);
  color: inherit;
}

/* Budget List Popup Dropdown Styles */
.budget-list-popup .btn-group {
  display: block;
}

.budget-list-popup .dropdown-toggle {
  width: 100%;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.budget-list-popup .dropdown-toggle::after {
  margin-left: auto;
}

.budget-list-popup .dropdown-menu {
  max-height: 300px;
  overflow-y: auto;
  width: 100%;
}

.budget-list-popup .dropdown-item {
  padding: 0.5rem 1rem;
  cursor: pointer;
}

.budget-list-popup .dropdown-item:hover {
  background-color: #f0f0f0;
}

/* Table Header Enhancement for Popups */
.budget-list-popup thead th,
.budget-details-popup thead th {
  font-weight: 700 !important;
  font-size: 0.95rem !important;
  color: #2c3e50 !important;
  background-color: #e9ecef !important;
  padding: 0.75rem 0.5rem !important;
  border-bottom: 2px solid #696cff !important;
  white-space: nowrap;
}

.budget-list-popup tbody td,
.budget-details-popup tbody td {
  padding: 0.65rem 0.5rem;
  vertical-align: middle;
}

.budget-list-popup tfoot td,
.budget-details-popup tfoot td {
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.75rem 0.5rem;
}

/* Pie Chart Legend - Single Line */
#pieChart + .chartjs-legend,
canvas#pieChart {
  max-width: 100%;
}

/* Force legend items to be inline */
.chartjs-legend ul,
.chartjs-legend ul li {
  display: inline-block !important;
  margin: 0 6px !important;
}
