/* Global light / dark theme — Tencent Cloud inspired tech blue */

html[data-theme="light"] {
  color-scheme: light;
  --wa-bg: #f5f7fa;
  --wa-bg-elevated: #ffffff;
  --wa-ink: #1a1a1a;
  --wa-muted: #666666;
  --wa-line: rgba(0, 0, 0, 0.08);
  --wa-primary: #0052d9;
  --wa-primary-hover: #0062ff;
  --wa-accent: #0052d9;
  --wa-hero-from: #eef5ff;
  --wa-hero-to: #d6e8ff;
  --wa-card: #ffffff;
  --wa-shadow: 0 8px 28px rgba(0, 40, 100, 0.08);
  --ink: #1a2332;
  --muted: #64748b;
  --line: #e2e8f0;
  --soft: #f5f7fa;
  --paper: #ffffff;
  --sidebar: #ffffff;
  --sidebar-2: #f5f8fc;
  --sidebar-text: #1a2332;
  --sidebar-muted: #64748b;
  --sidebar-link: #334155;
  --sidebar-hover: rgba(0, 82, 217, 0.06);
  --sidebar-active-bg: linear-gradient(90deg, rgba(0, 82, 217, 0.1), rgba(38, 111, 232, 0.06));
  --sidebar-active-border: rgba(0, 82, 217, 0.28);
  --sidebar-border: rgba(15, 23, 42, 0.08);
  --accent: #3b82f6;
  --accent-2: #0052d9;
  --blue: #0052d9;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --wa-bg: #0b1220;
  --wa-bg-elevated: #121a2b;
  --wa-ink: #e8eef7;
  --wa-muted: #9aa8bc;
  --wa-line: rgba(255, 255, 255, 0.1);
  --wa-primary: #4787f0;
  --wa-primary-hover: #69a1ff;
  --wa-accent: #4787f0;
  --wa-hero-from: #0f1a2e;
  --wa-hero-to: #16325c;
  --wa-card: #151e32;
  --wa-shadow: 0 10px 32px rgba(0, 0, 0, 0.35);
  --ink: #e8eef7;
  --muted: #9aa8bc;
  --line: #243044;
  --soft: #0b1220;
  --paper: #151e32;
  --sidebar: #070d18;
  --sidebar-2: #101a2c;
  --sidebar-text: #f8fafc;
  --sidebar-muted: #94a3b8;
  --sidebar-link: #cbd5e1;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active-bg: linear-gradient(90deg, rgba(71, 135, 240, 0.22), rgba(96, 165, 250, 0.1));
  --sidebar-active-border: rgba(71, 135, 240, 0.35);
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --accent: #60a5fa;
  --accent-2: #4787f0;
  --blue: #4787f0;
}

/* —— App shell: global top nav + sidebar TOC only —— */
html.wa-has-app-nav {
  --wa-app-nav-h: 56px;
}
.wa-app-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  height: var(--wa-app-nav-h, 56px);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  background: var(--wa-bg-elevated, #fff);
  border-bottom: 1px solid var(--wa-line, var(--line, #e2e8f0));
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}
html[data-theme="dark"] .wa-app-nav {
  background: var(--wa-bg-elevated, #121a2b);
  border-bottom-color: var(--wa-line, #243044);
}
.wa-app-logo {
  font-family: "Instrument Serif", Georgia, "PingFang SC", serif;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  color: var(--wa-ink, var(--ink, #1a2332));
  text-decoration: none;
  white-space: nowrap;
  flex: 0 0 auto;
}
.wa-app-logo em {
  font-style: italic;
  color: var(--wa-primary, #0052d9);
}
.wa-app-links {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.wa-app-links::-webkit-scrollbar { display: none; }
.wa-app-links a {
  flex: 0 0 auto;
  text-decoration: none;
  color: var(--wa-muted, var(--muted, #64748b));
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  white-space: nowrap;
  transition: color 0.15s ease, background 0.15s ease;
}
.wa-app-links a:hover {
  color: var(--wa-primary, #0052d9);
  background: rgba(0, 82, 217, 0.06);
  text-decoration: none;
}
.wa-app-links a.active {
  color: var(--wa-primary, #0052d9);
  background: rgba(0, 82, 217, 0.1);
}
html[data-theme="dark"] .wa-app-links a:hover,
html[data-theme="dark"] .wa-app-links a.active {
  background: rgba(71, 135, 240, 0.12);
}
.wa-app-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex: 0 0 auto;
}

html.wa-has-app-nav .sidebar {
  top: var(--wa-app-nav-h) !important;
  height: calc(100vh - var(--wa-app-nav-h)) !important;
  bottom: auto !important;
}
html.wa-has-app-nav .main {
  margin-top: var(--wa-app-nav-h);
}
html.wa-has-app-nav .topbar {
  top: var(--wa-app-nav-h);
}
html.wa-has-app-nav .sidebar .hub[data-wa-hub-legacy] {
  display: none !important;
}
html.wa-has-app-nav .sidebar .hub[data-wa-keep-hub],
html.wa-admin-page .sidebar .hub,
html.wa-admin-page .sidebar .admin-tabs {
  display: block !important;
  visibility: visible !important;
}
html.wa-admin-page .sidebar .admin-tabs > a,
html.wa-admin-page .sidebar .hub[data-wa-keep-hub] > a {
  display: block !important;
}
html.wa-has-app-nav .backdrop {
  top: var(--wa-app-nav-h);
}

@media (max-width: 900px) {
  .wa-app-nav { padding: 0 12px; gap: 10px; }
  .wa-app-links a { padding: 8px 10px; font-size: 13px; }
}

/* Sidebar brand → home */
.brand a.brand-home {
  display: block;
  text-decoration: none !important;
  color: inherit;
  cursor: pointer;
}
.brand a.brand-home:hover h1 {
  color: var(--wa-primary, #0052d9) !important;
}
.brand a.brand-home h1 {
  margin: 0;
}

/* Collapsible sidebar nav */
.wa-nav-toggle {
  cursor: pointer;
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  user-select: none;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}
.wa-nav-toggle:hover {
  color: var(--sidebar-text, #1a2332) !important;
  background: var(--sidebar-hover, rgba(0, 82, 217, 0.06));
}
.wa-nav-chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  opacity: 0.65;
  flex: 0 0 auto;
  transition: transform 0.2s ease;
  margin-right: 4px;
}
.is-collapsed > .wa-nav-toggle .wa-nav-chevron,
a.wa-has-sub.is-sub-collapsed .wa-nav-chevron {
  transform: rotate(-45deg);
  margin-top: -2px;
}
.hub.is-collapsed > :not(.toc-label),
.toc-group.is-collapsed > :not(.toc-label),
.toc.is-collapsed > :not(.toc-label),
.sub.is-collapsed {
  display: none !important;
}
a.wa-has-sub {
  position: relative;
  padding-right: 34px !important;
}
a.wa-has-sub .wa-sub-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
a.wa-has-sub .wa-sub-toggle:hover {
  background: var(--sidebar-hover, rgba(0, 82, 217, 0.08));
}
a.wa-has-sub .wa-sub-toggle .wa-nav-chevron {
  margin: 0;
}

/* Topbar placement on subpages */
.topbar-actions,
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.topbar-actions .topbar-meta {
  font-size: 12px;
  color: var(--muted, #94a3b8);
}
.topbar .wa-theme-slot-top,
.topbar-actions #wa-theme-slot,
.top-actions #wa-theme-slot {
  display: inline-flex;
  align-items: center;
}

/* Theme toggle control */
.wa-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--wa-line, rgba(0, 0, 0, 0.1));
  background: var(--wa-bg-elevated, #fff);
  color: var(--wa-ink, #1a1a1a);
  cursor: pointer;
  padding: 0;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
  flex: 0 0 auto;
}
.wa-theme-toggle:hover {
  transform: translateY(-1px);
  border-color: var(--wa-primary, #0052d9);
}
.wa-theme-toggle svg {
  width: 18px;
  height: 18px;
  display: block;
}
.wa-theme-toggle .wa-icon-sun { display: none; }
.wa-theme-toggle .wa-icon-moon { display: block; }
html[data-theme="dark"] .wa-theme-toggle .wa-icon-sun { display: block; }
html[data-theme="dark"] .wa-theme-toggle .wa-icon-moon { display: none; }

html[data-theme="dark"] .wa-theme-toggle {
  background: rgba(255, 255, 255, 0.06);
  color: #e8eef7;
  border-color: rgba(255, 255, 255, 0.12);
}

/* Subpage surface sync */
html[data-theme="light"] body,
html[data-theme="dark"] body {
  color: var(--ink);
  background: var(--soft);
}

html[data-theme="light"] .main,
html[data-theme="light"] .content,
html[data-theme="dark"] .main,
html[data-theme="dark"] .content {
  color: var(--ink);
  background: var(--soft);
}

html[data-theme="light"] .chapter,
html[data-theme="light"] .book-cover,
html[data-theme="light"] .panel,
html[data-theme="light"] .card,
html[data-theme="light"] .day-card,
html[data-theme="light"] .board,
html[data-theme="light"] .kanban,
html[data-theme="light"] article,
html[data-theme="light"] .paper,
html[data-theme="light"] .empty,
html[data-theme="light"] .task-card,
html[data-theme="dark"] .chapter,
html[data-theme="dark"] .book-cover,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .card,
html[data-theme="dark"] .day-card,
html[data-theme="dark"] .board,
html[data-theme="dark"] .kanban,
html[data-theme="dark"] article,
html[data-theme="dark"] .paper,
html[data-theme="dark"] .empty,
html[data-theme="dark"] .task-card {
  color: var(--ink) !important;
  background: var(--paper) !important;
  border-color: var(--line) !important;
}

html[data-theme="light"] .topbar {
  background: rgba(245, 247, 250, 0.92) !important;
  border-bottom-color: var(--line) !important;
  color: var(--muted);
}
html[data-theme="dark"] .topbar {
  background: rgba(15, 26, 42, 0.92) !important;
  border-bottom-color: var(--line) !important;
  color: var(--muted);
}
html[data-theme="light"] .topbar .crumb b,
html[data-theme="dark"] .topbar .crumb b,
html[data-theme="light"] .crumb b,
html[data-theme="dark"] .crumb b {
  color: var(--ink) !important;
}

html[data-theme="light"] h1,
html[data-theme="light"] h2,
html[data-theme="light"] h3,
html[data-theme="light"] h4,
html[data-theme="light"] .chapter h4,
html[data-theme="light"] .item .title,
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] .chapter h4,
html[data-theme="dark"] .item .title {
  color: var(--ink) !important;
}

html[data-theme="light"] p,
html[data-theme="light"] li,
html[data-theme="light"] td,
html[data-theme="light"] .depth,
html[data-theme="dark"] p,
html[data-theme="dark"] li,
html[data-theme="dark"] td,
html[data-theme="dark"] .depth {
  color: var(--ink);
}
html[data-theme="light"] .lead,
html[data-theme="light"] .book-cover .lead,
html[data-theme="light"] .item .src,
html[data-theme="light"] .muted,
html[data-theme="dark"] .lead,
html[data-theme="dark"] .book-cover .lead,
html[data-theme="dark"] .item .src,
html[data-theme="dark"] .muted {
  color: var(--muted) !important;
}

/* Hardcoded light cards / chips / callouts → theme-aware */
html[data-theme="dark"] .one-liner,
html[data-theme="dark"] .action,
html[data-theme="dark"] .tip,
html[data-theme="dark"] .tier,
html[data-theme="dark"] .section-block,
html[data-theme="dark"] .plan-item,
html[data-theme="dark"] .todo-item,
html[data-theme="dark"] .src-grid .src,
html[data-theme="dark"] .quick a {
  color: var(--ink) !important;
  background: rgba(71, 135, 240, 0.1) !important;
  border-color: rgba(71, 135, 240, 0.28) !important;
}
html[data-theme="light"] .one-liner,
html[data-theme="light"] .action {
  color: var(--ink) !important;
}

html[data-theme="dark"] .section-block.bonus {
  background: rgba(139, 92, 246, 0.12) !important;
  border-left-color: #8b5cf6 !important;
}
html[data-theme="dark"] .section-block.fw {
  background: rgba(37, 99, 235, 0.12) !important;
  border-left-color: #3b82f6 !important;
}
html[data-theme="dark"] .section-block.oss {
  background: rgba(5, 150, 105, 0.12) !important;
  border-left-color: #10b981 !important;
}
html[data-theme="dark"] .section-block.bp {
  background: rgba(217, 119, 6, 0.12) !important;
  border-left-color: #f59e0b !important;
}
html[data-theme="dark"] .section-block.src {
  background: rgba(2, 132, 199, 0.12) !important;
  border-left-color: #38bdf8 !important;
}

html[data-theme="light"] .chip,
html[data-theme="dark"] .chip {
  background: var(--paper) !important;
  border-color: var(--line) !important;
  color: var(--ink) !important;
}
html[data-theme="light"] .chip b,
html[data-theme="dark"] .chip b {
  color: var(--blue) !important;
}

html[data-theme="dark"] .note {
  color: #fde68a !important;
  background: rgba(120, 53, 15, 0.35) !important;
  border-color: rgba(245, 158, 11, 0.35) !important;
  border-left-color: #f59e0b !important;
}
html[data-theme="light"] .note {
  color: #92400e !important;
  background: #fffbeb !important;
}
/* sources 卡片内 .note 是说明文字，不是警告条 */
html[data-theme="dark"] .src .note,
html[data-theme="light"] .src .note {
  color: var(--muted) !important;
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
}
html[data-theme="dark"] .src .name,
html[data-theme="dark"] .src .kind {
  color: var(--ink) !important;
}
html[data-theme="dark"] .src .kind { color: var(--muted) !important; }

html[data-theme="dark"] table,
html[data-theme="dark"] th,
html[data-theme="dark"] td {
  background: var(--paper) !important;
  color: var(--ink) !important;
  border-color: var(--line) !important;
}
html[data-theme="dark"] th {
  background: rgba(255, 255, 255, 0.04) !important;
}
html[data-theme="light"] table,
html[data-theme="light"] th,
html[data-theme="light"] td {
  color: var(--ink);
  border-color: var(--line);
}

html[data-theme="dark"] .menu-btn,
html[data-theme="dark"] .top-actions button,
html[data-theme="dark"] .panel-head .add,
html[data-theme="dark"] .src .links a,
html[data-theme="dark"] .task-card select,
html[data-theme="dark"] .task-card .tag-edit {
  background: var(--paper) !important;
  color: var(--ink) !important;
  border-color: var(--line) !important;
}
html[data-theme="dark"] .top-actions button.primary,
html[data-theme="dark"] .src .links a.primary {
  background: var(--wa-primary) !important;
  color: #fff !important;
  border-color: var(--wa-primary) !important;
}

html[data-theme="dark"] .focus-input,
html[data-theme="dark"] .notes,
html[data-theme="dark"] .inline-edit,
html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
  color: var(--ink) !important;
  background: rgba(255, 255, 255, 0.04) !important;
  border-color: var(--line) !important;
}
html[data-theme="dark"] .focus-input::placeholder,
html[data-theme="dark"] .notes::placeholder,
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: var(--muted) !important;
}

html[data-theme="light"] .menu-btn,
html[data-theme="light"] .top-actions button:not(.primary) {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

/* Sidebar follows theme (light ↔ dark) */
html[data-theme="light"] .sidebar,
html[data-theme="dark"] .sidebar {
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%) !important;
  color: var(--sidebar-link) !important;
  border-right: 1px solid var(--sidebar-border) !important;
  transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}
html[data-theme="light"] .sidebar::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.15) !important;
}
html[data-theme="dark"] .sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15) !important;
}

html[data-theme="light"] .brand,
html[data-theme="dark"] .brand {
  background: color-mix(in srgb, var(--sidebar) 92%, transparent) !important;
  border-bottom: 1px solid var(--sidebar-border) !important;
  backdrop-filter: blur(8px);
}
html[data-theme="light"] .brand h1,
html[data-theme="dark"] .brand h1 {
  color: var(--sidebar-text) !important;
}
html[data-theme="light"] .brand p,
html[data-theme="dark"] .brand p {
  color: var(--sidebar-muted) !important;
}
html[data-theme="light"] .brand .mark {
  color: #fff !important;
  background: linear-gradient(135deg, #0052d9, #266fe8) !important;
}
html[data-theme="dark"] .brand .mark {
  color: #0b1220 !important;
  background: linear-gradient(135deg, #60a5fa, #4787f0) !important;
}

html[data-theme="light"] .hub,
html[data-theme="dark"] .hub,
html[data-theme="light"] .sidebar-foot,
html[data-theme="dark"] .sidebar-foot {
  border-color: var(--sidebar-border) !important;
  color: var(--sidebar-muted) !important;
}
html[data-theme="light"] .sidebar-foot a,
html[data-theme="dark"] .sidebar-foot a {
  color: var(--wa-primary) !important;
}

html[data-theme="light"] .toc-label,
html[data-theme="dark"] .toc-label,
html[data-theme="light"] .hub .toc-label,
html[data-theme="dark"] .hub .toc-label {
  color: var(--sidebar-muted) !important;
}

html[data-theme="light"] .hub a,
html[data-theme="light"] .toc a,
html[data-theme="light"] .toc a.day,
html[data-theme="dark"] .hub a,
html[data-theme="dark"] .toc a,
html[data-theme="dark"] .toc a.day {
  color: var(--sidebar-link) !important;
  border-color: transparent !important;
}
html[data-theme="light"] .hub a small,
html[data-theme="light"] .toc a small,
html[data-theme="light"] .toc a.day .hint,
html[data-theme="dark"] .hub a small,
html[data-theme="dark"] .toc a small,
html[data-theme="dark"] .toc a.day .hint {
  color: var(--sidebar-muted) !important;
}

html[data-theme="light"] .hub a:hover,
html[data-theme="light"] .toc a:hover,
html[data-theme="light"] .toc a.day:hover,
html[data-theme="dark"] .hub a:hover,
html[data-theme="dark"] .toc a:hover,
html[data-theme="dark"] .toc a.day:hover {
  background: var(--sidebar-hover) !important;
  color: var(--sidebar-text) !important;
  text-decoration: none !important;
}

html[data-theme="light"] .hub a.here,
html[data-theme="light"] .toc a.active,
html[data-theme="light"] .toc a.day.active,
html[data-theme="dark"] .hub a.here,
html[data-theme="dark"] .toc a.active,
html[data-theme="dark"] .toc a.day.active {
  background: var(--sidebar-active-bg) !important;
  color: var(--sidebar-text) !important;
  border-color: var(--sidebar-active-border) !important;
}
html[data-theme="light"] .hub a.here small,
html[data-theme="light"] .toc a.active small,
html[data-theme="dark"] .hub a.here small,
html[data-theme="dark"] .toc a.active small {
  color: var(--sidebar-muted) !important;
}

html[data-theme="light"] .toc .sub a::before {
  background: #94a3b8 !important;
}
html[data-theme="dark"] .toc .sub a::before {
  background: #475569 !important;
}

/* Auth widget inside light sidebar */
html[data-theme="light"] .sidebar .wa-auth-bar .wa-auth-user { color: #475569; }
html[data-theme="light"] .sidebar .wa-auth-bar a.wa-auth-btn,
html[data-theme="light"] .sidebar .wa-auth-bar button.wa-auth-btn {
  border-color: #dce4eb;
  background: #fff;
  color: #15202b;
}
html[data-theme="light"] .sidebar .wa-auth-bar a.wa-auth-btn.primary {
  background: linear-gradient(135deg, #0052d9, #266fe8);
  color: #fff;
  border: none;
}

/* Beian bar follows theme */
html[data-theme="dark"] .wa-beian {
  color: #8b9bb0;
  border-top-color: rgba(255, 255, 255, 0.08);
}
html[data-theme="dark"] .wa-beian a { color: #8b9bb0; }
html[data-theme="dark"] .wa-beian a:hover { color: #69a1ff; }

/* Auth bar on dark pages stays readable */
html[data-theme="light"] .wa-auth-bar.light a.wa-auth-btn.primary {
  background: linear-gradient(135deg, #0052d9, #266fe8);
  color: #fff;
}
