/* ==========================================================================
   应用框架：顶部分类、侧栏、面包屑、页面容器
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) auto minmax(0, 1fr);
  min-height: 100dvh;
  transition: grid-template-columns var(--t-base) var(--ease);
}
[data-collapsed="true"] .app { grid-template-columns: var(--sidebar-w-mini) minmax(0, 1fr); }

/* ---------- 顶栏 ---------- */
.topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding-right: var(--page-x);
  background: var(--head-bg);
  color: var(--head-text);
  border-bottom: 1px solid var(--head-line);
}

.head-brand { flex: none; width: var(--sidebar-w); padding: 0 8px; }

.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  padding: 0 8px;
  border-radius: var(--r-3);
  color: var(--head-text);
  transition: background var(--t-fast);
}
.brand-link:hover { background: var(--head-hover); }
.brand-logo {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--r-3);
  background: var(--brand);
  color: var(--brand-ink);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .22), 0 0 0 1px rgb(255 255 255 / .1);
}
.brand-logo svg { width: 17px; height: 17px; }
.brand-meta { flex: 1; min-width: 0; line-height: 1.25; }
.brand-meta > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-name { font-size: var(--fs-13); font-weight: 600; }
.brand-sub { font-size: var(--fs-11); color: var(--head-text-2); }

.top-nav { display: flex; align-items: center; gap: 2px; min-width: 0; }
.top-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 12px;
  border-radius: var(--r-3);
  color: var(--head-text-2);
  font-size: var(--fs-13);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
}
.top-link i { font-size: 12px; }
.top-link:hover { background: var(--head-hover); color: var(--head-text); }
.top-link.is-active { background: var(--head-active); color: var(--head-text); font-weight: 600; }
.top-link .count { min-width: 16px; height: 16px; padding: 0 4px; font-size: 10px; }

.top-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r-3);
  color: var(--text-2);
  font-size: 15px;
  transition: background var(--t-fast), color var(--t-fast);
}
.top-btn:hover { background: var(--surface-3); color: var(--text); }
.topbar .top-btn { color: var(--head-text-2); }
.topbar .top-btn:hover { background: var(--head-hover); color: var(--head-text); }
.top-btn .dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--head-bg);
}

.top-search {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 1 220px;
  min-width: 0;
  height: 34px;
  margin-left: auto;
  padding: 0 7px 0 11px;
  border: 1px solid var(--head-line);
  border-radius: var(--r-3);
  background: var(--head-hover);
  color: var(--head-text-2);
  font-size: var(--fs-13);
  white-space: nowrap;
  transition: border-color var(--t-fast);
}
.top-search:hover { border-color: var(--head-text-2); }
.top-search span { overflow: hidden; text-overflow: ellipsis; }
.top-search kbd { margin-left: auto; border-color: var(--head-line); background: transparent; color: var(--head-text-2); }
.top-actions { flex: none; display: flex; align-items: center; gap: 2px; }
.top-user { margin-left: 6px; border-radius: 50%; }
.top-user:hover .avatar { box-shadow: 0 0 0 2px var(--head-active); }

/* ---------- 侧栏 ---------- */
.sidebar {
  grid-column: 1;
  grid-row: 2 / -1;
  position: sticky;
  top: var(--topbar-h);
  z-index: 40;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--topbar-h));
  min-width: 0;
  background: var(--side-bg);
  color: var(--side-text);
  border-right: 1px solid var(--side-line);
}

.side-cats { display: none; }
.side-title {
  flex: none;
  padding: 18px 20px 8px;
  font-size: var(--fs-12);
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--side-text-3);
  white-space: nowrap;
}

.side-nav { flex: 1; min-height: 0; overflow-y: auto; padding: 0 10px 12px; scrollbar-width: thin; scrollbar-color: var(--side-line) transparent; }

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  height: 38px;
  margin-bottom: 2px;
  padding: 0 10px;
  border-radius: var(--r-3);
  color: var(--side-text-2);
  font-size: var(--fs-13);
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-link:hover { background: var(--side-hover); color: var(--side-text); }
.nav-link > .ico { flex: none; width: 16px; text-align: center; font-size: 14px; }
.nav-link > .txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-link > .caret { font-size: 9px; color: var(--side-text-3); transition: transform var(--t-base) var(--ease); }
.nav-group.is-open > .nav-link > .caret { transform: rotate(90deg); }
.nav-link.is-active { background: var(--side-active); color: var(--side-active-text); font-weight: 600; }

.nav-sub { display: none; position: relative; padding: 2px 0 4px 27px; }
.nav-sub::before { content: ""; position: absolute; left: 18px; top: 4px; bottom: 8px; width: 1px; background: var(--side-line); }
.nav-group.is-open .nav-sub { display: block; }
.nav-sub .nav-link { height: 32px; font-weight: 400; }
.nav-sub .nav-link.is-active { background: transparent; color: var(--side-active-text); font-weight: 600; }
.nav-sub .nav-link.is-active::before {
  content: "";
  position: absolute;
  left: -9.5px;
  top: 9px;
  bottom: 9px;
  width: 2px;
  border-radius: 1px;
  background: currentColor;
}

/* 收起态 */
[data-collapsed="true"] .side-title,
[data-collapsed="true"] .nav-link > .txt,
[data-collapsed="true"] .nav-link > .caret,
[data-collapsed="true"] .nav-link > .count,
[data-collapsed="true"] .nav-sub { display: none; }
[data-collapsed="true"] .side-nav { padding-top: 12px; }
[data-collapsed="true"] .nav-link { justify-content: center; padding: 0; }
[data-collapsed="true"] .nav-link.is-parent-active { background: var(--side-active); color: var(--side-active-text); }

/* ---------- 面包屑 ---------- */
.crumbbar {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  max-width: 1640px;
  height: 44px;
  margin: 0 auto;
  padding: 0 var(--page-x) 0 calc(var(--page-x) - 8px);
}
.crumbbar .top-btn { width: 30px; height: 30px; font-size: 14px; }
.crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: var(--fs-13); color: var(--text-3); }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { font-size: 9px; color: var(--text-4); }
.crumbs .cur { color: var(--text); font-weight: 500; white-space: nowrap; }

/* ---------- 页面容器 ---------- */
.page {
  grid-column: 2;
  grid-row: 3;
  width: 100%;
  max-width: 1640px;
  margin: 0 auto;
  padding: 8px var(--page-x) 40px;
  animation: fade-up .3s var(--ease);
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3) var(--sp-5);
  margin-bottom: 20px;
}
.page-title { font-size: var(--fs-24); font-weight: 600; letter-spacing: -.02em; }
.page-desc { margin-top: 4px; font-size: var(--fs-13); color: var(--text-3); }
.page-actions { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); }

/* ---------- 通知面板 ---------- */
.notice-panel { width: 380px; max-width: calc(100vw - 24px); padding: 0; }
.notice-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.notice-item { display: flex; gap: 11px; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: var(--fs-13); }
.notice-item:hover { background: var(--surface-2); }
.notice-item.is-unread { position: relative; }
.notice-item.is-unread::after { content: ""; position: absolute; right: 14px; top: 16px; width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }

/* ---------- 外观设置 ---------- */
.theme-group { margin-bottom: var(--sp-6); }
.theme-group > .label { display: block; margin-bottom: 10px; }
.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.swatch {
  aspect-ratio: 1;
  border-radius: var(--r-3);
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / .08);
  transition: transform var(--t-fast);
}
.swatch:hover { transform: scale(1.06); }
.swatch.is-active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }
.mode-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 11px 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  font-size: var(--fs-12);
  color: var(--text-2);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.mode-card i { font-size: 15px; }
.mode-card:hover { border-color: var(--line-strong); }
.mode-card.is-active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-text); }

/* ---------- 响应式 ---------- */
.side-mask { display: none; }

@media (max-width: 1280px) {
  .top-search { flex: none; width: 34px; padding: 0; justify-content: center; border: 0; background: none; }
  .top-search span, .top-search kbd { display: none; }
  .top-search:hover { background: var(--head-hover); }
}

@media (max-width: 1024px) {
  .app, [data-collapsed="true"] .app { grid-template-columns: minmax(0, 1fr); }
  .head-brand { width: 200px; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 70;
    width: 272px;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform var(--t-base) var(--ease);
  }
  .is-side-open .sidebar { transform: none; box-shadow: var(--shadow-4); }
  .is-side-open .side-mask { display: block; position: fixed; inset: 0; z-index: 65; background: var(--overlay); animation: fade-in var(--t-base); }
  .crumbbar, .page { grid-column: 1; }
  :root { --page-x: 16px; }

  [data-collapsed="true"] .side-title { display: block; }
  [data-collapsed="true"] .nav-link > .txt { display: block; }
  [data-collapsed="true"] .nav-link > .caret,
  [data-collapsed="true"] .nav-link > .count { display: inline-flex; }
  [data-collapsed="true"] .nav-group.is-open .nav-sub { display: block; }
  [data-collapsed="true"] .nav-link { justify-content: flex-start; padding: 0 10px; }
  [data-collapsed="true"] .side-nav { padding-top: 0; }
}

/* 宽度不足时，一级分类收进侧栏抽屉顶部 */
@media (max-width: 860px) {
  .top-nav { display: none; }
  .head-brand { flex: 1; width: auto; min-width: 0; max-width: 240px; }
  .top-search { margin-left: auto; }
  .side-cats {
    flex: none;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 12px 10px;
    border-bottom: 1px solid var(--side-line);
  }
  .side-cat {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    height: 36px;
    padding: 0 10px;
    border-radius: var(--r-3);
    color: var(--side-text-2);
    font-size: var(--fs-13);
    font-weight: 500;
    white-space: nowrap;
  }
  .side-cat i { width: 14px; text-align: center; font-size: 12px; }
  .side-cat .count { margin-left: auto; }
  .side-cat.is-active { background: var(--side-active); color: var(--side-active-text); font-weight: 600; }
}

@media (max-width: 720px) {
  .crumbs .crumb-parent, .crumbs .sep { display: none; }
  .page-title { font-size: var(--fs-20); }
  .top-only-wide { display: none; }
  .brand-sub { display: none; }
}

/* 可点击的通知 */
a.notice-item { color: inherit; text-decoration: none; }
.notice-go { align-self: center; margin-left: auto; }
.notice-item.is-unread .notice-go { margin-right: 14px; }
a.notice-item.is-unread::after { top: calc(50% - 3px); }
