/* ---------- THEME VARIABLES ---------- */
:root {
  --sidebar-width: 250px;
  --sidebar-collapsed-width: 70px;
  --primary: #e05b2f;
  --primary-rgb: 224, 91, 47;
  --secondary: #2c2e39;
  --background: #fdfdff;
  --light-gray: #f0f2f5;
  --text-dark: #141414;
  --text-light: #fdfdff;
  --border-light: rgba(10, 35, 66, 0.2);
  --sidebar-active: linear-gradient(
    90deg,
    color-mix(in srgb, var(--primary) 30%, transparent) 0%,
    color-mix(in srgb, var(--primary) 0%, transparent) 100%
  );
}

/* Firefox */
* {
  scrollbar-width: thin; /* auto | thin | none */
  scrollbar-color: #9ca3af transparent;
}
/* Width & height */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

/* Track */
::-webkit-scrollbar-track {
  background: transparent;
}

/* Thumb */
::-webkit-scrollbar-thumb {
  background-color: rgba(156, 163, 175, 0.6);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}

/* Hover effect */
::-webkit-scrollbar-thumb:hover {
  background-color: rgba(107, 114, 128, 0.9);
}
@media (prefers-color-scheme: dark) {
  * {
    scrollbar-color: #4b5563 transparent;
  }

  ::-webkit-scrollbar-thumb {
    background-color: rgba(75, 85, 99, 0.8);
  }

  ::-webkit-scrollbar-thumb:hover {
    background-color: rgba(107, 114, 128, 1);
  }
}
/* Firefox */
* {
  scrollbar-width: thin; /* auto | thin | none */
  scrollbar-color: #9ca3af transparent;
}

/* Apply light theme */
body {
  background-color: var(--background);
  color: var(--text-dark);
  margin: 0; /* Ensure no default margin */
  overflow-x: hidden; /* Prevent horizontal scroll on body */
}

/* ---------- DESKTOP SIDEBAR ---------- */
.sidebar {
  width: var(--sidebar-width);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  transition: width 0.3s ease;
  display: flex;
  flex-direction: column;
  background-color: var(--background);
  border-right: 1px solid var(--border-light);
  box-shadow: 0px 0px 4px rgba(44, 44, 44, 0.15);
  z-index: 1000;
  -webkit-transition: width 0.3s ease; /* Safari/Chrome */
  -moz-transition: width 0.3s ease; /* Firefox */
}

/* ---------- TOP BAR ---------- */
header {
  margin-left: var(--sidebar-width);
  background-color: var(--primary);
  color: var(--text-light);
  transition: margin-left 0.3s ease;
  display: flex;
  flex-direction: column;
  width: calc(100% - var(--sidebar-width));
  -webkit-transition: margin-left 0.3s ease; /* Safari/Chrome */
  -moz-transition: margin-left 0.3s ease; /* Firefox */
}

.topbar-title {
  font-size: clamp(1.2rem, 2.5vw, 1.5rem);
  margin: 0;
}

/* ---------- MAIN CONTENT LAYOUT ---------- */
.main-content {
  margin-left: var(--sidebar-width);
  transition: margin-left 0.3s ease;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--light-gray);
  width: calc(100% - var(--sidebar-width));
  box-sizing: border-box;
  overflow-x: hidden; /* Prevent horizontal overflow */
  -webkit-transition: margin-left 0.3s ease; /* Safari/Chrome */
  -moz-transition: margin-left 0.3s ease; /* Firefox */
}

/* Adjust for collapsed sidebar */
.sidebar.collapsed + .main-content,
.sidebar.collapsed + header,
body:has(.sidebar.collapsed) .main-content,
body:has(.sidebar.collapsed) header {
  margin-left: var(--sidebar-collapsed-width);
  width: calc(100% - var(--sidebar-collapsed-width));
}

/* Remove margin on mobile screens */
@media (max-width: 767.98px) {
  .main-content,
  header {
    margin-left: 0;
    width: 100%;
  }
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
  text-align: center;
  padding-left: 0;
  padding-right: 0;
}

.sidebar .nav-link {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* Handle long text gracefully */
  color: var(--text-dark);
}

.sidebar .nav-link:hover {
  background: var(--sidebar-active);
}

.sidebar.collapsed .nav-link {
  padding-inline: 0;
}

.sidebar.collapsed .nav-link span,
.sidebar.collapsed .nav-link .bi-chevron-down {
  display: none;
}

/* Active menu item - Solid background for top-level items without children */
.sidebar .nav-link.active:not(.dropdown-toggle) {
  background: var(--sidebar-active);
  font-weight: 500;
}

.sidebar.collapsed .nav-link.active:not(.dropdown-toggle) {
  background-color: var(--primary);
  color: var(--text-light);
}

/* Active parent with children - Subtle background only on parent */
.sidebar .nav-link.active.dropdown-toggle {
  background: var(--sidebar-active);
  font-weight: 500;
  color: var(--text-dark);
}

.sidebar.collapsed .nav-link.active.dropdown-toggle {
  background-color: var(--primary);
  color: var(--text-light);
}

/* Prevent background on active child items in collapsible */
.nav .nav .nav-link.active {
  background: transparent;
  color: var(--text-dark);
  font-weight: 500;
}

/* Sidebar header (title/avatar) */
.sidebar-header {
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  text-align: center;
}

.sidebar-title {
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--text-dark);
}

.sidebar-avatar {
  width: 40px;
  height: 40px;
  background-color: var(--primary);
  color: var(--text-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1rem;
  margin: 0 auto;
}

.sidebar.collapsed .sidebar-title {
  display: none;
}

.sidebar:not(.collapsed) .sidebar-avatar {
  display: none;
}

/* Scrollable menu */
.sidebar-nav {
  flex-grow: 1;
  overflow-y: auto;
  overflow-x: hidden;
  height: calc(100vh - 120px);
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on touch devices */
}

/* Toggle button (desktop) */
.toggle-btn {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  width: 1.5rem;
  height: 1.5rem;
  font-size: 1rem;
  padding: 0.125rem 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--primary);
  border: none;
  color: var(--text-light);
}

.toggle-btn:hover {
  background-color: var(--secondary);
  color: var(--text-light);
}

.sidebar.collapsed .toggle-btn {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

/* ---------- OFF-CANVAS (MOBILE) ---------- */
.offcanvas {
  background-color: var(--background);
  width: 250px; /* Fixed width for mobile off-canvas */
  max-width: 100%; /* Prevent overflow on small screens */
}

.offcanvas-header {
  background-color: var(--background);
  border-bottom: 1px solid var(--border-light);
}

.offcanvas-title {
  color: var(--text-dark);
}

.offcanvas .nav-link {
  color: var(--text-dark);
}

.offcanvas .nav-link:hover {
  color: var(--primary);
}

/* Active menu item - Solid background for top-level items without children */
.offcanvas .nav-link.active:not(.dropdown-toggle) {
  background-color: var(--sidebar-active);
  color: var(--text-light);
}

/* Active parent with children - Subtle background only on parent */
.offcanvas .nav-link.active.dropdown-toggle {
  background: var(--sidebar-active);
  color: var(--text-dark);
}

/* Prevent background on active child items in collapsible */
.offcanvas .nav .nav-link.active {
  background-color: transparent;
  color: var(--text-dark);
}

.offcanvas-body {
  display: flex;
  flex-direction: column;
  overflow-x: hidden; /* Prevent horizontal overflow */
}

.offcanvas-nav {
  flex-grow: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on touch devices */
}

.offcanvas-footer {
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
  margin-top: 1rem;
}

/* ---------- DROPDOWN AND COLLAPSIBLE STYLING ---------- */
.nav-link.dropdown-toggle::after {
  display: none;
}

.nav-link[data-bs-toggle="collapse"] {
  display: flex;
  align-items: center;
}

.nav-link .bi-chevron-down {
  transition: transform 0.3s ease;
  -webkit-transition: transform 0.3s ease; /* Safari/Chrome */
  -moz-transition: transform 0.3s ease; /* Firefox */
}

.nav-link[aria-expanded="true"] .bi-chevron-down {
  transform: rotate(180deg);
}

.nav .nav {
  padding: 0.5rem 0;
}

.sidebar.collapsed .collapse {
  display: none;
}

.sidebar:not(.collapsed) .dropdown-menu {
  display: none;
}

.sidebar.collapsed .dropdown-menu {
  background-color: var(--background);
  border: 1px solid var(--border-light);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: absolute;
  left: 70px;
  top: 0;
  min-width: 200px;
}

.sidebar.collapsed .dropdown-item {
  color: var(--text-dark);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
}

.sidebar.collapsed .dropdown-item:hover {
  background-color: rgba(0, 98, 65, 0.1);
  color: var(--primary);
}

.sidebar.collapsed .dropend .dropdown-menu {
  left: 100%;
  top: 0;
}

.sidebar.collapsed .dropdown-toggle::after {
  display: none;
}

.dropdown-menu .nav-link {
  padding: 0.5rem 1rem;
}

.sidebar.collapsed .dropdown-item.active {
  background: transparent;
}

/* Circle before child menu items - Hollow by default */
.nav .nav .nav-link::before,
.dropdown-menu .dropdown-item::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1px solid var(--text-dark);
  border-radius: 50%;
  margin-right: 10px;
  margin-top: -4px;
  vertical-align: middle;
  background-color: transparent;
}

/* Filled circle for active child items */
.nav .nav .nav-link.active::before,
.dropdown-menu .dropdown-item.active::before {
  background-color: var(--text-dark);
}

/* ---------- BUTTON TEMPLATES ---------- */
.btn-primary {
  background-color: var(--primary);
  border-color: var(--primary);
  color: var(--text-light);
}

.btn-primary:hover {
  background-color: var(--secondary);
  border-color: var(--secondary);
  color: var(--text-light);
}

.btn-outline-primary {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-outline-primary:hover {
  background-color: var(--primary);
  color: var(--text-light);
}

.btn-secondary {
  background-color: var(--secondary);
  border-color: var(--secondary);
  color: var(--text-light);
}

.btn-secondary:hover {
  background-color: var(--primary);
  border-color: var(--primary);
  color: var(--text-light);
}

.btn-outline-secondary {
  border-color: var(--secondary);
  color: var(--secondary);
}

.btn-outline-secondary:hover {
  background-color: var(--secondary);
  color: var(--text-light);
}

.btn-neutral {
  background-color: var(--light-gray);
  border-color: var(--border-light);
  color: var(--text-dark);
}

.btn-neutral:hover {
  background-color: #e0e3e7;
  border-color: var(--secondary);
  color: var(--text-dark);
}

.btn-outline-light {
  border-color: var(--text-light);
  color: var(--text-light);
}

.btn-outline-light:hover {
  background-color: var(--text-light);
  color: var(--primary);
}

.btn-close-white {
  filter: invert(1);
}

.btn-close {
  filter: brightness(0.2);
}

/* Ensure main-card content doesn't overflow */
.main-card {
  background: #ffffff;
  width: 100%;
  height: 100%;
  padding: 1rem;
  border-radius: 10px;
  box-shadow: 0px 0px 2px #cccccc;
  box-sizing: border-box;
  overflow-x: visible !important;
}

/* Table responsiveness */
.table-responsive {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on touch devices */
}

/* Ensure DataTables wrapper doesn't cause overflow */
.dataTables_wrapper {
  max-width: 100%;
  box-sizing: border-box !important;
}
.dataTables_wrapper .row {
  margin: 10px 6px 6px 6px !important;
}

/* Fix for mobile sidebar button alignment */
@media (max-width: 767.98px) {
  .container-fluid.d-flex {
    flex-wrap: wrap;
    gap: 10px;
  }
  .topbar-title {
    flex-grow: 1;
    text-align: center;
  }
  .btn.d-md-none {
    order: -1; /* Move mobile sidebar button to the start */
  }
}

/* Ensure cross-browser compatibility for flexbox */
.d-flex {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}

/* Prevent content overflow in smaller screens */
@media (max-width: 576px) {
  .main-card {
    padding: 0.5rem;
  }
  .table-responsive {
    font-size: 0.875rem; /* Slightly smaller font for tables on mobile */
  }
}
