/*
 * UBRU staff apps: เมนูหลัก (แถบซ้าย) และแถบชื่อเมนู เป็นสีม่วงเข้ม ตัดกับสีชมพูของแถบบน
 * บนมือถือ: แตะแถบชื่อเมนูเพื่อเปิดเมนูหลัก (ทำงานคู่กับ staff-menu.js)
 * โครงหน้าเหมือนเดิมทุกอย่าง ลบ <link> และ <script> ของไฟล์คู่นี้ออก = กลับเป็นแบบเดิม
 * ไฟล์นี้เหมือนกันทุกระบบ (แก้ที่เดียวแล้ว copy ไปทุก ubru_front_*)
 */
:root {
  --sm-plum: #35214d;
  --sm-plum-soft: #563b78; /* พื้นกลุ่มเมนูย่อยที่กางอยู่: ม่วงอ่อนกว่าแถบ แต่ตัวอักษรสีอ่อนยังอ่านชัด */
  --sm-plum-line: rgba(255, 255, 255, 0.08);
  --sm-text: #e3d9ec;
  --sm-muted: #b3a3c2;
  --sm-pink: #ed639e;
  --sm-pink-tint: rgba(237, 99, 158, 0.2);
}

/* ---------- แถบซ้าย: พื้นม่วงเข้ม ---------- */
/* กลุ่ม A (s01, s04, s05, s06, s10, s12) = .site-menubar.side-menu-bar / กลุ่ม B (permission, s02, s03, s07, s08, s09, s11) = .page-aside */
html body .site-menubar.side-menu-bar,
html body .site-menubar.side-menu-bar[class*="_PRIMARY_COLOR"],
html body .page-aside,
html body .page-aside[class*="_PRIMARY_COLOR"],
html body .page-aside .page-aside-inner {
  background-color: var(--sm-plum) !important;
  background-image: none !important;
  border-color: transparent !important;
  color: var(--sm-text);
}

/* หัวข้อ "เมนูหลัก" */
html body .site-menubar.side-menu-bar > div:first-child,
html body .page-aside .page-aside-title.topic-title {
  background-color: transparent !important;
  box-shadow: none !important;
  border-bottom: 1px solid var(--sm-plum-line);
  color: var(--sm-muted) !important;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* รายการเมนู: พื้นโปร่ง ตัวอักษรสีอ่อน */
html body .page-aside .site-menu-item,
html body .page-aside .list-group-item,
html body .page-aside .site-menu-sub,
html body .page-aside .site-menu-sub li,
html body .page-aside [class*="_PRIMARY_COLOR"],
html body .site-menubar.side-menu-bar .site-menu-item,
html body .site-menubar.side-menu-bar .site-menu-item.has-sub,
html body .site-menubar.side-menu-bar .site-menu-sub,
html body .site-menubar.side-menu-bar .site-menu-sub li {
  background-color: transparent !important;
  background-image: none !important;
  border-color: var(--sm-plum-line) !important;
}

html body .page-aside .list-group-item,
html body .page-aside .site-menu-item > a,
html body .page-aside .site-menu-title,
html body .site-menubar.side-menu-bar .site-menu-item > a,
html body .site-menubar.side-menu-bar .site-menu-item > a span,
html body .site-menubar.side-menu-bar .site-menu-title {
  color: var(--sm-text) !important;
}

html body .page-aside .list-group-item:hover,
html body .page-aside .site-menu-sub .site-menu-item > a:hover,
html body .site-menubar.side-menu-bar .site-menu-item > a:hover {
  background-color: rgba(255, 255, 255, 0.07) !important;
  color: #ffffff !important;
}

html body .site-menubar.side-menu-bar .site-menu-item > a:hover span {
  color: #ffffff !important;
}

/* เมนูที่เปิดอยู่: แถบชมพูด้านซ้าย + พื้นชมพูจาง */
html body .page-aside .list-group-item.active,
html body .page-aside .site-menu-item.active > a,
html body .page-aside .site-menu-sub .site-menu-item.active > a,
html body .site-menubar.side-menu-bar .site-menu-item.active > a,
html body .site-menubar.side-menu-bar .site-menu-item.has-sub.active > a {
  background-color: var(--sm-pink-tint) !important;
  box-shadow: inset 4px 0 0 var(--sm-pink);
  color: #ffffff !important;
}

html body .page-aside .site-menu-item.active > a .site-menu-title,
html body .site-menubar.side-menu-bar .site-menu-item.active > a span {
  color: #ffffff !important;
}

/* กลุ่มเมนูที่กางเมนูย่อย (กลุ่ม B): ของเดิมทาพื้นขาว/เทาตอน active/hover (.list-group > .site-menu-item:hover ฯลฯ)
   ทำให้ตัวอักษรสีอ่อนมองไม่เห็น -> ใช้พื้นม่วงอ่อน */
html body .page-aside .list-group > .site-menu-item.has-sub.active,
html body .page-aside .list-group > .site-menu-item.has-sub:hover,
html body .page-aside .list-group > .site-menu-item.has-sub:focus,
html body .page-aside .list-group > .site-menu-item.has-sub:focus-within {
  background-color: var(--sm-plum-soft) !important;
  border-radius: 12px !important;
}

html body .page-aside .list-group > .site-menu-item.has-sub > .site-menu-sub .site-menu-item > a,
html body .page-aside .list-group > .site-menu-item.has-sub > .site-menu-sub .site-menu-title {
  color: #f1eaf7 !important;
}

html body .page-aside .list-group > .site-menu-item.has-sub > .site-menu-sub .site-menu-item:hover > a {
  background-color: rgba(255, 255, 255, 0.12) !important;
  color: #ffffff !important;
}

/* ไอคอนเมนูกลุ่ม B: ของเดิมย้อมไอคอนเป็นสีดำตอน active/hover (สำหรับพื้นขาว) ให้คงเป็นสีขาวบนพื้นม่วง */
html body .page-aside .list-group-item img,
html body .page-aside .list-group-item.active img,
html body .page-aside .list-group-item:hover img,
html body .page-aside .site-menu-item.active img {
  filter: none !important;
}

html body .page-aside .list-group-item svg,
html body .page-aside .list-group-item i {
  color: inherit !important;
}

/* ไอคอนเมนูกลุ่ม A เป็น PNG ทำไว้สำหรับพื้นชมพู/พื้นขาว ปรับให้เป็นสีอ่อนบนพื้นม่วง */
html body .site-menubar.side-menu-bar .sub-menu img {
  filter: brightness(0) invert(0.88);
}

html body .site-menubar.side-menu-bar .site-menu-item.active .sub-menu img,
html body .site-menubar.side-menu-bar .site-menu-item > a:hover .sub-menu img {
  filter: brightness(0) invert(1);
}

/* ---------- เมนูหลักแถวบน: ระบบที่กำลังใช้อยู่ (staff-menu.js ใส่ .sm-top-active) ---------- */
/* ชั้นนอกของเมนูที่ซ้อน 2 ชั้น: ไม่ต้องมีกล่อง/เงาของตัวเองเมื่อชั้นในถูกไฮไลท์ */
html body .top-menu-icon:has(.sm-top-active),
html body .top-menu-icon:has(.sm-top-active):hover {
  box-shadow: none !important;
  background: transparent !important;
}

html body .top-menu-icon.sm-top-active,
html body .top-menu-icon.sm-top-active:hover {
  position: relative;
  box-sizing: border-box;
  height: auto !important;
  /* ระยะในเท่ากันทุกระบบ: บน 10 / ล่าง 14 (รวมแถบชมพู 4px) — ทับ padding-bottom: 30px / 5px ของธีมเดิม */
  padding: 10px 10px 14px !important;
  /* เว้นจากแถบด้านบน/ด้านล่างของแถวเมนู */
  margin-top: 6px !important;
  margin-bottom: 6px !important;
  background-color: #fbe6ef !important;
  border-radius: 14px !important;
  box-shadow: inset 0 -4px 0 var(--sm-pink) !important;
}

/* เฉพาะเมนูแบบซ้อน (div.top-menu-icon.col > li > a.top-menu-icon เช่น s05/s06): ชั้นในกว้างเท่าคอลัมน์แคบ
   -> ให้กว้างตามชื่อเมนูและอยู่กึ่งกลางคอลัมน์ ไม่ให้ขอบกินตัวหนังสือ
   (เมนูแบบชั้นเดียว เช่น s07 ห้ามใช้ min-width: 100% เพราะ 100% = ทั้งแถว) */
html body .top-menu-icon .top-menu-icon.sm-top-active,
html body .top-menu-icon .top-menu-icon.sm-top-active:hover {
  width: max-content !important;
  min-width: 100% !important;
  left: 50%;
  transform: translateX(-50%);
}

/* ระยะบน-ล่างเท่ากัน: ตัด margin ท้ายของชื่อเมนู (p มี margin-bottom 16px จากธีม) */
html body .top-menu-icon.sm-top-active p,
html body .top-menu-icon.sm-top-active > :last-child {
  margin-bottom: 0 !important;
}

html body .top-menu-icon.sm-top-active,
html body .top-menu-icon.sm-top-active a,
html body .top-menu-icon.sm-top-active .top-menu-icon-font,
html body .top-menu-icon.sm-top-active .site-menu-title {
  color: var(--sm-plum) !important;
  font-weight: 700 !important;
}

/* ---------- แถบชื่อเมนู (กลางหน้า): ม่วงเข้ม ---------- */
html body .container-fluid.content-page-header,
html body div.content-page-header,
html body p.content-page-header,
html body .alert.dark.alert-toppic {
  background-color: var(--sm-plum) !important;
  background-image: none !important;
  border-color: var(--sm-plum) !important;
  color: #ffffff !important;
}

/* p ที่อยู่ในกล่องหัวข้ออีกชั้น ไม่ต้องทาสีซ้ำ */
html body .content-page-header p.content-page-header {
  background-color: transparent !important;
}

/* ---------- มือถือ: แตะแถบชื่อเมนูเพื่อเปิดเมนูหลัก ---------- */
.sm-backdrop {
  display: none;
}

@media (max-width: 767.98px) {
  html.sm-js body .sm-toggle {
    position: relative;
    cursor: pointer;
    padding-left: 46px !important;
    padding-right: 46px !important;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  /* ไอคอนเมนู (ซ้าย) */
  html.sm-js body .sm-toggle::before {
    content: "";
    position: absolute;
    left: 16px;
    top: 50%;
    width: 18px;
    height: 2px;
    margin-top: -1px;
    border-radius: 2px;
    background: #ffffff;
    box-shadow: 0 -6px 0 #ffffff, 0 6px 0 #ffffff;
  }

  /* ลูกศร (ขวา) */
  html.sm-js body .sm-toggle::after {
    content: "";
    position: absolute;
    right: 18px;
    top: 50%;
    width: 9px;
    height: 9px;
    margin-top: -7px;
    border-right: 2px solid #ffffff;
    border-bottom: 2px solid #ffffff;
    transform: rotate(45deg);
    transition: transform 0.2s ease, margin-top 0.2s ease;
  }

  html.sm-js body.sm-menu-open .sm-toggle::after {
    margin-top: -2px;
    transform: rotate(-135deg);
  }

  html.sm-js body .sm-toggle:focus-visible {
    outline: 3px solid var(--sm-pink);
    outline-offset: 2px;
  }

  /* แถบสำรองสำหรับหน้าที่ไม่มีแถบชื่อเมนู */
  html.sm-js body .sm-toggle.sm-toggle-fallback {
    display: block;
    margin: 10px 12px;
    padding-top: 11px;
    padding-bottom: 11px;
    border-radius: 10px;
    background-color: var(--sm-plum);
    color: #ffffff;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
  }

  /* เมนูหลักเลื่อนออกมาทับจากด้านซ้าย */
  html.sm-js body.sm-menu-open .site-menubar.side-menu-bar,
  html.sm-js body.sm-menu-open .page-aside {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 272px !important;
    max-width: 84vw;
    height: 100% !important;
    margin: 0 !important;
    transform: none !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    z-index: 2100 !important;
    box-shadow: 8px 0 28px rgba(0, 0, 0, 0.35);
  }

  html.sm-js body.sm-menu-open .page-aside .page-aside-inner {
    height: auto !important;
    min-height: 100%;
    border: 0 !important;
  }

  html.sm-js body.sm-menu-open .page-aside .page-aside-switch {
    display: none !important;
  }

  /* เมนูย่อยในแถบซ้าย: แตะหัวข้อเพื่อกาง (เดิมกางด้วย hover ซึ่งมือถือไม่มี) */
  html.sm-js body.sm-menu-open .page-aside .site-menu-item.sm-sub-open > .site-menu-sub,
  html.sm-js body.sm-menu-open .site-menubar.side-menu-bar .site-menu-item.sm-sub-open > .site-menu-sub {
    display: block !important;
    position: static !important;
    height: auto !important;
    overflow: visible !important;
    padding: 4px 0 !important;
    background-color: rgba(0, 0, 0, 0.22) !important;
    border: 0 !important;
  }

  html.sm-js body.sm-menu-open .sm-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 2090;
    background: rgba(20, 16, 24, 0.55);
  }

  html.sm-js body.sm-menu-open {
    overflow: hidden !important;
  }
}

/* ---------- มือถือ: แถวไอคอนระบบ (เมนูหลักด้านบน) เป็นแถบเลื่อนซ้าย-ขวา แทนปุ่ม MENU ---------- */
@media (max-width: 767.98px) {
  /* hamburger ตรงโลโก้ซ้ำกับปุ่มที่แถบชื่อเมนู -> เอาออก (เมนูซ้ายเปิดจากแถบชื่อเมนู) */
  html.sm-js body .site-navbar .navbar-header .navbar-toggler.hamburger,
  html.sm-js body .site-navbar > .navbar-toggler.hamburger {
    display: none !important;
  }

  /* กลุ่ม content-page (s01, s04, s05, s06, s10, s12): ไม่ต้องมีปุ่ม MENU ให้แสดงแถวไอคอนเสมอ */
  html.sm-js body .top-menu-bar > .navbar-toggler {
    display: none !important;
  }
  html.sm-js body .top-menu-bar .navbar-collapse {
    display: block !important;
    height: auto !important;
    width: 100%;
  }
  html.sm-js body .top-menu-bar .navbar-collapse > .nav {
    width: 100% !important;
    display: block !important;
  }

  /* กลุ่ม admin (permission, s02, s03, s07, s08, s09, s11): แถบไอคอนระบบแสดงใต้หัวเว็บตลอด */
  html.sm-js body .site-menubar.site-menubar-topbar {
    display: block !important;
    position: relative !important;
    top: auto !important;
    left: auto !important;
    width: 100% !important;
    height: auto !important;
    transform: none !important;
    visibility: visible !important;
    opacity: 1 !important;
    overflow: visible !important;
    box-shadow: 0 1px 0 #ece4ef;
    z-index: 1;
  }
  html.sm-js body .site-menubar.site-menubar-topbar .site-menubar-body,
  html.sm-js body .site-menubar.site-menubar-topbar > div {
    height: auto !important;
    overflow: visible !important;
  }

  /* แถบเลื่อน */
  html.sm-js body .topbar_menu {
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    align-items: stretch;
    gap: 2px;
    width: 100% !important;
    margin: 0 !important;
    padding: 6px 8px 8px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  html.sm-js body .topbar_menu li {
    list-style: none;
    margin: 0;
    padding: 0;
  }
  html.sm-js body .topbar_menu::-webkit-scrollbar {
    display: none;
  }
  html.sm-js body .topbar_menu > .top-menu-icon,
  html.sm-js body .topbar_menu > .site-menu-item {
    flex: 0 0 auto !important;
    width: 88px !important;
    max-width: none !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    float: none !important;
    scroll-snap-align: center;
    list-style: none;
  }
  html.sm-js body .topbar_menu .top-menu-icon a,
  html.sm-js body .topbar_menu a.top-menu-icon {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    width: 100% !important;
    padding: 6px 4px 8px !important;
    white-space: normal !important;
    text-align: center;
  }
  html.sm-js body .topbar_menu img {
    width: 30px !important;
    height: 30px !important;
    object-fit: contain;
    margin: 0 0 4px !important;
  }
  html.sm-js body .topbar_menu .top-menu-icon-font,
  html.sm-js body .topbar_menu .site-menu-title {
    margin: 0 !important;
    font-size: 11.5px !important;
    line-height: 1.3 !important;
    white-space: normal !important;
  }
  /* ไฮไลท์ระบบปัจจุบันบนมือถือ: ขนาดเท่าช่องอื่น ไม่ต้องจัดกึ่งกลางแบบจอใหญ่ */
  html.sm-js body .topbar_menu .top-menu-icon.sm-top-active {
    min-width: 0 !important;
    left: auto !important;
    transform: none !important;
    margin: 0 !important;
    padding: 6px 4px 10px !important;
  }
  /* แบบชั้นเดียว (div.top-menu-icon เป็นช่องในแถบเอง): กว้างเท่าช่องอื่น */
  html.sm-js body .topbar_menu > .top-menu-icon.sm-top-active {
    width: 88px !important;
  }
  /* แบบซ้อน (ลิงก์ชั้นในของช่อง): เต็มช่อง */
  html.sm-js body .topbar_menu .top-menu-icon .top-menu-icon.sm-top-active {
    width: 100% !important;
  }

  /* กลุ่ม admin: ระยะบนของเนื้อหาเดิมเผื่อแถบเมนูแบบลอยของจอใหญ่ (45 + 55px) -> บนมือถือแถบอยู่ในหน้าแล้ว ลดลง */
  html.sm-js body:has(.site-menubar-topbar) .page-main {
    margin-top: 8px !important;
  }
  html.sm-js body:has(.site-menubar-topbar) .page-main .alert.alert-toppic {
    margin-top: 8px !important;
  }
}

@media (min-width: 768px) {
  .sm-toggle.sm-toggle-fallback {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  html.sm-js body .sm-toggle::after {
    transition: none;
  }
}
