/* ==========================================================================
   base.css — 设计令牌 / 重置 / 侧边栏 / 通用控件
   参考 kaworkai 的视觉语言：Apple 系灰阶、大圆角、药丸控件、13px 正文
   ========================================================================== */

:root {
  /* 圆角 */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-2xl: 28px;
  --r-pill: 999px;

  /* 字号 */
  --fs-11: 11px;
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-15: 15px;
  --fs-17: 17px;
  --fs-20: 20px;
  --fs-24: 24px;
  --fs-28: 28px;
  --fs-34: 34px;

  /* 间距 */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* 灰阶 */
  --gray-1: #fbfbfd;
  --gray-2: #f5f5f7;
  --gray-3: #f2f2f7;
  --gray-4: #f0f0f0;
  --gray-5: #e5e5ea;
  --gray-6: #e0e0e0;
  --gray-7: #d1d1d6;
  --gray-8: #c7c7cc;
  --gray-9: #a1a1a6;
  --gray-10: #86868b;
  --gray-11: #6e6e73;
  --gray-12: #48484a;
  --gray-13: #333336;
  --gray-14: #1d1d1f;

  /* 语义色（浅色） */
  --bg: #f5f5f7;
  --bg-alt: #ffffff;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --surface-3: #f2f2f7;
  --surface-hover: rgba(0, 0, 0, 0.035);
  --line: rgba(0, 0, 0, 0.08);
  --line-soft: rgba(0, 0, 0, 0.055);
  --line-faint: rgba(0, 0, 0, 0.028);
  --ink: #1d1d1f;
  --ink-2: #48484a;
  --ink-3: #6e6e73;
  --ink-muted: #86868b;
  --ink-faint: #a1a1a6;
  --accent: #35353c;
  --accent-hover: #48484a;
  --accent-ink: #ffffff;
  --brand: #6e56f8;
  --brand-soft: rgba(110, 86, 248, 0.10);
  --danger: #d93a3a;
  --ok: #2e9e5b;
  --warn: #c98a00;

  /* 阴影 */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.06), 0 0 0 0.5px rgba(0, 0, 0, 0.05);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.1);
  --shadow-3: 0 12px 40px rgba(0, 0, 0, 0.16);
  --shadow-pop: 0 8px 32px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.06);
  --vibrancy: saturate(180%) blur(20px);
  --vibrancy-bg: rgba(255, 255, 255, 0.78);

  --sidebar-w: 232px;
  --sidebar-w-collapsed: 64px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg: #101012;
  --bg-alt: #17171a;
  --surface: #1c1c1f;
  --surface-2: #202024;
  --surface-3: #26262b;
  --surface-hover: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.10);
  --line-soft: rgba(255, 255, 255, 0.07);
  --line-faint: rgba(255, 255, 255, 0.04);
  --ink: #f5f5f7;
  --ink-2: #d6d6da;
  --ink-3: #a8a8ae;
  --ink-muted: #8e8e93;
  --ink-faint: #6e6e73;
  --accent: #f5f5f7;
  --accent-hover: #ffffff;
  --accent-ink: #17171a;
  --brand: #8d7bff;
  --brand-soft: rgba(141, 123, 255, 0.16);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5), 0 0 0 0.5px rgba(255, 255, 255, 0.06);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.5);
  --shadow-3: 0 12px 40px rgba(0, 0, 0, 0.6);
  --shadow-pop: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 0 0.5px rgba(255, 255, 255, 0.08);
  --vibrancy-bg: rgba(24, 24, 27, 0.78);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  font-size: var(--fs-13);
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: 0.005em;
}

h1, h2, h3, h4, p, figure {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}

input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

svg {
  display: block;
}

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

::selection {
  background: var(--brand-soft);
}

/* 滚动条 */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--gray-8) transparent;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-thumb {
  background: var(--line-soft);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--ink-faint);
  background-clip: content-box;
}
*::-webkit-scrollbar-track {
  background: transparent;
}

/* ==========================================================================
   应用外壳
   ========================================================================== */

.page {
  min-height: 100vh;
  padding-left: var(--sidebar-w-collapsed);
  transition: padding-left 0.24s cubic-bezier(0.22, 0.61, 0.36, 1);
  animation: page-in 0.36s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

::selection {
  background: rgba(110, 86, 248, 0.18);
}

body.sidebar-expanded .page {
  padding-left: var(--sidebar-w);
}

/* ==========================================================================
   左侧全局导航
   ========================================================================== */

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-w-collapsed);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 10px;
  background: var(--bg-alt);
  border-right: 1px solid var(--line-soft);
  overflow: hidden;
  transition: width 0.24s cubic-bezier(0.22, 0.61, 0.36, 1);
}

body.sidebar-expanded .sidebar {
  width: var(--sidebar-w);
}

.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 4px;
  margin-bottom: 14px;
  flex: none;
}

.sb-logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  flex: none;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(140deg, #7b61ff, #4f46e5 55%, #1e1b4b);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
}

.sb-logo svg {
  width: 17px;
  height: 17px;
}

.sb-word {
  font-size: var(--fs-14);
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.18s, transform 0.18s;
}

body.sidebar-expanded .sb-word {
  opacity: 1;
  transform: none;
}

.sb-word small {
  display: block;
  font-size: var(--fs-11);
  font-weight: 400;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

.sb-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sb-group-title {
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 10px 10px 4px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.18s;
}

body.sidebar-expanded .sb-group-title {
  opacity: 1;
}

.sb-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--r-md);
  color: var(--ink-2);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.sb-item svg {
  width: 18px;
  height: 18px;
  flex: none;
  stroke-width: 1.7;
}

.sb-item span {
  font-size: var(--fs-13);
  opacity: 0;
  transform: translateX(-3px);
  transition: opacity 0.16s, transform 0.16s;
}

body.sidebar-expanded .sb-item span {
  opacity: 1;
  transform: none;
}

.sb-item:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.sb-item.is-active {
  background: var(--gray-3);
  color: var(--ink);
  font-weight: 500;
}

html[data-theme="dark"] .sb-item.is-active {
  background: rgba(255, 255, 255, 0.08);
}

.sb-item.is-active {
  background: var(--surface-3);
}

body:not(.sidebar-expanded) .sb-item.is-active::before {
  display: none;
}

/* 新建画布（侧栏主按钮） */
.sb-new {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px;
  margin: 2px 0 6px;
  border-radius: var(--r-md);
  background: var(--ink);
  color: var(--bg-alt);
  font-size: var(--fs-13);
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, transform 0.12s;
}

.sb-new:hover {
  background: var(--accent-hover);
}

.sb-new:active {
  transform: scale(0.985);
}

.sb-new svg {
  width: 16px;
  height: 16px;
  flex: none;
  stroke-width: 2;
}

.sb-new span {
  opacity: 0;
  transition: opacity 0.16s;
}

body.sidebar-expanded .sb-new span {
  opacity: 1;
}

body:not(.sidebar-expanded) .sb-new {
  width: 36px;
  height: 36px;
  margin: 2px auto 8px;
  padding: 0;
  justify-content: center;
}

body:not(.sidebar-expanded) .sb-new span {
  display: none;
}

html[data-theme="dark"] .sb-new {
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
}

html[data-theme="dark"] .sb-new:hover {
  background: rgba(255, 255, 255, 0.16);
}

/* 额度卡片 */
.sb-credits {
  display: block;
  width: 100%;
  padding: 9px 10px;
  margin-top: 2px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  text-align: left;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.sb-credits:hover {
  background: var(--line-soft);
}

.sb-credits .row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: var(--fs-11);
  color: var(--ink-3);
}

.sb-credits .row b {
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.sb-credits .row em {
  font-style: normal;
  color: var(--brand);
  font-size: 14px;
}

.sb-credits .sb-bar {
  display: block;
  height: 3px;
  margin-top: 8px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.sb-credits .sb-bar i {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, #7b61ff, #4f46e5);
  transition: width 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
}

body:not(.sidebar-expanded) .sb-credits {
  padding: 7px 0;
  background: var(--surface-3);
  text-align: center;
}

body:not(.sidebar-expanded) .sb-credits:hover {
  background: var(--surface-hover);
}

body:not(.sidebar-expanded) .sb-credits .row {
  justify-content: center;
}

body:not(.sidebar-expanded) .sb-credits .row span,
body:not(.sidebar-expanded) .sb-credits .sb-bar {
  display: none;
}

body:not(.sidebar-expanded) .sb-credits .row b {
  font-size: var(--fs-12);
}

/* 折叠态 tooltip */
body:not(.sidebar-expanded) .sb-item::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) scale(0.96);
  transform-origin: left center;
  background: var(--ink);
  color: var(--bg-alt);
  font-size: var(--fs-12);
  padding: 4px 8px;
  border-radius: var(--r-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s, transform 0.14s;
  z-index: 10;
}

body:not(.sidebar-expanded) .sb-item:hover::after {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

.sb-spacer {
  flex: 1;
}

.sb-foot {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sb-user {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 8px;
  border-radius: var(--r-md);
  white-space: nowrap;
}

.sb-user:hover {
  background: var(--surface-hover);
}

.sb-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex: none;
  background: linear-gradient(140deg, #ffb37b, #f2645a);
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.sb-user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  opacity: 0;
  transition: opacity 0.16s;
}

body.sidebar-expanded .sb-user-meta {
  opacity: 1;
}

.sb-user-meta b {
  font-size: var(--fs-12);
  font-weight: 500;
}

.sb-user-meta em {
  font-style: normal;
  font-size: 13px;
  color: var(--ink-faint);
}

/* ==========================================================================
   通用控件
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  font-size: var(--fs-13);
  font-weight: 500;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background: var(--surface-3);
}

.btn:active {
  transform: scale(0.98);
}

.btn svg {
  width: 15px;
  height: 15px;
  stroke-width: 1.8;
}

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-2);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.btn-sm {
  height: 28px;
  padding: 0 11px;
  font-size: var(--fs-12);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--r-md);
}

.icon-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  color: var(--ink-3);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.icon-btn svg {
  width: 17px;
  height: 17px;
  stroke-width: 1.7;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border-radius: var(--r-pill);
  font-size: var(--fs-12);
  color: var(--ink-2);
  background: transparent;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.pill:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.pill svg {
  width: 14px;
  height: 14px;
  stroke-width: 1.8;
}

.pill-caret {
  width: 12px !important;
  height: 12px !important;
  color: var(--ink-faint);
  margin-left: 1px;
}

.pill-sep {
  width: 1px;
  height: 11px;
  background: var(--line);
  margin: 0 1px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > label {
  font-size: var(--fs-12);
  color: var(--ink-3);
  font-weight: 500;
}

.input {
  height: 34px;
  padding: 0 11px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: var(--fs-13);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

.input:focus {
  border-color: var(--ink-faint);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.hint {
  font-size: var(--fs-11);
  color: var(--ink-faint);
  line-height: 1.5;
}

/* ==========================================================================
   弹层
   ========================================================================== */

.popover {
  position: absolute;
  z-index: 120;
  min-width: 180px;
  padding: 6px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  border: 1px solid var(--line-soft);
  animation: pop-in 0.14s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.pop-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 9px;
  border-radius: var(--r-sm);
  font-size: var(--fs-13);
  color: var(--ink-2);
  text-align: left;
}

.pop-item:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.pop-item.is-on {
  color: var(--ink);
  font-weight: 500;
}

.pop-item .check {
  margin-left: auto;
  color: var(--brand);
  width: 14px;
  height: 14px;
}

.pop-head {
  padding: 6px 9px 4px;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.pop-sep {
  height: 1px;
  background: var(--line-soft);
  margin: 5px 4px;
}

/* 对话框 */
.dialog-mask {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fade-in 0.16s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.dialog {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  border: 1px solid var(--line-soft);
  padding: 22px;
  animation: dialog-in 0.2s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.dialog h3 {
  font-size: var(--fs-17);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.dialog p {
  margin-top: 8px;
  font-size: var(--fs-13);
  color: var(--ink-3);
  line-height: 1.6;
}

.dialog-body {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* Toast */
.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 15px;
  border-radius: var(--r-pill);
  background: var(--ink);
  color: var(--bg-alt);
  font-size: var(--fs-12);
  box-shadow: var(--shadow-3);
  animation: toast-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.toast svg {
  width: 14px;
  height: 14px;
}

.toast.is-out {
  animation: toast-out 0.2s ease forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* 骨架屏 */
@keyframes shimmer {
  from { background-position: -200% 0; }
  to { background-position: 200% 0; }
}

.shimmer {
  background: linear-gradient(
    90deg,
    var(--surface-3) 25%,
    var(--surface-hover) 37%,
    var(--surface-3) 63%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

/* 登录 / 注册弹窗 */
.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-3);
  border-radius: 10px;
  margin-bottom: 12px;
}

.auth-tabs button {
  flex: 1;
  height: 32px;
  border-radius: 8px;
  font-size: 16px;
  color: var(--ink-3);
}

.auth-tabs button.is-on {
  background: var(--surface);
  color: var(--ink);
  font-weight: 500;
  box-shadow: var(--shadow-1);
}

.auth-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.auth-row .input {
  flex: 1;
  min-width: 0;
}

.auth-row .btn {
  flex: none;
  height: 38px;
}
/* 品牌 Logo（黑底白 M，深色下反相成白底黑 M） */
.cv-logo,
.sb-mark {
  overflow: hidden;
}

.cv-logo img,
.sb-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 50%;
}

html[data-theme="dark"] .cv-logo img,
html[data-theme="dark"] .sb-mark img {
  filter: invert(1);
}

.sb-mark img {
  width: 18px;
  height: 18px;
}