/* Modern Sidebar Navigation */
:root {
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 70px;
  --topbar-height: 60px;
  --sidebar-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  /* Sidebar theme variables — overridden per color theme in color-themes.css.
   * Defaults: neutral sidebar (body background) so the sidebar blends with the page.
   * The active-item tint uses --bs-primary-rgb so it shifts automatically with the accent theme. */
  --theme-sidebar-bg: var(--bs-body-bg);
  --theme-sidebar-border: var(--bs-border-color);
  --theme-sidebar-text: var(--bs-body-color);
  --theme-sidebar-text-muted: var(--bs-secondary-color);
  --theme-sidebar-hover-bg: var(--bs-secondary-bg);
  --theme-sidebar-active-bg: rgba(var(--bs-primary-rgb), 0.10);
  --theme-sidebar-active-text: var(--zyte-primary);
  --theme-sidebar-active-border: var(--zyte-primary);
  --theme-sidebar-label-color: var(--bs-secondary-color);
  --theme-sidebar-scrollbar: var(--bs-border-color);
}

/* ========================================
   PAGE TRANSITION FADE-IN
   ======================================== */

/* NOTE: Page fade-in animation was removed — CSS opacity/transform animations on
   container elements create stacking contexts that trap Bootstrap modals, causing
   the backdrop to render on top of modal dialogs and block click events. */

/* Apply Inter font globally */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  font-size: 0.875rem; /* 14px - better for business applications */
}

/* Reduce button sizes for more compact UI */
.btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
}

/* Make pagination more compact */
.pagination {
  font-size: 0.8125rem;
}

.pagination .page-link {
  padding: 0.3rem 0.6rem;
  font-size: 0.8125rem;
}

/* Layout Structure */
body {
  padding-top: var(--topbar-height) !important;
}

.app-container {
  display: flex;
  min-height: calc(100vh - var(--topbar-height));
  position: relative;
}

/* Top Bar (Slim) — stays neutral; does not participate in color theming */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--bs-body-bg);
  border-bottom: 1px solid var(--bs-border-color);
  z-index: 1030;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: var(--sidebar-transition);
}

[data-bs-theme="dark"] .topbar {
  background: var(--zyte-surface);
  border-bottom-color: rgba(255, 255, 255, 0.1);
}

.topbar-brand {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--zyte-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-brand::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--zyte-primary);
  flex-shrink: 0;
}

.topbar-brand:hover {
  color: var(--zyte-primary-variant);
}

@media (max-width: 768px) {
  .topbar {
    padding: 0 0.75rem;
  }

  .topbar-brand {
    font-size: 0.95rem;
  }
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Accent color picker in topbar */
.accent-color-dot-nav {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5a2d82, #3e1f5a);
  flex-shrink: 0;
}

.accent-color-menu {
  min-width: auto;
}

.accent-color-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.accent-swatch-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.accent-swatch-btn:hover {
  transform: scale(1.2);
}

.accent-swatch-btn.active {
  border-color: var(--bs-body-color);
}

/* Dark mode sidebar: use Zyte surface colour (slightly elevated from body bg) */
[data-bs-theme="dark"] {
  --theme-sidebar-bg: var(--zyte-surface);
  --theme-sidebar-border: rgba(255, 255, 255, 0.1);
  --theme-sidebar-active-bg: rgba(var(--bs-primary-rgb), 0.15);
}

/* ========================================
   SIDEBAR — themed via --theme-sidebar-* variables
   ======================================== */

.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  background: var(--theme-sidebar-bg);
  border-right: 1px solid var(--theme-sidebar-border);
  overflow-y: auto;
  overflow-x: hidden;
  transition: var(--sidebar-transition);
  z-index: 1020;
}

/* Sidebar scrollbar styling */
.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--theme-sidebar-scrollbar);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* Sidebar Toggle Button (lives in the topbar — neutral) */
.sidebar-toggle {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--bs-body-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  margin-right: 0.5rem;
}

.sidebar-toggle:hover {
  background: var(--bs-secondary-bg);
}

.sidebar-toggle i {
  font-size: 1.25rem;
}

/* Sidebar Nav */
.sidebar-nav {
  list-style: none;
  padding: 1rem 0.75rem 6rem 0.75rem;
  margin: 0;
  min-height: 100%;
}

.sidebar-nav-item {
  margin-bottom: 0.25rem;
}

/* Main nav links */
.sidebar-nav-link {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  color: var(--theme-sidebar-text);
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.2s;
  font-size: 0.95rem;
  font-weight: 500;
  gap: 0.75rem;
  position: relative;
}

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

.sidebar-nav-link:hover {
  background: var(--theme-sidebar-hover-bg);
  color: var(--theme-sidebar-active-text);
}

.sidebar-nav-link.active {
  background: var(--theme-sidebar-active-bg);
  color: var(--theme-sidebar-active-text);
  font-weight: 600;
  border-left: 3px solid var(--theme-sidebar-active-border);
  padding-left: calc(1rem - 3px);
}

/* Sidebar sections with collapsible sub-items */
.sidebar-section {
  margin-bottom: 0.25rem;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  color: var(--theme-sidebar-text);
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.2s;
  font-size: 0.95rem;
  font-weight: 500;
  gap: 0.75rem;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.sidebar-section-header i.section-icon {
  font-size: 1.25rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-section-header:hover {
  background: var(--theme-sidebar-hover-bg);
}

/* Don't show background when section is expanded - only sub-items should be highlighted */
.sidebar-section.expanded .sidebar-section-header {
  background: transparent !important;
}

/* Allow subtle hover on expanded section headers */
.sidebar-section.expanded .sidebar-section-header:hover {
  background: rgba(255, 255, 255, 0.04) !important;
}

.sidebar-section-header .chevron {
  margin-left: auto;
  transition: transform 0.2s;
  font-size: 0.875rem;
}

.sidebar-section.expanded .chevron {
  transform: rotate(90deg);
}

/* Sub-items */
.sidebar-subitems {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.sidebar-section.expanded .sidebar-subitems {
  max-height: 2000px;
}

.sidebar-subitem {
  display: flex;
  align-items: center;
  padding: 0.625rem 1rem 0.625rem 3.25rem;
  color: var(--theme-sidebar-text-muted);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.2s;
  font-size: 0.875rem;
  margin: 0.125rem 0;
  gap: 0.625rem;
}

.sidebar-subitem i {
  font-size: 1rem;
  width: 18px;
  text-align: center;
}

.sidebar-subitem:hover {
  background: var(--theme-sidebar-hover-bg);
  color: var(--theme-sidebar-active-text);
}

.sidebar-subitem.active {
  background: var(--theme-sidebar-active-bg);
  color: var(--theme-sidebar-active-text);
  font-weight: 600;
  border-left: 2px solid var(--theme-sidebar-active-border);
  padding-left: calc(3.25rem - 2px);
}

/* Sidebar divider */
.sidebar-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 0.5rem 1rem;
}

/* Main Content Area */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 2rem;
  transition: var(--sidebar-transition);
  min-height: calc(100vh - var(--topbar-height));
}

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

body.sidebar-collapsed .main-content {
  margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .sidebar-nav-link span,
body.sidebar-collapsed .sidebar-section-header span,
body.sidebar-collapsed .sidebar-section-header .chevron {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

body.sidebar-collapsed .sidebar-nav-link,
body.sidebar-collapsed .sidebar-section-header {
  justify-content: center;
  padding: 0.75rem 0.5rem;
}

body.sidebar-collapsed .sidebar-subitems {
  display: none;
}

/* Tooltip for collapsed sidebar */
body.sidebar-collapsed .sidebar-nav-link[data-bs-toggle="tooltip"],
body.sidebar-collapsed .sidebar-section-header[data-bs-toggle="tooltip"] {
  position: relative;
}

/* Mobile Styles */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1019;
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
  }

  /* Mobile hamburger button */
  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--bs-body-color);
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
  }

  .mobile-menu-toggle:hover {
    background: var(--bs-secondary-bg);
  }

  .mobile-menu-toggle i {
    font-size: 1.5rem;
  }
}

@media (min-width: 769px) {
  .mobile-menu-toggle {
    display: none;
  }

  .sidebar-backdrop {
    display: none !important;
  }
}

/* User menu at sidebar bottom */
.sidebar-user {
  padding: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: auto;
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.sidebar-user-info:hover {
  background: var(--theme-sidebar-hover-bg);
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--zyte-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.sidebar-user-details {
  overflow: hidden;
  transition: all 0.3s;
}

.sidebar-user-name {
  font-weight: 600;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--theme-sidebar-text);
}

.sidebar-user-role {
  font-size: 0.75rem;
  color: var(--theme-sidebar-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.sidebar-collapsed .sidebar-user-details {
  width: 0;
  opacity: 0;
}

/* Adjust sticky table headers for new layout */
.table thead th {
  top: 0 !important;
}

/* Footer spacing */
footer {
  margin-left: var(--sidebar-width);
  transition: var(--sidebar-transition);
}

body.sidebar-collapsed footer {
  margin-left: var(--sidebar-collapsed-width);
}

@media (max-width: 768px) {
  footer {
    margin-left: 0;
  }
}

/* ========================================
   TOPBAR — User Initials Avatar
   ======================================== */

.user-initials-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--zyte-primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  user-select: none;
  flex-shrink: 0;
}

/* ========================================
   SIDEBAR — Section Labels
   ======================================== */

.sidebar-section-label {
  list-style: none;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--theme-sidebar-label-color);
  padding: 1.125rem 1rem 0.375rem 1rem;
  opacity: 0.65;
}

body.sidebar-collapsed .sidebar-section-label {
  opacity: 0;
  height: 0;
  padding: 0;
  overflow: hidden;
}
