/* Modern Sidebar Implementation - Fresh Start */

/* ===== LAYOUT VARIABLES ===== */
:root {
  --sidebar-width: 200px;
  --sidebar-collapsed-width: 0px;
  --sidebar-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-bg: var(--surface-elevated, #ffffff);
  --sidebar-border: var(--border-color, #e5e7eb);
  --sidebar-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --sidebar-text: var(--text-primary, var(--foreground, #374151));
  --sidebar-text-muted: var(--text-muted, var(--muted, #6b7280));
  --sidebar-hover-bg: var(--surface-secondary, #f3f4f6);
  --sidebar-active-bg: var(--status-info, var(--primary, #3b82f6));
  --sidebar-active-text: #ffffff;
  --mobile-breakpoint: 768px;
}

/* Dark mode adjustments */
[data-theme="dark"] {
  --sidebar-bg: var(--surface-elevated, #1f2937);
  --sidebar-border: var(--border-color, #374151);
  --sidebar-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --sidebar-text: var(--text-primary, var(--foreground, #f9fafb));
  --sidebar-text-muted: var(--text-muted, var(--muted, #9ca3af));
  --sidebar-hover-bg: var(--surface-secondary, #374151);
}

/* ===== MAIN LAYOUT ===== */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--background, #f9fafb);
  /* Prevent any unwanted borders or outlines */
  border: none;
  outline: none;
  /* Ensure clean layout */
  overflow-x: hidden;
}

/* ===== HEADER ===== */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  box-shadow: var(--sidebar-shadow);
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
}

.header-content {
  display: flex;
  align-items: center;
}

/* Show mobile toggle on all screen sizes */
.sidebar-toggle-mobile {
  display: flex;
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0.5rem;
  border-radius: 0.375rem;
}

.sidebar-toggle-mobile:hover {
  background: var(--sidebar-hover-bg);
}

/* Hide the old sidebar toggle since we're using the header toggle */
.sidebar-toggle {
  display: none;
}

/* Adjust layout for header */
.app-layout .app-main {
  margin-top: 64px;
  min-height: calc(100vh - 64px);
}

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  box-shadow: var(--sidebar-shadow);
  transition: var(--sidebar-transition);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Ensure content is properly contained */
  contain: layout style;
  /* Prevent any content from bleeding outside */
  isolation: isolate;
}

.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  transition: var(--sidebar-transition);
  min-height: 100vh;
  background: var(--background, #f9fafb);
  /* Prevent focus outline issues */
  outline: none;
  /* Prevent border artifacts */
  border: none;
  /* Ensure proper box model */
  box-sizing: border-box;
}

/* ===== SIDEBAR STATES ===== */

/* Collapsed state (desktop only) - completely hidden */
.app-sidebar.collapsed {
  width: 0;
  transform: translateX(-100%);
  opacity: 0;
  visibility: hidden;
}

.app-sidebar.collapsed+.app-main {
  margin-left: 0;
}

/* Mobile overlay state */
@media (max-width: 767px) {
  .app-sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
    box-shadow: none;
  }

  .app-sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--sidebar-shadow);
  }

  .app-main {
    margin-left: 0;
  }

  .app-sidebar.collapsed+.app-main {
    margin-left: 0;
  }
}

/* Mobile overlay backdrop */
.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.sidebar-backdrop.active {
  opacity: 1;
  visibility: visible;
}

/* ===== SIDEBAR HEADER ===== */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  min-height: 64px;
  /* Prevent double borders - critical fix */
  border: none !important;
  border-bottom: none !important;
  border-top: none !important;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--sidebar-text);
  font-weight: 600;
  font-size: 1.125rem;
  transition: var(--sidebar-transition);
}

.sidebar-brand i {
  font-size: 1.5rem;
  color: var(--primary, #3b82f6);
  flex-shrink: 0;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--sidebar-text-muted);
  font-size: 1.25rem;
  padding: 0.5rem;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
}

/* Collapsed state - sidebar is completely hidden, no special rules needed */

/* ===== SIDEBAR CONTENT ===== */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 0;
}

.sidebar-nav {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-items {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-section {
  margin-bottom: 2rem;
}

.nav-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sidebar-text-muted);
  padding: 0 1rem;
  margin-bottom: 0.5rem;
  transition: var(--sidebar-transition);
}

.nav-item {
  margin: 0.125rem 0.5rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--sidebar-text, #374151);
  text-decoration: none;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  font-weight: 500;
  position: relative;
}

/* Ensure nav links are always visible with proper fallbacks */
.nav-link {
  color: var(--sidebar-text, var(--text-primary, var(--foreground, #374151))) !important;
}

.nav-link:hover {
  background: var(--state-hover, var(--sidebar-hover-bg, var(--surface-secondary, #f3f4f6)));
  color: var(--sidebar-text, var(--text-primary, var(--foreground, #374151))) !important;
}

/* Dark theme specific fixes */
[data-theme="dark"] .nav-link {
  color: var(--sidebar-text, var(--text-primary, var(--foreground, #f9fafb))) !important;
}

[data-theme="dark"] .nav-link:hover {
  color: var(--sidebar-text, var(--text-primary, var(--foreground, #f9fafb))) !important;
}

.nav-link:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
}

.nav-link.active {
  background: var(--sidebar-active-bg, var(--primary, #3b82f6));
  color: var(--sidebar-active-text, #ffffff) !important;
  font-weight: 600;
}

/* Better contrast for active state - align with main UI */
.nav-link.active {
  background: var(--status-info, var(--primary, #3b82f6)) !important;
  color: #ffffff !important;
  border-left: 3px solid var(--primary, #3b82f6);
  font-weight: 600;
}

/* Dark theme active state */
[data-theme="dark"] .nav-link.active {
  background: var(--status-info, var(--primary, #3b82f6)) !important;
  color: #ffffff !important;
  border-left: 3px solid var(--primary, #3b82f6);
}

.nav-link i {
  font-size: 1.125rem;
  flex-shrink: 0;
  width: 1.25rem;
  text-align: center;
}

.nav-link-text {
  transition: var(--sidebar-transition);
  white-space: nowrap;
}

/* Collapsed state - sidebar is completely hidden, no content rules needed */

/* No tooltips needed since sidebar is completely hidden when collapsed */

/* ===== USER MENU IN HEADER ===== */

.user-menu-container {
  position: relative;
  /* Ensure dropdown is contained within this container */
  overflow: visible;
  z-index: 1000;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  color: var(--sidebar-text);
}

.user-menu:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
}

.user-menu:focus {
  outline: 2px solid var(--primary, #3b82f6);
  outline-offset: 2px;
}

.user-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: white;
  color: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
  border: 1px solid var(--sidebar-border, #e5e7eb);
}

.user-info {
  flex: 1;
  min-width: 0;
  transition: var(--sidebar-transition);
}

.user-name {
  font-weight: 500;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.75rem;
  color: var(--sidebar-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-chevron {
  font-size: 0.875rem;
  color: var(--sidebar-text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.user-menu[aria-expanded="true"] .user-menu-chevron {
  transform: rotate(180deg);
}

/* User Menu Dropdown */
.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: var(--sidebar-bg);
  border: 1px solid var(--sidebar-border);
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-0.5rem);
  transition: all 0.15s ease-out;
  z-index: 1002;
  min-width: 200px;
  max-height: 200px;
  overflow: hidden;
}

.user-menu-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--sidebar-text);
  text-decoration: none;
  transition: all 0.2s ease;
  border-radius: 0.375rem;
  margin: 0.25rem;
}

.user-menu-item:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
}

.user-menu-item:focus {
  outline: 2px solid var(--primary, #3b82f6);
  outline-offset: 2px;
}

.user-menu-item i {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.user-menu-item span {
  font-weight: 500;
  font-size: 0.875rem;
}

/* User menu is in header, not affected by sidebar collapse */

/* Mobile adjustments for header layout */
@media (max-width: 767px) {
  .user-menu-dropdown {
    right: 1rem;
    left: auto;
    min-width: 180px;
  }

  .user-menu {
    padding: 0.5rem;
  }
}



/* ===== ANIMATIONS ===== */
@keyframes slideIn {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: translateX(0);
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
  }

  to {
    transform: translateX(-100%);
  }
}

/* ===== ACCESSIBILITY ===== */
.sidebar-toggle:focus,
.nav-link:focus,
.user-menu:focus {
  outline: 2px solid var(--primary, #3b82f6);
  outline-offset: 2px;
}

/* Prevent unwanted focus outlines and borders in main content */
.app-main:focus,
.app-main *:focus:not(input):not(textarea):not(select):not(button):not(a):not([tabindex]) {
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
}

/* Ensure proper focus styles for interactive elements */
.app-main input:focus,
.app-main textarea:focus,
.app-main select:focus,
.app-main button:focus,
.app-main a:focus,
.app-main [tabindex]:focus {
  outline: 2px solid var(--primary, #3b82f6);
  outline-offset: 2px;
}

/* Prevent any border artifacts between sidebar and main content */
.app-sidebar::after,
.app-main::before {
  display: none !important;
}

/* Ensure no pseudo-elements create unwanted lines */
.app-layout *::before,
.app-layout *::after {
  border: none !important;
}

/* Specific fix for any resize handles or similar elements */
.app-main {
  resize: none !important;
}

/* Prevent any selection artifacts */
.app-layout::selection,
.app-layout *::selection {
  background: transparent;
}

/* Additional fixes for white line issue */
.app-layout,
.app-layout * {
  /* Prevent any unwanted borders */
  border-left: none !important;
  border-right: none !important;
}

/* Restore necessary borders only where needed */
.app-sidebar {
  border-right: 1px solid var(--sidebar-border) !important;
}

/* Prevent any click/focus artifacts in main content */
.app-main * {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Restore text selection for content elements */
.app-main input,
.app-main textarea,
.app-main [contenteditable],
.app-main p,
.app-main span,
.app-main div[class*="text"],
.app-main .selectable {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {

  .app-sidebar,
  .app-main,
  .sidebar-backdrop,
  .nav-link,
  .sidebar-toggle {
    transition: none;
  }
}