/* ============================================================
   layout.css — 应用外壳 / 侧栏 / 顶栏 / 工作区 / 响应式
   ============================================================ */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------- 侧栏 ---------- */
.sidebar {
  position: sticky; top: 0; align-self: start;
  height: 100vh; display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--s4) var(--s3); }
.brand-mark {
  width: 44px; height: 44px; flex: none; border-radius: 13px;
  display: grid; place-items: center;
  font-family: var(--font-code); font-weight: 700; font-size: 17px;
  color: var(--on-brand);
  background: linear-gradient(140deg, var(--brand) 0%, var(--brand-strong) 100%);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.25);
}
.brand h1 { font-size: var(--fs-md); font-weight: 750; letter-spacing: -.01em; }
.brand p { font-size: var(--fs-xs); color: var(--ink-mute); font-family: var(--font-code); letter-spacing: .02em; }

.sidebar-tools { padding: var(--s2) var(--s4) var(--s3); }
.search-input {
  width: 100%; padding: 9px 12px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: var(--fs-sm); transition: var(--transition);
}
.search-input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); background: var(--surface); }

.sidebar-stats { padding: 0 var(--s4) var(--s3); display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.mini-stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; }
.mini-stat b { display: block; font-size: var(--fs-lg); color: var(--brand); font-family: var(--font-code); line-height: 1.1; }
.mini-stat span { font-size: var(--fs-xs); color: var(--ink-mute); }

.sidebar-statline { padding: 0 var(--s4) var(--s2); font-size: var(--fs-xs); color: var(--ink-mute); }
.sidebar-statline b { color: var(--brand); font-family: var(--font-code); }
.sidebar-training {
  display: grid; gap: 3px; margin: 0 var(--s3) var(--s3); padding: 10px 12px;
  border: 1px solid var(--brand); border-radius: var(--r); background: var(--brand-soft);
  color: var(--brand-ink); text-align: left;
}
.sidebar-training span { color: var(--ink-soft); font-size: 11px; }

.course-nav {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-gutter: stable; padding: var(--s2) var(--s3) var(--s6);
  border-top: 1px solid var(--line);
}

.nav-module { margin-bottom: 2px; }
.nav-module-head {
  width: 100%; display: flex; align-items: center; gap: var(--s2);
  padding: 9px 10px; border-radius: var(--r-sm); text-align: left;
  color: var(--ink-soft); font-weight: 650; font-size: var(--fs-sm);
  transition: var(--transition);
}
.nav-module-head:hover { background: var(--surface-2); color: var(--ink); }
.nav-module-head .chev { transition: transform var(--transition); color: var(--ink-mute); font-size: 11px; }
.nav-module.is-open .nav-module-head .chev { transform: rotate(90deg); }
.nav-module-no {
  width: 22px; height: 22px; flex: none; border-radius: 7px; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-ink); font-family: var(--font-code);
  font-size: 11px; font-weight: 700;
}
.nav-module-prog { margin-left: auto; font-size: 11px; color: var(--ink-mute); font-family: var(--font-code); }

.nav-unit-list { overflow: hidden; padding: 2px 0 6px 8px; }
.nav-module:not(.is-open) .nav-unit-list { display: none; }
.nav-unit {
  width: 100%; display: flex; align-items: center; gap: var(--s2);
  padding: 7px 10px; border-radius: var(--r-sm); text-align: left;
  color: var(--ink-soft); font-size: var(--fs-sm); line-height: 1.35;
  border-left: 2px solid transparent; transition: var(--transition);
}
.nav-unit:hover { background: var(--surface-2); color: var(--ink); }
.nav-unit.is-active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 650; border-left-color: var(--brand); }
.nav-unit-id { font-family: var(--font-code); font-size: 11px; color: var(--ink-mute); flex: none; }
.nav-unit.is-active .nav-unit-id { color: var(--brand); }
.nav-unit-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-unit-flag { margin-left: auto; font-size: 10px; flex: none; }
.nav-unit.is-done .nav-unit-flag { color: var(--ok); }
.nav-unit.is-ready .nav-unit-flag { color: var(--brand); font-weight: 750; }
.nav-unit.is-draft .nav-unit-flag { color: var(--ink-mute); }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s5);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.topbar-title .kicker { margin-bottom: 1px; }
.topbar-title strong { font-size: var(--fs-md); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s2); }
.cpp-home-back { display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 0 11px; border: 1px solid var(--line); border-radius: var(--r-full); background: var(--surface-2); color: var(--ink-soft); font-size: var(--fs-xs); font-weight: 700; text-decoration: none; }
.cpp-home-back:hover { border-color: var(--brand); color: var(--brand); }
.cpp-home-back svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.cpp-account { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.cpp-account a { max-width: 140px; overflow: hidden; color: var(--ink); font-size: var(--fs-xs); font-weight: 750; text-overflow: ellipsis; }
.cpp-account button { color: var(--ink-mute); font-size: 11px; text-decoration: underline; text-underline-offset: 3px; }

/* 顶栏主导航 */
.top-nav { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; min-width: 0; }
.top-link { padding: 7px 13px; border-radius: var(--r-sm); font-size: var(--fs-sm); font-weight: 600; color: var(--ink-soft); white-space: nowrap; transition: var(--transition); }
.top-link:hover { background: var(--surface-2); color: var(--ink); }
.top-link.is-active { background: var(--brand-soft); color: var(--brand-ink); }
[data-theme="dark"] .top-link.is-active { color: var(--brand-strong); }

/* ---------- 工作区 ---------- */
.workspace { min-width: 0; display: flex; flex-direction: column; }
.content { flex: 1; width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--s5) var(--s5) var(--s8); }

.icon-button, .menu-toggle { display: none; }

/* 遮罩:默认 fixed + 隐藏,绝不参与网格布局(仅移动端展开导航时显示) */
.scrim { display: none; position: fixed; inset: 0; z-index: 25; background: rgba(8, 18, 14, .42); backdrop-filter: blur(2px); }

/* ---------- 响应式 ---------- */
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; width: min(86vw, 320px);
    transform: translateX(-102%); transition: transform var(--transition);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; }
  .menu-toggle { display: grid; place-items: center; width: 38px; height: 38px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--line); font-size: 18px; }
  .content { padding: var(--s5) var(--s4) var(--s7); }
  .cpp-home-back span { display: none; }
  .cpp-home-back { width: 36px; justify-content: center; padding: 0; }
}
@media (max-width: 560px) {
  .topbar { padding: var(--s3) var(--s4); }
  .topbar-title strong { font-size: var(--fs-base); }
}
@media (max-width: 760px) {
  .top-nav { display: none; }
  .topbar { min-height: 62px; }
}
