/* =====================================================
   CM Group - Product-Specific Header Navigation
   Version: 2.0 - Investment Bank Grade
   ===================================================== */

/* ===== CSS 变量 ===== */
:root {
  /* Header 尺寸 */
  --header-height: 56px;
  
  /* 基础色 */
  --header-bg: #ffffff;
  --header-border: #e8e8e8;
  --header-text: #1a1a1a;
  --header-text-muted: #71717a;
  
  /* 产品主题色（由页面覆盖） */
  --product-color: #024d8f;
  --product-color-light: rgba(2, 77, 143, 0.08);
  
  /* 交互色 */
  --hover-bg: #f4f4f5;
  --active-bg: #e4e4e7;
  --focus-ring: rgba(0, 0, 0, 0.12);
}

/* 产品主题色定义 */
[data-product="bauxite"] {
  --product-color: #F15A29;
  --product-color-light: rgba(241, 90, 41, 0.1);
}

[data-product="alumina"] {
  --product-color: #8DC63F;
  --product-color-light: rgba(141, 198, 63, 0.1);
}

[data-product="tungsten"] {
  --product-color: #7B6BA0;
  --product-color-light: rgba(123, 107, 160, 0.1);
}

[data-product="primary_al"] {
  --product-color: #8E9298;
  --product-color-light: rgba(142, 146, 152, 0.1);
}

[data-product="magnesium"] {
  --product-color: #B71C1C;
  --product-color-light: rgba(183, 28, 28, 0.1);
}

[data-product="scandium"] {
  --product-color: #3F51B5;
  --product-color-light: rgba(63, 81, 181, 0.1);
}

/* ===== Header 主容器 ===== */
.product-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
}

/* Hide old header when product-header is used */
[data-product] .header:not(.product-header) {
  display: none !important;
}

.product-header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 32px;
  display: flex;
  align-items: center;
  height: var(--header-height);
  gap: 20px;
}

/* ===== Logo ===== */
.ph-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.ph-logo img {
  height: 28px;
}

.ph-logo-divider {
  display: none;
}

/* ===== 产品切换器 ===== */
.product-switcher {
  position: relative;
  flex-shrink: 0;
  margin-left: 12px;
}

.product-switcher-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--hover-bg);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.12s ease;
  font-family: inherit;
}

.product-switcher-btn:hover {
  background: var(--active-bg);
}

.product-switcher-btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.product-switcher-btn.open {
  background: var(--active-bg);
  border-color: var(--header-border);
}

.product-switcher-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--product-color);
  color: #fff;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: -0.5px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.product-switcher-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--header-text);
  letter-spacing: -0.2px;
}

.product-switcher-arrow {
  font-size: 8px;
  color: var(--header-text-muted);
  transition: transform 0.15s ease;
  margin-left: 2px;
}

.product-switcher-btn.open .product-switcher-arrow {
  transform: rotate(180deg);
}

/* 产品下拉菜单 */
.product-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 260px;
  background: #fff;
  border: 1px solid var(--header-border);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.04);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all 0.15s ease;
  z-index: 1001;
}

.product-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.product-dropdown-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--header-border);
  font-size: 10px;
  font-weight: 600;
  color: var(--header-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.product-dropdown-list {
  padding: 6px;
}

.product-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--header-text);
  transition: background 0.1s ease;
}

.product-dropdown-item:hover {
  background: var(--hover-bg);
}

.product-dropdown-item:focus {
  outline: none;
  background: var(--hover-bg);
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

.product-dropdown-item.active {
  background: var(--product-color-light);
}

.product-dropdown-item-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.product-dropdown-item-info {
  flex: 1;
  min-width: 0;
}

.product-dropdown-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--header-text);
  letter-spacing: -0.1px;
}

.product-dropdown-item-desc {
  font-size: 11px;
  color: var(--header-text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-dropdown-item-check {
  color: var(--product-color);
  font-size: 14px;
  font-weight: 600;
}

.product-dropdown-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--header-border);
}

.product-dropdown-footer a {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--header-text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.1s ease;
}

.product-dropdown-footer a:hover {
  color: var(--header-text);
}

/* ===== 子功能导航 ===== */
.product-nav {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 1;
  margin-left: 16px;
  height: 100%;
}

.product-nav-item {
  position: relative;
  padding: 0 16px;
  height: 100%;
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--header-text-muted);
  text-decoration: none;
  transition: color 0.1s ease;
  white-space: nowrap;
  letter-spacing: -0.1px;
}

.product-nav-item:hover {
  color: var(--header-text);
}

.product-nav-item:focus {
  outline: none;
  color: var(--header-text);
}

.product-nav-item.active {
  color: var(--header-text);
  font-weight: 600;
}

.product-nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 16px;
  right: 16px;
  height: 2px;
  background: var(--header-text);
  border-radius: 2px 2px 0 0;
}

/* ===== 右侧操作区 ===== */
.product-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.ph-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--header-text-muted);
  transition: all 0.1s ease;
}

.ph-icon-btn:hover {
  background: var(--hover-bg);
  color: var(--header-text);
}

.ph-icon-btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.ph-icon-btn svg {
  width: 18px;
  height: 18px;
}

/* 用户菜单 */
.ph-user-menu {
  position: relative;
}

.ph-user-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  background: transparent;
  border: 1px solid var(--header-border);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.1s ease;
  font-family: inherit;
}

.ph-user-btn:hover {
  background: var(--hover-bg);
  border-color: #d1d5db;
}

.ph-user-btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.ph-user-avatar {
  width: 26px;
  height: 26px;
  background: var(--product-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

.ph-user-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--header-text);
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ph-user-arrow {
  font-size: 8px;
  color: var(--header-text-muted);
}

/* 用户下拉菜单 */
.ph-user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: #fff;
  border: 1px solid var(--header-border);
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.04);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all 0.15s ease;
  z-index: 1001;
}

.ph-user-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.ph-user-dropdown a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--header-text);
  text-decoration: none;
  transition: background 0.1s ease;
}

.ph-user-dropdown a:first-child {
  border-radius: 8px 8px 0 0;
}

.ph-user-dropdown a:last-child {
  border-radius: 0 0 8px 8px;
}

.ph-user-dropdown a:hover {
  background: var(--hover-bg);
}

.ph-user-dropdown a:focus {
  outline: none;
  background: var(--hover-bg);
}

.ph-user-dropdown a svg {
  width: 15px;
  height: 15px;
  color: var(--header-text-muted);
}

.ph-user-dropdown .divider {
  height: 1px;
  background: var(--header-border);
  margin: 4px 0;
}

.ph-user-dropdown .logout {
  color: #dc2626;
}

.ph-user-dropdown .logout svg {
  color: #dc2626;
}

/* ===== 响应式 ===== */
@media (max-width: 1024px) {
  .product-header-inner {
    padding: 0 20px;
    gap: 12px;
  }
  
  .product-nav-item {
    padding: 0 12px;
    font-size: 12px;
  }
  
  .product-nav-item.active::after {
    left: 12px;
    right: 12px;
  }
  
  .ph-user-name {
    display: none;
  }
}

@media (max-width: 768px) {
  .product-header-inner {
    padding: 0 16px;
    gap: 8px;
  }
  
  .product-switcher-name {
    display: none;
  }
  
  .product-nav {
    display: none;
  }
  
  /* 移动端显示汉堡菜单 */
  .ph-mobile-menu-btn {
    display: flex;
  }
}

/* 页面内容区域padding */
.page-with-product-header {
  padding-top: calc(var(--header-height) + 24px);
}

/* ===== Dropdown Overlay ===== */
.product-dropdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: transparent;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.product-dropdown-overlay.active {
  pointer-events: auto;
  opacity: 1;
}

/* ===== Page Layout Adjustments for Product Header ===== */
/* Any page with product-header gets layout fix automatically */
body:has(.product-header) .sidebar {
  top: 56px;
  max-height: calc(100vh - 56px);
}
body:has(.product-header) .detail-panel {
  top: 56px;
  height: calc(100vh - 56px);
}
body:has(.product-header) #mineProfile {
  top: 56px;
  height: calc(100vh - 56px);
}
body:has(.product-header) .main-layout {
  min-height: calc(100vh - 56px);
  padding-top: 56px;
}

/* Keep data-product selectors for explicit overrides */
[data-product] .sidebar {
  top: 56px;
  max-height: calc(100vh - 56px);
}

[data-product] .detail-panel {
  top: 56px;
  height: calc(100vh - 56px);
}

[data-product] #mineProfile {
  top: 56px;
  height: calc(100vh - 56px);
}

[data-product] .main-layout {
  min-height: calc(100vh - 56px);
  padding-top: 56px;
}

/* ===== Keyboard Navigation ===== */
.product-nav-item:focus-visible,
.product-dropdown-item:focus-visible,
.product-switcher-btn:focus-visible,
.ph-user-btn:focus-visible,
.ph-icon-btn:focus-visible {
  outline: 2px solid var(--product-color);
  outline-offset: 2px;
}

/* ===== Smooth Transitions ===== */
* {
  -webkit-tap-highlight-color: transparent;
}

.product-header *,
.product-header *::before,
.product-header *::after {
  box-sizing: border-box;
}
