:root {
  color-scheme: light;
  --psu-deep-blue: #123e68;
  --psu-blue-sky: #00a3d9;
  --psu-ocean-blue: #3567ad;
  --psu-andaman-blue: #008ba8;
  --psu-river-blue: #55c6dd;
  --psu-sritrang: #b8b6d8;
  --psu-ink: #183047;
  --psu-muted: #5e7183;
  --psu-canvas: #f3f7fb;
  --psu-surface: #fff;
  --psu-border: #d8e2ec;
  --psu-focus: #f3a712;
  --psu-radius-sm: 0.5rem;
  --psu-radius-md: 0.875rem;
  --psu-radius-lg: 1.25rem;
  --psu-shadow-card: 0 0.5rem 1.5rem rgb(18 62 104 / 8%);
  --bs-primary: var(--psu-deep-blue);
  --bs-primary-rgb: 18, 62, 104;
  --bs-link-color: var(--psu-ocean-blue);
  --bs-link-hover-color: var(--psu-deep-blue);
}

@font-face {
  font-family: "PSU Stidti";
  src: url("../images/psu_brand/font/webfont/psu-stidti-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "PSU Stidti";
  src: url("../images/psu_brand/font/webfont/psu-stidti-bold.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

html {
  min-height: 100%;
  background: var(--psu-canvas);
}

body {
  min-height: 100vh;
  color: var(--psu-ink);
  background: var(--psu-canvas);
  font-family: "PSU Stidti", "Kanit", system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.55;
}

*:focus-visible {
  outline: 3px solid var(--psu-focus);
  outline-offset: 3px;
}

.psu-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.psu-pagination__nav .pagination {
  gap: 0.25rem;
  margin-bottom: 0;
}

.psu-pagination__nav .page-link {
  display: inline-flex;
  min-width: 2.25rem;
  min-height: 2.25rem;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--psu-border);
  border-radius: var(--psu-radius-sm) !important;
  background: var(--psu-surface);
  color: var(--psu-deep-blue);
  line-height: 1.25;
  text-decoration: none;
}

.psu-pagination__nav .page-link:hover {
  border-color: var(--psu-deep-blue);
  background: var(--psu-canvas);
  color: var(--psu-deep-blue);
}

.psu-pagination__nav .page-link:focus-visible {
  outline: 3px solid var(--psu-focus);
  outline-offset: 2px;
  box-shadow: none;
}

.psu-pagination__nav .page-item.active .page-link {
  border-color: var(--psu-border);
  background: var(--psu-canvas);
  color: var(--psu-muted);
}

.psu-pagination__nav .page-item.disabled .page-link,
.psu-pagination__nav .page-link:disabled {
  border-color: var(--psu-border);
  background: var(--psu-canvas);
  color: var(--psu-muted);
  opacity: 0.7;
}

.psu-topbar {
  background: var(--psu-deep-blue);
  color: #fff;
}

.psu-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.25rem 0.5rem;
  color: inherit;
  text-decoration: none;
}

.psu-brand:hover {
  color: inherit;
}

.psu-brand__logo {
  width: min(14rem, 48vw);
  height: auto;
  max-height: 3.5rem;
  object-fit: contain;
  object-position: left center;
  filter: brightness(0) invert(1);
}

.psu-brand__logo--custom {
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  background: #fff;
  filter: none;
}

.psu-brand__divider {
  width: 1px;
  height: 2.25rem;
  background: rgb(255 255 255 / 38%);
}

.psu-brand__app {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.25;
}

.psu-dashboard-navbar .psu-brand {
  gap: 0.625rem;
}

.psu-dashboard-navbar .psu-brand__logo {
  width: min(10rem, 35vw);
  max-height: 2.5rem;
}

.psu-dashboard-navbar .psu-brand__divider {
  height: 1.875rem;
}

.psu-dashboard-navbar .psu-brand__app {
  font-size: 0.85rem;
}

.psu-nav-account {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.625rem;
  margin-top: 1rem;
  padding-top: 1rem;
  min-width: 0;
  border-top: 1px solid rgb(255 255 255 / 18%);
}

.psu-nav-account__name {
  color: rgb(255 255 255 / 70%);
  font-size: 0.875rem;
}

.psu-nav-account__toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  max-width: 100%;
  padding: 0.25rem 0;
  border: 0;
  color: inherit;
  background: transparent;
  font: inherit;
}

.psu-nav-account__toggle:hover .psu-nav-account__name,
.psu-nav-account__toggle:focus-visible .psu-nav-account__name {
  color: #fff;
}

.psu-nav-account__toggle .psu-nav-account__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.psu-nav-account__avatar {
  width: 2.5rem;
  height: 2.5rem;
  flex: 0 0 2.5rem;
  border: 2px solid rgb(255 255 255 / 60%);
  border-radius: 50%;
  object-fit: cover;
}

.psu-nav-account__avatar--placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--psu-deep-blue);
  background: #fff;
  font-size: 1.25rem;
}

.site-logo-preview {
  display: block;
  width: min(100%, 22rem);
  height: 7rem;
  padding: 0.75rem;
  border: 1px solid var(--psu-border);
  border-radius: var(--psu-radius-sm);
  background: #fff;
  object-fit: contain;
}

.psu-main {
  width: 100%;
  flex: 1;
}

.psu-card {
  border: 1px solid var(--psu-border);
  border-radius: var(--psu-radius-lg);
  background: var(--psu-surface);
  box-shadow: var(--psu-shadow-card);
  /* padding เริ่มต้นของเนื้อหาในการ์ด (กันเนื้อหาชิดขอบ)
     ชิ้นส่วนที่ต้อง full-bleed (accent bar / content-card header) ใช้ negative margin ชดเชย */
  padding: 1.25rem 1.5rem 1.5rem;
}

.psu-card__accent {
  height: 0.375rem;
  margin: -1.25rem -1.5rem 1.25rem;
  border-radius: var(--psu-radius-lg) var(--psu-radius-lg) 0 0;
  background: linear-gradient(90deg, var(--psu-deep-blue), var(--psu-blue-sky), var(--psu-river-blue));
}

/* หัวการ์ดแบบ psu-content-card__header เมื่ออยู่ใน .psu-card ให้ยืดเต็มขอบการ์ด (border-bottom ครบความกว้าง)
   แล้วเว้นช่องว่างใต้เส้นให้เนื้อหา — ประหยัดกับ padding ของการ์ดด้วย negative margin ตามแพทเทิร์นเทมเพลต */
.psu-card > .psu-content-card__header {
  margin: -1.25rem -1.5rem 1.25rem;
}

.psu-welcome {
  overflow: hidden;
  border-radius: var(--psu-radius-lg);
  background: linear-gradient(115deg, var(--psu-deep-blue), var(--psu-ocean-blue) 65%, var(--psu-andaman-blue));
  box-shadow: var(--psu-shadow-card);
  color: #fff;
}

.psu-welcome .psu-eyebrow {
  color: #b7e9f4;
}

.psu-module-card {
  border: 1px solid var(--psu-border);
  border-radius: var(--psu-radius-md);
  background: var(--psu-surface);
  box-shadow: var(--psu-shadow-card);
  color: var(--psu-ink);
  text-decoration: none;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.psu-module-card:hover {
  transform: translateY(-2px);
  border-color: var(--psu-river-blue);
  box-shadow: 0 0.75rem 1.75rem rgb(18 62 104 / 13%);
  color: var(--psu-ink);
}

.psu-module-card__icon {
  display: grid;
  width: 3rem;
  height: 3rem;
  place-items: center;
  border-radius: 1rem;
  background: #e8f5fa;
  color: var(--psu-deep-blue);
  font-size: 1.5rem;
}

.psu-content-card {
  overflow: hidden;
  border: 1px solid var(--psu-border);
  border-radius: var(--psu-radius-lg);
  background: var(--psu-surface);
  box-shadow: var(--psu-shadow-card);
}

.psu-content-card__header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--psu-border);
}

.psu-content-card__body {
  padding: 1rem;
}

.psu-dashboard-period-filter {
  min-width: 0;
}

.psu-dashboard-period-filter .form-select {
  width: 16rem;
  min-width: 14rem;
  flex: 0 0 16rem;
}

.psu-kpi-card {
  display: flex;
  min-height: 9rem;
  flex-direction: column;
  align-items: flex-start;
  padding: 1.25rem;
  border: 1px solid var(--psu-border);
  border-radius: var(--psu-radius-md);
  background: var(--psu-surface);
  box-shadow: var(--psu-shadow-card);
}

.psu-kpi-card__icon {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  margin-bottom: 0.75rem;
  place-items: center;
  border-radius: 0.875rem;
  font-size: 1.25rem;
}

.psu-kpi-card__icon--blue {
  color: var(--psu-deep-blue);
  background: #e8eef7;
}

.psu-kpi-card__icon--cyan {
  color: #00799f;
  background: #e5f6fb;
}

.psu-kpi-card__icon--teal {
  color: #007c80;
  background: #e4f5f2;
}

.psu-kpi-card__icon--amber {
  color: #8a5b00;
  background: #fff3d6;
}

.psu-kpi-card__icon--green {
  color: #18794e;
  background: #e7f5ec;
}

.psu-kpi-card__value {
  color: var(--psu-deep-blue);
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.psu-chart-wrap {
  position: relative;
  min-height: 18rem;
}

.psu-status-list__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--psu-border);
}

.psu-status-list__item:first-child {
  padding-top: 0.25rem;
}

.psu-status-list__item:last-child {
  padding-bottom: 0.25rem;
  border-bottom: 0;
}

.psu-status-list__item strong {
  color: var(--psu-deep-blue);
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.psu-responsive-table {
  min-width: 48rem;
}

.psu-member-avatar {
  display: block;
  width: 7rem;
  height: 7rem;
  object-fit: cover;
}

.psu-member-avatar[hidden] {
  display: none;
}

.psu-member-avatar-placeholder {
  display: inline-grid;
  width: 7rem;
  height: 7rem;
  place-items: center;
}

.psu-member-avatar-placeholder[hidden] {
  display: none;
}

.psu-profile-field {
  height: 100%;
  padding: 1rem;
  border: 1px solid var(--psu-border);
  border-radius: var(--psu-radius-sm);
  background: var(--psu-canvas);
}

.psu-profile-summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
}

.psu-profile-summary__avatar {
  display: grid;
  width: 7rem;
  height: 7rem;
  overflow: hidden;
  place-items: center;
  border-radius: 50%;
  background: #e9ecef;
}

.psu-profile-summary__avatar img,
.psu-profile-summary__placeholder {
  width: 100%;
  height: 100%;
}

.psu-profile-summary__placeholder {
  display: inline-grid;
  place-items: center;
  color: var(--psu-muted);
  font-size: 2rem;
}

.psu-profile-summary__placeholder[hidden] {
  display: none;
}

.psu-profile-field__label {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--psu-muted);
  font-size: 0.875rem;
}

.psu-profile-field__value {
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.psu-eyebrow {
  color: var(--psu-ocean-blue);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.psu-text-muted {
  color: var(--psu-muted);
}

.btn-primary {
  --bs-btn-bg: var(--psu-deep-blue);
  --bs-btn-border-color: var(--psu-deep-blue);
  --bs-btn-hover-bg: #0c3153;
  --bs-btn-hover-border-color: #0c3153;
  --bs-btn-active-bg: #0c3153;
  --bs-btn-active-border-color: #0c3153;
  --bs-btn-disabled-bg: #69839c;
  --bs-btn-disabled-border-color: #69839c;
}

.form-control,
.form-select {
  min-height: 2.875rem;
  border-color: var(--psu-border);
  border-radius: var(--psu-radius-sm);
}

.psu-footer {
  color: var(--psu-muted);
  font-size: 0.875rem;
}

.psu-error-state__icon {
  display: inline-grid;
  width: 4.5rem;
  height: 4.5rem;
  place-items: center;
  border: 1px solid var(--psu-border);
  border-radius: 50%;
  color: var(--psu-deep-blue);
  background: #e8eef7;
  font-size: 2rem;
}

.psu-fallback-card {
  width: 100%;
  max-width: 52rem;
  margin-inline: auto;
}

.psu-fallback-card h1 {
  text-wrap: balance;
}

.psu-login-sso {
  text-align: left;
}

.psu-login-sso > p {
  text-align: center;
}

.psu-sso-button {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  width: 100%;
  min-height: 4.5rem;
  padding: 0.75rem 1rem;
  color: #123e68;
  text-align: left;
  text-decoration: none;
  background: linear-gradient(110deg, #ffffff 0%, #edf7ff 100%);
  border: 1px solid #b8d2e7;
  border-radius: 0.75rem;
  box-shadow: 0 0.25rem 0.75rem rgb(18 62 104 / 8%);
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, color 160ms ease, transform 160ms ease;
}

.psu-sso-button:hover {
  color: #ffffff;
  background: linear-gradient(110deg, #123e68 0%, #087fac 100%);
  border-color: #087fac;
  box-shadow: 0 0.5rem 1.25rem rgb(18 62 104 / 20%);
  transform: translateY(-1px);
}

.psu-sso-button:focus-visible {
  outline: 3px solid rgb(8 127 172 / 40%);
  outline-offset: 3px;
}

.psu-sso-button__icon {
  display: grid;
  flex: 0 0 2.75rem;
  width: 2.75rem;
  height: 2.75rem;
  color: #ffffff;
  font-size: 1.2rem;
  place-items: center;
  background: linear-gradient(145deg, #123e68, #087fac);
  border-radius: 0.65rem;
}

.psu-sso-button:hover .psu-sso-button__icon {
  color: #123e68;
  background: #ffffff;
}

.psu-sso-button__label {
  display: grid;
  flex: 1 1 auto;
  gap: 0.15rem;
  min-width: 0;
}

.psu-sso-button__label strong {
  font-size: 1rem;
}

.psu-sso-button__label small {
  color: #61778d;
  font-size: 0.82rem;
}

.psu-sso-button:hover .psu-sso-button__label small {
  color: rgb(255 255 255 / 82%);
}

.psu-sso-button__arrow {
  flex: 0 0 auto;
  font-size: 1.1rem;
  transition: transform 160ms ease;
}

.psu-sso-button:hover .psu-sso-button__arrow {
  transform: translateX(3px);
}

.psu-mobile-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

.psu-mobile-action {
  flex: 0 0 auto;
}

.psu-mobile-actions > form {
  margin: 0;
}

.psu-mobile-actions--center {
  justify-content: center;
}

@media (min-width: 768px) {
  .psu-brand__logo {
    width: 16rem;
    max-height: 4rem;
  }

  .psu-dashboard-navbar .psu-brand__logo {
    width: 12rem;
    max-height: 3rem;
  }
}

@media (max-width: 575.98px) {
  .psu-dashboard-period-filter {
    width: 100%;
  }

  .psu-dashboard-period-filter .form-select {
    width: 100%;
    min-width: 0;
    flex: 1 1 auto;
  }
}

@media (max-width: 575.98px) {
  .psu-mobile-actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .psu-mobile-actions.flex-column-reverse {
    flex-direction: column-reverse;
  }

  .psu-mobile-actions > .btn,
  .psu-mobile-action {
    width: 100%;
  }

  .psu-mobile-actions > form,
  .psu-mobile-actions > form > .btn {
    width: 100%;
  }
}

@media (min-width: 1200px) {
  .psu-nav-account {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    margin: 0 0 0 1rem;
    padding: 0;
    border-top: 0;
  }
}

@media (min-width: 768px) {
  .psu-kpi-card {
    padding: 1.5rem;
  }

  .psu-content-card__header {
    padding: 1.5rem;
  }

  .psu-content-card__body {
    padding: 1.5rem;
  }
}

@media (max-width: 767.98px) {
  .psu-responsive-table {
    min-width: 0;
  }

  .psu-responsive-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .psu-responsive-table tbody,
  .psu-responsive-table tbody tr,
  .psu-responsive-table tbody td {
    display: block;
    width: 100%;
  }

  .psu-responsive-table tbody tr {
    margin-bottom: 0.75rem;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--psu-border);
    border-radius: var(--psu-radius-sm);
    background: var(--psu-canvas);
  }

  .psu-responsive-table tbody td {
    display: grid;
    grid-template-columns: minmax(6.5rem, 40%) minmax(0, 1fr);
    align-items: start;
    gap: 0.75rem;
    padding: 0.5rem 0.25rem;
    border: 0;
    text-align: left;
    overflow-wrap: anywhere;
  }

  .psu-responsive-table tbody td::before {
    color: var(--psu-muted);
    content: attr(data-label);
    font-weight: 600;
    text-align: left;
    overflow-wrap: anywhere;
  }

  .psu-responsive-table tbody td[colspan] {
    display: block;
    text-align: center;
  }

  .psu-responsive-table tbody td[colspan]::before {
    content: none;
  }

  .psu-responsive-table .psu-table-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
  }

  .psu-responsive-table tbody td[data-label="การดำเนินการ"] > div,
  .psu-responsive-table tbody td[data-label="แสดงรายการ"] > div {
    min-width: 0;
  }
}

@media (max-width: 575.98px) {
  .psu-chart-wrap {
    min-height: 15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* label ฟอร์มตัวหนาสม่ำเสมอทั้งระบบ (เทียบเท่า fw-semibold) */
.psu-main .form-label {
  font-weight: 600;
}

/* หัวกลุ่ม section ของฟอร์มยาว (จัดกลุ่มอินพุตเป็นช่วง ๆ) */
.psu-form-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  background: rgba(53, 103, 173, 0.08);
  border-left: 4px solid var(--psu-ocean-blue);
  border-radius: 0.25rem;
  padding: 0.5rem 0.875rem;
}
.psu-form-section .bi {
  color: var(--psu-ocean-blue);
}

/* พรีวิวรูปภาพที่แนบก่อนบันทึก (.psu-upload-preview สร้างอัตโนมัติจาก psu-ui.js) */
.psu-upload-preview {
  margin-top: 0.5rem;
}
.psu-upload-preview img {
  display: block;
  max-height: 160px;
  max-width: 100%;
  border-radius: 0.25rem;
  border: 1px solid var(--bs-border-color, #dee2e6);
  background: #f8f9fa;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* แพนย่อยใน section ของฟอร์ม (แยกกลุ่มอินพุตภายใน section เดียว) */
.psu-form-subpanel {
  background: #fff;
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 0.375rem;
  padding: 0.875rem 1rem;
}

/* หัวคอลัมน์ตาราง: ตัวหนา + สีเดียวกันเสมอ (ทั้งระบบ — ครอบตามกฎ ux-design-guide §4) */
.psu-main thead th {
  font-weight: 600;
  color: var(--bs-body-color);
}

/* ฟอร์มค้นหาและปุ่มล้างค่าในหัวการ์ด: ให้อยู่ในแถวเดียวบนจอใหญ่ และปรับเป็นยืดเต็มกว้างบนจอมือถือ */
.psu-content-card__header > .me-lg-auto {
  min-width: 0;
}
.psu-content-card__header form[role="search"] {
  flex-wrap: nowrap;
  flex-shrink: 0;
}
.psu-content-card__header form[role="search"] .input-group {
  width: 14.5rem;
  min-width: 10rem;
  flex: 0 1 auto;
}
.psu-content-card__header form[role="search"] .form-select {
  width: auto;
  min-width: 9rem;
  max-width: 11.5rem;
  flex: 0 0 auto;
}
.psu-content-card__header form[role="search"] .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

@media (max-width: 575.98px) {
  /* ปรับ padding การ์ดให้มีพื้นที่แสดงผลมากขึ้นบนมือถือ */
  .psu-card {
    padding: 1rem;
  }

  .psu-card__accent {
    margin: -1rem -1rem 1rem;
  }

  .psu-card > .psu-content-card__header {
    margin: -1rem -1rem 1rem;
    padding: 1rem;
  }

  .psu-card > .psu-content-card__body {
    padding: 0.25rem 0 0;
  }

  /* แถบชื่อแบรนด์ไม่ให้เบียดปุ่มเมนูบนจอเล็ก */
  .psu-brand {
    gap: 0.5rem;
    max-width: calc(100% - 3.5rem);
  }

  .psu-brand__logo {
    width: min(9.5rem, 38vw);
    max-height: 2.5rem;
  }

  .psu-brand__divider {
    height: 1.75rem;
  }

  .psu-brand__app {
    font-size: 0.8rem;
  }

  /* ฟอร์มค้นหาในหัวการ์ดให้พับบรรทัดได้และยืดเต็มความกว้างบนมือถือ */
  .psu-content-card__header form[role="search"] {
    flex-wrap: wrap !important;
    width: 100%;
  }

  .psu-content-card__header form[role="search"] .input-group {
    width: 100%;
    min-width: 0;
    flex: 1 1 100%;
  }

  .psu-content-card__header form[role="search"] .form-select {
    width: auto;
    min-width: 0;
    max-width: 100%;
    flex: 1 1 auto;
  }

  /* ลดความสูงแผนที่และรูปแยกส่วนบนจอมือถือเพื่อให้สัดส่วนสมดุล */
  #map {
    height: 320px !important;
  }

  .psu-part-img {
    height: 10rem !important;
  }
}
