/* แถบข้างสีขาว + ไฮไลต์ม่วงอ่อน */
:root {
  --admin-sidebar-bg: #ffffff;
  --admin-sidebar-text: #334155;
  --admin-sidebar-muted: #64748b;
  --admin-sidebar-hover: #f5f3ff;
  --admin-sidebar-active: #ede9fe;
  --admin-sidebar-active-border: #a78bfa;
  --admin-sidebar-border: #e2e8f0;
  --admin-topbar-h: 60px;
}

.admin-body {
  font-family: 'Sarabun', system-ui, sans-serif;
  background: #f1f5f9;
  min-height: 100vh;
}

.admin-wrapper {
  display: flex;
  min-height: 100vh;
}

.admin-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--admin-sidebar-bg);
  color: var(--admin-sidebar-text);
  border-right: 1px solid var(--admin-sidebar-border);
  box-shadow: 4px 0 24px rgba(15, 23, 42, 0.04);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  align-self: flex-start;
  min-height: 100vh;
  z-index: 1030;
}

.admin-brand {
  height: var(--admin-topbar-h);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0 1.1rem;
  border-bottom: 1px solid var(--admin-sidebar-border);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  color: #0f172a;
}
.admin-brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: #0f172a;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}
.admin-brand-link,
.admin-brand-link:visited,
.admin-brand-link:hover,
.admin-brand-link:active,
.admin-brand-link:focus,
.admin-brand-link:focus-visible {
  text-decoration: none !important;
  color: #0f172a !important;
}

.admin-brand .logo-dot {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1rem;
}

.admin-brand-link > span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  max-width: 100%;
}

.admin-nav {
  padding: 0.75rem 0;
  flex: 1;
  overflow-y: auto;
}

.admin-nav .nav-section {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--admin-sidebar-muted);
}

/* กลุ่มย่อ-ขยายหัวข้อเมนู */
.admin-nav .nav-group {
  padding: 0 0.35rem;
  margin-bottom: 0.15rem;
}

.admin-nav .nav-group-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem 0.5rem 0.75rem;
  margin: 0.15rem 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--admin-sidebar-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.admin-nav .nav-group-toggle:hover {
  background: var(--admin-sidebar-hover);
  color: #5b21b6;
}

.admin-nav .nav-group-toggle:focus-visible {
  outline: 2px solid #c4b5fd;
  outline-offset: 2px;
}

.admin-nav .nav-group-toggle .nav-chevron {
  flex-shrink: 0;
  font-size: 0.85rem;
  opacity: 0.65;
  transition: transform 0.2s ease;
}

.admin-nav .nav-group-toggle:not(.collapsed) .nav-chevron {
  transform: rotate(90deg);
}

.admin-nav .nav-group-inner {
  padding-bottom: 0.35rem;
}

.admin-nav .nav-link {
  color: var(--admin-sidebar-text);
  padding: 0.55rem 1rem 0.55rem 1.15rem;
  margin: 0.1rem 0.5rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.92rem;
  border-left: 3px solid transparent;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.admin-nav .nav-link:hover {
  background: var(--admin-sidebar-hover);
  color: #4c1d95;
}

.admin-nav .nav-link.active {
  background: var(--admin-sidebar-active);
  color: #5b21b6;
  font-weight: 600;
  border-left-color: var(--admin-sidebar-active-border);
}

.admin-nav .nav-link .bi {
  opacity: 0.85;
  font-size: 1.05rem;
}

.admin-nav .badge-soon {
  font-size: 0.65rem;
  font-weight: 600;
  margin-left: auto;
}

.admin-nav .nav-link.pe-none:hover {
  background: transparent;
  color: var(--admin-sidebar-muted);
}

.admin-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

@media (min-width: 992px) {
  .admin-body.sidebar-collapsed .admin-sidebar {
    width: 0;
    min-width: 0;
    border-right: 0;
    overflow: hidden;
    box-shadow: none;
  }
}

.admin-topbar {
  height: var(--admin-topbar-h);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.admin-content {
  padding: 1.25rem 1.25rem 2rem;
}

/* ตัวกรองช่วงวันที่ — ขนาดเทียบเท่า form-sm ทั่วไป */
.admin-date-filter {
  border-radius: 12px;
  background: #fff;
}
.admin-date-filter .card-body {
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
}
.admin-date-filter__group-label {
  font-size: 0.8rem;
  line-height: 1.3;
}
.admin-date-filter__field-label {
  font-size: 0.72rem;
  color: #64748b;
  line-height: 1.2;
}
.admin-date-filter__select-day {
  min-width: 3.35rem;
}
.admin-date-filter__select-month {
  min-width: 5.25rem;
}
.admin-date-filter__select-year {
  min-width: 4.25rem;
}
.admin-date-filter__row {
  gap: 0.5rem 0.75rem;
}

.kpi-card {
  border: 0;
  border-radius: 14px;
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

.kpi-card .kpi-label {
  font-size: 0.82rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-card .kpi-value {
  font-size: 1.65rem;
  font-weight: 700;
  color: #0f172a;
}

.kpi-card .kpi-delta {
  font-size: 0.85rem;
}

.panel-card {
  border: 0;
  border-radius: 14px;
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

.page-hero {
  border-radius: 16px;
  border: 1px solid #ece9f2;
  background: #f4f2f7;
}

.panel-card .card-header {
  background: transparent;
  border-bottom: 1px solid #f1f5f9;
  font-weight: 600;
}

.code-hint {
  font-size: 0.8rem;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  color: #475569;
}

/* รายการรายงานกำหนดเอง — ให้เลื่อนเมื่อรายการเยอะ */
.custom-report-list-scroll {
  /* สูงตามการ์ดฝั่งขวา แล้วเลื่อนในบล็อคนี้ */
  max-height: none;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

/* ทำให้คอลัมน์ซ้ายสูงเท่ากับการ์ดฝั่งขวา */
.custom-report-saved-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

.custom-report-left {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* หน้า report_smiv — ตารางรายละเอียด: แสดงประมาณ 20 แถวข้อมูล แล้วเลื่อนในกรอบ */
.smiv-report-table-scroll--detail {
  /* หัวตาราง ~1 แถว + แสดงได้ประมาณ 20 แถวข้อมูล แล้วเลื่อน */
  max-height: min(calc(2.75rem + 20 * 1.9rem), 65vh);
  overflow: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

.smiv-report-table-scroll--detail .table {
  margin-bottom: 0;
}

.smiv-report-table-scroll--detail thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: #f8f9fa;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.08);
}

/* ตารางสรุปฝั่งขวา — ไม่ยืดสูงเท่าตารางซ้าย; ถ้ายาวเกินค่อยเลื่อน */
.smiv-report-table-scroll--summary {
  max-height: min(22rem, 50vh);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.smiv-report-table-scroll--summary .table {
  margin-bottom: 0;
}

.smiv-report-table-scroll--summary thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: #f8f9fa;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.08);
}

/* ใช้เน้นชื่อกลุ่มโรค (เช่น สมองเสื่อม) ในตารางตัวอย่าง */
.text-purple-emphasis {
  color: #7c3aed !important;
  font-weight: 600;
}

/* หน้า index — การ์ดลิงก์ตัวอย่างรายงาน */
.index-sample-card {
  transition: box-shadow 0.15s ease, transform 0.15s ease;
  border: 1px solid #e2e8f0 !important;
}
a.text-decoration-none:hover .index-sample-card {
  box-shadow: 0 6px 22px rgba(15, 23, 42, 0.09) !important;
  transform: translateY(-2px);
}

@media (max-width: 991.98px) {
  .admin-sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 32px rgba(15, 23, 42, 0.12);
  }
  .admin-sidebar.show {
    transform: translateX(0);
  }
  .admin-main {
    width: 100%;
  }
}
