:root {
  --r-bg: #fafbfe;
  --r-card: #ffffff;
  --r-text: #1f2937;
  --r-muted: #7b8496;
  --r-line: #edf0f5;
  --r-primary: #5b5ce2;
  --r-primary-soft: #f0f0ff;
  --r-primary-strong: #4546c8;
  --r-soft-blue: #f4f7ff;
  --r-soft-green: #eefcf5;
  --r-soft-amber: #fff8e8;
  --r-bottom-nav-item-h: 50px;
  --r-bottom-nav-pad-y: 6px;
  --r-bottom-nav-core-h: calc(var(--r-bottom-nav-item-h) + (var(--r-bottom-nav-pad-y) * 2));
  --r-bottom-nav-offset: calc(var(--r-bottom-nav-core-h) + env(safe-area-inset-bottom, 0px));
  --app-surface: #ffffff;
  --app-border: var(--r-line);
  --app-muted: var(--r-muted);
  --app-ink: var(--r-text);
  --app-bg: var(--r-bg);
}

body {
  background: var(--r-bg);
  font-family: "Noto Sans Thai", "Public Sans", system-ui, sans-serif;
  color: var(--r-text);
}

a {
  color: var(--r-primary);
}

a:hover {
  color: var(--r-primary-strong);
}

.layout-wrapper,
.layout-page,
.content-wrapper {
  background: var(--r-bg);
}

.container-xxl.container-p-y {
  padding-top: 1.75rem;
}

.layout-menu {
  background: #fff !important;
  border-right: 1px solid var(--r-line);
  box-shadow: 10px 0 30px rgba(31, 41, 55, .04);
}

.app-brand {
  min-height: 78px;
  padding-right: 1.5rem;
  padding-left: 1.5rem;
}

.app-brand-text {
  color: #202437;
  letter-spacing: -.02em;
}

.r-brand-mark {
  display: inline-flex;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 15px;
  color: #fff;
  background: linear-gradient(135deg, #6670ff 0%, #4b4bd7 100%);
  box-shadow: 0 12px 24px rgba(91, 92, 226, .24);
}

.r-brand-mark--img {
  background: transparent;
  padding: 0;
  overflow: hidden;
}

.r-brand-mark--img img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: inherit;
}

.menu .app-brand.demo {
  width: auto;
}

.menu-header {
  color: #9aa3b5 !important;
  font-weight: 700;
  letter-spacing: .05em;
}

.menu-vertical .menu-item {
  margin: .15rem 1rem;
}

.menu-vertical .menu-item .menu-link {
  border-radius: 12px;
  color: #6b7280;
  font-weight: 500;
}

.menu-vertical .menu-item .menu-icon {
  color: #8b95a7;
}

.menu-vertical .menu-item.active > .menu-link,
.menu-vertical .menu-item.open > .menu-link {
  background: var(--r-primary-soft) !important;
  color: var(--r-primary) !important;
  box-shadow: none !important;
}

.menu-vertical .menu-item.active > .menu-link .menu-icon,
.menu-vertical .menu-item.open > .menu-link .menu-icon {
  color: var(--r-primary) !important;
}

.menu-vertical .menu-item:not(.active) > .menu-link:hover {
  background: #f6f7fb;
  color: #374151;
}

.btn-primary {
  background-color: var(--r-primary);
  border-color: var(--r-primary);
  box-shadow: 0 10px 18px rgba(91, 92, 226, .18);
}

.btn-primary:hover,
.btn-primary:focus {
  background-color: var(--r-primary-strong) !important;
  border-color: var(--r-primary-strong) !important;
}

.btn-outline-secondary {
  color: #6b7280;
  border-color: #dde2eb;
  background: #fff;
}

.form-control,
.form-select {
  border-color: #e7eaf1;
  border-radius: 12px;
  color: #263143;
}

.form-control:focus,
.form-select:focus {
  border-color: #b9bcff;
  box-shadow: 0 0 0 .2rem rgba(91, 92, 226, .12);
}

.select2-container--default .select2-selection--single {
  min-height: 40px;
  border: 1px solid #e7eaf1;
  border-radius: 12px;
  background-color: #fff;
  display: flex;
  align-items: center;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
  border-color: #b9bcff;
  box-shadow: 0 0 0 .2rem rgba(91, 92, 226, .12);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
  color: #263143;
  line-height: 38px;
  padding-left: .95rem;
  padding-right: 2.25rem;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
  color: #a1a8b5;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 38px;
  right: .65rem;
}

.select2-container--default .select2-selection--single .select2-selection__clear {
  height: 38px;
  margin-right: 1.8rem;
  color: #9aa3b5;
}

.select2-container--default.select2-container--disabled .select2-selection--single {
  background-color: #f6f7fb;
  color: #9aa3b5;
}

.select2-dropdown {
  border: 1px solid var(--r-line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 44px rgba(31, 41, 55, .12);
}

.select2-container--default .select2-search--dropdown {
  padding: .75rem;
  background: #fff;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
  border: 1px solid #e7eaf1;
  border-radius: 12px;
  padding: .55rem .75rem;
  outline: 0;
}

.select2-container--default .select2-search--dropdown .select2-search__field:focus {
  border-color: #b9bcff;
  box-shadow: 0 0 0 .2rem rgba(91, 92, 226, .1);
}

.select2-results__options {
  padding: .35rem;
}

.select2-container--default .select2-results__option {
  border-radius: 10px;
  margin: .1rem 0;
  padding: .55rem .75rem;
  color: #3f4757;
}

.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
  background-color: var(--r-primary-soft);
  color: var(--r-primary);
}

.select2-container--default .select2-results__option--selected {
  background-color: #f6f7fb;
  color: #202437;
  font-weight: 600;
}

.r-page-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.r-page-title {
  font-size: clamp(1.5rem, 2.2vw, 2.05rem);
  font-weight: 800;
  letter-spacing: -.035em;
  margin: 0;
  color: #202437;
}

.r-page-subtitle,
.r-muted {
  color: var(--r-muted);
}

.r-card {
  background: var(--r-card);
  border: 1px solid var(--r-line);
  border-radius: 20px;
  box-shadow: 0 18px 44px rgba(31, 41, 55, .055);
}

.r-stat {
  padding: 1.25rem;
  min-height: 132px;
}

.r-stat__label {
  color: var(--r-muted);
  font-size: .92rem;
}

.r-stat__value {
  font-size: 2.1rem;
  font-weight: 800;
  line-height: 1.1;
  color: #202437;
}

.r-case-card {
  padding: 1rem;
  transition: transform .12s ease, box-shadow .12s ease;
}

.r-case-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 42px rgba(31, 41, 55, .08);
}

.r-case-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  color: var(--r-muted);
  font-size: .9rem;
}

.r-timeline {
  position: relative;
  padding-left: 1rem;
}

.r-timeline::before {
  content: "";
  position: absolute;
  left: 4px;
  top: .25rem;
  bottom: .25rem;
  width: 2px;
  background: var(--r-line);
}

.r-timeline-item {
  position: relative;
  padding: 0 0 1rem 1rem;
}

.r-timeline-item::before {
  content: "";
  position: absolute;
  left: -1px;
  top: .35rem;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--r-primary);
}

.card,
.modal-content,
.dropdown-menu {
  border-color: var(--r-line);
  border-radius: 18px;
  box-shadow: 0 18px 44px rgba(31, 41, 55, .055);
}

.alert {
  border-radius: 14px;
}

.bg-label-primary,
.badge.bg-label-primary {
  background-color: var(--r-primary-soft) !important;
  color: var(--r-primary) !important;
}

.r-print-page {
  page-break-after: always;
}

@media (max-width: 767px) {
  .r-page-head {
    display: block;
  }
  .r-page-head .btn {
    width: 100%;
    margin-top: .75rem;
  }
}

/* PWA install + notification prompts */
.r-pwa-install-prompt,
.r-pwa-push-prompt {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 1090;
  padding: 0 12px;
  pointer-events: none;
}

.r-pwa-install-card {
  pointer-events: auto;
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid rgba(91, 92, 226, 0.15);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.r-pwa-install-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(91, 92, 226, 0.12);
  color: var(--r-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.r-pwa-install-copy {
  flex: 1;
  min-width: 0;
}

.r-pwa-install-title {
  font-weight: 600;
  font-size: 0.92rem;
  color: #1f2937;
}

.r-pwa-install-desc {
  font-size: 0.78rem;
  color: #6b7280;
  margin-top: 2px;
}

.r-pwa-noti-swal {
  padding: 0 !important;
  overflow: hidden;
}

.r-pwa-noti-modal {
  text-align: left;
}

.r-pwa-noti-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid #eef0f3;
}

.r-pwa-noti-title {
  font-weight: 600;
  font-size: 1rem;
  color: #111827;
}

.r-pwa-noti-close {
  border: 0;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: #9ca3af;
  padding: 0 4px;
}

.r-pwa-noti-body {
  padding: 14px 16px 16px;
}

.r-pwa-noti-meta {
  font-size: 0.78rem;
  color: #6b7280;
  margin-bottom: 8px;
}

.r-pwa-noti-message {
  font-size: 0.92rem;
  color: #374151;
  line-height: 1.5;
  white-space: pre-wrap;
}

.r-pwa-noti-actions {
  margin-top: 14px;
}

@media (display-mode: standalone) {
  .r-pwa-install-prompt {
    display: none !important;
  }
}

.refer-date-sticky-header {
  position: sticky;
  top: 4.5rem;
  z-index: 1015;
  width: fit-content;
  max-width: calc(100% - 1rem);
  padding: .35rem .65rem .35rem .5rem !important;
  margin-bottom: .25rem;
  border: 1px solid rgba(91, 92, 226, .14);
  border-radius: 999px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 .35rem 1rem rgba(67, 89, 113, .08);
  backdrop-filter: blur(6px);
}

.refer-table-card-list {
  margin-bottom: 0;
}

.refer-table-card-list li {
  line-height: 1.45;
}

.refer-table-badge-dept {
  background: rgba(91, 92, 226, .12) !important;
  color: var(--r-primary) !important;
}

.refer-table-card-actions .btn {
  flex: 1 1 auto;
}

.refer-table-card.is-refer-highlighted {
  border-color: var(--r-primary) !important;
  box-shadow: 0 0 0 .2rem rgba(91, 92, 226, .16), 0 .5rem 1.25rem rgba(67, 89, 113, .12) !important;
}

/* ---------- Mobile bottom nav (เหมือน /o/) ---------- */
@media (max-width: 1199.98px) {
  html {
    overflow-x: hidden;
    max-width: 100%;
  }

  body {
    overflow-x: hidden;
    max-width: 100%;
  }

  .layout-wrapper,
  .layout-container,
  .layout-page,
  .content-wrapper,
  .container-xxl,
  .container-xxl.container-p-y {
    overflow-x: clip;
    max-width: 100%;
  }

  .layout-page,
  .content-wrapper {
    padding-bottom: calc(var(--r-bottom-nav-offset) + 6px);
  }

  #layout-menu,
  .layout-overlay,
  .content-backdrop,
  .drag-target {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
    z-index: -1 !important;
    opacity: 0 !important;
  }

  .layout-wrapper.layout-content-navbar .layout-page {
    padding-left: 0 !important;
  }

  .bottom-nav a,
  .bottom-nav .bottom-nav-more-trigger {
    touch-action: manipulation;
  }

  html:has(.bottom-nav),
  body:has(.bottom-nav) {
    overflow-x: hidden;
    max-width: 100%;
  }
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1041;
  display: flex;
  justify-content: flex-start;
  align-items: stretch;
  box-sizing: border-box;
  overflow: hidden;
  background: var(--app-surface);
  border-top: 1px solid var(--app-border);
  padding: var(--r-bottom-nav-pad-y) 4px calc(var(--r-bottom-nav-pad-y) + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -4px 12px rgba(15, 23, 42, 0.06);
}

.bottom-nav a,
.bottom-nav .bottom-nav-more-trigger {
  position: relative;
  flex: 1 1 0;
  align-self: stretch;
  min-width: 0;
  min-height: var(--r-bottom-nav-item-h);
  height: var(--r-bottom-nav-item-h);
  max-height: var(--r-bottom-nav-item-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--app-muted);
  font-size: .72rem;
  font-weight: 500;
  line-height: 1.15;
  padding: 4px 2px;
  border-radius: 12px;
  border: 0 !important;
  outline: none;
  background: transparent;
  box-shadow: none !important;
  transition: color .2s ease, background-color .2s ease;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(91, 92, 226, 0.12);
}

.bottom-nav a > *,
.bottom-nav .bottom-nav-more-trigger > * {
  pointer-events: none;
}

.bottom-nav .bottom-nav-icon-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
}

.bottom-nav .bottom-nav-label {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.15;
}

.bottom-nav a i,
.bottom-nav .bottom-nav-more-trigger i {
  font-size: 1.35rem;
  line-height: 1;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s ease, background-color .2s ease;
}

.bottom-nav a.active,
.bottom-nav .bottom-nav-more-trigger.active {
  color: var(--r-primary) !important;
  font-weight: 600;
  background: rgba(91, 92, 226, 0.08);
}

.bottom-nav a.active i,
.bottom-nav .bottom-nav-more-trigger.active i {
  color: var(--r-primary) !important;
  background: rgba(91, 92, 226, 0.14);
}

.bottom-nav a.is-loading i {
  opacity: 0.55;
}

.r-mobile-more-offcanvas.offcanvas-bottom {
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  max-height: min(88vh, 720px);
}

.r-mobile-more-offcanvas .offcanvas-body {
  overflow-y: auto;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

.mobile-more-grid .col-6 {
  min-width: 0;
}

.mobile-more-card {
  display: block;
  border-radius: 12px;
  border: 1px solid var(--app-border);
  padding: .75rem;
  min-height: 108px;
  background: var(--app-surface);
  color: inherit;
  transition: transform .15s ease, box-shadow .15s ease;
}

.mobile-more-card:active,
.mobile-more-card:hover,
.mobile-more-card:focus {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
  color: inherit;
}

.mobile-more-card-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: .45rem;
  font-size: 1.1rem;
}

.mobile-more-card-title {
  display: block;
  font-size: .86rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--app-ink);
}

.mobile-more-card-desc {
  display: block;
  font-size: .72rem;
  line-height: 1.25;
  color: var(--app-muted);
  margin-top: .2rem;
}

.mobile-more-card.tone-blue { background: #eff6ff; border-color: #bfdbfe; }
.mobile-more-card.tone-blue .mobile-more-card-icon { background: #dbeafe; color: #1d4ed8; }
.mobile-more-card.tone-emerald { background: #ecfdf5; border-color: #a7f3d0; }
.mobile-more-card.tone-emerald .mobile-more-card-icon { background: #d1fae5; color: #047857; }
.mobile-more-card.tone-rose { background: #fff1f2; border-color: #fecdd3; }
.mobile-more-card.tone-rose .mobile-more-card-icon { background: #ffe4e6; color: #be123c; }
.mobile-more-card.tone-indigo { background: #eef2ff; border-color: #c7d2fe; }
.mobile-more-card.tone-indigo .mobile-more-card-icon { background: #e0e7ff; color: #4338ca; }
.mobile-more-card.tone-violet { background: #f5f3ff; border-color: #ddd6fe; }
.mobile-more-card.tone-violet .mobile-more-card-icon { background: #ede9fe; color: #6d28d9; }
.mobile-more-card.tone-sky { background: #f0f9ff; border-color: #bae6fd; }
.mobile-more-card.tone-sky .mobile-more-card-icon { background: #e0f2fe; color: #0369a1; }
.mobile-more-card.tone-slate { background: #f8fafc; border-color: #cbd5e1; }
.mobile-more-card.tone-slate .mobile-more-card-icon { background: #e2e8f0; color: #334155; }
.mobile-more-card.tone-coral { background: #fff7ed; border-color: #fed7aa; }
.mobile-more-card.tone-coral .mobile-more-card-icon { background: #ffedd5; color: #c2410c; }
.mobile-more-card.tone-amber { background: #fffbeb; border-color: #fde68a; }
.mobile-more-card.tone-amber .mobile-more-card-icon { background: #fef3c7; color: #a16207; }

.content-footer.footer {
  border-top: 1px solid var(--app-border);
  background: var(--app-surface);
}

.content-footer a.text-muted {
  color: var(--app-muted) !important;
}

.content-footer a.text-muted:hover {
  color: var(--r-primary) !important;
}

@media (max-width: 1199.98px) {
  .r-pwa-install-prompt,
  .r-pwa-push-prompt {
    bottom: calc(var(--r-bottom-nav-offset) + 12px);
  }

  .refer-date-sticky-header {
    top: 0.75rem;
  }
}
