/* Modern Dark Sidebar Styling */

/* CSS Variables */
:root {
  --sidebar-bg: #0f172a;
  /* Deep Navy */
  --sidebar-text: #94a3b8;
  --sidebar-accent: #10b981;
  /* Emerald */
  --sidebar-hover-bg: rgba(16, 185, 129, 0.15);
  --sidebar-active-bg: rgba(16, 185, 129, 0.25);
  --sidebar-muted: black;
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-width: 270px;
  --sidebar-collapsed-width: 80px;
  --transition-speed: 0.35s;
  --transition-timing: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base Body Styles for Sidebar Mode */
body.use-sidebar {
  display: flex;
  background-color: #f1f5f9;
  min-height: 100vh;
}

body.use-sidebar.dark-theme {
  background-color: #0f172a;
}

/* Hide navigation based on current mode */
body.use-sidebar .top-navbar,
body.use-sidebar nav.no-print {
  display: none !important;
}

body.use-navbar #main-sidebar {
  display: none !important;
}

body.use-navbar .mobile-top-bar {
  display: none !important;
}

/* Main Content Adjustments */
body.use-sidebar .main-content-wrapper {
  flex-grow: 1;
  margin-right: var(--sidebar-width);
  /* RTL */
  transition: margin-right var(--transition-speed) var(--transition-timing);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  width: calc(100% - var(--sidebar-width));
}

body.use-sidebar.sidebar-collapsed .main-content-wrapper {
  margin-right: var(--sidebar-collapsed-width);
  width: calc(100% - var(--sidebar-collapsed-width));
}

html[dir="ltr"] body.use-sidebar .main-content-wrapper {
  margin-right: 0;
  margin-left: var(--sidebar-width);
}

html[dir="ltr"] body.use-sidebar.sidebar-collapsed .main-content-wrapper {
  margin-left: var(--sidebar-collapsed-width);
}

/* Sidebar Container */
.main-sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: var(--sidebar-text);
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  z-index: 1050;
  transition: width var(--transition-speed) var(--transition-timing);
  display: flex;
  flex-direction: column;
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  border-left: 1px solid var(--sidebar-border);
}

html[dir="ltr"] .main-sidebar {
  right: auto;
  left: 0;
  border-left: none;
  border-right: 1px solid var(--sidebar-border);
  box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
}

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

/* Header Area */
.sidebar-header {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.02);
}

.sidebar-header .brand a {
  display: flex;
  align-items: center;
  color: #fff;
  text-decoration: none;
  font-size: 1.2rem;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: -0.5px;
}

.sidebar-header .brand img {
  height: 38px;
  margin-left: 12px;
  transition: all var(--transition-speed) var(--transition-timing);
}

html[dir="ltr"] .sidebar-header .brand img {
  margin-left: 0;
  margin-right: 12px;
}

.sidebar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

body.sidebar-collapsed .sidebar-header {
  padding: 0;
  justify-content: center;
}

body.sidebar-collapsed .brand-text {
  display: none;
}

body.sidebar-collapsed .brand img {
  margin: 0;
  transform: scale(1.1);
}

/* Action Buttons */
.sidebar-toggle-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--sidebar-border);
  color: var(--sidebar-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.sidebar-toggle-btn:hover {
  background: var(--sidebar-accent);
  color: #fff;
  border-color: var(--sidebar-accent);
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

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

/* Scrollable Menu Area */
.sidebar-scrollable {
  flex-grow: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 12px;
}

.sidebar-scrollable::-webkit-scrollbar {
  width: 4px;
}

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

.sidebar-scrollable::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

/* Menu Items */
.sidebar-menu {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-item {
  margin-bottom: 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  color: var(--sidebar-muted);
  text-decoration: none;
  padding: 12px 16px;
  border-radius: 12px;
  transition: all 0.25s var(--transition-timing);
  position: relative;
  white-space: nowrap;
  font-weight: 500;
  font-size: 0.925rem;
}

.sidebar-link:hover {
  color: var(--sidebar-accent);
  background-color: var(--sidebar-hover-bg);
  padding-right: 20px;
  /* Slight push on hover RTL */
}

html[dir="ltr"] .sidebar-link:hover {
  padding-right: 16px;
  padding-left: 20px;
}

.sidebar-item.active>.sidebar-link {
  color: var(--sidebar-accent);
  /* background-color: var(--sidebar-active-bg); */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.sidebar-item.active>.sidebar-link::before {
  content: '';
  position: absolute;
  right: 0;
  top: 20%;
  height: 60%;
  width: 3px;
  background-color: var(--sidebar-accent);
  border-radius: 0 4px 4px 0;
}

html[dir="ltr"] .sidebar-item.active>.sidebar-link::before {
  right: auto;
  left: 0;
  border-radius: 4px 0 0 4px;
}

.sidebar-icon {
  font-size: 1.15rem;
  min-width: 28px;
  text-align: center;
  margin-left: 12px;
  transition: transform 0.3s var(--transition-timing);
}

html[dir="ltr"] .sidebar-icon {
  margin-left: 0;
  margin-right: 12px;
}

.sidebar-link:hover .sidebar-icon {
  transform: scale(1.12);
  color: var(--sidebar-accent);
}

.sidebar-text {
  flex-grow: 1;
  opacity: 1;
  transition: opacity 0.2s;
}

.submenu-arrow {
  font-size: 0.75rem;
  transition: transform 0.3s var(--transition-timing);
  opacity: 0.7;
}

/* Collapsed State modifications */
body.sidebar-collapsed .sidebar-text,
body.sidebar-collapsed .submenu-arrow {
  opacity: 0;
  visibility: hidden;
  width: 0;
  display: none;
}

body.sidebar-collapsed .sidebar-link {
  justify-content: center;
  padding: 14px 0;
  margin: 0 10px;
}

body.sidebar-collapsed .sidebar-icon {
  margin: 0;
  font-size: 1.35rem;
}

/* Submenu Styles */
.sidebar-submenu {
  list-style: none;
  padding: 0;
  margin: 4px 0 8px 0;
  max-height: 0;
  overflow: hidden;
  transition: all 0.4s var(--transition-timing);
  /* background: rgba(0, 0, 0, 0.2); */
  border-radius: 12px;
}

.sidebar-item.open>.sidebar-link {
  background-color: rgba(255, 255, 255, 0.03);
  color: var(--sidebar-accent);
}

.sidebar-item.open>.sidebar-link .submenu-arrow {
  transform: rotate(180deg);
  color: var(--sidebar-accent);
}

.sidebar-submenu li a {
  display: flex;
  align-items: center;
  color: var(--sidebar-muted);
  text-decoration: none;
  padding: 10px 16px 10px 48px;
  font-size: 0.875rem;
  transition: all 0.2s ease;
  border-radius: 8px;
  margin: 2px 8px;
}

html[dir="ltr"] .sidebar-submenu li a {
  padding: 10px 48px 10px 16px;
}

.sidebar-submenu li a i {
  font-size: 0.8rem;
  margin-left: 10px;
  opacity: 0.6;
}

html[dir="ltr"] .sidebar-submenu li a i {
  margin-left: 0;
  margin-right: 10px;
}

.sidebar-submenu li a:hover {
  color: var(--sidebar-accent);
  background: rgba(16, 185, 129, 0.08);
  padding-right: 20px;
}

html[dir="ltr"] .sidebar-submenu li a:hover {
  padding-right: 16px;
  padding-left: 20px;
}

.submenu-header {
  padding: 12px 24px 6px 24px;
  font-size: 0.65rem;
  text-transform: uppercase;
  color: #475569;
  font-weight: 700;
  letter-spacing: 1px;
}

.submenu-divider {
  height: 1px;
  background-color: var(--sidebar-border);
  margin: 6px 20px;
  opacity: 0.5;
}

/* Hover expand for collapsed sidebar */
body.sidebar-collapsed .main-sidebar:hover {
  width: var(--sidebar-width);
  box-shadow: -15px 0 40px rgba(0, 0, 0, 0.4);
}

html[dir="ltr"] body.sidebar-collapsed .main-sidebar:hover {
  box-shadow: 15px 0 40px rgba(0, 0, 0, 0.4);
}

body.sidebar-collapsed .main-sidebar:hover .sidebar-text,
body.sidebar-collapsed .main-sidebar:hover .submenu-arrow {
  display: inline-block;
  opacity: 1;
  visibility: visible;
  width: auto;
}

body.sidebar-collapsed .main-sidebar:hover .sidebar-link {
  justify-content: flex-start;
  padding: 12px 16px;
  margin: 0;
}

body.sidebar-collapsed .main-sidebar:hover .sidebar-icon {
  margin-left: 12px;
}

html[dir="ltr"] body.sidebar-collapsed .main-sidebar:hover .sidebar-icon {
  margin-left: 0;
  margin-right: 12px;
}

body.sidebar-collapsed .main-sidebar:hover .sidebar-header {
  justify-content: space-between;
  padding: 0 24px;
}

body.sidebar-collapsed .main-sidebar:hover .brand-text {
  display: inline;
}

body.sidebar-collapsed .main-sidebar:hover .sidebar-actions {
  display: flex;
}

/* Mobile Responsiveness */
.mobile-top-bar {
  display: none;
  height: 64px;
  background-color: #fff;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.dark-theme .dark-theme-text-white {
  color: #fff !important;
}

.mobile-top-bar .brand a {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dark-theme .mobile-top-bar {
  background-color: #1e293b;
  border-bottom: 1px solid var(--sidebar-border);
}

.page-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1040;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.page-overlay.active {
  opacity: 1;
  visibility: visible;
}

@media (max-width: 992px) {
  body.use-sidebar .mobile-top-bar {
    display: flex;
  }

  body.use-sidebar .main-sidebar {
    transform: translateX(100%);
    box-shadow: none;
  }

  html[dir="ltr"] body.use-sidebar .main-sidebar {
    transform: translateX(-100%);
  }

  body.use-sidebar.sidebar-mobile-open .main-sidebar {
    transform: translateX(0);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.3);
  }

  html[dir="ltr"] body.use-sidebar.sidebar-mobile-open .main-sidebar {
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.3);
  }

  body.use-sidebar .main-content-wrapper {
    margin-right: 0 !important;
    width: 100% !important;
  }

  html[dir="ltr"] body.use-sidebar .main-content-wrapper {
    margin-left: 0 !important;
  }

  body.use-sidebar.sidebar-mobile-open {
    overflow: hidden;
  }
}

/* Switcher Button Styles */
.nav-switcher-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 18px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  color: #1e293b;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.dark-theme .nav-switcher-btn {
  background-color: #1e293b;
  border-color: #334155;
  color: #f1f5f9;
}

.nav-switcher-btn:hover {
  transform: translateY(-2px);
  border-color: var(--sidebar-accent);
  color: var(--sidebar-accent);
  box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.15);
}

.nav-switcher-btn i {
  font-size: 1rem;
}