body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-panel);
  backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  padding: var(--space-6) var(--space-4);
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 100;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Prevent flexbox overflow */
  overflow: hidden;
}

.header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-8);
  background: var(--bg-panel);
  backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  position: sticky;
  top: 0;
  z-index: 90;
}

.container {
  padding: var(--space-8);
  flex: 1;
  overflow-y: auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-header);
  font-weight: 600;
  font-size: var(--text-xl);
  color: var(--text-primary);
  margin-bottom: var(--space-10);
  padding: 0 var(--space-2);
}

.logo-icon {
  display: block;
  flex: 0 0 auto;
  width: 36px;
  height: 40px;
  background: var(--accent-blue);
  filter: drop-shadow(0 8px 11px rgba(27, 96, 63, 0.28));
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 44'%3E%3Cpath d='M20 1.25C25.8 5.2 32.3 7.3 38.25 7.7V20.1C38.25 30.2 31.7 38.2 20 42.75C8.3 38.2 1.75 30.2 1.75 20.1V7.7C7.7 7.3 14.2 5.2 20 1.25Z' fill='black'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 44'%3E%3Cpath d='M20 1.25C25.8 5.2 32.3 7.3 38.25 7.7V20.1C38.25 30.2 31.7 38.2 20 42.75C8.3 38.2 1.75 30.2 1.75 20.1V7.7C7.7 7.3 14.2 5.2 20 1.25Z' fill='black'/%3E%3C/svg%3E") center / contain no-repeat;
}


.nav-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-standard);
  color: var(--text-primary);
  transition: var(--transition-base);
  font-weight: 500;
  font-size: var(--text-sm);
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.nav-item.active {
  background-color: rgba(27, 166, 122, 0.1);
  color: var(--text-primary);
  box-shadow: inset 0 0 10px rgba(27, 166, 122, 0.2);
  border: 1px solid rgba(27, 166, 122, 0.3);
}

/* === Accordion Nav === */
.accordion-item {
  border-radius: var(--radius-md);
  overflow: hidden;
}

.accordion-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-standard);
  color: var(--text-primary);
  cursor: pointer;
  font-weight: 500;
  font-size: var(--text-sm);
  transition: var(--transition-base);
  user-select: none;
}

.accordion-link:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.accordion-item.open > .accordion-link {
  color: var(--text-primary);
  background-color: rgba(27, 166, 122, 0.1);
}

.accordion-arrow {
  width: 16px !important;
  height: 16px !important;
  transition: transform 180ms var(--ease-out);
  flex-shrink: 0;
}

.accordion-item.open .accordion-arrow {
  transform: rotate(180deg);
}

.accordion-submenu {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 0;
  overflow-y: auto;
  transition: max-height 220ms var(--ease-out);
  padding-left: var(--space-4);
  scrollbar-width: thin;
  scrollbar-color: var(--glass-border) transparent;
}

.accordion-submenu::-webkit-scrollbar {
  width: 4px;
}

.accordion-submenu::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 10px;
}

.accordion-item.open .accordion-submenu {
  /* max-height set by JS */
}

.accordion-subitem {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: var(--text-sm);
  transition: var(--transition-base);
  margin-top: 2px;
}

.accordion-subitem:hover {
  background-color: var(--glass-bg-hover);
  color: var(--text-primary);
}

.accordion-subitem.active {
  background-color: rgba(27, 96, 63, 0.15);
  color: var(--text-primary);
  font-weight: var(--font-semibold);
}

.accordion-subitem i {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.user-profile {
  margin-top: auto;
  padding: var(--space-4);
  background-color: var(--bg-element);
  border-radius: var(--radius-standard);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--bg-panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text-primary);
  border: 2px solid rgba(27, 39, 36, 0.1);
}

.nav-item i,
.accordion-link i,
.accordion-subitem i,
.header .btn i {
  color: #ffffff !important;
  stroke: currentColor !important;
}

.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name {
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
}

/* === Mobile Adaptation === */
@media (max-width: 768px) {
  #app {
    flex-direction: column;
  }
  
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(280px, 86vw);
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform 240ms var(--ease-drawer);
    z-index: 1000;
    padding-bottom: max(var(--space-6), env(safe-area-inset-bottom));
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
  }
  
  .mobile-overlay.active {
    display: block;
  }

  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-standard);
  }
  
  .desktop-only {
    display: none;
  }

  .header {
    padding: 0 var(--space-4);
    justify-content: space-between;
    gap: var(--space-2);
  }

  .header > div:first-child {
    min-width: 0;
    gap: var(--space-2) !important;
  }
  
  .header h1 {
    overflow: hidden;
    min-width: 0;
    font-size: 16px !important;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .header-actions {
    flex: 0 0 auto;
    gap: var(--space-2) !important;
  }

  .header-actions .btn {
    width: 40px;
    padding: 0;
  }

  .container {
    padding: var(--space-4);
    padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
    overflow-x: hidden;
  }

  .card {
    padding: var(--space-4);
  }
  
  /* Tables horizontally scrollable */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
}
