html {
  font-size: 12px;
  direction: rtl;
}

/* Critical: Ensure header and navbar are always visible */
header,
header *,
.navbar,
.navbar * {
  box-sizing: border-box;
}

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

body {
  font-size: 0.9rem;
  line-height: 1.4;
  direction: rtl;
  text-align: right;
}

h1, h2, h3, h4, h5, h6 {
  margin-bottom: 0.5rem;
  font-weight: 600;
}

h2 {
  font-size: 1.5rem;
}

h3 {
  font-size: 1.25rem;
}

.form-label {
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
  font-weight: 500;
}

.form-control, .form-select {
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
  direction: rtl;
  text-align: right;
}

.btn {
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
}

.table {
  font-size: 0.85rem;
}

.table th, .table td {
  padding: 0.4rem 0.5rem;
  vertical-align: middle;
  text-align: right;
  direction: rtl;
}

.card {
  margin-bottom: 0.75rem;
}

.card-header {
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

.card-body {
  padding: 0.75rem;
}

.container {
  padding-left: 0.75rem;
  padding-right: 0.75rem;
  direction: rtl;
  max-width: 100%;
}

@media (max-width: 576px) {
  .container {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
}

.row {
  margin-left: -0.25rem;
  margin-right: -0.25rem;
  direction: rtl;
}

.row > * {
  padding-left: 0.25rem;
  padding-right: 0.25rem;
  direction: rtl;
}

.g-3 {
  --bs-gutter-y: 0.5rem;
  --bs-gutter-x: 0.5rem;
}

/* Move dropdown arrows to the left for RTL */
.form-select {
  background-position: left 0.75rem center !important;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e") !important;
  padding-left: 2.5rem !important;
  padding-right: 0.75rem !important;
  text-align: right !important;
  direction: rtl !important;
  background-repeat: no-repeat;
  background-size: 16px 12px;
}

.form-select:focus {
  background-position: left 0.75rem center !important;
  border-color: #86b7fe;
  outline: 0;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.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 {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* Remove border radius from all elements */
* {
  border-radius: 0 !important;
}

.btn,
.form-control,
.form-select,
.input-group,
.card,
.modal-content,
.dropdown-menu,
.alert,
.badge,
.navbar,
.table,
.img-thumbnail,
.pagination,
.page-link,
.list-group-item,
.breadcrumb,
.breadcrumb-item,
.progress,
.progress-bar,
.tooltip,
.popover,
.tag-item,
.tags-input-container {
  border-radius: 0 !important;
}

/* RTL improvements */
.input-group {
  direction: rtl;
  flex-direction: row-reverse;
}

.input-group > .form-control,
.input-group > .form-select {
  direction: rtl;
  text-align: right;
}

.navbar-nav {
  direction: rtl;
}

.navbar-nav .nav-link {
  text-align: right;
}

.btn-group {
  direction: rtl;
  flex-direction: row-reverse;
}

.card-header,
.card-body {
  direction: rtl;
  text-align: right;
}

.form-label {
  text-align: right;
  direction: rtl;
}

textarea.form-control {
  direction: rtl;
  text-align: right;
}

/* Select2 RTL and styling */
.select2-container {
  direction: rtl;
  text-align: right;
}

.select2-container--bootstrap-5 .select2-selection {
  border-radius: 0 !important;
  border: 1px solid #ced4da;
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
}

.select2-container--bootstrap-5 .select2-selection--single {
  height: auto;
  line-height: 1.5;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
  padding-right: 2.5rem !important;
  padding-left: 0.75rem !important;
  text-align: right !important;
  direction: rtl !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__arrow {
  right: auto !important;
  left: 0.75rem !important;
  height: 100%;
}

/* Move Clear button to the left side for RTL */
.select2-container--bootstrap-5 .select2-selection--single .select2-selection__clear {
  float: left !important;
  margin-left: 0.5rem !important;
  margin-right: 0 !important;
  right: auto !important;
  left: 0.5rem !important;
  position: absolute !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
  padding-right: 2.5rem !important;
  padding-left: 2rem !important; /* Add space for clear button on left */
  text-align: right !important;
  direction: rtl !important;
}

.select2-dropdown {
  border-radius: 0 !important;
  border: 1px solid #ced4da;
  direction: rtl;
  text-align: right;
}

.select2-search--dropdown .select2-search__field {
  border-radius: 0 !important;
  border: 1px solid #ced4da;
  padding: 0.35rem 0.5rem;
  direction: rtl;
  text-align: right;
}

.select2-results__option {
  text-align: right;
  padding: 0.5rem 0.75rem;
}

.select2-results__option--highlighted {
  background-color: #0d6efd;
  color: white;
}

/* Tags input container - ensure correct order: select, input, button */
.tags-input-container .input-group {
  flex-direction: row !important;
  direction: rtl;
}

/* Professional Navbar Styling */
.custom-navbar {
  background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
  padding: 0.6rem 1rem;
  border-bottom: 3px solid rgba(255, 255, 255, 0.15);
  display: flex !important;
  flex-wrap: nowrap;
  align-items: center;
  position: relative;
  width: 100%;
  z-index: 1030;
  min-height: 56px;
  overflow-x: auto;
  overflow-y: hidden;
}

.custom-navbar .navbar-brand {
  font-size: 1.2rem;
  color: #ffffff !important;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  transition: all 0.3s ease;
  border-radius: 6px;
  margin-right: 0.75rem;
}

.custom-navbar .navbar-brand:hover {
  background-color: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

.custom-navbar .brand-icon {
  font-size: 1.5rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.custom-navbar .brand-text {
  font-weight: 700;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.custom-navbar .navbar-nav {
  gap: 0.3rem;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.custom-navbar .nav-link {
  color: rgba(255, 255, 255, 0.9) !important;
  font-weight: 500;
  padding: 0.5rem 0.8rem !important;
  border-radius: 6px;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  position: relative;
  margin: 0 0.1rem;
  font-size: 0.85rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.custom-navbar .nav-link:hover {
  background-color: rgba(255, 255, 255, 0.15);
  color: #ffffff !important;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.custom-navbar .nav-link.active {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 0%, rgba(255, 255, 255, 0.15) 100%);
  color: #ffffff !important;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.custom-navbar .nav-link.active::before {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 60%;
  background: linear-gradient(180deg, #ffffff 0%, rgba(255, 255, 255, 0.7) 100%);
  border-radius: 0 4px 4px 0;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

.custom-navbar .nav-link.active::after {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 60%;
  background: linear-gradient(180deg, #ffffff 0%, rgba(255, 255, 255, 0.7) 100%);
  border-radius: 4px 0 0 4px;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

.custom-navbar .nav-icon {
  font-size: 1rem;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
  transition: transform 0.3s ease;
  line-height: 1;
  flex-shrink: 0;
}

.custom-navbar .nav-link:hover .nav-icon,
.custom-navbar .nav-link.active .nav-icon {
  transform: scale(1.1);
}

.custom-navbar .nav-text {
  font-size: 0.8rem;
  line-height: 1.2;
  white-space: nowrap;
}

.custom-navbar .navbar-toggler {
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

@media (min-width: 992px) {
  .custom-navbar .navbar-toggler {
    display: none !important;
  }
}

.custom-navbar .navbar-toggler:focus {
  box-shadow: 0 0 0 0.25rem rgba(255, 255, 255, 0.25);
}

.custom-navbar .navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba(255, 255, 255, 0.9)' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
  width: 1.5em;
  height: 1.5em;
  display: block;
}

/* Desktop navbar layout */
@media (min-width: 992px) {
  .custom-navbar .navbar-nav {
    display: inline-flex;
    flex-direction: row;
    justify-content: flex-start;
    width: auto;
    align-items: center;
    flex-wrap: nowrap;
    flex-shrink: 0;
  }
  
  .custom-navbar .navbar-nav:last-child {
    margin-left: auto;
    justify-content: flex-end;
    flex-shrink: 0;
  }
  
  .custom-navbar .container-fluid {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    width: 100%;
    overflow: visible;
  }
  
  .custom-navbar .navbar-collapse {
    display: flex !important;
    flex-wrap: nowrap;
    width: 100%;
    overflow: visible;
  }
}

/* Responsive adjustments */
@media (max-width: 991px) {
  .custom-navbar {
    flex-wrap: wrap;
  }
  
  .custom-navbar .container-fluid {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    width: 100%;
  }
  
  .custom-navbar .navbar-brand {
    margin-right: auto;
    margin-left: 0;
  }
  
  .custom-navbar .navbar-toggler {
    margin-left: 0.5rem;
    order: 2;
  }
  
  .custom-navbar .navbar-collapse {
    flex-basis: 100%;
    flex-grow: 1;
    align-items: stretch;
    width: 100%;
    margin-top: 0.5rem;
  }
  
  .custom-navbar .navbar-collapse:not(.show) {
    display: none;
  }
  
  .custom-navbar .navbar-collapse.show {
    display: flex !important;
    flex-direction: column;
  }
  
  .custom-navbar .navbar-collapse.collapsing {
    display: flex !important;
    flex-direction: column;
    height: 0;
    overflow: hidden;
    transition: height 0.35s ease;
  }
  
  .custom-navbar .navbar-nav {
    margin-top: 0;
    gap: 0.25rem;
    flex-direction: column;
    width: 100%;
  }
  
  .custom-navbar .nav-link {
    padding: 0.65rem 0.9rem !important;
    margin: 0.2rem 0;
    width: 100%;
    justify-content: flex-start;
    font-size: 0.85rem;
  }
  
  .custom-navbar .nav-icon {
    font-size: 1rem;
  }
  
  .custom-navbar .nav-text {
    font-size: 0.8rem;
  }
}

/* Mobile specific styles */
@media (max-width: 576px) {
  .container {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
  
  .custom-navbar {
    padding: 0.5rem 0.75rem;
    display: flex !important;
    visibility: visible !important;
  }
  
  .custom-navbar .container-fluid {
    display: flex !important;
    flex-wrap: wrap;
    width: 100%;
  }
  
  .custom-navbar .navbar-brand {
    font-size: 1.1rem;
    padding: 0.4rem 0.75rem;
    display: flex !important;
    visibility: visible !important;
  }
  
  .custom-navbar .navbar-toggler {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  .custom-navbar .brand-text {
    font-size: 0.9rem;
  }
  
  .custom-navbar .nav-link {
    padding: 0.55rem 0.75rem !important;
    font-size: 0.8rem;
  }
  
  .custom-navbar .nav-icon {
    font-size: 0.95rem;
  }
  
  .custom-navbar .nav-text {
    font-size: 0.75rem;
  }
  
  h2 {
    font-size: 1.25rem;
  }
  
  h3 {
    font-size: 1.1rem;
  }
  
  .btn {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
  }
  
  .table {
    font-size: 0.75rem;
  }
  
  .table th, .table td {
    padding: 0.3rem 0.4rem;
  }
  
  .card-body {
    padding: 0.5rem;
  }
  
  .card-header {
    padding: 0.4rem 0.5rem;
    font-size: 0.85rem;
  }
  
  .form-control, .form-select {
    font-size: 0.8rem;
    padding: 0.3rem 0.4rem;
  }
  
  .form-label {
    font-size: 0.8rem;
  }
}

/* Tablet styles */
@media (min-width: 577px) and (max-width: 991px) {
  .container {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  
  .custom-navbar .nav-link {
    padding: 0.55rem 0.85rem !important;
    font-size: 0.85rem;
  }
  
  .custom-navbar .nav-icon {
    font-size: 1rem;
  }
  
  .custom-navbar .nav-text {
    font-size: 0.8rem;
  }
}

/* Ensure tables are responsive */
@media (max-width: 991px) {
  .table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .table {
    min-width: 600px;
  }
}

/* Ensure buttons don't wrap on mobile */
@media (max-width: 576px) {
  .btn-group {
    flex-wrap: wrap;
  }
  
  .d-flex.justify-content-between {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .d-flex.justify-content-between > div {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
  }
}

/* Table Header Styling - Match Navbar Colors */
.table-dark,
.table thead.table-dark th,
.table thead th {
  background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%) !important;
  color: #ffffff !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
  font-weight: 600;
}

.table-dark th,
.table thead.table-dark th {
  background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%) !important;
  color: #ffffff !important;
}

/* Pagination Styling - Match Navbar Colors */
.pagination .page-link {
  color: #4a5568;
  background-color: #ffffff;
  border-color: #dee2e6;
  transition: all 0.3s ease;
}

.pagination .page-link:hover {
  color: #ffffff;
  background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
  border-color: #4a5568;
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.pagination .page-item.active .page-link {
  background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
  border-color: #2d3748;
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.pagination .page-item.disabled .page-link {
  color: #6c757d;
  background-color: #ffffff;
  border-color: #dee2e6;
  opacity: 0.6;
}

/* Actions Column Styling - Consistent across all pages */
.table td:first-child,
.table th:first-child,
.table td[data-column="Actions"],
.table th[data-column="Actions"] {
  width: 1% !important;
  white-space: nowrap !important;
  min-width: fit-content !important;
  max-width: none !important;
}

.table td:first-child .btn-group,
.table td[data-column="Actions"] .btn-group {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 0.15rem;
  width: auto;
}

.table td:first-child .btn,
.table td[data-column="Actions"] .btn {
  white-space: nowrap;
  flex-shrink: 0;
  width: auto;
  padding: 0.15rem 0.4rem;
  font-size: 0.7rem;
  line-height: 1.2;
}

/* Override table layout for actions column */
.table {
  table-layout: auto;
}

/* Ensure navbar is always visible and functional */
.navbar {
  position: relative;
  z-index: 1030;
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

header {
  display: block !important;
  visibility: visible !important;
}

.custom-navbar {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.navbar-collapse {
  flex-basis: 100%;
  flex-grow: 1;
  align-items: center;
}

@media (min-width: 992px) {
  .navbar-collapse {
    display: flex !important;
    flex-wrap: nowrap;
    overflow: visible;
  }
}

/* Force navbar elements to be visible on mobile */
@media (max-width: 991px) {
  .custom-navbar,
  .custom-navbar .container-fluid,
  .custom-navbar .navbar-brand,
  .custom-navbar .navbar-toggler {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  .custom-navbar .navbar-toggler {
    display: block !important;
  }
}

/* Ensure container-fluid works properly on mobile */
.container-fluid {
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

@media (max-width: 576px) {
  .container-fluid {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
}