:root {
  --ap-navy: #16314f;
  --ap-navy-dark: #0e2238;
  --ap-gold: #b8902f;
  --ap-bg: #f4f6f9;
  --ap-border: #e2e6ec;
  --ap-sidebar-width: 260px;
  --ap-navbar-height: 120px;
}

body {
  font-family: 'Sarabun', sans-serif;
  background-color: var(--ap-bg);
  color: #1f2937;
}

/* ============================================================
   NAVBAR - ปรับขนาดให้ใหญ่ขึ้น
   ============================================================ */
.ap-navbar {
  background: linear-gradient(135deg, #0a2b4e 0%, #1a4a7a 100%);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1070;
  height: var(--ap-navbar-height);
  padding: 0.5rem 1rem;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.ap-navbar .navbar-brand {
  font-weight: 700;
  font-size: 1.3rem;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
}

.ap-navbar .navbar-brand img {
  max-height: 120px;  
  width: auto;
  transition: all 0.3s ease;
}

.ap-navbar .navbar-brand img:hover {
  transform: scale(1.05);
}

/* ============================================================
   SIDEBAR - ปรับขนาดและข้อความ
   ============================================================ */
.ap-sidebar {
  position: fixed;
  top: var(--ap-navbar-height);
  left: 0;
  bottom: 0;
  width: var(--ap-sidebar-width);
  background: #1a1d23;
  color: #fff;
  padding: 0.75rem 0.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1050;
  transition: transform 0.3s ease, width 0.3s ease;
  box-shadow: 2px 0 8px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
}

.ap-sidebar .nav-link {
  color: rgba(255, 255, 255, 0.8);
  padding: 0.4rem 0.6rem 0.4rem 1.3rem; 
  border-radius: 6px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.ap-sidebar .nav-link i {
  font-size: 1.1rem;
  min-width: 1.5rem;
  text-align: center;
  flex-shrink: 0;
}

.ap-sidebar .nav-link span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ap-sidebar .nav-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

/* ✨ แถบเมนู (Active) สีเหลืองทอง */
.ap-sidebar .nav-link.active {
  color: #ffc107;
  background: rgba(255, 193, 7, 0.15);
  font-weight: 600;
}

.ap-sidebar .nav-link .bi-chevron-right {
  font-size: 0.7rem;
  opacity: 0.5;
  flex-shrink: 0;
}

/* ✨ หมวดหมู่เมนู - พื้นหลังสีชมพู ตัวหนังสือสีขาว */
.ap-sidebar .ap-nav-group-label {
  background-color: #d81b60; /* สีพื้นหลังชมพู (โทนเดียวกับ Theme) */
  color: #ffffff !important; /* ตัวหนังสือสีขาว */
  padding: 0.5rem 0.8rem;    /* ปรับช่องไฟให้พอดีกับกรอบ */
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 6px;        /* ทำมุมให้โค้งมนดูสวยงาม */
  margin-top: 0.8rem;        /* เว้นระยะห่างด้านบนจากเมนูก่อนหน้า */
  margin-bottom: 0.4rem;
  border-bottom: none;       /* เอาเส้นกั้นขอบล่างของเดิมออก */
  box-shadow: 0 2px 4px rgba(216, 27, 96, 0.3); /* เพิ่มเงาให้ปุ่มดูมีมิติ */
}

.ap-sidebar .ap-nav-group-label i {
  font-size: 1.1rem;
  color: #ffffff !important; /* เปลี่ยนไอคอนให้เป็นสีขาวด้วย */
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 0.75rem 0.6rem 0.5rem;
  font-size: 0.65rem;
  opacity: 0.5;
  border-top: 1px solid rgba(255,255,255,0.1);
  margin-top: auto;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.ap-main {
  margin-left: var(--ap-sidebar-width);
  padding-top: var(--ap-navbar-height);
  min-height: 100vh;
  transition: margin-left 0.3s ease;
  background: #f8f9fa;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 767.98px) {
  :root {
    --ap-sidebar-width: 0px;
    --ap-navbar-height: 70px;
  }

  /* ✨ 1. บังคับให้ Navbar อยู่บรรทัดเดียว ไม่ให้ปุ่มถูกดันตกจอ ✨ */
  .ap-navbar .container-fluid {
    flex-wrap: nowrap;
  }

  /* ✨ 2. จัดการโลโก้และชื่อระบบไม่ให้ล้น (ถ้ายาวไปจะตัดเป็น ...) ✨ */
  .ap-navbar .navbar-brand {
    font-size: 0.9rem;
    margin-left: 45px; /* เว้นที่ให้ปุ่มซ้าย */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100vw - 140px); /* ล็อกความกว้าง เว้นที่ให้ปุ่มซ้าย-ขวา */
  }
  .ap-navbar .navbar-brand img { max-height: 40px; }

  /* ✨ 3. ปุ่มเมนูขวา (ชื่อผู้ใช้/Logout) ✨ */
  .navbar-toggler {
    z-index: 1080;
    padding: 4px 8px;
    border-color: rgba(255,255,255,0.5);
  }

  /* ✨ 4. กล่องเมนู Dropdown (กางลงมา) ✨ */
  .ap-navbar .navbar-collapse {
    background: #b3164a;
    position: absolute; /* กลับมาใช้ absolute เพื่อให้ลอยทับเนื้อหา */
    top: var(--ap-navbar-height);
    left: 10px;
    right: 10px;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 1060;
  }
  
  .ap-navbar .text-end {
    text-align: left !important;
    margin-right: 0 !important;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
  }

  /* --- โค้ด Sidebar ส่วนอื่นคงเดิม --- */
  .ap-sidebar {
    transform: translateX(-100%);
    width: 280px;
    max-width: 80vw;
    top: 0;
    padding-top: 0.5rem;
  }

  .ap-sidebar.show { transform: translateX(0); }

  .ap-main {
    margin-left: 0 !important;
    padding-top: var(--ap-navbar-height);
  }

  .ap-sidebar .ap-nav-group-label { font-size: 0.85rem; padding: 0.3rem 0.6rem 0.15rem; }
  .ap-sidebar .nav-link { font-size: 0.85rem; padding: 0.35rem 0.5rem 0.35rem 1.1rem; }
}



@media (min-width: 768px) and (max-width: 991.98px) {
  :root {
    --ap-sidebar-width: 220px;
    --ap-navbar-height: 75px;
  }
  .ap-navbar .navbar-brand img { max-height: 50px; }
  .ap-sidebar .nav-link { font-size: 0.8rem; padding: 0.3rem 0.5rem 0.3rem 1.1rem; }
  .ap-sidebar .ap-nav-group-label { font-size: 0.8rem; padding: 0.3rem 0.5rem 0.15rem; }
}

@media (min-width: 992px) {
  :root {
    --ap-sidebar-width: 260px;
    --ap-navbar-height: 120px;
  }
  .ap-sidebar .ap-nav-group-label { font-size: 1rem; padding: 0.5rem 0.6rem 0.25rem; }
}

/* ============================================================
   SIDEBAR - SCROLLBAR
   ============================================================ */
.ap-sidebar::-webkit-scrollbar { width: 4px; }
.ap-sidebar::-webkit-scrollbar-track { background: #2d3238; }
.ap-sidebar::-webkit-scrollbar-thumb { background: #6c757d; border-radius: 4px; }
.ap-sidebar::-webkit-scrollbar-thumb:hover { background: #adb5bd; }
.ap-sidebar { scrollbar-width: thin; scrollbar-color: #6c757d #2d3238; }

/* ============================================================
   SIDEBAR TOGGLE BUTTON
   ============================================================ */
.sidebar-toggle-btn {
  display: none;
  position: fixed;
  top: 15px; /* ให้อยู่กึ่งกลาง navbar แนวตั้ง */
  left: 12px;
  z-index: 1080; /* ✨ ต้องมากกว่า .ap-navbar (1070) เพื่อไม่ให้โดนทับ ✨ */
  background: #b3164a;
  border: 1px solid rgba(255,255,255,0.6);
  border-radius: 6px;
  color: #fff;
  font-size: 1.5rem;
  padding: 4px 10px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  transition: all 0.3s ease;
}

.sidebar-toggle-btn:hover { background: #be185d; transform: scale(1.05); }

@media (max-width: 767.98px) {
  .sidebar-toggle-btn { display: block; }
}

/* ============================================================
   SIDEBAR OVERLAY & CLOSE BUTTON
   ============================================================ */
.sidebar-overlay {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.5); z-index: 1040; opacity: 0; transition: opacity 0.3s ease;
}
.sidebar-overlay.show { display: block; opacity: 1; }

.sidebar-close-btn {
  display: none; position: absolute; top: 10px; right: 10px;
  background: transparent; border: none; color: #fff; font-size: 1.5rem;
  cursor: pointer; padding: 4px 8px; border-radius: 4px; transition: background 0.2s;
}
.sidebar-close-btn:hover { background: rgba(255,255,255,0.1); }

@media (max-width: 767.98px) {
  .sidebar-close-btn { display: block; }
}

/* ============================================================
   OTHER STYLES
   ============================================================ */
.ap-login-card { border: none; border-top: 4px solid var(--ap-gold); }
.ap-stat-card { border: none; border-left: 4px solid var(--ap-navy); }
.ap-stat-number { font-size: 1.8rem; font-weight: 700; color: var(--ap-navy); }
.ap-stat-label { color: #6b7280; font-size: 0.85rem; }

.btn-primary { background-color: var(--ap-navy); border-color: var(--ap-navy); }
.btn-primary:hover, .btn-primary:focus { background-color: var(--ap-navy-dark); border-color: var(--ap-navy-dark); }

.ap-sort-link { color: inherit; text-decoration: none; }
.ap-sort-link:hover { text-decoration: underline; }

.ap-list-table thead th { background-color: #fafbfc; font-size: 0.85rem; color: #4b5563; white-space: nowrap; }
.ap-view-dl dt { font-size: 0.85rem; }
.card-header { background-color: #fafbfc; }

/* ============================================================
   THEME: สีชมพู
   ============================================================ */
.ap-navbar { background: linear-gradient(135deg, #d81b60 0%, #b3164a 100%) !important; }

.btn-primary { background-color: #d81b60 !important; border-color: #d81b60 !important; color: white !important; }
.btn-primary:hover { background-color: #be185d !important; border-color: #be185d !important; }

.btn-outline-primary { color: #d81b60 !important; border-color: #d81b60 !important; }
.btn-outline-primary:hover { background-color: #d81b60 !important; color: white !important; }

.border-pink { border: 1px solid #ced4da !important; color: #495057 !important; }
.border-pink:focus { border-color: #d81b60 !important; box-shadow: 0 0 0 0.25rem rgba(216, 27, 96, 0.25) !important; }

.row-pink-header th {
  background-color: #d81b60 !important;
  color: white !important;
  border-bottom: 2px solid #b31650 !important;
  font-weight: 500;
}
.row-pink-header a { color: white !important; text-decoration: none; }
.row-pink-header a:hover { color: #fce7f3 !important; }

.ts-dropdown {
  z-index: 1056; /* สูงกว่า modal/sticky header ของ Bootstrap */
}

.ts-wrapper .ts-dropdown { display: none !important; }
.ts-wrapper .ts-dropdown.show { display: block !important; }
.ts-wrapper .ts-dropdown .option.selected { background-color: #d81b60 !important; color: white !important; }

/* ============================================================
   AP-COMBOBOX
   ============================================================ */
.ap-combobox { position: relative; }
.ap-combobox-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 1080; margin-top: 2px;
  max-height: 260px; overflow-y: auto; background: #fff;
  border: 1px solid var(--ap-border, #e2e6ec); border-radius: 0.375rem;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}
.ap-combobox-item { padding: 0.5rem 0.75rem; cursor: pointer; font-size: 0.9rem; }
.ap-combobox-item:hover { background-color: #fce7f3; color: #d81b60; }
.ap-combobox-empty { padding: 0.5rem 0.75rem; font-size: 0.85rem; color: #6c757d; }

/* ============================================================
   FLASH MESSAGE & UTILITY
   ============================================================ */
.alert { border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.text-ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* ============================================================
   ACTION BUTTONS (ปุ่มจัดการในตาราง list)
   ============================================================ */
.action-buttons.btn-group {
  display: inline-flex;
  gap: 6px;
  flex-wrap: nowrap;
}

.action-buttons.btn-group > .btn {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: none;
  font-size: 0.85rem;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.action-buttons .btn i {
  font-size: 0.9rem;
  line-height: 1;
}

.action-buttons .btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.18);
}

/* ดู */
.action-buttons .btn-outline-secondary { background-color: #e8edf5; color: #16314f; }
.action-buttons .btn-outline-secondary:hover { background-color: #16314f; color: #fff; }

/* ดู/ดาวน์โหลดไฟล์ */
.action-buttons .btn-outline-success { background-color: #e6f9ef; color: #1a7f4e; }
.action-buttons .btn-outline-success:hover { background-color: #1a7f4e; color: #fff; }

/* แก้ไข - ใช้สีธีมชมพูของระบบ */
.action-buttons .btn-outline-primary { background-color: #fce7f3; color: #d81b60; }
.action-buttons .btn-outline-primary:hover { background-color: #d81b60; color: #fff; }

/* ลบ */
.action-buttons .btn-outline-danger { background-color: #fdeaea; color: #dc3545; }
.action-buttons .btn-outline-danger:hover { background-color: #dc3545; color: #fff; }

/* ล็อกแก้ไข (disabled) */
.action-buttons .btn-light {
  background-color: #f1f3f5;
  color: #adb5bd;
  box-shadow: none;
  cursor: not-allowed;
}
.action-buttons .btn-light:hover { transform: none; box-shadow: none; }

