/* ==========================================================================
   表面活性剂知识库 · 基础层
   tokens / reset / 壳层布局（侧栏 + 顶栏 + 内容区）/ 主题
   ========================================================================== */

:root {
  color-scheme: light;

  /* RC3 Paper & Ink (default light) */
  --bg: #f6f2e9;
  --bg-soft: #f1ebdf;
  --surface: #fffdf8;
  --surface-2: #f1ebdf;
  --surface-3: #e9e1d2;
  --surface-inset: #f6f0e4;
  --line: #d9d0bf;
  --line-soft: rgba(23, 26, 25, 0.08);
  --line-strong: #c9bfae;

  --text: #171a19;
  --text-2: #3f4543;
  --text-3: #6b716d;
  --text-4: #959a94;

  --accent: #2f5d62;
  --accent-strong: #1e4449;
  --accent-soft: rgba(47, 93, 98, 0.10);
  --accent-line: rgba(47, 93, 98, 0.30);
  --violet: #6f5b8c;
  --violet-soft: rgba(111, 91, 140, 0.10);
  --teal: #3f7a6f;
  --teal-soft: rgba(63, 122, 111, 0.10);
  --green: #3f7a5c;
  --green-soft: rgba(63, 122, 92, 0.10);
  --amber: #a8782b;
  --amber-soft: rgba(168, 120, 43, 0.11);
  --rose: #9c5a67;
  --rose-soft: rgba(156, 90, 103, 0.10);

  --route-r1: #3d6e91;
  --route-r2: #75618f;
  --route-r3: #437a6a;
  --route-r4: #a47430;
  --route-m: #99566b;
  --chart-baseline: rgba(61, 110, 145, 0.42);

  --shadow-sm: 0 1px 2px rgba(35, 31, 22, 0.06);
  --shadow: 0 1px 2px rgba(35, 31, 22, 0.05), 0 12px 30px -18px rgba(35, 31, 22, 0.25);
  --shadow-lg: 0 40px 100px -40px rgba(35, 31, 22, 0.45);
  --glow: 0 0 0 1px var(--accent-line), 0 10px 28px -20px rgba(35, 31, 22, 0.3);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;

  --sidebar-w: 248px;
  --topbar-h: 64px;
  --content-max: 1560px;

  --font-sans: "Inter", "SF Pro Text", -apple-system, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC",
    system-ui, sans-serif;
  --font-serif: Georgia, Cambria, "Songti SC", "SimSun", "Noto Serif CJK SC", serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", "Cascadia Mono", Consolas,
    "Liberation Mono", monospace;

  --ease: cubic-bezier(0.22, 0.68, 0.35, 1);
  --dur: 0.18s;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  /* RC3 Lab Graphite (dark variant) */
  --bg: #0c1116;
  --bg-soft: #0f151b;
  --surface: #121a21;
  --surface-2: #16212a;
  --surface-3: #1d2b36;
  --surface-inset: #0f171e;
  --line: #26343f;
  --line-soft: rgba(148, 178, 190, 0.14);
  --line-strong: #334552;

  --text: #e9f1f4;
  --text-2: #b6c6cd;
  --text-3: #8297a1;
  --text-4: #5f737d;

  --accent: #5ed4c8;
  --accent-strong: #8ef0e6;
  --accent-soft: rgba(94, 212, 200, 0.14);
  --accent-line: rgba(94, 212, 200, 0.32);
  --violet: #b39ddb;
  --violet-soft: rgba(179, 157, 219, 0.14);
  --teal: #5ed4c8;
  --teal-soft: rgba(94, 212, 200, 0.12);
  --green: #57d6a4;
  --green-soft: rgba(87, 214, 164, 0.12);
  --amber: #e5b567;
  --amber-soft: rgba(229, 181, 103, 0.12);
  --rose: #ef9bb0;
  --rose-soft: rgba(239, 155, 176, 0.13);

  --route-r1: #58a6ff;
  --route-r2: #b39ddb;
  --route-r3: #57d6a4;
  --route-r4: #e5b567;
  --route-m: #ef9bb0;
  --chart-baseline: rgba(88, 166, 255, 0.45);

  --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.03);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03), 0 18px 40px -24px rgba(0, 0, 0, 0.75);
  --shadow-lg: 0 30px 80px -30px rgba(0, 0, 0, 0.9);
  --glow: 0 0 0 1px var(--accent-line), 0 12px 34px -18px rgba(0, 0, 0, 0.55);

  --radius-xs: 4px;
  --radius-sm: 5px;
  --radius: 6px;
  --radius-lg: 10px;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(1100px 460px at 12% -12%, rgba(56, 189, 248, 0.1), transparent 62%),
    radial-gradient(900px 420px at 96% 4%, rgba(167, 139, 250, 0.08), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

:root[data-theme="light"] body {
  background-image:
    radial-gradient(1100px 460px at 12% -12%, rgba(2, 132, 199, 0.08), transparent 62%),
    radial-gradient(900px 420px at 96% 4%, rgba(124, 58, 237, 0.05), transparent 60%);
}

h1, h2, h3, h4, h5, p, ul, ol, figure, dl, dd {
  margin: 0;
}

h1, h2, h3, h4 {
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

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

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--dur) var(--ease);
}
a:hover { color: var(--accent-strong); }

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

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}

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

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

::selection { background: var(--accent-soft); color: var(--text); }

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

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------------------------------------- shell --- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.skip-link {
  position: fixed;
  top: -60px;
  left: 16px;
  z-index: 200;
  padding: 10px 16px;
  background: var(--accent);
  color: #04121f;
  border-radius: var(--radius-sm);
  font-weight: 650;
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: 12px; color: #04121f; }

/* ---- sidebar ---- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 14px 14px;
  background: linear-gradient(180deg, rgba(14, 22, 34, 0.96), rgba(8, 13, 21, 0.98));
  border-right: 1px solid var(--line);
  z-index: 60;
  overflow-y: auto;
  overscroll-behavior: contain;
}

:root[data-theme="light"] .sidebar {
  background: linear-gradient(180deg, #ffffff, #f4f8fd);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 8px 16px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 6px;
  color: var(--text);
}
.brand:hover { color: var(--text); }

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 11px;
  background:
    radial-gradient(120% 120% at 20% 0%, rgba(56, 189, 248, 0.38), transparent 60%),
    linear-gradient(160deg, #123049, #0b1726);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
:root[data-theme="light"] .brand-mark {
  background: linear-gradient(160deg, #e0f2fe, #bae6fd);
  color: #0369a1;
}
.brand-mark svg { width: 22px; height: 22px; }

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name {
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav-group { margin-top: 10px; }
.nav-label {
  padding: 0 10px 6px;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-4);
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  height: 38px;
  padding: 0 11px;
  margin: 2px 0;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 520;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-link svg { width: 17px; height: 17px; flex: none; opacity: 0.85; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link:hover svg { opacity: 1; }
.nav-link.is-active {
  background: linear-gradient(90deg, var(--accent-soft), transparent 85%);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}
.nav-link.is-active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
}
.nav-link.is-active svg { color: var(--accent); opacity: 1; }

.nav-count {
  margin-left: auto;
  min-width: 22px;
  padding: 0 7px;
  height: 19px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  border: 1px solid var(--line);
  color: var(--text-2);
  font: 600 10.5px/1 var(--font-mono);
}
.nav-link.is-active .nav-count { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

.sidebar-foot {
  margin-top: auto;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-inset);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-3);
}
.sidebar-foot .row { display: flex; align-items: center; gap: 7px; }
.sidebar-foot strong { color: var(--text-2); font-weight: 600; }
.sidebar-foot .sep { height: 1px; background: var(--line-soft); margin: 8px 0; }
.sidebar-foot .mono { font-size: 10px; color: var(--text-4); word-break: break-all; }

/* ---- main column ---- */
.main-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--line-soft);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  border: 1px solid transparent;
  transition: all var(--dur) var(--ease);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--line-soft); }
.icon-btn.is-on { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }

.menu-btn { display: none; }

.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 12.5px;
  color: var(--text-3);
}
.crumbs .sep { color: var(--text-4); opacity: 0.7; }
.crumbs strong { color: var(--text); font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs a { color: var(--text-3); }

.topbar-spacer { flex: 1; }

.search-trigger {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 34px;
  width: min(330px, 30vw);
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-3);
  font-size: 12.5px;
  transition: all var(--dur) var(--ease);
}
.search-trigger:hover { border-color: var(--line-strong); color: var(--text-2); background: var(--surface-2); }
.search-trigger svg { width: 15px; height: 15px; flex: none; }
.search-trigger .kbd { margin-left: auto; }

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 26px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-3);
  white-space: nowrap;
}
.mode-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-4); }
.mode-pill.is-live { color: var(--green); border-color: color-mix(in srgb, var(--green) 34%, transparent); background: var(--green-soft); }
.mode-pill.is-live .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.mode-pill.is-mock { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 32%, transparent); background: var(--amber-soft); cursor: pointer; }
.mode-pill.is-mock .dot { background: var(--amber); }
.mode-pill.is-mock:hover { filter: brightness(1.12); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 34px;
  padding: 0 6px 0 4px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  transition: all var(--dur) var(--ease);
}
.user-chip:hover { background: var(--surface-2); border-color: var(--line-soft); }
.avatar {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: linear-gradient(150deg, #1d4ed8, #0e7490);
  color: #e6f6ff;
  font-size: 11px;
  font-weight: 700;
}
:root[data-theme="light"] .avatar { background: linear-gradient(150deg, #0369a1, #0891b2); }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.user-name { font-size: 12px; font-weight: 600; color: var(--text); }
.user-role { font-size: 10px; color: var(--text-3); }

/* ---- content ---- */
.content {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 26px 28px 64px;
  animation: page-in 0.26s var(--ease);
}
@keyframes page-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.page-title-wrap { min-width: 0; }
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.eyebrow .line { width: 18px; height: 1px; background: var(--accent-line); }
.page-title {
  font-size: clamp(22px, 2.4vw, 28px);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-desc {
  margin-top: 6px;
  max-width: 780px;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.65;
}
.page-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

/* mobile scrim */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: none;
  background: rgba(3, 7, 15, 0.62);
  backdrop-filter: blur(3px);
}
.scrim.is-open { display: block; }

/* ---------------------------------------------------------- responsive --- */
@media (max-width: 1180px) {
  :root { --sidebar-w: 226px; }
  .content { padding: 22px 20px 56px; }
  .user-meta { display: none; }
  .search-trigger { width: 220px; }
}

@media (max-width: 1024px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 268px;
    transform: translateX(-102%);
    transition: transform 0.24s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: none; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px 56px; }
  .search-trigger { width: 40px; padding: 0; justify-content: center; }
  .search-trigger .placeholder, .search-trigger .kbd { display: none; }
}

@media (max-width: 640px) {
  .topbar { gap: 8px; }
  .mode-pill .mode-text { display: none; }
  .page-head { align-items: flex-start; }
  .page-title { font-size: 22px; }
  .breadcrumbs-extra { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
