html {
  font-size: 14px;
  height: 100%;
}

/* Ensure confirm modal always appears on top of other modals */
#confirmModal {
  z-index: 1060 !important;
}

#confirmModal.show {
  z-index: 1060 !important;
}

/* Ensure confirm modal backdrop appears above other modal backdrops */
body.modal-open #confirmModal ~ .modal-backdrop,
body.modal-open .modal-backdrop:last-of-type {
  z-index: 1050 !important;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

/* Top Header */
.top-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1030;
  height: 60px;
}

.top-header .navbar {
  height: 60px;
  padding: 0.5rem 1rem;
}

/* Wrapper cho sidebar và main content */
.wrapper {
  display: flex;
  flex-direction: column; /* Wrapper chứa content-wrapper và footer */
  margin-top: 60px; /* Chiều cao của top header */
  flex: 1;
  width: 100%;
  min-height: calc(100vh - 60px); /* Chiều cao viewport trừ header */
  position: relative;
}

/* Content wrapper chứa sidebar và main-content */
.content-wrapper {
  display: flex !important;
  flex-direction: row !important; /* Sidebar và main-content nằm ngang */
  flex: 1;
  min-height: 0;
  overflow: hidden;
  width: 100%;
  align-items: stretch; /* Đảm bảo sidebar và main-content có cùng chiều cao */
}

/* Sidebar */
.sidebar {
  width: 250px;
  min-width: 250px;
  max-width: 250px;
  background-color: #f8f9fa;
  border-right: 1px solid #dee2e6;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  flex-grow: 0;
  transition: transform 0.3s ease;
  height: 100%; /* Chiều cao 100% của content-wrapper */
  display: block; /* Đảm bảo sidebar là block element */
}

@media (max-width: 767.98px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 60px;
    bottom: 0;
    z-index: 1020;
    transform: translateX(-100%);
  }
  
  .sidebar.show {
    transform: translateX(0);
  }
  
  .sidebar-overlay {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1019;
    display: none;
  }
  
  .sidebar-overlay.show {
    display: block;
  }
}

.sidebar-nav {
  padding: 1rem 0;
}

.sidebar-nav .nav-link {
  color: #495057;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.sidebar-nav .nav-link:hover {
  background-color: #e9ecef;
  color: #0d6efd;
  border-left-color: #0d6efd;
}

.sidebar-nav .nav-link.active {
  background-color: #e7f1ff;
  color: #0d6efd;
  border-left-color: #0d6efd;
  font-weight: 600;
}

.sidebar-nav .nav-link i {
  width: 24px;
  margin-right: 0.75rem;
  font-size: 1.1rem;
}

/* Main Content */
.main-content {
  flex: 1;
  flex-grow: 1;
  flex-shrink: 1;
  background-color: #ffffff;
  overflow-y: auto; /* Cho phép scroll nếu nội dung dài */
  overflow-x: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0; /* Quan trọng cho flexbox */
  min-width: 0; /* Quan trọng: cho phép flexbox tính toán width tự động */
  width: auto; /* Tự động tính width còn lại */
}

.main-content .container-fluid {
  padding: 1.5rem;
  padding-bottom: 2rem;
  flex: 1;
}

@media (max-width: 767.98px) {
  .main-content {
    width: 100%;
  }
}

footer {
  background-color: #f8f9fa;
  border-top: 1px solid #dee2e6;
  padding: 1.5rem 0;
  margin-top: auto;
  position: relative;
  z-index: 1;
  width: 100%;
}

/* Logo trong header có background trắng để nổi bật */
.navbar-brand img {
  background-color: white;
  padding: 4px;
  border-radius: 4px;
  object-fit: contain;
}

/* Alert container fixed ở góc phải trên */
.alert-container {
  position: fixed !important;
  top: 70px !important; /* Ngay dưới header */
  right: 20px !important;
  left: auto !important;
  z-index: 99999 !important; /* Rất cao để luôn nằm trên mọi thứ */
  width: auto !important;
  max-width: 400px !important;
  min-width: 300px !important;
  pointer-events: none; /* Cho phép click xuyên qua khi không có alert */
  display: flex !important;
  flex-direction: column-reverse !important; /* Alert mới (thêm vào cuối) sẽ hiển thị ở trên */
  align-items: flex-end !important;
  gap: 10px !important;
}

.alert-container .alert {
  z-index: 99999 !important; /* Đảm bảo alert cũng có z-index cao */
}

.alert-container .alert {
  width: 100% !important;
  max-width: 400px !important;
  min-width: 300px !important;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  margin-bottom: 0 !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  pointer-events: auto; /* Cho phép tương tác với alert */
}

/* Làm nhạt màu background của alert */
.alert-container .alert-success {
  /* background-color: rgba(25, 135, 84, 0.15) !important; */
  border-color: rgba(25, 135, 84, 0.3) !important;
  color: #0f5132 !important;
}

.alert-container .alert-danger {
  /* background-color: rgba(220, 53, 69, 0.15) !important; */
  border-color: rgba(220, 53, 69, 0.3) !important;
  color: #842029 !important;
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 99999;
  display: flex;
  justify-content: center;
  align-items: center;
}

.loading-spinner {
  text-align: center;
  color: white;
}

.loading-spinner p {
  font-size: 1.1rem;
  margin-top: 1rem;
}

/* Select2 trong modal - đảm bảo z-index cao hơn modal backdrop */
.modal .select2-container {
  z-index: 1055 !important; /* Cao hơn modal (1050) */
  width: 100% !important; /* Đảm bảo chiếm toàn bộ width của parent */
  position: relative !important;
}

/* Select2 selection trong modal - đảm bảo không bị overflow */
.modal .select2-selection {
  z-index: 1055 !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

/* Select2 selection rendered trong modal */
.modal .select2-selection__rendered {
  max-width: 100% !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  display: block !important;
  box-sizing: border-box !important;
}

/* Select2 selection single trong modal */
.modal .select2-selection__choice {
  max-width: 100% !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

/* Select2 dropdown - đảm bảo hiển thị trên modal */
.select2-dropdown {
  z-index: 10050 !important; /* Rất cao để luôn nằm trên modal (1050) và backdrop (1040) */
  box-sizing: border-box !important;
  position: absolute !important; /* Đảm bảo positioning đúng */
  max-height: 300px !important; /* Giới hạn chiều cao để không bị overflow */
  overflow-y: auto !important;
}

/* Select2 search field trong dropdown - đảm bảo có thể gõ được */
.select2-search--dropdown {
  z-index: 10001 !important;
  position: relative !important;
  pointer-events: auto !important;
}

.select2-search--dropdown .select2-search__field {
  z-index: 10002 !important;
  position: relative !important;
  pointer-events: auto !important;
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
  opacity: 1 !important;
  background-color: white !important;
}

/* Đảm bảo Select2 dropdown có thể tương tác được */
.select2-container--open .select2-dropdown {
  z-index: 10050 !important;
}

/* Đảm bảo Select2 results có thể click được */
.select2-results {
  z-index: 10050 !important;
  position: relative;
  pointer-events: auto !important;
}

.select2-results__option {
  z-index: 10050 !important;
  position: relative;
  pointer-events: auto !important;
}

/* Đảm bảo Select2 container trong modal */
.modal .select2-container--open {
  z-index: 10050 !important;
}

/* Select2 selection trong modal - đã được định nghĩa ở trên */

/* Đảm bảo Select2 dropdown không bị modal backdrop che */
.modal.show .select2-dropdown {
  z-index: 10050 !important;
}

/* Đảm bảo Select2 search input có thể focus và gõ được */
.select2-container--open .select2-search--dropdown .select2-search__field {
  z-index: 10002 !important;
  position: relative !important;
  pointer-events: auto !important;
  opacity: 1 !important;
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
  background-color: white !important;
}

/* Đảm bảo Select2 dropdown được append vào body để tránh vấn đề z-index */
body > .select2-container {
  z-index: 10050 !important;
}

body > .select2-dropdown {
  z-index: 10050 !important;
}

/* Đảm bảo Select2 dropdown trong modal-dialog hiển thị đúng */
.modal-dialog .select2-dropdown {
  position: absolute !important;
  top: 100% !important;
  left: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  margin-top: -1px !important;
  z-index: 10050 !important;
}

/* Đảm bảo modal-dialog không bị overflow hidden */
.modal-dialog {
  overflow: visible !important;
}

.modal-content {
  overflow: visible !important;
}

/* Đảm bảo Select2 dropdown trong modal-dialog có thể tương tác */
.modal-dialog .select2-dropdown {
  position: absolute !important;
  z-index: 10050 !important;
  pointer-events: auto !important;
}

.modal-dialog .select2-search--dropdown {
  pointer-events: auto !important;
  z-index: 10051 !important;
}

.modal-dialog .select2-search--dropdown .select2-search__field {
  pointer-events: auto !important;
  z-index: 10052 !important;
  position: relative !important;
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
  cursor: text !important;
  background-color: white !important;
}

.modal-dialog .select2-results {
  pointer-events: auto !important;
  z-index: 10051 !important;
}

.modal-dialog .select2-results__option {
  pointer-events: auto !important;
  cursor: pointer !important;
}

/* Đảm bảo Select2 container không bị overflow trong modal */
.modal .select2-container--default .select2-selection--single {
  height: auto !important;
  min-height: 38px !important; /* Chiều cao tối thiểu của Bootstrap form-control */
}

.modal .select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 38px !important;
  padding-left: 12px !important;
  padding-right: 20px !important;
}

/* Đảm bảo Select2 arrow không bị đẩy ra ngoài */
.modal .select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 36px !important;
  right: 1px !important;
}

/* Đảm bảo modal backdrop không chặn Select2 */
.modal-backdrop {
  z-index: 1040 !important; /* Thấp hơn Select2 (10000) */
}

/* Khi Select2 mở, backdrop không chặn pointer events */
.modal.show ~ .select2-dropdown,
body > .select2-dropdown {
  z-index: 10050 !important; /* Cao hơn modal (1050) và backdrop (1040) */
  position: fixed !important;
}

/* Đảm bảo Select2 search input có thể focus */
.select2-search__field:focus {
  outline: none !important;
  border-color: #258cfb !important;
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb !important;
}

/* Đảm bảo Select2 dropdown không bị ẩn bởi modal */
.modal.show ~ .select2-dropdown,
.modal.show ~ .select2-container {
  z-index: 10050 !important;
}

/* Khi Select2 mở trong modal, backdrop không chặn */
body:has(.select2-container--open) .modal-backdrop {
  pointer-events: none !important;
}

/* Đảm bảo Select2 search input có thể tương tác được */
.select2-container--open .select2-dropdown {
  pointer-events: auto !important;
}

.select2-container--open .select2-search--dropdown {
  pointer-events: auto !important;
  z-index: 10051 !important;
}

.select2-container--open .select2-search--dropdown .select2-search__field {
  pointer-events: auto !important;
  z-index: 10052 !important;
  position: relative !important;
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
  cursor: text !important;
}

/* Select2 dropdown khi mở phải có z-index rất cao */
.select2-container--open .select2-dropdown {
  z-index: 10050 !important;
}

