/* ============================================================================
   基础样式：reset、排版、焦点、布局骨架
   ========================================================================= */

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
p,
figure,
blockquote,
dl,
dd {
  margin: 0;
}

h1,
h2,
h3,
h4 {
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  letter-spacing: -0.01em;
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

img,
svg {
  display: block;
  max-width: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
  font-size: 0.94em;
}

pre {
  margin: 0;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--sp-5) 0;
}

/* ---- 焦点：旧版本整份样式表里一条 :focus 都没有，键盘用户完全看不到自己在哪 ---- */
:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ---- 尊重「减少动态效果」的系统设置 ---- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- 仅供读屏，不占视觉空间 ---- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 跳到主内容：键盘用户第一个 Tab 就能跳过导航 */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--sp-4);
  z-index: var(--z-toast);
  padding: var(--sp-2) var(--sp-4);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--r-md);
  font-weight: var(--fw-medium);
  transition: top var(--dur-base) var(--ease);
}

.skip-link:focus-visible {
  top: var(--sp-4);
  text-decoration: none;
}

/* ---- 滚动条 ---- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  border-radius: var(--r-full);
  background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--text-3);
  background-clip: content-box;
}

/* ============================================================================
   应用骨架
   ========================================================================= */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "brand topbar"
    "nav   main";
  min-height: 100vh;
}

/* ---- 品牌区 ---- */
.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  background: var(--surface);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  flex: none;
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.brand-text {
  min-width: 0;
}

.brand-name {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.brand-sub {
  font-size: var(--fs-xs);
  color: var(--text-3);
  line-height: 1.3;
}

/* ---- 顶栏 ---- */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-spacer {
  flex: 1;
  min-width: var(--sp-2);
}

.topbar-meta {
  font-size: var(--fs-sm);
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---- 侧栏导航 ---- */
.sidebar {
  grid-area: nav;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--sp-4) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.nav-link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: var(--fw-semibold);
}

.nav-link svg {
  flex: none;
  width: 17px;
  height: 17px;
  opacity: 0.85;
}

.nav-spacer {
  flex: 1;
}

.nav-note {
  padding: var(--sp-3);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: var(--fs-xs);
  line-height: var(--lh-normal);
}

/* ---- 主内容 ---- */
.main {
  grid-area: main;
  padding: var(--sp-6);
  max-width: var(--content-max);
  width: 100%;
  min-width: 0;
}

.view-header {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}

.view-header h2 {
  font-size: var(--fs-xl);
}

.view-header p {
  margin-top: var(--sp-1);
  color: var(--text-2);
  font-size: var(--fs-base);
  max-width: 68ch;
}

.view-header-actions {
  margin-left: auto;
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

/* ============================================================================
   响应式
   ========================================================================= */

@media (max-width: 1080px) {
  :root {
    --sidebar-w: 68px;
  }

  .brand-text,
  .nav-link span,
  .nav-note {
    display: none;
  }

  .brand {
    justify-content: center;
    padding: 0;
  }

  .nav-link {
    justify-content: center;
    padding: var(--sp-3);
  }
}

@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) auto 1fr;
    grid-template-areas:
      "topbar"
      "nav"
      "main";
  }

  .brand {
    display: none;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: var(--sp-2) var(--sp-3);
  }

  .nav-link span {
    display: inline;
  }

  .nav-link {
    padding: var(--sp-2) var(--sp-3);
    white-space: nowrap;
  }

  .topbar {
    padding: 0 var(--sp-4);
  }

  .main {
    padding: var(--sp-4);
  }
}
