/* ===== CSS Variables and Root Settings ===== */
:root {
  --theme-color: #87ceeb; /* Light Sky Blue */
  --theme-color-dark: #5f9ea0; /* Cadet Blue */
  --text-color-dark: #2c3e50; /* Darker text for contrast */
  --card-shadow: rgba(0, 0, 0, 0.1);
  --card-hover-shadow: rgba(135, 206, 235, 0.25); /* Shadow based on theme color */
}

/* ===== Global Styles ===== */
* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
  height: 100%;
  /* 确保不影响 position: fixed 元素 */
  transform: none;
}

body {
  font-family: 'Segoe UI', 'Roboto', 'Calibri', sans-serif;
  line-height: 1.6;
  margin: 0;
  padding: 0;
  background-color: #f4f7f6;
  padding-top: 56px; /* Navbar height */
  overflow-x: hidden;
  overflow-y: auto;
  height: 100%;
  min-height: 100vh;
  /* ❌ 移除 position: relative - 这会导致 fixed 元素抖动 */
  /* position: relative !important; */
  /* 确保不影响 position: fixed 元素 */
  transform: none;
  perspective: none;
  filter: none;
}

/* ===== Scrollbar Styles ===== */
::-webkit-scrollbar {
  width: 12px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* ===== Loader Animation ===== */
.loader-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #ffffff;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition: opacity 0.5s ease;
}

.loader-gif {
  width: 150px;
  height: 150px;
}

/* ===== Navigation Bar Styles ===== */
.navbar-nav .nav-link {
  font-size: 1rem !important;
  padding: 0.5rem 0.75rem !important;
}

.navbar-brand {
  font-size: 1.25rem !important;
}

.navbar-collapse {
  overflow: visible !important;
}

.navbar {
  overflow: visible !important;
}

/* ===== Main Layout ===== */
.content-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  overflow: visible;
}

/* ===== First Block (Hero Section) ===== */
#first-block {
  margin: 10vh 0 30vh 0;
  width: 80%;
  padding: 40px;
  text-align: center;
}

#first-block h2,
#first-block p {
  color: var(--text-color-dark);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 1s ease-out, transform 1s ease-out;
}

#first-block h2 {
  font-size: 3rem;
  font-weight: 700;
  font-style: normal;
}

#first-block p {
  font-size: 1.5rem;
  transition-delay: 0.5s;
}

.fade-in {
  opacity: 1 !important;
  transform: translateY(0) !important;
}

/* ===== Card Styles ===== */
.card-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin-top: 50px;
  align-items: center;
  gap: 30px;
}

.card {
  width: 90%;
  max-width: 1000px;
  background-color: #ffffff;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 4px 6px var(--card-shadow);
  transition: all 0.3s ease;
  cursor: pointer;
  border: none;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 17px var(--card-hover-shadow);
}

.card-content {
  display: flex;
  align-items: center;
}

.card-content-reverse {
  display: flex;
  align-items: center;
  flex-direction: row-reverse;
}

.card-image {
  width: 300px;
  height: 300px;
  object-fit: cover;
}

.card-text {
  flex: 1;
  padding: 30px;
}

.card-preview {
  font-size: 1.8rem;
  color: var(--text-color-dark);
  margin: 0;
  font-weight: 600;
}

.card-full-content {
  display: none;
  font-size: 1.1rem;
  color: #666;
  margin-top: 15px;
}

.card.expanded .card-full-content {
  display: block;
}

/* ===== Fade-in Section Styles ===== */
.fade-section {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
  margin-top: 15vh;
  width: 100%;
  display: flex;
  justify-content: center;
}

.fade-section.active {
  opacity: 1;
  transform: translateY(0);
}

/* ===== Additional Content Section ===== */
.additional-content {
  width: 90%;
  max-width: 1000px;
  margin-bottom: 30px;
  background-color: #ffffff;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 4px 6px var(--card-shadow);
  padding: 30px;
  display: flex;
  align-items: center;
}

.additional-content-text {
  flex: 1;
  padding: 30px;
}

.additional-content-text h3 {
  font-size: 2rem;
  color: var(--text-color-dark);
  margin-top: 0;
}

.additional-content-image {
  width: 40%;
  height: auto;
  object-fit: contain;
  margin: 40px;
}

.read-more-wrapper {
  margin-top: 20px;
}

.read-more-button {
  padding: 10px 20px;
  background-color: var(--theme-color);
  color: white;
  text-decoration: none;
  border-radius: 5px;
  font-size: 1rem;
  font-weight: 500;
  transition: background-color 0.3s ease;
}

.read-more-button:hover {
  background-color: var(--theme-color-dark);
  color: white;
}

/* ===== A.P.E. Solution Section ===== */
.ape-solution {
  width: 90%;
  max-width: 1000px;
  margin-bottom: 30px;
  background-color: #ffffff;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 4px 6px var(--card-shadow);
  padding: 30px;
  text-align: center;
}

.ape-solution h2 {
  font-size: 2.5rem;
  color: var(--text-color-dark);
  margin-bottom: 40px;
}

.ape-solution h2 span {
  color: var(--theme-color);
}

.ape-row {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 30px;
  text-align: left;
}

.ape-icon {
  width: 150px;
  height: 150px;
  margin-right: 30px;
}

.ape-text {
  flex: 1;
}

.ape-title {
  font-size: 1.5rem;
  color: var(--text-color-dark);
  margin: 0 0 5px 0;
}

.highlight-letter {
  color: var(--theme-color);
  font-size: 1.5em;
  font-weight: 700;
}

.ape-description {
  font-size: 1.1rem;
  color: #666;
  margin: 0;
}

/* ===== Last Block (Footer Section) ===== */
#last-block {
  padding: 40px;
  text-align: center;
  margin-top: 15vh;
  margin-bottom: 15vh;
}

#last-block h4,
#last-block h2 {
  color: var(--text-color-dark);
  font-style: italic;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

#last-block h4 {
  font-size: 1.5rem;
}

#last-block h2 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-top: 2rem;
  color: var(--theme-color-dark);
}

/* ===== Sidebar Styles (参考 bnuzh-china) ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.5vh; /* 从1vh减小到0.5vh */
  height: fit-content;
  font-family: 'Segoe UI', 'Roboto', 'Calibri', sans-serif;
  /* ✅ 关键修复: 移除!important,允许JavaScript动态切换position */
  /* ⚠️ 不设置 position 和 top，完全由 JavaScript 控制三段式定位 */
  /* position: fixed; */
  /* top: 80px; */
  left: 20px; /* 距离左侧的距离 */
  width: 260px; /* 从280px减小到260px */
  min-width: 260px;
  padding: 1.5rem 1.2rem; /* 从2rem 1.5rem减小到1.5rem 1.2rem */
  background-color: #ffffff;
  border-radius: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  z-index: 900; /* 提高层级,确保在其他元素之上 */
  /* 防止父元素transform影响 */
  transform: none !important;
  /* 平滑的transform动画(防遮挡方案) */
  transition: transform 0.3s ease-out;
}

/* Sidebar滚动条样式优化 */
.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: #555;
}

.sidebar-title {
  font-size: 1.5rem; /* 从1.8rem减小到1.5rem */
  font-weight: 700;
  margin-bottom: 1.2rem; /* 从1.5rem减小到1.2rem */
  color: var(--theme-color-dark);
  border-bottom: 3px solid var(--theme-color);
  padding-bottom: 0.5rem;
}

.sidebar-nav-item {
  font-size: 0.9rem; /* 从1rem减小到0.9rem */
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  margin-bottom: 0.6rem; /* 从0.8rem减小到0.6rem */
  padding: 0.5rem 0.8rem; /* 从0.6rem 1rem减小到0.5rem 0.8rem */
  border-radius: 8px;
  transition: all 0.3s ease;
  color: var(--text-color-dark);
}

.sidebar-nav-item:hover {
  background-color: rgba(135, 206, 235, 0.1);
  color: var(--theme-color-dark);
  transform: translateX(5px);
}

.sidebar-nav-item.active,
.sidebar-nav-item.bright {
  color: var(--theme-color);
  font-weight: 700;
  font-size: 1rem; /* 从1.1rem减小到1rem */
  background-color: rgba(135, 206, 235, 0.15);
  border-left: 4px solid var(--theme-color);
  padding-left: 1.2rem; /* 从1.5rem减小到1.2rem */
}

.sidebar-submenu {
  display: flex;
  flex-direction: column;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.4s ease, opacity 0.4s ease;
  padding-left: 0.8rem; /* 从1rem减小到0.8rem */
}

.sidebar-submenu.show {
  opacity: 1;
  max-height: 1000px; /* 足够大的值 */
}

.sidebar-sub-item {
  font-size: 0.85rem; /* 从0.9rem减小到0.85rem */
  font-weight: 400;
  cursor: pointer;
  padding: 0.4rem 0.7rem; /* 从0.5rem 0.8rem减小到0.4rem 0.7rem */
  margin: 0.25rem 0; /* 从0.3rem减小到0.25rem */
  border-radius: 6px;
  transition: all 0.3s ease;
  color: #666;
}

.sidebar-sub-item:hover {
  background-color: rgba(135, 206, 235, 0.08);
  color: var(--theme-color-dark);
  transform: translateX(3px);
}

.sidebar-sub-item.active,
.sidebar-sub-item.bright {
  color: var(--theme-color);
  font-weight: 600;
  background-color: rgba(135, 206, 235, 0.12);
}

/* ===== Main Content Layout with Sidebar ===== */
.content-with-sidebar {
  display: block; /* 改为 block,因为 sidebar 是 fixed */
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  padding-left: 320px; /* 为 fixed sidebar 留出空间 (260px + 60px 间距) */
}

.main-content {
  width: 100%;
  min-width: 0;
}

/* ===== 合并的回到顶部+进度指示器 (右下角) ===== */
#back-to-top-with-progress {
  /* 关键: position: fixed 相对于浏览器视口定位 */
  position: fixed !important;
  bottom: 25px !important;
  right: 30px !important;
  z-index: 1000;
  width: 70px;
  height: 70px;
  cursor: pointer;
  transition: all 0.3s ease;
  opacity: 1;
  visibility: visible;
  /* 防止父元素transform影响 */
  transform: none !important;
}

#back-to-top-with-progress:hover {
  opacity: 0.9;
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.25));
}

/* 进度环背景和进度条 */
#back-to-top-with-progress .progress-ring-bg,
#back-to-top-with-progress .progress-ring-bar {
  fill: transparent;
  stroke-width: 4;
}

#back-to-top-with-progress .progress-ring-bg {
  stroke: #e6e6e6;
}

#back-to-top-with-progress .progress-ring-bar {
  stroke: var(--theme-color);
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  transition: stroke-dashoffset 0.1s linear;
}

/* 回到顶部图标 - 内层圆形按钮 */
.back-to-top-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  background-color: var(--theme-color);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 24px;
  color: white;
  font-weight: bold;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  pointer-events: none; /* 让点击事件穿透到父元素 */
}

#back-to-top-with-progress:hover .back-to-top-icon {
  background-color: var(--theme-color-dark);
}

/* ===== 高分辨率显示修复（增强版） ===== */
@media screen and (min-resolution: 96dpi) {
  html, body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: auto !important;
    min-height: 100vh !important;
    max-height: none !important;
    transform: none !important; /* 确保不影响 fixed 定位 */
    filter: none !important;
    perspective: none !important;
  }
  
  .container-fluid, .container {
    overflow: visible !important;
    max-height: none !important;
  }
  
  /* 修复导航栏在高分辨率下的问题 */
  .navbar-collapse {
    overflow: visible !important;
    max-height: none !important;
  }
  
  .dropdown-menu {
    position: absolute !important;
    max-height: none !important;
  }
}


/* ===== 修复125%缩放下的问题 ===== */
@media screen and (min-resolution: 120dpi) {
  html {
    /* 移除 transform,因为它会影响 position: fixed */
    /* zoom: 1; */
    /* transform: scale(1); */
    /* transform-origin: 0 0; */
    transform: none !important; /* 确保没有 transform */
  }
  
  body {
    font-size: 14px; /* 略微减小字体防止溢出 */
    overflow-y: scroll !important;
    transform: none !important; /* 确保没有 transform */
  }
  
  .content-wrapper {
    max-width: 1100px; /* 减小最大宽度适应缩放 */
  }
  
  #first-block h2 {
    font-size: 2.5rem; /* 减小标题字体 */
  }
  
  #first-block p {
    font-size: 1.3rem; /* 减小段落字体 */
  }
}

/* ===== 强制修复导航栏问题 ===== */
.navbar {
  overflow: visible !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  z-index: 1030 !important;
}

.dropdown-menu.show {
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
  transform: translateY(0) !important;
}

/* 防止下拉菜单自动展开 */
.dropdown-menu:not(.show) {
  display: none !important;
}

/* ===== 大屏幕布局 (1201px 以上) ===== */
@media (min-width: 1201px) {
  .sidebar {
    /* ✅ 移除position和top,完全由JavaScript控制 */
    /* position: fixed; */
    /* top: 80px; */
    /* left: 20px; */
    width: 260px;
    min-width: 260px;
    transform: none !important; /* transform仍需!important防止被覆盖 */
    z-index: 900;
  }
  
  .content-with-sidebar {
    padding-left: 320px; /* 260px + 60px */
  }
  
  #back-to-top-with-progress {
    position: fixed !important;
    bottom: 25px !important;
    right: 30px !important;
    transform: none !important;
    z-index: 1000 !important;
  }
}

/* ===== Responsive Design ===== */
/* 🔧 修复: 1200px断点不再干扰sidebar的三段式定位 */
@media (max-width: 1200px) and (min-width: 769px) {
  .navbar-nav .nav-link {
    font-size: 0.9rem !important;
    padding: 0.4rem 0.6rem !important;
  }
  
  .navbar-brand {
    font-size: 1.1rem !important;
  }
  
  /* 🎯 关键修复: 缩小sidebar宽度,适应中小屏幕 */
  .sidebar {
    /* position由JS动态管理,不强制fixed */
    width: 200px; /* 👈 从220改为200 */
    min-width: 200px;
    padding: 15px; /* 👈 减小padding */
    font-size: 0.85rem;
    /* left由JS动态管理,不强制覆盖 */
  }
  
  .content-with-sidebar {
    max-width: 100%;
    padding: 15px;
    padding-left: 240px; /* 👈 为 sidebar 留空间 (20+200+20=240px) */
  }
}

/* 🔧 992px断点合并到768px,避免不必要的干扰 */
/* @media (max-width: 992px) 已移除,统一使用768px断点 */

/* 🔧 中等屏幕适配 (769px-1200px) - 保持桌面布局,支持三段式定位 */
@media (min-width: 769px) and (max-width: 1200px) {
  #first-block h2 { 
    font-size: 2.8rem; 
  }
  
  #first-block p { 
    font-size: 1.4rem; 
  }
  
  /* 🎯 关键: 保持左右布局,sidebar使用JS三段式定位 */
  .content-with-sidebar {
    padding-left: 240px; /* 👈 为sidebar留空间 (20+200+20=240px) */
    padding-right: 20px;
  }
  
  .main-content {
    max-width: 100%;
  }
}

/* 🔧 真正的移动端布局 (768px及以下) */
@media (max-width: 768px) {
  #first-block h2 { 
    font-size: 2.5rem; 
  }
  
  #first-block p { 
    font-size: 1.2rem; 
  }
  
  .card-content, 
  .card-content-reverse {
    flex-direction: column;
  }

  .card-content-reverse {
    flex-direction: column-reverse;
  }

  .card-image {
    width: 100%;
    height: 200px;
  }
  
  .additional-content {
    flex-direction: column;
  }
  
  .additional-content-image {
    width: 80%;
    margin: 20px 0;
  }

  .ape-row {
    flex-direction: column;
    text-align: center;
  }
  
  .ape-icon {
    margin-right: 0;
    margin-bottom: 15px;
  }
  
  /* 移动端 Sidebar 调整 */
  .content-with-sidebar {
    flex-direction: column;
    padding-left: 20px; /* 移动端也保持左侧留白 */
  }
  
  .sidebar {
    /* 关键: 移动端也必须强制 fixed 定位! */
    position: fixed !important;
    top: 70px !important;
    left: 5% !important;
    width: 90%;
    max-width: 90%;
    max-height: 60vh; /* 限制高度 */
    z-index: 900 !important;
    transform: none !important; /* 防止transform影响 */
  }
  
  .main-content {
    width: 100%;
    margin-top: 20px; /* 给 sidebar 留出空间 */
  }
  
  /* 移动端进度圆圈和回到顶部按钮调整 */
  #scroll-progress-container {
    position: fixed !important; /* 强制保持 fixed */
    bottom: 15px !important;
    left: 15px !important;
    transform: none !important; /* 防止transform影响 */
    /* 不使用 transform scale,直接调整 SVG 尺寸 */
  }
  
  #back-to-top-with-progress {
    position: fixed !important; /* 强制保持 fixed */
    bottom: 15px !important;
    right: 15px !important;
    width: 62px;
    height: 62px;
    transform: none !important;
  }
  
  #back-to-top-with-progress .progress-ring {
    width: 62px;
    height: 62px;
  }
  
  #back-to-top-with-progress .back-to-top-icon {
    width: 45px;
    height: 45px;
    font-size: 22px;
  }
  
  #back-to-top-with-progress:hover {
    transform: none !important;
  }
}

/* ===== 超小屏幕优化 ===== */
@media (max-width: 480px) {
  /* 超小屏幕也必须保持 fixed */
  .sidebar {
    position: fixed !important;
    top: 70px !important;
    left: 2.5% !important;
    width: 95%;
    max-width: 95%;
    transform: none !important;
  }
  
  .sidebar-title {
    font-size: 1.3rem;
  }
  
  .sidebar-nav-item {
    font-size: 0.9rem;
    padding: 0.5rem 0.8rem;
  }
  
  .sidebar-sub-item {
    font-size: 0.85rem;
  }
  
  /* 不使用 transform,直接调整 SVG 尺寸 */
  #back-to-top-with-progress {
    position: fixed !important; /* 强制保持 fixed */
    width: 60px;
    height: 60px;
    transform: none !important;
  }
  
  #back-to-top-with-progress .progress-ring {
    width: 60px;
    height: 60px;
  }
  
  #back-to-top-with-progress .back-to-top-icon {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
}