/* ============================================================
   全局 reset + 三列 Grid 布局 + Header
   ============================================================ */

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
}

/* ---------- 三列 Grid 布局 ---------- */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--toc-width);
  grid-template-rows: var(--header-height) 1fr;
  grid-template-areas:
    "header header header"
    "sidebar content toc";
  height: 100vh;
  overflow: hidden;
}

.app-header  { grid-area: header; }
.app-sidebar { grid-area: sidebar; overflow-y: auto; }
.app-content { grid-area: content; overflow-y: auto; position: relative; }
.app-toc     { grid-area: toc; overflow-y: auto; }

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background-color: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border);
  z-index: 10;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.app-header__logo {
  flex-shrink: 0;
  color: var(--color-primary);
}

.app-header__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.2px;
}

.header-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: background-color var(--transition-fast),
              color var(--transition-fast);
}
.header-action:hover {
  background-color: var(--color-bg-hover);
  color: var(--color-text);
}

.menu-toggle { display: none; }

/* 主题图标：浅色显示月亮（点击切到深色），深色显示太阳 */
.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun  { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: none; }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 6px;
  border: 2px solid var(--color-bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* ---------- Loading spinner ---------- */
.content-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--color-bg);
}
.content-loading[hidden] { display: none; }
.content-loading__spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 响应式 ---------- */
.sidebar-backdrop { display: none; }

@media (max-width: 1200px) {
  .app-layout {
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-areas:
      "header header"
      "sidebar content";
  }
  .app-toc { display: none; }
}

@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "content";
  }
  .menu-toggle { display: inline-flex; }
  .app-sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background-color: var(--color-bg-sidebar);
    border-right: 1px solid var(--color-border);
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    z-index: 50;
  }
  .app-sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop.is-visible {
    display: block;
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 40;
  }
}
