:root {
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 68px;
  --header-height: 56px;
}

/* Base Document Reset */
html, body {
  min-height: 100vh;
  max-width: 100vw;
  background-color: #f8f9fa;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

/* App Structural Wrappers */
.app-wrapper {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Top Header */
.app-header {
  height: var(--header-height);
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  display: flex;
  align-items: center;
  z-index: 1030;
}

/* Main Two-Pane Layout Container */
.app-container {
  display: flex !important;
  flex-direction: row !important;
  align-items: flex-start !important;
  min-height: calc(100vh - var(--header-height));
  width: 100%;
  flex: 1;
}

/* Base Sidebar Styling */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: #ffffff;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.25s ease-in-out, left 0.25s ease-in-out;
  flex-shrink: 0;
  box-sizing: border-box;
}

/* Custom Slim Scrollbars */
.app-sidebar::-webkit-scrollbar,
.app-content::-webkit-scrollbar {
  width: 5px;
}

.app-sidebar::-webkit-scrollbar-thumb,
.app-content::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

/* Sidebar Navigation Items */
.app-sidebar .nav-link {
  color: #495057;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  white-space: nowrap;
  font-weight: 500;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app-sidebar .nav-link i {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.app-sidebar .nav-link:hover,
.app-sidebar .nav-link.active {
  background-color: #e9ecef;
  color: #0d6efd;
}

/* Main Content Pane */
.app-content {
  box-sizing: border-box;
  width: 100%;
}

/* ================= DESKTOP STYLES (> 768px) ================= */
@media (min-width: 769px) {
  .app-sidebar {
    position: sticky !important;
    top: var(--header-height) !important;
    height: calc(100vh - var(--header-height)) !important;
    z-index: 1020;
  }

  .app-content {
    flex: 1 1 auto !important;
    min-width: 0 !important; /* Prevents wide grid tables/cards from overflowing viewport */
    height: calc(100vh - var(--header-height)) !important;
    overflow-y: auto !important; /* Enables independent right-side scrolling */
  }

  /* Desktop Collapsed Sidebar State */
  .sidebar-collapsed .app-sidebar {
    width: var(--sidebar-collapsed-width);
  }

  .sidebar-collapsed .app-sidebar .nav-label {
    display: none;
  }

  .sidebar-collapsed .app-sidebar .nav-link {
    justify-content: center;
    padding: 12px;
  }
}

/* ================= MOBILE STYLES (<= 768px) ================= */
@media (max-width: 768px) {
  .app-sidebar {
    position: fixed !important;
    top: var(--header-height) !important;
    bottom: 0;
    height: calc(100vh - var(--header-height)) !important;
    left: calc(-1 * var(--sidebar-width));
    width: var(--sidebar-width) !important;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    z-index: 1040;
  }

  .app-sidebar.mobile-open {
    left: 0 !important;
  }

  .app-sidebar .nav-label {
    display: inline !important;
  }

  .app-sidebar .nav-link {
    justify-content: flex-start !important;
    padding: 10px 14px !important;
  }

  .app-content {
    width: 100%;
    min-width: 0;
  }

  /* Container Padding Adjustments for Mobile */
  .container-fluid,
  .app-header {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .card-body {
    padding: 12px !important;
  }
}

/* ================= CUSTOM STATUS BADGES ================= */
.badge.status-badge {
  font-weight: 600;
  font-size: 0.75rem;
  padding: 0.35em 0.65em;
  border-radius: 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge.status-badge.status-pending,
.badge.status-badge.status-created,
.badge.status-badge.status-draft {
  --bs-badge-color: #856404 !important;
  color: #856404 !important;
  background-color: #fff3cd !important;
  border: 1px solid #ffeeba !important;
}

.badge.status-badge.status-processing,
.badge.status-badge.status-accepted,
.badge.status-badge.status-assigned {
  --bs-badge-color: #004085 !important;
  color: #004085 !important;
  background-color: #cce5ff !important;
  border: 1px solid #b8daff !important;
}

.badge.status-badge.status-dispatched,
.badge.status-badge.status-out_for_delivery {
  --bs-badge-color: #383d41 !important;
  color: #383d41 !important;
  background-color: #e2e3e5 !important;
  border: 1px solid #d6d8db !important;
}

.badge.status-badge.status-delivered,
.badge.status-badge.status-completed {
  --bs-badge-color: #155724 !important;
  color: #155724 !important;
  background-color: #d4edda !important;
  border: 1px solid #c3e6cb !important;
}

.badge.status-badge.status-cancelled {
  --bs-badge-color: #721c24 !important;
  color: #721c24 !important;
  background-color: #f8d7da !important;
  border: 1px solid #f5c6cb !important;
}