/**
 * Karwan88 横向标签页式导航系统
 * 设计理念：顶部一级菜单 + 下方横向二级标签页
 * 参考：Microsoft 365, Google Workspace, Salesforce
 */

/* ==================== 重置topbar样式 ==================== */

.topbar {
  padding: 0 !important;
  margin: 0 !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  height: auto !important;
  overflow: visible !important;
  position: sticky !important;
  top: 0 !important;
  z-index: 1000 !important;
  /* 突破父容器限制，拉满整个屏幕宽度 */
  width: 100vw !important;
  margin-left: calc(-50vw + 50%) !important;
  margin-right: calc(-50vw + 50%) !important;
}

/* ==================== 导航栏主容器 ==================== */

.system-navigation {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  position: relative;
  width: 100%;
}

.nav-container {
  max-width: 100%;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

/* ==================== Logo ==================== */

.nav-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
  font-weight: 600;
  font-size: 18px;
  cursor: pointer;
  transition: opacity 0.2s;
  flex-shrink: 0;
}

.nav-logo:hover {
  opacity: 0.9;
}

.logo-icon {
  font-size: 24px;
}

.logo-text {
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* ==================== 一级菜单（横向） ==================== */

.nav-menu {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  margin: 0 32px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.nav-menu::-webkit-scrollbar {
  display: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  transition: all 0.2s;
  white-space: nowrap;
  cursor: pointer;
  position: relative;
}

.nav-item i {
  font-size: 16px;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.25);
  color: white;
  font-weight: 600;
}

.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 20px;
  right: 20px;
  height: 3px;
  background: white;
  border-radius: 2px 2px 0 0;
}

/* ==================== 右侧工具栏 ==================== */

.nav-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.nav-tool-btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.nav-tool-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.nav-tool-btn .badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
}

/* ==================== 用户菜单 ==================== */

.nav-user-menu {
  position: relative;
}

.nav-user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
}

.nav-user-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.user-avatar {
  font-size: 20px;
}

.user-name {
  font-weight: 500;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-icon {
  font-size: 10px;
  transition: transform 0.2s;
}

.nav-user-menu:hover .dropdown-icon {
  transform: rotate(180deg);
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  min-width: 240px;
  padding: 8px 0;
  display: none;
  z-index: 10000;
  border: 1px solid rgba(0, 0, 0, 0.05);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

/* 显示下拉菜单 - 通过JavaScript控制 */
.user-dropdown[style*="display: block"] {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* 备用：hover效果（如果JavaScript未加载） */
.nav-user-menu:hover .user-dropdown {
  display: block;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.user-dropdown .dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: #374151;
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
}

.user-dropdown .dropdown-item:hover {
  background: #f3f4f6;
  color: #1e3a8a;
}

.user-dropdown .dropdown-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 8px 0;
}

/* 用户信息内联显示（顶部按钮） */
.user-info-inline {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.user-info-inline .user-name {
  font-size: 14px;
  font-weight: 500;
}

.user-info-inline .user-role {
  font-size: 11px;
  opacity: 0.8;
}

/* 用户信息卡片（下拉菜单顶部） */
.user-info-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  margin: -8px 0 0 0;
  border-radius: 8px 8px 0 0;
}

.user-avatar-large {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name-large {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  opacity: 0.9;
}

.user-role-badge {
  background: rgba(255, 255, 255, 0.25);
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 500;
}

.user-dept {
  opacity: 0.8;
}

/* 下拉菜单项样式增强 */
.user-dropdown .dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: #374151;
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  position: relative;
}

.user-dropdown .dropdown-item .item-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.user-dropdown .dropdown-item .item-text {
  flex: 1;
}

/* 退出按钮特殊样式 - 醒目设计 */
.user-dropdown .logout-item {
  color: #dc2626;
  font-weight: 500;
  margin-top: 4px;
}

.user-dropdown .logout-item:hover {
  background: #fee2e2;
  color: #991b1b;
}

.user-dropdown .logout-item .logout-arrow {
  font-size: 16px;
  font-weight: bold;
  opacity: 0;
  transform: translateX(-10px);
  transition: all 0.3s;
}

.user-dropdown .logout-item:hover .logout-arrow {
  opacity: 1;
  transform: translateX(0);
}

/* ==================== 二级菜单标签页（横向） ==================== */

.nav-submenu-bar {
  background: white;
  border-bottom: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  display: none;
  /* 突破父容器限制，拉满整个屏幕宽度 */
  width: 100vw !important;
  margin-left: calc(-50vw + 50%) !important;
  margin-right: calc(-50vw + 50%) !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  /* 优化过渡效果，防止闪烁 */
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}

.nav-submenu-bar.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.nav-submenu-container {
  max-width: 100%;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.nav-submenu-container::-webkit-scrollbar {
  height: 4px;
}

.nav-submenu-container::-webkit-scrollbar-track {
  background: #f3f4f6;
}

.nav-submenu-container::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 2px;
}

.nav-submenu-container::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

.nav-submenu-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  color: #6b7280;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  transition: all 0.2s;
  white-space: nowrap;
  cursor: pointer;
  position: relative;
  border-bottom: 2px solid transparent;
}

.nav-submenu-item i {
  font-size: 14px;
}

.nav-submenu-item:hover {
  background: #f3f4f6;
  color: #1e3a8a;
}

.nav-submenu-item.active {
  color: #1e3a8a;
  font-weight: 600;
  border-bottom-color: #1e3a8a;
  background: #eff6ff;
}

.nav-submenu-item .badge {
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
}

/* ==================== 移动端适配 ==================== */

.nav-mobile-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-mobile-toggle:hover {
  background: rgba(255, 255, 255, 0.2);
}

@media (max-width: 768px) {
  .nav-container {
    padding: 0 16px;
    height: 56px;
  }

  .nav-logo .logo-text {
    display: none;
  }

  .nav-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
    flex-direction: column;
    gap: 0;
    margin: 0;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  }

  .nav-menu.active {
    display: flex;
  }

  .nav-item {
    width: 100%;
    justify-content: flex-start;
  }

  .nav-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .nav-toolbar {
    gap: 8px;
  }

  .nav-tool-btn {
    width: 36px;
    height: 36px;
  }

  .user-name {
    display: none;
  }

  .nav-submenu-container {
    padding: 0 16px;
    gap: 4px;
  }

  .nav-submenu-item {
    padding: 6px 12px;
    font-size: 12px;
  }
}

/* ==================== 搜索弹窗 ==================== */

.search-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10001;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 100px;
}

.search-modal-content {
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 600px;
  max-height: 70vh;
  overflow: hidden;
  animation: searchModalIn 0.2s ease-out;
}

@keyframes searchModalIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px;
  border-bottom: 1px solid #e5e7eb;
}

.search-icon {
  font-size: 20px;
  color: #9ca3af;
}

#search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 16px;
  color: #111827;
}

.search-close {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: #f3f4f6;
  border: none;
  color: #6b7280;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
}

.search-close:hover {
  background: #e5e7eb;
  color: #111827;
}

/* ==================== 三级菜单 ==================== */

.nav-submenu-item-wrapper {
  position: relative;
}

.nav-submenu-item.has-children {
  cursor: pointer;
  position: relative;
  padding-right: 32px;
}

.nav-submenu-item.has-children .submenu-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  transition: transform 0.3s;
  color: #9ca3af;
}

.nav-submenu-item-wrapper.expanded .submenu-arrow {
  transform: translateY(-50%) rotate(180deg);
}

.nav-submenu-item-wrapper.expanded .nav-submenu-item.has-children {
  background: #eff6ff;
  color: #1e3a8a;
}

.nav-third-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: white;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 180px;
  padding: 8px 0;
  z-index: 1000;
  margin-top: 4px;
  border: 1px solid #e5e7eb;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s, transform 0.2s;
}

.nav-third-menu.active {
  display: block;
}

.nav-third-menu.expanded {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.nav-third-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  color: #6b7280;
  text-decoration: none;
  font-size: 13px;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-third-menu-item i {
  font-size: 12px;
  width: 16px;
  text-align: center;
}

.nav-third-menu-item:hover {
  background: #f3f4f6;
  color: #1e3a8a;
}

.nav-third-menu-item.active {
  background: #eff6ff;
  color: #1e3a8a;
  font-weight: 600;
}

.nav-third-menu-item .badge {
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: auto;
}
