/* ============================================
   TMS DASHBOARD - GLOBAL STYLES

   Organization:
   1. CSS Custom Properties & Root Styles
   2. Sidebar & Brand
   3. Sidebar Navigation
   4. Navbar & Layout
   5. Breadcrumb & Controls
   6. Mobile Responsive
   7. Theme Toggle
   8. Login Page Styles
   9. Table Styles
   10. Pagination

   Note: Theme-specific component styles (light/dark)
   are compiled in bootstrap.scss for consistency.
   ============================================ */

/* Tie native form-control rendering (select options, scrollbars, date pickers)
   to the app's actual theme. With "light dark" the browser used the OS
   preference, causing a dark flash on OS=dark + app=light when opening native
   pickers. Binding color-scheme to data-bs-theme makes the native picker match
   the app from frame one. */
html {
  color-scheme: light;
}

[data-bs-theme="dark"] {
  color-scheme: dark;
}

input[type="time"].form-control::-webkit-calendar-picker-indicator {
  cursor: pointer;
  filter: brightness(0) saturate(100%) invert(30%) sepia(12%) saturate(911%) hue-rotate(176deg) brightness(91%) contrast(87%) !important;
  opacity: 0.9;
}

[data-bs-theme="dark"] input[type="time"].form-control {
  color-scheme: dark;
}

[data-bs-theme="dark"] input[type="time"].form-control::-webkit-calendar-picker-indicator {
  filter: brightness(0) saturate(100%) invert(93%) sepia(8%) saturate(630%) hue-rotate(177deg) brightness(101%) contrast(91%) !important;
  opacity: 0.95;
}

/* ============================================
   Z-INDEX HIERARCHY (organized scale)
   ============================================
   1-10: Default elements, form validation
   100-999: Leaflet map controls
   1000: Base overlay layers
   1020: Breadcrumb and sticky page headers
   1030: Navbar
   1045: Sidebar navigation
   1046: Sidebar collapse button
   1050-1070: Modal backdrop & modal (Bootstrap defaults)
   3000: Toast notifications (highest)
   ============================================ */

#toastContainer {
  z-index: 3000;
}

/* ============================================
   2. SIDEBAR STRUCTURE
   ============================================ */

.sidebar {
  /* Navy surface: links use the bright brand color, not the darker text shade. */
  --bs-link-color: var(--tenant-web-primary);
  --bs-link-color-rgb: var(--tenant-web-primary-rgb);
  --bs-offcanvas-width: var(--sidebar-width);
  --bs-offcanvas-bg: var(--tenant-web-sidebar-bg);
  --bs-offcanvas-color: var(--tenant-web-sidebar-color);
  --bs-offcanvas-border-color: var(--tenant-web-sidebar-border-color);
  --bs-offcanvas-padding-x: 0;
  --bs-offcanvas-padding-y: 0;
  --bs-nav-link-color: var(--tenant-web-sidebar-muted);
  --bs-nav-link-hover-color: var(--tenant-web-sidebar-hover-text);
  --bs-nav-pills-link-active-bg: var(--tenant-web-sidebar-hover-bg);
  --bs-nav-pills-link-active-color: var(--tenant-web-sidebar-hover-text);
  background: var(--tenant-web-sidebar-bg);
  border-right: 1px solid var(--tenant-web-sidebar-border-color);
  color: var(--tenant-web-sidebar-color);
}

/* Docked column only from lg up; below lg Bootstrap's .offcanvas-lg must keep position: fixed. */
@media (min-width: 992px) {
  .sidebar {
    flex: 0 0 var(--sidebar-width);
    width: var(--sidebar-width);
    min-height: 100dvh;
    position: sticky;
    top: 0;
    align-self: flex-start;
    overflow: visible;
    z-index: 1045; /* under the modal backdrop (1050) */
    transition: width var(--transition-smooth), flex-basis var(--transition-smooth);
  }
}

.sidebar .offcanvas-body {
  min-height: 100dvh;
  background: inherit;
  position: relative;
  overflow-y: auto;
}

.sidebar #sidebarBrandLogo {
  max-width: 10rem;
  max-height: 7rem;
  object-fit: contain;
}

.sidebar-toggle {
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  position: fixed;
  top: 1.25rem;
  left: calc(var(--sidebar-width) - 0.95rem);
  z-index: 1046; /* above the sidebar, under the modal backdrop */
  color: #0f172a;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.22);
  transition: left var(--transition-smooth), background-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

/* Hover only grows the button: same opaque colours, so the sidebar never shows through. */
.sidebar-toggle:hover,
.sidebar-toggle:focus,
.sidebar-toggle:active {
  color: #0f172a;
  background: #f8fafc;
  border-color: #cbd5e1;
  opacity: 1;
  transform: scale(1.12);
}

.sidebar-toggle i {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  line-height: 1;
  font-size: 0.8rem;
  transition: transform var(--transition-smooth);
}

[data-bs-theme="dark"] .sidebar-toggle {
  color: #f8fafc;
  background: #111827;
  border-color: rgba(148, 163, 184, 0.72);
  box-shadow: 0 12px 28px rgba(2, 6, 23, 0.46);
}

[data-bs-theme="dark"] .sidebar-toggle:hover,
[data-bs-theme="dark"] .sidebar-toggle:focus,
[data-bs-theme="dark"] .sidebar-toggle:active {
  color: #f8fafc;
  background: #111827;
  border-color: rgba(148, 163, 184, 0.72);
}

.sidebar .nav-link {
  color: var(--bs-nav-link-color);
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-md);
  font-weight: 700;
  transition: background-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.sidebar .nav-link::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 65%);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.sidebar .nav-link::after {
  content: "";
  position: absolute;
  left: 0.4rem;
  top: 0.45rem;
  bottom: 0.45rem;
  width: 0.22rem;
  border-radius: var(--radius-pill);
  background: rgba(var(--tenant-web-primary-rgb), 0.9);
  opacity: 0;
  transform: scaleY(0.35);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.sidebar .nav-link:focus-visible {
  outline: 2px solid rgba(var(--tenant-web-primary-rgb), 0.45);
  outline-offset: 2px;
}

.sidebar .nav-link:hover,
.sidebar .nav-link:focus,
.sidebar .nav-link:active {
  background: var(--tenant-web-sidebar-hover-bg);
  color: var(--tenant-web-sidebar-hover-text);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.14);
}

.sidebar .nav-link:hover::before,
.sidebar .nav-link:focus::before,
.sidebar .nav-link:active::before,
.sidebar .nav-link.active::before {
  opacity: 1;
}

.sidebar .nav-link:hover::after,
.sidebar .nav-link:focus::after,
.sidebar .nav-link:active::after,
.sidebar .nav-link.active::after {
  opacity: 1;
  transform: scaleY(1);
}

.sidebar .nav-link.active {
  background: var(--tenant-web-sidebar-hover-bg);
  color: var(--tenant-web-sidebar-hover-text);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tenant-web-sidebar-indicator) 60%, transparent);
}

.sidebar .nav-link i {
  width: 1.5rem;
  text-align: center;
  position: relative;
  z-index: 1;
  transition: transform 0.18s ease;
}

.sidebar .nav-link span {
  position: relative;
  z-index: 1;
  transition: transform 0.18s ease;
}

.sidebar .nav-link:hover i,
.sidebar .nav-link:focus i,
.sidebar .nav-link:active i,
.sidebar .nav-link.active i {
  transform: translateX(0.12rem) scale(1.04);
}

.sidebar .nav-link:hover span,
.sidebar .nav-link:focus span,
.sidebar .nav-link:active span,
.sidebar .nav-link.active span {
  transform: translateX(0.08rem);
}

.sidebar .brand-copy,
.sidebar .nav-text {
  min-width: 0;
}

.sidebar .nav-section-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 1rem;
  color: rgba(248, 250, 252, 0.72) !important;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

.sidebar .nav-section-header::before,
.sidebar .nav-section-header::after {
  content: "";
  height: 1px;
  flex: 1 1 auto;
  background: rgba(248, 250, 252, 0.18);
}

.brand-copy:empty,
.login-panel .title:empty,
.login-panel .subtitle:empty {
  display: none;
}

/* Sidebar spacing. Comfortable by default; compact on short screens (laptops)
   so every menu entry fits without scrolling the menu. */
.sidebar-body {
  padding: 1rem;
  gap: 1rem;
}

.sidebar-brand {
  gap: 1rem;
  padding-bottom: 1rem;
}

.sidebar-brand-icon {
  padding: 1rem;
  font-size: 1.75rem;
}

.sidebar .nav-link {
  padding: 0.5rem 1rem;
}

.sidebar .nav-section-header {
  padding-inline: 1rem;
}

@media (max-height: 820px) {
  .sidebar-body {
    padding: 0.75rem;
    gap: 0.5rem;
  }

  .sidebar-brand {
    gap: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .sidebar-brand-icon {
    padding: 0.5rem;
    font-size: 1.25rem;
  }

  .sidebar #sidebarBrandLogo {
    max-height: 3rem;
  }

  .sidebar #sidebarBrandSubtitle {
    display: none;
  }

  .sidebar .nav-link {
    padding: 0.25rem 0.75rem;
  }

  .sidebar .nav-section-header {
    margin-top: 0.5rem;
  }
}

/* ============================================
   4. NAVBAR & MAIN LAYOUT
   ============================================ */

.main-wrapper {
  min-width: 0;
}

[data-bs-theme="light"] .main-wrapper,
[data-bs-theme="light"] main {
  background-color: var(--tenant-web-page-bg);
}

[data-bs-theme="dark"] .main-wrapper,
[data-bs-theme="dark"] main {
  background-color: var(--tenant-web-page-bg);
}

[data-bs-theme="light"] .sidebar,
[data-bs-theme="dark"] .sidebar {
  background: var(--tenant-web-sidebar-bg);
  border-right-color: var(--tenant-web-sidebar-border-color);
  color: var(--tenant-web-sidebar-color);
}

[data-bs-theme="light"] .sidebar .nav-link.active,
[data-bs-theme="dark"] .sidebar .nav-link.active {
  background: var(--tenant-web-sidebar-hover-bg);
  color: var(--tenant-web-sidebar-hover-text);
}

[data-bs-theme="light"] nav[aria-label="breadcrumb"],
[data-bs-theme="dark"] nav[aria-label="breadcrumb"] {
  background: var(--tenant-web-surface-bg);
  border-bottom-color: var(--tenant-web-border-color);
}

.page-container {
  color: var(--tenant-web-body-color);
  overflow-x: clip;
}

/* .navbar's own `position: relative` (bootstrap.css) is defined after
   .sticky-top in the cascade and wins on equal specificity, silently
   breaking the sticky header. Restore it with higher specificity. */
header.navbar.sticky-top {
  position: sticky;
  top: 0;
  /* The Bootstrap build gives .navbar 1050; keep it under the sidebar collapse button (1046). */
  z-index: 1030;
}

/* Breadcrumb shell: sticky under navbar */
.page-breadcrumb-shell {
  position: sticky;
  z-index: 1020;
  top: var(--navbar-height);
  background: var(--tenant-web-surface-bg);
  border-bottom: 1px solid var(--tenant-web-border-color);
}



/* ============================================
   5. NAVBAR CONTROLS & BREADCRUMB
   ============================================ */

.breadcrumb-item a {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: color 0.2s;
}

.breadcrumb-item a:hover {
  color: var(--bs-primary);
}

.breadcrumb-item.active {
  font-weight: 500;
}

.notification-dropdown-menu {
  width: min(420px, calc(100vw - 1.5rem));
  max-height: min(70vh, 640px);
  overflow: hidden;
}

.navbar .dropdown-menu .dropdown-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  transition: transform 0.18s ease, background-color 0.18s ease, color 0.18s ease;
}

.navbar .dropdown-menu .dropdown-item::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 65%);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.navbar .dropdown-menu .dropdown-item::after {
  content: "";
  position: absolute;
  left: 0.35rem;
  top: 0.35rem;
  bottom: 0.35rem;
  width: 0.2rem;
  border-radius: var(--radius-pill);
  background: rgba(var(--tenant-web-primary-rgb), 0.9);
  opacity: 0;
  transform: scaleY(0.35);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.navbar .dropdown-menu .dropdown-item:hover,
.navbar .dropdown-menu .dropdown-item:focus {
  color: var(--tenant-web-hover-text);
  background: var(--tenant-web-hover-bg);
  transform: translateX(0.18rem);
}

.navbar .dropdown-menu .dropdown-item:hover::before,
.navbar .dropdown-menu .dropdown-item:focus::before {
  opacity: 1;
}

.navbar .dropdown-menu .dropdown-item:hover::after,
.navbar .dropdown-menu .dropdown-item:focus::after {
  opacity: 1;
  transform: scaleY(1);
}

.navbar .dropdown-menu .dropdown-item > * {
  position: relative;
  z-index: 1;
}

[data-bs-theme="dark"] .navbar .btn.bg-body-tertiary {
  background-color: transparent !important;
  color: var(--tenant-web-body-color);
}

[data-bs-theme="dark"] .navbar .btn.bg-body-tertiary:hover,
[data-bs-theme="dark"] .navbar .btn.bg-body-tertiary:focus,
[data-bs-theme="dark"] .navbar .btn.bg-body-tertiary:active,
[data-bs-theme="dark"] .navbar .btn.bg-body-tertiary.active,
[data-bs-theme="dark"] .navbar .btn.bg-body-tertiary[aria-expanded="true"],
[data-bs-theme="dark"] .navbar .btn.bg-body-tertiary.show {
  background-color: rgba(248, 250, 252, 0.08) !important;
  color: var(--tenant-web-sidebar-color);
}

.notification-dropdown-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--tenant-web-border-color);
}

.notification-dropdown-header h6 {
  margin: 0;
  font-weight: 700;
}

.notification-dropdown-body {
  max-height: min(52vh, 520px);
  overflow-y: auto;
}

.notification-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.85rem;
  padding: 1rem;
  border-bottom: 1px solid var(--tenant-web-border-color);
}

.notification-item:last-child {
  border-bottom: 0;
}

.notification-item.is-read {
  opacity: 0.78;
}

.notification-item-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.notification-item-copy {
  min-width: 0;
}

.notification-item-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.notification-item-meta strong {
  display: block;
  line-height: 1.3;
}

.notification-item-time {
  color: var(--tenant-web-muted-color);
  font-size: 0.75rem;
  white-space: nowrap;
}

.notification-item-copy p {
  color: var(--tenant-web-body-color);
  font-size: 0.92rem;
  line-height: 1.45;
}

.notification-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.5rem 1rem;
  color: var(--tenant-web-muted-color);
  text-align: center;
}

.notification-empty-state i {
  font-size: 1.35rem;
}

@media (max-width: 767.98px) {
  .notification-dropdown-header {
    flex-direction: column;
  }

  .notification-item-meta {
    flex-direction: column;
    gap: 0.3rem;
  }

  .notification-item-time {
    white-space: normal;
  }
}

/* ============================================
   6. MOBILE RESPONSIVE
   ============================================ */

@media (min-width: 992px) {
  .sidebar.offcanvas-lg,
  .sidebar.offcanvas-lg .offcanvas-body {
    background-color: var(--tenant-web-sidebar-bg) !important;
  }

  .sidebar.offcanvas-lg {
    border-right: 1px solid var(--tenant-web-sidebar-border-color) !important;
  }

  .sidebar .offcanvas-body {
    padding-top: 1rem !important;
  }

  html.sidebar-collapsed .sidebar {
    flex-basis: var(--sidebar-collapsed);
    width: var(--sidebar-collapsed);
  }

  html.sidebar-collapsed .sidebar-toggle {
    left: calc(var(--sidebar-collapsed) - 0.95rem);
  }

  html.sidebar-collapsed .sidebar .offcanvas-body {
    padding-left: var(--space-2) !important;
    padding-right: var(--space-2) !important;
  }

  html.sidebar-collapsed .sidebar .brand-copy,
  html.sidebar-collapsed .sidebar .nav-text {
    display: none !important;
  }

  html.sidebar-collapsed .sidebar .nav-section-header {
    color: transparent !important;
    gap: 0.35rem;
    justify-content: center;
    font-size: 0;
    letter-spacing: 0;
  }

  html.sidebar-collapsed .sidebar .nav-section-header::before,
  html.sidebar-collapsed .sidebar .nav-section-header::after {
    flex: 0 0 1.1rem;
  }

  html.sidebar-collapsed .sidebar #sidebarBrandLogo {
    max-width: 2.75rem;
    padding: 0.35rem;
  }

  html.sidebar-collapsed .sidebar #sidebarBrandIcon {
    padding: 0.65rem !important;
    font-size: 1.1rem !important;
  }

  html.sidebar-collapsed .sidebar .nav-link {
    justify-content: center;
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  html.sidebar-collapsed .sidebar .nav-link i {
    margin-right: 0;
  }

  html.sidebar-collapsed .sidebar-toggle i {
    transform: rotate(180deg);
  }
}

@media (max-width: 991.98px) {
  /* Below lg the sidebar is Bootstrap's fixed offcanvas drawer; it must stay out of the page flow. */
  .sidebar {
    background: var(--tenant-web-sidebar-bg);
  }

  .sidebar-toggle {
    display: none !important;
  }
}

/* ============================================
   7. THEME TOGGLE
   ============================================ */

#themeToggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  min-height: 2rem;
}

.theme-icon-light,
.theme-icon-dark {
  position: absolute;
  inset: 0;
  display: inline-block;
  width: 100%;
  height: 100%;
  transition: opacity .12s linear, visibility .12s linear;
}

[data-theme-ready="false"] .theme-icon-light,
[data-theme-ready="false"] .theme-icon-dark {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

[data-theme-ready="true"][data-bs-theme="light"] .theme-icon-dark {
  visibility: hidden;
  opacity: 0;
}

[data-theme-ready="true"][data-bs-theme="dark"] .theme-icon-light {
  visibility: hidden;
  opacity: 0;
}

[data-theme-ready="true"] .theme-icon-light,
[data-theme-ready="true"] .theme-icon-dark {
  visibility: visible;
  opacity: 1;
}

/* ── Global scrollbar styling ─────────────────────────────────────────── */

* {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
  transition: scrollbar-color 0.2s;
}

*:hover {
  scrollbar-color: rgba(var(--bs-secondary-rgb), 0.35) transparent;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 999px;
  transition: background 0.2s;
}

*:hover::-webkit-scrollbar-thumb {
  background: rgba(var(--bs-secondary-rgb), 0.35);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(var(--bs-secondary-rgb), 0.55);
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* Round user/quick-action badges in the top navbar */
.navbar-avatar {
  width: 2rem;
  height: 2rem;
}
