/* study-note: layout.css
 * 作用：全站骨架层，包含页头、导航、搜索浮层、页脚、返回顶部和移动端抽屉。
 * 与 home.css 的关系：layout.css 负责每个页面都会出现的框架；home.css 只负责首页主体栏目。
 * 学习重点：同一个导航数据由 JS 渲染到桌面导航和移动抽屉，CSS 只关心不同容器的呈现方式。
 */
/* ===== Site Header =====
 * 页头是全局最高层之一：z-index 30 保证下拉菜单和搜索浮层覆盖主体内容。
 * 背景使用学院主色，品牌 logo、快捷链接、搜索按钮都放在 masthead 内部。
 */
.site-header {
  position: relative;
  z-index: 30;
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 3px 16px rgba(0, 0, 0, 0.18);
}

.masthead {
  position: relative;
}

.masthead-inner {
  min-height: 116px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  position: relative;
}

.nav-toggle {
  display: none;
}

.masthead-links {
  grid-column: 2;
  justify-self: end;
  gap: 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  justify-self: start;
  grid-column: 1;
}

.brand-logo {
  display: block;
  width: min(700px, 64vw);
  max-height: 110px;
  object-fit: contain;
}

/* Topbar links
 * 桌面端显示在页头右上角；移动端同一批链接会由 JS 复制到抽屉的 utility 区域。
 */
.topbar-links {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
  flex-wrap: wrap;
}

.topbar-links-list {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar-links a {
  color: rgba(255, 255, 255, 0.9);
}

.topbar-links a:hover,
.topbar-links a:focus-visible {
  color: #fff;
}

/* Site search
 * 搜索框默认 hidden，由 main.js 切换 hidden 和 aria-expanded。
 * 浮层定位在页头内部，宽度用 min() 防止窄屏溢出。
 */
.site-search-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: min(420px, calc(100vw - 24px));
  padding: 16px;
  background: #fff;
  color: #2d2623;
  border-radius: var(--radius-sm);
  box-shadow: 0 22px 42px rgba(31, 39, 52, 0.2);
  z-index: 40;
}

.site-search-form {
  display: grid;
  gap: 10px;
}

.site-search-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-primary);
}

.site-search-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.site-search-field input {
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 1px solid rgba(143, 43, 43, 0.18);
  border-radius: 999px;
  padding: 0 16px;
  font-size: 15px;
  color: #2d2623;
  background: #fff;
}

.site-search-field input:focus {
  outline: 2px solid rgba(143, 43, 43, 0.18);
  outline-offset: 1px;
}

.site-search-submit {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
}

.site-search-submit svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

/* ===== Main Navigation =====
 * 桌面主导航：横向 flex 等分，每个 .nav-item 都可以承载一个 mega-menu。
 * 手机端直接隐藏，改用左侧移动抽屉，避免导航项过多导致换行拥挤。
 */
.main-nav {
  border-top: 1px solid rgba(255, 255, 255, 0.13);
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
}

.main-nav .wrap {
  position: relative;
}

.nav-list {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
}

.nav-item {
  position: relative;
  min-width: 0;
  flex: 1 1 auto;
}

.nav-item > a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 0 6px;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
  text-align: center;
  transition: background var(--motion-fast);
}

.nav-item > a:hover,
.nav-item > a:focus-visible,
.nav-item.is-open > a {
  background: rgba(255, 255, 255, 0.09);
}

/* ===== Mega Menu (Dropdown) =====
 * 下拉菜单通过 opacity/visibility/pointer-events 三件套控制显示，既能过渡动画，也能避免隐藏菜单被误点击。
 * hover、focus-within、JS 添加的 is-open 都能打开菜单，兼顾鼠标、键盘和触屏环境。
 */
.mega-menu {
  position: absolute;
  left: 0;
  top: 100%;
  width: 100%;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity var(--motion-fast),
    transform var(--motion-fast),
    visibility var(--motion-fast);
  z-index: 50;
}

.nav-item:hover .mega-menu,
.nav-item.is-open .mega-menu,
.nav-item:focus-within .mega-menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.mega-panel {
  background: var(--color-hover-blue);
  color: #fff;
  box-shadow: 0 20px 40px rgba(23, 74, 124, 0.26);
  border-top: 3px solid var(--color-hover-blue-dark);
  border-radius: 0 0 8px 8px;
  padding: 12px 0;
}

.mega-column {
  display: flex;
  flex-direction: column;
}

.mega-column h3 {
  font-size: 14px;
  line-height: 1.2;
  font-weight: 800;
  margin-bottom: 8px;
  padding: 0 16px;
  color: #fff;
}

.mega-column a {
  display: block;
  padding: 8px 16px;
  font-size: 14px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.9);
  border-radius: 0;
  transition: background var(--motion-fast), color var(--motion-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mega-column a:hover,
.mega-column a:focus-visible {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

/* ===== Site Footer =====
 * 页脚复用主色形成首尾呼应。上半部分为链接矩阵，下半部分为品牌信息和联系方式。
 */
.site-footer {
  background: var(--color-primary);
  color: rgba(255, 255, 255, 0.9);
  padding: 48px 0 36px;
}

.footer-columns {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 22px;
}

.footer-column h3 {
  margin-bottom: 18px;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 800;
  color: #fff;
}

.footer-column a {
  display: block;
  padding: 6px 0;
  font-size: 16px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.72);
  transition: color var(--motion-fast);
}

.footer-column a:hover,
.footer-column a:focus-visible {
  color: #fff;
}

.footer-divider {
  height: 1px;
  margin: 38px 0 36px;
  background: rgba(255, 255, 255, 0.18);
}

.footer-bottom {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 28px;
  align-items: center;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 18px;
}

.footer-logo {
  width: 100px;
  height: 100px;
  border: 2px dashed rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-size: 13px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.06);
}

.footer-brand-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.footer-brand-copy strong {
  font-size: 26px;
  line-height: 1.1;
  font-weight: 800;
  color: #fff;
}

.footer-brand-copy span {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.9);
}

.footer-contact h3 {
  font-size: 18px;
  line-height: 1.4;
  margin-bottom: 12px;
  color: #fff;
}

.footer-contact p {
  font-size: 16px;
  line-height: 1.8;
  color: rgba(255, 255, 255, 0.82);
}

/* ===== Back to Top =====
 * 返回顶部按钮默认透明且不响应点击，滚动超过阈值后由 JS 添加 is-visible。
 */
.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(143, 43, 43, 0.95);
  color: #fff;
  box-shadow: 0 10px 24px rgba(55, 20, 20, 0.28);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
  z-index: 50;
}

.back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.back-to-top svg {
  width: 22px;
  height: 22px;
  margin: 0 auto;
  fill: currentColor;
}

/* ===== Mobile Drawer =====
 * 移动抽屉使用 fixed 覆盖全屏，backdrop 负责遮罩，panel 通过 translateX 实现滑入滑出。
 * body.menu-open 会锁住底层页面滚动。
 */
.mobile-drawer {
  position: fixed;
  inset: 0;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.mobile-drawer.is-open {
  opacity: 1;
  pointer-events: auto;
}

.mobile-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(25, 18, 18, 0.55);
}

.mobile-drawer-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: min(84vw, 360px);
  height: 100%;
  background: #fff;
  color: var(--color-text);
  transform: translateX(-100%);
  transition: transform 0.26s ease;
  overflow-y: auto;
}

.mobile-drawer.is-open .mobile-drawer-panel {
  transform: translateX(0);
}

.mobile-drawer-head {
  height: 70px;
  padding: 0 18px 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-primary);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
}

.drawer-close {
  color: #fff;
}

.mobile-utility-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 18px 16px 10px;
  background: #f8f7f5;
}

.mobile-utility-links a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--color-primary);
  background: #fff;
}

.mobile-nav {
  padding: 10px 16px 20px;
}

.mobile-nav details {
  border-bottom: 1px solid #ece7e2;
}

.mobile-nav summary {
  list-style: none;
  cursor: pointer;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 18px;
  font-weight: 700;
  color: #2e2927;
}

.mobile-nav summary::-webkit-details-marker {
  display: none;
}

.mobile-nav summary::after {
  content: '+';
  font-size: 22px;
  color: var(--color-primary);
}

.mobile-nav details[open] summary::after {
  content: '\2212';
}

.mobile-submenu {
  padding: 0 0 14px;
  display: grid;
  gap: 8px;
}

.mobile-submenu a,
.mobile-nav-link {
  display: block;
  padding: 6px 0;
  font-size: 15px;
  color: #5c5450;
}

.mobile-nav-link {
  padding-top: 12px;
  font-weight: 700;
  color: var(--color-primary);
}

/* ===== Responsive =====
 * 响应式策略：先压缩 logo 和导航字号；到 767px 以下隐藏桌面导航，启用移动端按钮和抽屉。
 */
@media (max-width: 1180px) {
  .masthead-inner {
    min-height: 104px;
  }

  .brand-logo {
    width: min(560px, 58vw);
    max-height: 90px;
  }

  .nav-list {
    gap: 8px;
  }

  .nav-item > a {
    font-size: 15px;
    padding: 0 6px;
  }

  .footer-columns {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .footer-bottom {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1024px) {
  .masthead-inner {
    min-height: 96px;
    gap: 14px;
  }

  .brand-logo {
    width: min(500px, 55vw);
    max-height: 80px;
  }

  .nav-list {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0;
  }

  .nav-item {
    flex: 0 1 auto;
  }

  .nav-item > a {
    min-height: 50px;
    padding: 0 12px;
  }

  .footer-columns {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .footer-bottom {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 767px) {
  .topbar-links-list {
    display: none;
  }

  .masthead {
    position: relative;
  }

  .masthead-inner {
    min-height: 74px;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 10px;
  }

  .nav-toggle {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    display: inline-flex;
  }

  .masthead-links {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
  }

  .brand {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
    align-self: center;
    min-width: 0;
  }

  .top-search-toggle {
    width: 38px;
    height: 38px;
  }

  .brand-logo {
    width: min(255px, 64vw);
    max-height: 48px;
  }

  .site-search-popover {
    left: 12px;
    right: 12px;
    width: auto;
  }

  .main-nav {
    display: none;
  }

  .footer-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 14px;
  }

  .footer-column h3 {
    font-size: 16px;
    margin-bottom: 12px;
  }

  .footer-column a {
    font-size: 14px;
  }

  .footer-divider {
    margin: 24px 0;
  }

  .footer-bottom {
    gap: 18px;
  }

  .footer-brand {
    align-items: flex-start;
    gap: 12px;
  }

  .footer-logo {
    width: 66px;
    height: 66px;
    font-size: 20px;
  }

  .footer-brand-copy strong {
    font-size: 22px;
  }

  .footer-brand-copy span {
    font-size: 14px;
  }

  .footer-contact h3 {
    font-size: 16px;
  }

  .footer-contact p {
    font-size: 13px;
    line-height: 1.6;
  }

  .back-to-top {
    right: 14px;
    bottom: 14px;
    width: 44px;
    height: 44px;
  }
}
