*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-ui);
  font-size: var(--fs-14);
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
  text-rendering: optimizeLegibility;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
h1, h2, h3, h4, p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
.ic { flex: none; display: block; }
[hidden] { display: none !important; }
.mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: var(--ls-display); }
.echo-type { font-family: var(--font-echo); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-xs); }
::selection { background: var(--primary-soft); color: var(--ink); }

* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

/* ---------- Shell ---------- */
/* 桌面软件的窗体：一块浮台，左侧是固定的三段式导航，右侧内容独立滚动 */
.shell {
  height: 100vh; height: 100dvh;
  /* Android 边到边 / iOS 刘海：把系统安全区叠进浮台外边距。
     桌面浏览器 env() 全为 0，因此这一行在 Web/桌面壳下不产生任何视觉变化 */
  padding:
    calc(var(--shell-pad) + env(safe-area-inset-top, 0px))
    calc(var(--shell-pad) + env(safe-area-inset-right, 0px))
    calc(var(--shell-pad) + env(safe-area-inset-bottom, 0px))
    calc(var(--shell-pad) + env(safe-area-inset-left, 0px));
}
.shell-slab {
  display: flex; flex-direction: column; height: 100%; overflow: hidden;
  border-radius: var(--r-workspace);
  background: var(--slab);
  box-shadow: var(--shadow-workspace);
}
.shell-body { flex: 1; min-height: 0; display: flex; position: relative; }
.shell-main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }

/* ---------- 桌面壳窗体（Electron） ----------
   没有系统标题栏：整个窗口就是这块浮台，四角的弧度按设计令牌裁出来。
   全屏浮层（登录门、引导页、弹层遮罩）也要跟着窗口圆角走，
   否则它们会把透明的四个角重新涂实。
   Web 下 html 上没有 is-desktop，下面这些一条都不生效。 */
html.is-desktop, html.is-desktop body { background: transparent; }
html.is-desktop .shell { padding: 0; }
html.is-desktop .shell-slab { border-radius: var(--r-workspace); box-shadow: none; }
html.is-desktop .login-gate,
html.is-desktop .start-guide,
html.is-desktop .scrim,
html.is-desktop .lightbox { border-radius: var(--r-workspace); }
html.is-desktop.win-max .shell-slab,
html.is-desktop.win-max .login-gate,
html.is-desktop.win-max .start-guide,
html.is-desktop.win-max .scrim,
html.is-desktop.win-max .lightbox { border-radius: 0; }

/* 拖拽：顶栏整行与登录门左栏，按钮和输入框照常可点 */
html.is-desktop .topbar { -webkit-app-region: drag; }
/* 登录门打开时顶栏在它下面：别让被盖住的拖拽区抢走门上的点击 */
html.is-desktop.lg-lock .topbar { -webkit-app-region: no-drag; }
html.is-desktop .topbar button,
html.is-desktop .topbar a,
html.is-desktop .topbar input,
html.is-desktop .topbar [data-action] { -webkit-app-region: no-drag; }
html.is-desktop .lg-brand { -webkit-app-region: drag; }
html.is-desktop .lg-brand a,
html.is-desktop .lg-brand button,
html.is-desktop .lg-brand input { -webkit-app-region: no-drag; }
/* 顶栏最右侧给自绘的窗口按钮留出位置，页头与正文的左右边线仍然对齐 */
html.is-desktop .topbar-inner::after { content: ""; flex: none; width: 132px; }

.win-controls {
  position: fixed; top: 8px; right: 10px; z-index: 120;
  display: flex; gap: 2px; -webkit-app-region: no-drag;
}
.win-btn {
  width: 38px; height: 28px; display: grid; place-items: center;
  border-radius: 8px; color: var(--ink-3);
  transition: background var(--t-fast), color var(--t-fast);
}
.win-btn svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.1; stroke-linecap: round; stroke-linejoin: round; }
.win-btn:hover { background: var(--bg-sunk); color: var(--ink); }
.win-btn.win-close:hover { background: #c94f45; color: #fff; }
.win-btn .ic-restore { display: none; }
.win-btn.is-max .ic-max { display: none; }
.win-btn.is-max .ic-restore { display: block; }

/* 顶：品牌；中：可滚动分组导航；底：折叠按钮 + 账户，永远贴在栏底（设置入口在账户菜单里） */
.sidebar {
  position: relative; flex: none;
  width: var(--side-w, 248px); height: 100%;
  display: flex; flex-direction: column;
  background: var(--card);
  border-right: 1px solid var(--line);
  transition: width var(--t-med) var(--ease);
  overflow: hidden;
}
.sidebar[data-collapsed="true"] { width: 72px; }
/* 拖动时关掉 width 过渡，否则栏宽会跟在鼠标后面漂 */
.sidebar.resizing { transition: none; }

/* 把手骑在侧栏与正文的分界线上（不是贴在侧栏内侧），
   这样不会盖住导航区那条 6px 宽的滚动条。悬停/聚焦/拖动时才显出竖线。 */
.side-resizer {
  position: absolute; z-index: 3; top: 0; bottom: 0;
  left: calc(var(--side-w, 248px) - 4px); width: 9px;
  padding: 0; border: 0; background: none;
  cursor: col-resize; touch-action: none;
}
.side-resizer::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px;
  border-radius: var(--r-pill); background: var(--line-strong);
  opacity: 0; transition: opacity var(--t-fast);
}
.side-resizer:hover::after, .side-resizer:focus-visible::after,
.side-resizer.dragging::after { opacity: 1; }
.side-resizer:focus-visible { outline: none; }
.sidebar[data-collapsed="true"] ~ .side-resizer { display: none; }
body.resizing, body.resizing * { cursor: col-resize !important; user-select: none; }

.side-brand-row { flex: none; height: 68px; display: flex; align-items: center; padding: 0 var(--s-4); }
.side-brand {
  display: flex; align-items: center; gap: var(--s-2h); min-width: 0;
  padding: var(--s-1) var(--s-1h); margin-left: calc(var(--s-1h) * -1);
  border-radius: var(--r-field);
  transition: background var(--t-fast);
}
.side-brand:hover { background: var(--bg-sunk); }
.side-brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sidebar .side-brand-mark { width: 34px; height: 34px; }
.side-brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.12; }
.side-brand-text b { font-size: var(--fs-15); font-weight: 650; letter-spacing: var(--ls-display); color: var(--ink); }

.side-nav {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: var(--s-1) var(--s-3) var(--s-3);
  display: flex; flex-direction: column; gap: var(--s-3h);
}
.side-nav::-webkit-scrollbar { width: 6px; }
.side-nav::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: var(--r-pill); }
.side-group { display: flex; flex-direction: column; gap: var(--s-0h); }
.side-group-label {
  padding: var(--s-1h) var(--s-2h) var(--s-1);
  font-size: var(--fs-micro); font-weight: 600; line-height: 1.4;
  letter-spacing: var(--ls-caps); color: var(--ink-4);
}
.side-nav-item {
  position: relative; display: flex; align-items: center; gap: var(--s-2h);
  min-height: 42px; padding: 0 var(--s-2h);
  border-radius: 9px;
  color: var(--ink-2); font-size: 13.5px; font-weight: 450;
  transition: background var(--t-fast), color var(--t-fast);
}
.side-nav-item .ic { color: var(--ink-3); transition: color var(--t-fast); }
.side-nav-item:hover { background: color-mix(in srgb, var(--accent-soft) 62%, var(--card)); color: var(--ink); }
.side-nav-item:hover .ic { color: var(--accent); }
.side-nav-item[aria-current="page"] { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(30, 30, 40, .06); }
.side-nav-item[aria-current="page"]::before { content: ""; position: absolute; left: -8px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.side-nav-item[aria-current="page"] .ic { color: var(--accent); }
.side-nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.side-nav-ic { width: 22px; display: grid; place-items: center; flex: none; }
.side-nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-nav-count {
  margin-left: auto; min-width: 21px; height: 19px; padding: 0 var(--s-1h);
  display: grid; place-items: center; flex: none;
  border-radius: var(--r-pill); background: var(--bg-sunk); color: var(--ink-3);
  font-size: var(--fs-micro); line-height: 1; font-family: var(--font-mono);
}
.side-nav-item[aria-current="page"] .side-nav-count {
  background: color-mix(in srgb, var(--accent) 16%, var(--card));
  color: var(--accent);
}
.side-nav-dot { margin-left: auto; width: 6px; height: 6px; border-radius: 50%; background: var(--orange); flex: none; }
.side-nav-dot.live { background: var(--accent); animation: pulse 1.6s var(--ease) infinite; }

/* 无组标题的那一组（首页单独放）不需要标签行的上间距 */
.side-group.is-plain { gap: 0; }

/* 底：固定栏。账户和收起按钮同处一栏，靠底色而不是描边和栏身断开；
   左右内距与 .side-nav 一致，所以头像正好落在导航图标那一列上。 */
.side-foot {
  flex: none; height: 64px; padding: 0 var(--s-3);
  background: var(--side-foot-bg);
  display: flex; align-items: center; gap: var(--s-1);
}
.side-collapse {
  flex: none; width: 30px; height: 30px; margin-left: auto;
  display: grid; place-items: center;
  border-radius: var(--r-xs); background: var(--side-chip); color: var(--ink-3);
  transition: background var(--t-fast), color var(--t-fast);
}
.side-collapse:hover { background: var(--side-chip-hover); color: var(--ink); }
.side-collapse:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* 账户项按内容收宽，不铺满整条底座，剩下的空白交给右侧的收起圆片压住栏尾 */
.account-entry {
  flex: 0 1 auto; min-width: 0; height: 44px; padding: 0 var(--s-2h);
  display: flex; align-items: center; gap: var(--s-2h);
  border-radius: 10px; text-align: left;
  transition: background var(--t-fast);
}
.account-entry:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.account-entry[aria-current="page"] { background: var(--accent-soft); }
.account-entry:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.avatar.account-avatar { width: 40px; height: 40px; flex: none; font-size: var(--fs-14); }
.account-meta { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; }
.account-name { font-size: var(--fs-13); font-weight: 650; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-sub { font-size: var(--fs-micro); color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar[data-collapsed="true"] .side-brand-row { padding: 0; justify-content: center; }
.sidebar[data-collapsed="true"] .side-brand { padding: var(--s-1h); margin: 0; }
.sidebar[data-collapsed="true"] .side-brand-text,
.sidebar[data-collapsed="true"] .side-group-label,
.sidebar[data-collapsed="true"] .side-nav-label,
.sidebar[data-collapsed="true"] .account-meta { display: none; }
.sidebar[data-collapsed="true"] .side-nav {
  padding: var(--s-1h) var(--s-2h) var(--s-2h);
  align-items: center; gap: var(--s-2);
}
.sidebar[data-collapsed="true"] .side-group { width: 100%; align-items: center; gap: var(--s-0h); }
.sidebar[data-collapsed="true"] .side-nav-item {
  width: 44px; min-height: 44px; padding: 0; justify-content: center; border-radius: 10px;
}
.sidebar[data-collapsed="true"] .side-nav-count {
  position: absolute; top: 4px; right: 3px; margin: 0;
  min-width: 16px; height: 16px; padding: 0 var(--s-fine-1);
  font-size: var(--fs-tick-sm);
  background: var(--accent); color: var(--accent-fg);
  box-shadow: 0 0 0 2px var(--card);
}
.sidebar[data-collapsed="true"] .side-nav-dot { position: absolute; top: 8px; right: 8px; margin: 0; }
.sidebar[data-collapsed="true"] .side-foot {
  height: auto; flex-direction: column; gap: var(--s-1h);
  padding: var(--s-2h) 0 var(--s-3);
}
.sidebar[data-collapsed="true"] .account-entry { flex: none; width: 44px; height: 44px; padding: 0; justify-content: center; }
.sidebar[data-collapsed="true"] .account-avatar { width: 36px; height: 36px; }
.sidebar[data-collapsed="true"] .side-collapse { margin-left: 0; }

.topbar {
  flex: none;
  height: var(--topbar-h);
  padding: 0 var(--view-pad-x);
}
/* 内层跟 .page 用同一套居中，顶栏这一行的左右边线才对得上正文列 */
.topbar-inner {
  height: 100%; max-width: var(--content-max); margin: 0 auto;
  display: flex; align-items: center; gap: var(--s-3);
}
kbd {
  font-family: var(--font-mono); font-size: var(--fs-11); color: var(--ink-3);
  padding: var(--s-hair) var(--s-1h); border-radius: var(--r-cell); border: 1px solid var(--line); background: var(--bg);
}
.topbar-spacer { flex: 1; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--r-sm);
  color: var(--ink-2); transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--bg-sunk); color: var(--ink); }
.icon-btn.sm { width: 28px; height: 28px; border-radius: var(--r-control-sm); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--lavender-soft), var(--primary-soft));
  color: var(--primary-ink); font-weight: 600; font-size: var(--fs-13);
  box-shadow: inset 0 0 0 1px var(--primary-line);
  overflow: hidden; flex: none;
}
.avatar.has-photo { background: var(--bg-sunk); }
.avatar.has-art { background: none; }
.avatar img, .avatar svg { width: 100%; height: 100%; display: block; }
.avatar img { object-fit: cover; }
.focus-pill {
  display: inline-flex; align-items: center; gap: var(--s-2); height: 30px; padding: 0 var(--s-3) 0 var(--s-2h);
  border-radius: var(--r-pill); background: var(--primary-soft); color: var(--primary-ink);
  font-size: var(--fs-13); font-weight: 500;
}
.focus-pill .pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); animation: pulse 1.6s var(--ease) infinite; }

/* 滚动契约：浮台外框、顶栏、图标轨、页头（.page-head）常驻不动；
   页内卡片、时间线、图表随内容在 .view 里滚动 */
.view { flex: 1; min-width: 0; min-height: 0; overflow-y: auto; padding: 0 var(--view-pad-x) 120px; outline: none; }
.page { max-width: var(--content-max); margin: 0 auto; }
/* 没有常驻页头的页面（如漂流瓶），自己补一段顶部呼吸 */
.page:not(:has(.page-head)) { padding-top: var(--s-3); }
.page.enter { animation: page-in var(--t-page) var(--ease) both; }
.nav-dot.live { background: var(--primary); animation: pulse 1.6s var(--ease) infinite; }
.focus-pill .pill-label { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 同步状态：全站只有顶栏这一处，各页不许自己画 */
.sync-pill {
  display: inline-flex; align-items: center; gap: var(--s-2); height: 30px; padding: 0 var(--s-3);
  border-radius: var(--r-pill); border: 1px solid var(--line);
  background: var(--card); color: var(--ink-2);
  font-size: var(--fs-13); font-weight: 500; white-space: nowrap;
}
.sync-pill .ic { opacity: .8; }
.sync-pill:disabled { cursor: default; }
.sync-pill[data-phase="syncing"] { border-color: var(--primary-line); background: var(--primary-soft); color: var(--primary-ink); }
.sync-pill[data-phase="syncing"] .ic { animation: spin 1.1s linear infinite; }
.sync-pill[data-phase="error"] { border-color: transparent; background: var(--urgent-soft); color: var(--urgent); }
.sync-pill[data-phase="conflict"] { border-color: transparent; background: var(--rose-soft); color: var(--rose); }
.sync-pill[data-phase="blocked"] { border-color: transparent; background: var(--urgent-soft); color: var(--urgent); }
.sync-pill[data-phase="offline"] { opacity: .7; }
/* 等自动重试：还在办事，但不用转圈——转圈会让人以为已经连上了。 */
.sync-pill[data-phase="retry"] { border-color: var(--primary-line); color: var(--primary-ink); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 900px) { .sync-pill .sync-label { display: none; } .sync-pill { padding: 0 var(--s-2h); } }

@keyframes page-in { from { opacity: 0; transform: translateY(var(--s-1h)); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- FAB ---------- */
.fab-stack { position: fixed; right: var(--s-7); bottom: var(--s-7); z-index: 30; display: flex; flex-direction: column; align-items: flex-end; gap: var(--s-2h); }
.fab {
  display: inline-flex; align-items: center; gap: var(--s-2);
  height: 44px; padding: 0 var(--s-4h) 0 var(--s-3h); border-radius: var(--r-pill);
  font-weight: 500; font-size: var(--fs-14);
  box-shadow: var(--shadow-1);
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast);
}
.fab:hover { transform: translateY(-1px); }
.fab:active { transform: translateY(0) scale(.98); }
.fab-new { background: var(--ink); color: var(--card); }
[data-mode="dark"] .fab-new { background: var(--primary); color: var(--on-primary); }
.fab-ai { height: 38px; background: var(--card); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow-1); }
.fab-ai .ic { color: var(--lavender); }

/* ---------- Mobile nav ---------- */
.mobile-nav { display: none; }

@media (max-width: 1080px) {
  :root { --view-pad-x: var(--s-4); }
}

@media (max-width: 760px) {
  :root { --shell-pad: 0px; }
  .shell-slab { border-radius: 0; }
  .sidebar, .side-resizer, .fab-stack { display: none; }
  .view { padding: 0 var(--view-pad-x) calc(96px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
