/* ============================================================
   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-strong);
  z-index: 30;
}
.sidebar-head { position: relative; flex: 0 0 62px; min-height: 62px; }
.brand { display: flex; align-items: center; gap: 10px; width: 100%; height: 62px; min-height: 62px; padding: 0 18px; border-bottom: 1px solid var(--line-strong); }
.brand--link { width: 100%; border: 0; border-bottom: 1px solid var(--line-strong); padding-right: 58px; border-radius: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; transition: background var(--transition); }
.brand--link:hover { background: var(--brand-soft); }
.brand--link:focus-visible { outline: 2px solid var(--brand); outline-offset: -4px; }
.brand-mark {
  width: 38px; height: 38px; flex: none; border-radius: 12px;
  display: grid; place-items: center;
  font-family: var(--font-ui); font-weight: 800; font-size: 14px; letter-spacing: .5px;
  color: var(--on-brand);
  background: linear-gradient(140deg, var(--brand) 0%, var(--brand-strong) 100%);
}
.brand h1 { font-size: 15px; font-weight: 750; letter-spacing: -.01em; }
.brand p { font-size: 12px; color: var(--ink-mute); font-family: var(--font-ui); letter-spacing: 0; }
.sidebar-collapse { position: absolute; z-index: 2; top: 13px; right: 12px; display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid var(--line); border-radius: 10px; color: var(--ink-soft); background: var(--surface); box-shadow: var(--shadow-sm); font: 800 22px/1 Arial,sans-serif; cursor: pointer; }
.sidebar-collapse:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
@media (min-width: 981px) {
  body.cpp-sidebar-collapsed .app-shell { grid-template-columns: 56px minmax(0,1fr); }
  body.cpp-sidebar-collapsed .sidebar .brand--link, body.cpp-sidebar-collapsed .sidebar .sidebar-scroll { display: none; }
  body.cpp-sidebar-collapsed .sidebar .sidebar-collapse { inset: 13px 10px auto; }
}

.sidebar-scroll {
  display: block; flex: 1 1 auto; min-height: 0; overflow-y: auto;
  overscroll-behavior: contain; padding: 12px 12px 24px;
  scrollbar-color: color-mix(in srgb,var(--brand) 35%,transparent) transparent;
}
.sidebar-tools { padding: 0; }
.search-input {
  width: 100%; margin: 0 0 10px; padding: 8px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 13px; transition: var(--transition);
}
.search-input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); background: var(--surface); }

.course-nav {
  display: block; min-height: 0; padding: 0;
}

.nav-module { margin-bottom: 4px; }
.nav-module-head {
  width: 100%; display: flex; align-items: center; gap: var(--s2);
  padding: 8px 6px; border-radius: 10px; text-align: left;
  color: var(--ink-soft); font-weight: 700; font-size: 13.5px;
  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: 10px; }
.nav-module.is-open .nav-module-head .chev { transform: rotate(90deg); }
.nav-module-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-module-count { flex: 0 0 auto; margin-left: auto; color: var(--ink-mute); font-size: 11px; font-weight: 600; }

.nav-unit-list { overflow: hidden; padding: 2px 0 6px 14px; }
.nav-module:not(.is-open) .nav-unit-list { display: none; }
.nav-unit {
  width: 100%; display: flex; align-items: baseline; gap: var(--s2);
  padding: 6px 8px; border-radius: 8px; text-align: left;
  color: var(--ink-soft); font-size: 13px; line-height: 1.35;
  transition: var(--transition);
}
.nav-unit:hover { background: var(--surface-2); color: var(--ink); }
.nav-unit.is-active { background: var(--brand); color: var(--on-brand); font-weight: 650; }
.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: rgba(255,255,255,.75); }
.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);
  width: 100%; height: 62px; min-height: 62px; padding: 8px var(--s5);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line-strong);
}
.cpp-global-brand { position: relative; display: flex; align-items: center; justify-content: flex-start; flex: 0 0 136px; width: 136px; height: 46px; padding: 4px 14px 4px 2px; border-right: 1px solid var(--line); background: transparent; }
.cpp-global-brand img { display: block; width: 118px; height: auto; }
.cpp-global-brand::after { content: ""; position: absolute; inset: 0 14px 0 2px; display: none; pointer-events: none; background: #67d8ba; -webkit-mask: url("/logo.png") left center / contain no-repeat; mask: url("/logo.png") left center / contain no-repeat; }
[data-theme="dark"] .cpp-global-brand img { opacity: 0; }
[data-theme="dark"] .cpp-global-brand::after { display: block; }
.cpp-global-brand:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.topbar-context { min-width: 0; max-width: 240px; margin-left: 2px; padding-left: 12px; overflow: hidden; border-left: 1px solid var(--line); color: var(--ink-mute); font-size: var(--fs-xs); font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s2); }
.cpp-account { display: inline-flex; align-items: center; gap: 4px; padding: 3px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); box-shadow: var(--shadow-sm); white-space: nowrap; }
.cpp-account-link { display: flex; min-width: 0; max-width: 190px; height: 40px; align-items: center; gap: 8px; padding: 0 10px 0 5px; border-radius: 11px; color: var(--ink); transition: background var(--transition); }
.cpp-account-link:hover { background: var(--surface); }
.cpp-account-avatar { display: grid; width: 31px; height: 31px; flex: 0 0 auto; place-items: center; border-radius: 9px; color: #fff; background: linear-gradient(145deg,var(--brand),var(--brand-strong)); box-shadow: 0 4px 10px color-mix(in srgb,var(--brand) 24%,transparent); font-size: 12px; font-weight: 900; }
.cpp-account-copy { display: grid; min-width: 0; gap: 2px; line-height: 1; }
.cpp-account-copy small { color: var(--ink-mute); font-size: 9px; font-weight: 700; }
.cpp-account-copy strong { max-width: 106px; overflow: hidden; font-size: 12px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.cpp-account-alert { display: grid; width: 17px; height: 17px; place-items: center; border-radius: 50%; color: #fff; background: #f5a623; font-size: 10px; font-weight: 900; }
.cpp-account-logout { display: inline-flex; height: 34px; align-items: center; justify-content: center; gap: 5px; padding: 0 10px; border: 1px solid transparent; border-radius: 9px; color: var(--ink-mute); background: var(--surface); font-size: 11px; font-weight: 700; transition: color var(--transition),border-color var(--transition),background var(--transition); }
.cpp-account-logout:hover { color: #c15d5d; border-color: color-mix(in srgb,#c15d5d 35%,var(--line)); background: color-mix(in srgb,#c15d5d 8%,var(--surface)); }
.cpp-account-logout svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.cpp-account--loading { color: var(--ink-mute); font-size: var(--fs-xs); }

@media (min-width: 1600px) {
  .cpp-global-brand { flex-basis: 174px; width: 174px; height: 54px; }
  .cpp-global-brand img { width: 154px; }
}

@media (max-width: 1280px) and (min-width: 561px) {
  .cpp-global-brand { flex-basis: 120px; width: 120px; }
  .cpp-global-brand img { width: 104px; }
  .cpp-account-link { max-width: 156px; }
}

/* 顶栏主导航 */
.top-nav { display: flex; align-items: center; gap: 0; flex-wrap: nowrap; min-width: 0; }
.top-link { padding: 7px 11px; 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); }
}
@media (max-width: 980px) and (min-width: 761px) {
  .topbar { gap: 6px; padding-inline: 10px; }
  .cpp-global-brand { flex-basis: 105px; width: 105px; padding-right: 8px; }
  .cpp-global-brand img { width: 94px; }
  .cpp-global-brand::after { inset-right: 8px; }
  .top-link { padding-inline: 7px; font-size: 12px; }
  .topbar-context { display: none; }
  .topbar-actions { gap: 4px; }
  .cpp-account-link { max-width: 140px; }
}
@media (max-width: 1400px) and (min-width: 981px) {
  .topbar { gap: 6px; padding-inline: 12px; }
  .cpp-global-brand { flex-basis: 105px; width: 105px; padding-right: 8px; }
  .cpp-global-brand img { width: 94px; }
  .cpp-global-brand::after { inset-right: 8px; }
  .top-link { padding-inline: 7px; font-size: 12px; }
  .topbar-context { display: none; }
  .cpp-account-link { max-width: 140px; }
}
@media (max-width: 560px) {
  .topbar { padding: var(--s3) var(--s4); }
  .cpp-global-brand { flex-basis: 76px; width: 76px; height: 34px; padding: 5px 8px 5px 4px; }
  .cpp-global-brand img { width: 64px; }
  .topbar-context { padding-left: 8px; }
  .cpp-account { gap: 2px; padding: 2px; border-radius: 12px; }
  .cpp-account-link { width: 34px; height: 34px; padding: 0; }
  .cpp-account-avatar { width: 30px; height: 30px; margin: auto; }
  .cpp-account-copy, .cpp-account-alert { display: none; }
  .cpp-account-logout { width: 32px; height: 32px; padding: 0; }
  .cpp-account-logout > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}
@media (max-width: 760px) {
  .top-nav { display: none; }
  .topbar { min-height: 62px; }
}
