/* ============================================================
   云笔记系统 · 布局层
   Shell: Sidebar(232) + Topbar(60) + Main
   断点: ≥1200 三栏 | 1024-1199 侧栏可折叠 | <1024 抽屉侧栏 | <768 底部Tab
   ============================================================ */

/* ---------- Shell ---------- */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  background: var(--bg-page);
  /* 双保险：防止任何子元素意外撑破视口宽度 */
  max-width: 100vw;
  overflow-x: clip;
}

/* ---------- 侧边栏 ---------- */
.app-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-default);
  z-index: var(--z-sticky);
  transition: width var(--t-slow) var(--ease-out),
              transform var(--t-slow) var(--ease-out);
}
.app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
.app.is-collapsed .app-sidebar { width: var(--sidebar-w-collapsed); }
.app.is-collapsed .nav-label,
.app.is-collapsed .side-brand__text,
.app.is-collapsed .side-user__meta,
.app.is-collapsed .storage-card,
.app.is-collapsed .side-sec-title { display: none; }
.app.is-collapsed .nav-item { justify-content: center; padding-left: 0; padding-right: 0; }
.app.is-collapsed .nav-item .ic { margin: 0; }

.side-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--sp-4);
  flex: none;
  border-bottom: 1px solid var(--border-subtle);
}
.side-brand__mark {
  flex: none;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: linear-gradient(140deg, var(--brand-400), var(--brand-700));
  color: #fff;
  box-shadow: var(--sh-brand);
}
.side-brand__mark svg { width: 18px; height: 18px; }
.side-brand__text { min-width: 0; }
.side-brand__name {
  font-family: var(--font-serif);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  letter-spacing: 0.04em;
  line-height: 1.1;
}
.side-brand__sub { font-size: 10px; color: var(--text-muted); letter-spacing: 0.14em; text-transform: uppercase; }

.side-nav {
  flex: 1;
  padding: var(--sp-4) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  overflow-y: auto;
  min-height: 0;
}
.side-sec-title {
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  letter-spacing: var(--ls-wide);
}
.side-sec-title:first-child { padding-top: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: 38px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  transition: background-color var(--t-fast) var(--ease-out),
              color var(--t-fast) var(--ease-out);
  position: relative;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.is-active {
  background: var(--bg-active);
  color: var(--accent-soft-text);
  font-weight: var(--fw-semibold);
}
.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: -12px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: var(--brand-600);
  border-radius: 0 var(--r-full) var(--r-full) 0;
}
.nav-item .ic { color: currentColor; flex: none; }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count {
  flex: none;
  min-width: 20px; height: 19px;
  padding: 0 5px;
  display: grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--bg-inset);
  font-size: 11px;
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.nav-item.is-active .nav-count { background: var(--brand-100); color: var(--brand-700); }
[data-theme="dark"] .nav-item.is-active .nav-count { background: var(--brand-200); color: var(--brand-900); }

/* 存储用量卡 */
.storage-card {
  margin: 0 var(--sp-3) var(--sp-3);
  padding: var(--sp-3);
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  flex: none;
}
.storage-card__top {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: var(--fs-xs); color: var(--text-muted); margin-bottom: var(--sp-2);
}
.storage-card__val { font-weight: var(--fw-semibold); color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* 用户卡 */
.side-user {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  margin: 0 var(--sp-3) var(--sp-3);
  border-radius: var(--r-md);
  transition: background-color var(--t-fast) var(--ease-out);
  position: relative;
}
.side-user:hover { background: var(--bg-hover); }
.side-user__meta { min-width: 0; flex: 1; }
.side-user__name { font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.side-user__mail { font-size: 11px; color: var(--text-muted); }

/* ---------- 顶栏 ---------- */
.app-body { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }

.app-topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-6);
  background: color-mix(in srgb, var(--bg-page) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border-default);
  z-index: var(--z-topbar);
}
@supports not (backdrop-filter: blur(1px)) {
  .app-topbar { background: var(--bg-page); }
}
.app.is-collapsed .app-topbar { padding-left: var(--sp-5); }

.topbar__title { min-width: 0; }
.topbar__title h1 { font-size: var(--fs-lg); line-height: 1.2; }
.topbar__crumb { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 1px; }

.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: var(--r-md);
  color: var(--text-secondary);
  transition: background-color var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
  flex: none;
  position: relative;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn.is-active { background: var(--bg-active); color: var(--accent); }
.icon-btn__dot {
  position: absolute; top: 6px; right: 6px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--danger-500);
  border: 2px solid var(--bg-page);
}

.topbar-search {
  width: min(320px, 34vw);
  height: 34px;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  transition: all var(--t-fast) var(--ease-out);
}
.topbar-search:hover { background: var(--bg-hover); border-color: var(--border-default); }
.topbar-search .ic { flex: none; }
.topbar-search__kbd { margin-left: auto; }

/* ---------- 主内容 ---------- */
.app-main {
  flex: 1;
  padding: var(--sp-6);
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  min-width: 0;
  animation: fadeUp var(--t-slow) var(--ease-out);
}
.app-main--flush { padding: 0; max-width: none; }

/* 页面标题条 */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
  /* 顶栏是 sticky，标题条需自行留出让位空间，避免被压住 */
  padding-top: var(--sp-1);
}
.page-head__title { min-width: 0; }
.page-head__sub { font-size: var(--fs-base); color: var(--text-muted); margin-top: var(--sp-1); }
.page-head__actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

/* 工具条 */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
  padding: var(--sp-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xs);
}
.toolbar__sep { width: 1px; height: 20px; background: var(--border-subtle); }

/* 统计卡 */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-4); }
.stat {
  position: relative;
  padding: var(--sp-5);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xs);
  overflow: hidden;
  transition: all var(--t-base) var(--ease-out);
}
.stat:hover { box-shadow: var(--sh-md); transform: translateY(-2px); }
.stat::after {
  content: "";
  position: absolute;
  top: -30px; right: -30px;
  width: 110px; height: 110px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--stat-tint, var(--brand-50)), transparent 70%);
  opacity: 0.9;
  pointer-events: none;
}
.stat__top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.stat__label { font-size: var(--fs-sm); color: var(--text-muted); font-weight: var(--fw-medium); }
.stat__icon {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--stat-tint, var(--brand-50));
  color: var(--stat-color, var(--brand-600));
  flex: none;
}
.stat__value {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  line-height: 1.15;
  margin-top: var(--sp-3);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.stat__foot { display: flex; align-items: center; gap: var(--sp-1); margin-top: var(--sp-1); font-size: var(--fs-xs); color: var(--text-muted); }
.stat__trend { display: inline-flex; align-items: center; gap: 2px; font-weight: var(--fw-medium); }
.stat__trend--up { color: var(--success-700); }
.stat__trend--down { color: var(--danger-600); }

/* ---------- 笔记卡片网格 ---------- */
.note-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: var(--sp-4); }

.note-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: var(--sp-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xs);
  cursor: pointer;
  transition: all var(--t-base) var(--ease-out);
  min-height: 168px;
  text-align: left;
  width: 100%;
  overflow: hidden;
}
.note-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--note-color, transparent);
  opacity: 0;
  transition: opacity var(--t-base) var(--ease-out);
}
.note-card:hover { box-shadow: var(--sh-md); border-color: var(--border-strong); transform: translateY(-3px); }
.note-card:hover::before { opacity: 1; }
.note-card.is-active { border-color: var(--brand-400); background: var(--bg-selected); }
.note-card__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
  margin-bottom: var(--sp-2);
  padding-right: var(--sp-8);
}
.note-card__excerpt {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  line-height: var(--lh-snug);
  flex: 1;
  margin-bottom: var(--sp-3);
}
.note-card__tags { display: flex; flex-wrap: wrap; gap: var(--sp-1); margin-bottom: var(--sp-3); }
.note-card__foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  font-size: var(--fs-xs); color: var(--text-muted);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border-subtle);
}
.note-card__actions {
  position: absolute;
  top: var(--sp-2); right: var(--sp-2);
  display: flex; gap: 2px;
  opacity: 0;
  transform: translateX(4px);
  transition: all var(--t-fast) var(--ease-out);
  background: var(--bg-raised);
  border-radius: var(--r-sm);
  box-shadow: var(--sh-sm);
  padding: 2px;
}
.note-card:hover .note-card__actions,
.note-card:focus-within .note-card__actions { opacity: 1; transform: none; }
.note-card__pin {
  position: absolute; top: var(--sp-3); right: var(--sp-3);
  color: var(--gold-500);
}

/* 列表视图行 */
.note-row {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-out);
  width: 100%;
  text-align: left;
}
.note-row:hover { background: var(--bg-hover); border-color: var(--border-subtle); }
.note-row__icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--note-tint, var(--bg-inset));
  color: var(--note-color, var(--text-muted));
  flex: none;
}
.note-row__main { flex: 1; min-width: 0; }
.note-row__title { font-size: var(--fs-base); font-weight: var(--fw-medium); }
.note-row__excerpt { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 1px; }
.note-row__meta { flex: none; font-size: var(--fs-xs); color: var(--text-muted); text-align: right; }

/* ---------- 编辑器 ---------- */
.editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 316px;
  gap: 0;
  min-height: calc(100vh - var(--topbar-h));
}
.editor__main { padding: var(--sp-8) var(--sp-8) var(--sp-16); min-width: 0; }
.editor__side {
  border-left: 1px solid var(--border-default);
  background: var(--bg-surface);
  padding: var(--sp-5);
  display: flex; flex-direction: column; gap: var(--sp-5);
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.editor__title-input {
  width: 100%;
  border: none;
  background: none;
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: var(--fw-bold);
  line-height: 1.3;
  letter-spacing: 0.01em;
  color: var(--text-primary);
  padding: 0;
  margin-bottom: var(--sp-2);
}
.editor__title-input::placeholder { color: var(--text-placeholder); font-weight: var(--fw-normal); }
.editor__title-input:focus { outline: none; }

.editor__meta {
  display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap;
  font-size: var(--fs-sm); color: var(--text-muted);
  padding-bottom: var(--sp-4);
  margin-bottom: var(--sp-5);
  border-bottom: 1px solid var(--border-subtle);
}

.rte-toolbar {
  position: sticky;
  top: calc(var(--topbar-h) + var(--sp-3));
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 1px;
  flex-wrap: wrap;
  padding: var(--sp-1);
  margin-bottom: var(--sp-5);
  background: color-mix(in srgb, var(--bg-surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  box-shadow: var(--sh-sm);
}
.rte-btn {
  display: grid; place-items: center;
  min-width: 30px; height: 30px;
  padding: 0 var(--sp-2);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  transition: all var(--t-fast) var(--ease-out);
}
.rte-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.rte-btn.is-active { background: var(--bg-active); color: var(--accent); }
.rte-sep { width: 1px; height: 18px; background: var(--border-subtle); margin: 0 var(--sp-1); }

.editor__body {
  font-size: var(--fs-md);
  line-height: var(--lh-loose);
  color: var(--text-primary);
  min-height: 380px;
}
.editor__body:focus { outline: none; }
.editor__body h1 { font-size: 1.6rem; margin: var(--sp-6) 0 var(--sp-3); }
.editor__body h2 { font-size: 1.3rem; margin: var(--sp-6) 0 var(--sp-3); }
.editor__body h3 { font-size: 1.1rem; margin: var(--sp-5) 0 var(--sp-2); }
.editor__body p { margin-bottom: var(--sp-4); }
.editor__body ul, .editor__body ol { margin: 0 0 var(--sp-4) var(--sp-5); list-style: revert; }
.editor__body li { margin-bottom: var(--sp-2); }
.editor__body blockquote {
  margin: var(--sp-4) 0;
  padding: var(--sp-2) var(--sp-5);
  border-left: 3px solid var(--brand-300);
  background: var(--bg-inset);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  color: var(--text-secondary);
  font-style: italic;
}
.editor__body code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--bg-inset);
  padding: 2px 5px;
  border-radius: var(--r-xs);
  border: 1px solid var(--border-subtle);
}
.editor__body pre {
  background: var(--ink-900);
  color: #E8E6E1;
  padding: var(--sp-4);
  border-radius: var(--r-md);
  overflow-x: auto;
  margin-bottom: var(--sp-4);
  font-size: var(--fs-sm);
  line-height: 1.6;
}
.editor__body pre code { background: none; border: none; padding: 0; color: inherit; }
.editor__body img { border-radius: var(--r-md); margin: var(--sp-3) 0; box-shadow: var(--sh-sm); }
.editor__body hr { border: none; border-top: 1px solid var(--border-subtle); margin: var(--sp-6) 0; }
.editor__body a { text-decoration: underline; text-underline-offset: 3px; }
.editor__body table { width: 100%; border-collapse: collapse; margin-bottom: var(--sp-4); font-size: var(--fs-base); }
.editor__body th, .editor__body td { border: 1px solid var(--border-default); padding: var(--sp-2) var(--sp-3); }
.editor__body th { background: var(--bg-inset); font-weight: var(--fw-semibold); }
.editor__body:empty::before,
.editor__body.is-empty::before {
  content: attr(data-placeholder);
  color: var(--text-placeholder);
  pointer-events: none;
}

/* 编辑器侧栏分组 */
.side-group { display: flex; flex-direction: column; gap: var(--sp-3); }
.side-group__title {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  letter-spacing: var(--ls-wide);
  display: flex; align-items: center; gap: var(--sp-2);
}
.side-group__title::after { content: ""; flex: 1; height: 1px; background: var(--border-subtle); }

/* ---------- 备忘录 ---------- */
.memo-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.memo-item {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-left: 3px solid var(--memo-accent, var(--brand-400));
  border-radius: var(--r-md);
  transition: all var(--t-fast) var(--ease-out);
}
.memo-item:hover { box-shadow: var(--sh-sm); border-color: var(--border-strong); border-left-color: var(--memo-accent, var(--brand-400)); }
.memo-item.is-done { opacity: 0.55; }
.memo-item.is-done .memo-item__text { text-decoration: line-through; }
.memo-item__check { margin-top: 1px; }
.memo-item__main { flex: 1; min-width: 0; }
.memo-item__text { font-size: var(--fs-base); line-height: var(--lh-snug); word-break: break-word; }
.memo-item__meta { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-1); flex-wrap: wrap; }
.memo-item__actions { display: flex; gap: 2px; opacity: 0; transition: opacity var(--t-fast); flex: none; }
.memo-item:hover .memo-item__actions, .memo-item:focus-within .memo-item__actions { opacity: 1; }

.prio-1 { --memo-accent: var(--danger-500); }
.prio-2 { --memo-accent: var(--warning-500); }
.prio-3 { --memo-accent: var(--brand-400); }

/* 快速添加 */
.quick-add {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  transition: all var(--t-fast) var(--ease-out);
}
.quick-add:focus-within { border-color: var(--brand-400); border-style: solid; background: var(--bg-selected); }
.quick-add .input { border: none; background: none; padding-left: 0; }
.quick-add .input:focus { box-shadow: none; }

/* ---------- AI 对话 ---------- */
.chat {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 0;
  height: calc(100vh - var(--topbar-h));
}
.chat__main { display: flex; flex-direction: column; min-width: 0; }
.chat__scroll { flex: 1; overflow-y: auto; padding: var(--sp-6) var(--sp-8) var(--sp-4); }
.chat__inner { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--sp-5); }
.chat__side {
  border-left: 1px solid var(--border-default);
  background: var(--bg-surface);
  padding: var(--sp-5);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--sp-5);
}
.chat__composer {
  flex: none;
  padding: var(--sp-4) var(--sp-8) var(--sp-5);
  border-top: 1px solid var(--border-default);
  background: var(--bg-page);
}
.chat__composer-inner { max-width: 780px; margin: 0 auto; }
.composer {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-2);
  background: var(--bg-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.composer:focus-within { border-color: var(--brand-400); box-shadow: var(--sh-focus); }
.composer__input {
  flex: 1;
  border: none; background: none; resize: none;
  padding: var(--sp-2);
  font-size: var(--fs-md);
  line-height: var(--lh-snug);
  max-height: 168px;
  min-height: 40px;
  min-width: 0;
}
.composer__input:focus { outline: none; }
.composer__send {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, var(--ai-500), var(--ai-600));
  color: #fff;
  flex: none;
  transition: all var(--t-fast) var(--ease-out);
}
[data-theme="dark"] .composer__send { color: #1E1938; }
.composer__send:hover:not(:disabled) { filter: brightness(1.1); }
.composer__send:disabled { opacity: 0.4; cursor: not-allowed; }
.composer__tools { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-2); flex-wrap: wrap; }

/* 消息气泡 */
.msg { display: flex; gap: var(--sp-3); animation: fadeUp var(--t-base) var(--ease-out); }
.msg--user { flex-direction: row-reverse; }
.msg__avatar { flex: none; width: 32px; height: 32px; }
.msg__body { min-width: 0; max-width: 100%; }
.msg--user .msg__body { display: flex; flex-direction: column; align-items: flex-end; }
.msg__bubble {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-lg);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  white-space: pre-wrap;
  word-break: break-word;
}
.msg--ai .msg__bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-top-left-radius: var(--r-xs);
}
.msg--user .msg__bubble {
  background: linear-gradient(180deg, var(--brand-500), var(--brand-600));
  color: #fff;
  border-top-right-radius: var(--r-xs);
  max-width: 78%;
}
.msg__foot {
  display: flex; align-items: center; gap: var(--sp-2);
  margin-top: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.msg__actions { display: flex; gap: 2px; opacity: 0; transition: opacity var(--t-fast); }
.msg:hover .msg__actions { opacity: 1; }
.typing { display: inline-flex; gap: 4px; align-items: center; padding: var(--sp-1) 0; }
.typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: fadeUp 1.1s var(--ease-in-out) infinite;
}
.typing span:nth-child(2) { animation-delay: 0.16s; }
.typing span:nth-child(3) { animation-delay: 0.32s; }

/* 模型选择卡 */
.model-card {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--bg-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-out);
  width: 100%;
  text-align: left;
}
.model-card:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.model-card.is-active { border-color: var(--ai-400); background: var(--ai-50); box-shadow: 0 0 0 1px var(--ai-300); }
.model-card__radio {
  flex: none; width: 16px; height: 16px; margin-top: 2px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  display: grid; place-items: center;
  transition: all var(--t-fast) var(--ease-out);
}
.model-card__radio::after {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--ai-500); transform: scale(0);
  transition: transform var(--t-fast) var(--ease-spring);
}
.model-card.is-active .model-card__radio { border-color: var(--ai-500); }
.model-card.is-active .model-card__radio::after { transform: scale(1); }
.model-card__main { flex: 1; min-width: 0; }
.model-card__name {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-base); font-weight: var(--fw-medium);
  font-family: var(--font-mono);
}
.model-card__desc { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; line-height: var(--lh-snug); }
.model-card__cost { flex: none; font-size: var(--fs-xs); color: var(--gold-600); font-weight: var(--fw-medium); font-variant-numeric: tabular-nums; }

/* ---------- 画图工作台 ---------- */
.studio { display: grid; grid-template-columns: 344px minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.studio__panel {
  position: sticky; top: calc(var(--topbar-h) + var(--sp-5));
  display: flex; flex-direction: column; gap: var(--sp-5);
  max-height: calc(100vh - var(--topbar-h) - var(--sp-10));
  overflow-y: auto;
  padding-right: 2px;
}
.studio__canvas {
  min-height: 460px;
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-6);
  background:
    linear-gradient(var(--bg-inset) 1px, transparent 1px) 0 0 / 100% 22px,
    linear-gradient(90deg, var(--bg-inset) 1px, transparent 1px) 0 0 / 22px 100%,
    var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
}

/* 比例选择 */
.ratio-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.ratio-opt {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-2);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  background: var(--bg-raised);
  transition: all var(--t-fast) var(--ease-out);
  cursor: pointer;
}
.ratio-opt:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.ratio-opt.is-active { border-color: var(--ai-400); background: var(--ai-50); box-shadow: 0 0 0 1px var(--ai-300); }
.ratio-opt__shape {
  border: 1.5px solid currentColor;
  border-radius: 3px;
  color: var(--text-muted);
  transition: color var(--t-fast) var(--ease-out);
}
.ratio-opt.is-active .ratio-opt__shape { color: var(--ai-600); border-width: 2px; }
.ratio-opt__label { font-size: var(--fs-xs); font-weight: var(--fw-medium); font-family: var(--font-mono); }

/* 生成结果 */
.gen-result {
  position: relative;
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--sh-lg);
  background: var(--bg-inset);
  max-width: 100%;
}
.gen-result img { width: 100%; height: auto; display: block; }
.gen-result__bar {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: color-mix(in srgb, var(--bg-raised) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border-subtle);
}
.gen-result__acts { margin-left: auto; display: flex; gap: var(--sp-1); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: var(--sp-3); }
.gallery__item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--bg-inset);
  border: 1px solid var(--border-default);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-out);
}
.gallery__item:hover { transform: scale(1.02); box-shadow: var(--sh-md); border-color: var(--brand-400); }
.gallery__item img { width: 100%; height: 100%; object-fit: cover; }
.gallery__item-badge {
  position: absolute; bottom: var(--sp-1); left: var(--sp-1);
  padding: 1px var(--sp-2);
  background: rgba(20,23,25,0.68);
  color: #fff;
  border-radius: var(--r-xs);
  font-size: 10px;
  font-family: var(--font-mono);
}

/* 生成中动画 */
.gen-loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-12);
  color: var(--text-muted);
}
.gen-loading__orb {
  width: 84px; height: 84px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, var(--ai-400), var(--brand-400), var(--ai-600), var(--ai-400));
  filter: blur(1px);
  animation: spin 2.6s linear infinite;
  position: relative;
}
.gen-loading__orb::after {
  content: "";
  position: absolute; inset: 8px;
  border-radius: 50%;
  background: var(--bg-surface);
}
.gen-loading__orb-icon { position: absolute; inset: 0; display: grid; place-items: center; z-index: 1; color: var(--ai-600); }
.gen-loading__text { font-size: var(--fs-base); }
.gen-loading__bar { width: 180px; }

/* ---------- 分享 ---------- */
.share-card {
  display: flex; align-items: flex-start; gap: var(--sp-4);
  padding: var(--sp-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  transition: all var(--t-fast) var(--ease-out);
}
.share-card:hover { box-shadow: var(--sh-md); border-color: var(--border-strong); }
.share-card__thumb {
  width: 68px; height: 68px;
  border-radius: var(--r-md);
  object-fit: cover;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  flex: none;
}
.share-card__main { flex: 1; min-width: 0; }
.share-card__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.share-card__link {
  display: flex; align-items: center; gap: var(--sp-2);
  margin-top: var(--sp-2);
  padding: var(--sp-1) var(--sp-2);
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  min-width: 0;
}
.share-card__meta { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-2); flex-wrap: wrap; }

/* 公开分享页（免登录） */
.public-page {
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 12% -8%, var(--brand-50), transparent 62%),
    radial-gradient(900px 480px at 96% 4%, var(--ai-50), transparent 58%),
    var(--bg-page);
}
.public-bar {
  height: 58px;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-4);
  padding: 0 var(--sp-6);
  border-bottom: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--bg-page) 80%, transparent);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: var(--z-sticky);
}
.public-wrap { max-width: 780px; margin: 0 auto; padding: var(--sp-10) var(--sp-5) var(--sp-16); }
.public-doc {
  background: var(--bg-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  padding: var(--sp-10) var(--sp-8);
}
@media (max-width: 640px) { .public-doc { padding: var(--sp-6) var(--sp-5); border-radius: var(--r-lg); } }

/* 密码墙 */
.pwd-wall {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: var(--sp-6);
  background:
    radial-gradient(900px 460px at 50% -6%, var(--ai-50), transparent 60%),
    var(--bg-page);
}
.pwd-card {
  width: min(400px, 100%);
  padding: var(--sp-8);
  background: var(--bg-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-xl);
  text-align: center;
}
.pwd-lock {
  width: 60px; height: 60px;
  margin: 0 auto var(--sp-4);
  display: grid; place-items: center;
  border-radius: var(--r-xl);
  background: linear-gradient(140deg, var(--ai-100), var(--bg-inset));
  color: var(--ai-600);
}
.pwd-lock .ic { width: 26px; height: 26px; }

/* 分享长图预览 */
.poster {
  position: relative;
  border-radius: var(--r-xl);
  overflow: hidden;
  box-shadow: var(--sh-xl);
  border: 1px solid var(--border-default);
  background: var(--bg-raised);
}
.poster__head {
  padding: var(--sp-8) var(--sp-6) var(--sp-5);
  background: linear-gradient(140deg, var(--brand-600), var(--ai-600));
  color: #fff;
  text-align: center;
}
.poster__body { padding: var(--sp-8) var(--sp-6); }
.poster__foot {
  padding: var(--sp-5) var(--sp-6);
  border-top: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  background: var(--bg-inset);
}
.poster__qr {
  width: 64px; height: 64px;
  border-radius: var(--r-sm);
  background: #fff;
  padding: 4px;
  flex: none;
}

/* ---------- 积分中心 ---------- */
.credit-hero {
  position: relative;
  padding: var(--sp-8);
  border-radius: var(--r-2xl);
  background:
    radial-gradient(700px 300px at 88% -30%, rgba(255,255,255,0.28), transparent 60%),
    linear-gradient(135deg, var(--gold-500), var(--gold-400) 45%, var(--brand-500));
  color: #fff;
  overflow: hidden;
  box-shadow: var(--sh-lg);
}
.credit-hero::after {
  content: "";
  position: absolute; right: -40px; bottom: -60px;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
}
.credit-hero__label { font-size: var(--fs-sm); opacity: 0.92; font-weight: var(--fw-medium); }
.credit-hero__value {
  font-size: 3.25rem;
  font-weight: var(--fw-bold);
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  margin: var(--sp-2) 0 var(--sp-1);
}
.credit-hero__foot { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; position: relative; z-index: 1; }
.credit-hero .btn { background: rgba(255,255,255,0.94); color: var(--gold-700); }
.credit-hero .btn:hover { background: #fff; }

.ledger-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border-subtle);
}
.ledger-item:last-child { border-bottom: none; }
.ledger-item__icon {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  flex: none;
}
.ledger-item__icon--minus { background: var(--danger-50); color: var(--danger-600); }
.ledger-item__icon--plus { background: var(--success-50); color: var(--success-700); }
.ledger-item__amt { font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; flex: none; }
.ledger-item__amt--minus { color: var(--danger-600); }
.ledger-item__amt--plus { color: var(--success-700); }

/* 定价表 */
.price-row {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-4);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  background: var(--bg-surface);
  transition: all var(--t-fast) var(--ease-out);
}
.price-row:hover { border-color: var(--border-strong); box-shadow: var(--sh-sm); }
.price-input {
  width: 92px;
  height: 32px;
  padding: 0 var(--sp-2);
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: var(--fw-semibold);
  background: var(--bg-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  color: var(--text-primary);
}
.price-input:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--sh-focus); }

/* ---------- 登录页 ---------- */
.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
}
.auth__aside {
  position: relative;
  overflow: hidden;
  padding: var(--sp-12);
  display: flex; flex-direction: column; justify-content: space-between;
  background:
    radial-gradient(900px 480px at 18% 12%, rgba(255,255,255,0.16), transparent 58%),
    linear-gradient(150deg, #0E6762 0%, #0C8179 42%, #5C43C7 100%);
  color: #fff;
}
.auth__aside::before {
  content: "";
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.055) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 30% 25%, #000, transparent 78%);
  -webkit-mask-image: radial-gradient(circle at 30% 25%, #000, transparent 78%);
}
.auth__aside > * { position: relative; z-index: 1; }
.auth__brand { display: flex; align-items: center; gap: var(--sp-3); }
.auth__brand-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--r-lg);
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.28);
  backdrop-filter: blur(6px);
}
.auth__pitch { max-width: 460px; }
.auth__pitch h1 {
  font-family: var(--font-serif);
  font-size: 2.6rem;
  font-weight: var(--fw-bold);
  line-height: 1.24;
  letter-spacing: 0.02em;
  margin-bottom: var(--sp-4);
}
.auth__pitch p { font-size: var(--fs-md); line-height: var(--lh-loose); opacity: 0.9; }
.auth__features { display: flex; flex-direction: column; gap: var(--sp-3); margin-top: var(--sp-8); }
.auth__feature { display: flex; align-items: center; gap: var(--sp-3); font-size: var(--fs-base); }
.auth__feature-icon {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: rgba(255,255,255,0.16);
  border: 1px solid rgba(255,255,255,0.2);
  flex: none;
}
.auth__stats { display: flex; gap: var(--sp-8); }
.auth__stat-v { font-size: var(--fs-xl); font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; }
.auth__stat-l { font-size: var(--fs-xs); opacity: 0.78; }

.auth__main {
  display: grid; place-items: center;
  padding: var(--sp-8) var(--sp-6);
  background: var(--bg-page);
  overflow-y: auto;
}
.auth__form { width: min(400px, 100%); }
/* 宽屏收紧左右比例，让表单成为视觉重心而非被空白稀释 */
@media (min-width: 901px) {
  .auth { grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.85fr); }
  .auth__main { padding: var(--sp-10) var(--sp-8); }
}
.auth__title { font-family: var(--font-serif); font-size: 1.85rem; font-weight: var(--fw-bold); letter-spacing: 0.02em; }
.auth__switch { display: flex; gap: var(--sp-4); margin-bottom: var(--sp-6); border-bottom: 1px solid var(--border-subtle); }
.auth__tab {
  position: relative;
  padding: var(--sp-2) 0 var(--sp-3);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  transition: color var(--t-fast) var(--ease-out);
}
.auth__tab:hover { color: var(--text-primary); }
.auth__tab.is-active { color: var(--accent); }
.auth__tab.is-active::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px; background: var(--brand-600);
  border-radius: var(--r-full) var(--r-full) 0 0;
}

@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth__aside { display: none; }
}

/* ---------- 移动端 ---------- */
.app-mobile-nav { display: none; }
.mobile-mask { display: none; }

@media (max-width: 1023px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app-sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    box-shadow: var(--sh-xl);
    /* 隐藏态彻底脱离命中与滚动计算：只靠 transform 会让负坐标元素
       撑大 scrollWidth，移动端出现可横向拖动的空白区域 */
    visibility: hidden;
    pointer-events: none;
  }
  .app.is-drawer-open .app-sidebar {
    transform: none;
    visibility: visible;
    pointer-events: auto;
  }
  .app.is-drawer-open .app-sidebar { transform: none; }
  .app.is-collapsed .app-sidebar { width: var(--sidebar-w); }
  .app.is-collapsed .nav-label,
  .app.is-collapsed .side-brand__text,
  .app.is-collapsed .side-user__meta,
  .app.is-collapsed .storage-card,
  .app.is-collapsed .side-sec-title { display: initial; }
  .app.is-collapsed .nav-item { justify-content: flex-start; padding-left: var(--sp-3); padding-right: var(--sp-3); }
  .app.is-drawer-open .mobile-mask {
    display: block;
    position: fixed; inset: 0;
    background: rgba(20,23,25,0.4);
    z-index: calc(var(--z-sticky) - 1);
    animation: fadeIn var(--t-base) var(--ease-out);
  }
  .studio { grid-template-columns: minmax(0, 1fr); }
  .studio__panel { position: static; max-height: none; }
  .chat { grid-template-columns: minmax(0, 1fr); }
  .chat__side { display: none; }
  .editor { grid-template-columns: minmax(0, 1fr); }
  .editor__side {
    position: static;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--border-default);
  }
}

@media (max-width: 767px) {
  .app-topbar { padding: 0 var(--sp-4); gap: var(--sp-2); }
  .app-main { padding: var(--sp-4); }
  .topbar-search { display: none; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  .stat { padding: var(--sp-4); }
  .stat__value { font-size: var(--fs-xl); }
  .editor__main { padding: var(--sp-5) var(--sp-4) var(--sp-12); }
  .editor__title-input { font-size: 1.5rem; }
  .chat__scroll { padding: var(--sp-4); }
  .chat__composer { padding: var(--sp-3) var(--sp-4) var(--sp-4); }
  .note-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--sp-3); }
  .public-wrap { padding: var(--sp-6) var(--sp-4) var(--sp-12); }
  .public-doc { padding: var(--sp-6) var(--sp-5); }
  .credit-hero { padding: var(--sp-6) var(--sp-5); border-radius: var(--r-xl); }
  .credit-hero__value { font-size: 2.4rem; }
  .ratio-grid { grid-template-columns: repeat(3, 1fr); }
  .modal { width: calc(100vw - 20px); max-height: calc(100vh - 40px); }
  .modal__head, .modal__body { padding-left: var(--sp-5); padding-right: var(--sp-5); }
  .modal__foot { padding-left: var(--sp-5); padding-right: var(--sp-5); }
  .toast-host { top: auto; bottom: calc(var(--touch-min) + var(--sp-6) + var(--sp-3)); right: var(--sp-3); left: var(--sp-3); max-width: none; }

  .app-mobile-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--touch-min) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--bg-surface) 94%, transparent);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border-default);
    z-index: var(--z-topbar);
  }
  .mnav-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: var(--fw-medium);
    transition: color var(--t-fast);
  }
  .mnav-item.is-active { color: var(--accent); }
  .mnav-item .ic { width: 21px; height: 21px; }
  .app { padding-bottom: calc(var(--touch-min) + env(safe-area-inset-bottom, 0px)); }
  .app-topbar { top: 0; }
  .toast-host { bottom: calc(var(--touch-min) + var(--sp-6)); }
}

@media (min-width: 768px) {
  .m-only { display: none !important; }
}
@media (max-width: 767px) {
  .d-only { display: none !important; }
}
