/* ═══════════════════════════════════════════════════════════════
   NoteWeb Public Design Tokens & Components
   从 src/app.css 提取，确保所有对外页面视觉一致
   ═══════════════════════════════════════════════════════════════ */

/* ── 字体栈 ── */
:root {
  --font-ui: "Aptos", "Segoe UI Variable", "Segoe UI", "Microsoft YaHei", sans-serif;
  --font-mono: "Cascadia Code", "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

/* ── 暗色主题（默认） ── */
:root {
  --bg: #101312;
  --surface: #161a18;
  --surface-2: #1a201c;
  --surface-3: #222923;
  --sidebar: #131715;
  --elevated: #1d231f;
  --input-bg: #111512;
  --editor-bg: #101412;
  --editor-text: #d9e1dc;
  --text: #d9e1dc;
  --text-2: #89958d;
  --text-faint: #5d6a62;
  --border: #29312c;
  --border-strong: #3a453e;
  --accent: #68d5ae;
  --accent-hover: #8be3c2;
  --accent-dim: #437d69;
  --accent-soft: rgba(104, 213, 174, 0.1);
  --warning: #e9b872;
  --warning-dim: #8a6438;
  --danger: #ef8f8f;
  --danger-soft: rgba(239, 143, 143, 0.1);
  --success: #68d5ae;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.34), 0 2px 10px rgba(0, 0, 0, 0.22);
  --radius-xs: 3px;
  --radius-sm: 4px;
  --radius-md: 5px;
  --radius-lg: 6px;
  --radius-xl: 7px;
  --radius-2xl: 9px;
  --radius-3xl: 10px;
  color-scheme: dark;
}

/* ── 亮色主题 ── */
:root[data-theme="light"] {
  --bg: #f7f8f6;
  --surface: #ffffff;
  --surface-2: #f4f6f3;
  --surface-3: #e9eeea;
  --sidebar: #f0f3ef;
  --elevated: #ffffff;
  --input-bg: #ffffff;
  --editor-bg: #fbfcfa;
  --editor-text: #2d3731;
  --text: #27312b;
  --text-2: #6b7870;
  --text-faint: #96a199;
  --border: #dce2dc;
  --border-strong: #c5cec7;
  --accent: #19876a;
  --accent-hover: #106c53;
  --accent-dim: #73a995;
  --accent-soft: rgba(25, 135, 106, 0.09);
  --warning: #aa6f24;
  --warning-dim: #c5a57d;
  --danger: #c65757;
  --danger-soft: rgba(198, 87, 87, 0.08);
  --success: #19876a;
  --shadow: 0 18px 50px rgba(36, 52, 43, 0.16), 0 2px 8px rgba(36, 52, 43, 0.08);
  color-scheme: light;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-size: 14px;
  line-height: 1.6;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; color: inherit; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* ── Focus 环（与 NoteWeb 主应用一致） ── */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

/* ── 滚动条 ── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text-faint) 45%, transparent);
  border: 3px solid transparent;
  border-radius: 8px;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
  border: 3px solid transparent;
  background-clip: content-box;
}

/* ── Utility ── */
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ── Brand Mark（与主应用完全一致） ── */
.brand-mark {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  width: 19px;
  height: 20px;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  flex-shrink: 0;
}
.brand-mark i {
  display: block;
  width: 3px;
  border-radius: 1px;
  background: #11251d;
  transform: skewY(-24deg);
}
.brand-mark i:nth-child(1) { height: 8px; }
.brand-mark i:nth-child(2) { height: 13px; }
.brand-mark i:nth-child(3) { height: 10px; }
.brand-mark.lg { width: 36px; height: 38px; padding: 5px; border-radius: var(--radius-lg); }
.brand-mark.lg i { width: 5px; border-radius: 2px; }
.brand-mark.lg i:nth-child(1) { height: 15px; }
.brand-mark.lg i:nth-child(2) { height: 25px; }
.brand-mark.lg i:nth-child(3) { height: 19px; }

/* ── 按钮组件（同源） ── */
.nw-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 80ms ease;
  white-space: nowrap;
  border: 1px solid transparent;
  text-decoration: none;
}
.nw-btn:active { transform: translateY(1px); }
.nw-btn:disabled { opacity: .45; cursor: not-allowed; }

/* 主按钮（主应用 .primary-button 风格） */
.nw-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #11251d;
}
.nw-btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.nw-btn-primary:active { background: var(--accent-hover); }

/* 次要按钮（主应用 .secondary-button 风格） */
.nw-btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-2);
}
.nw-btn-secondary:hover { background: var(--surface-3); border-color: var(--border-strong); color: var(--text); }

/* 幽灵按钮（透明背景 + 文字强调色） */
.nw-btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
}
.nw-btn-ghost:hover { background: var(--accent-soft); }

/* 危险按钮（主应用 .danger-button 风格） */
.nw-btn-danger {
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
}
.nw-btn-danger:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); }

/* 大号按钮 */
.nw-btn-lg { min-height: 44px; padding: 11px 24px; font-size: 14px; }

/* 小号按钮 */
.nw-btn-sm { min-height: 28px; padding: 4px 10px; font-size: 11px; border-radius: var(--radius-sm); }

/* 全宽 */
.nw-btn-full { width: 100%; }

/* 图标按钮 */
.nw-icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
  border: none;
}
.nw-icon-btn:hover { background: var(--surface-3); color: var(--text); }
.nw-icon-btn.active { color: var(--accent); background: var(--accent-soft); }
.nw-icon-btn svg { width: 16px; height: 16px; }

/* ── 输入框（同源） ── */
.nw-input, .nw-textarea, .nw-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font-ui);
  transition: border-color 120ms ease;
}
.nw-input:hover, .nw-textarea:hover, .nw-select:hover { border-color: var(--border-strong); }
.nw-input:focus, .nw-textarea:focus, .nw-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-dim);
}
.nw-textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
.nw-input::placeholder, .nw-textarea::placeholder { color: var(--text-faint); }

/* ── 卡片组件 ── */
.nw-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 20px;
}
.nw-card-elevated {
  background: var(--elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow);
}

/* ── 标签 ── */
.nw-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.nw-tag-accent { background: var(--accent-soft); color: var(--accent); }
.nw-tag-warning { background: color-mix(in srgb, var(--warning) 12%, transparent); color: var(--warning); }
.nw-tag-danger { background: var(--danger-soft); color: var(--danger); }
.nw-tag-faint { background: var(--surface-3); color: var(--text-2); }

/* ── Toast 提示条（与主应用 .toast 完全同源） ── */
.nw-toast-stack {
  position: fixed;
  z-index: 2200;
  right: 18px;
  bottom: 40px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.nw-toast {
  max-width: min(440px, 88vw);
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 13px;
  border: 1px solid var(--border-strong);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  background: var(--elevated);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 12px;
  line-height: 1.5;
  pointer-events: auto;
  animation: nw-toast-in 180ms ease-out;
}
.nw-toast svg { flex: 0 0 auto; margin-top: 1px; color: var(--accent); }
.nw-toast-error { border-left-color: var(--danger); }
.nw-toast-error svg { color: var(--danger); }
.nw-toast-info { border-left-color: var(--warning); }
.nw-toast-info svg { color: var(--warning); }
.nw-toast.success { border-left-color: var(--accent); }
@keyframes nw-toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── 模态覆盖层（与主应用 .overlay 完全同源） ── */
.nw-overlay {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 8, 6, 0.56);
  backdrop-filter: blur(4px);
  animation: nw-overlay-in 140ms ease-out;
}
@keyframes nw-overlay-in { from { opacity: 0; } to { opacity: 1; } }

/* ── 确认对话框（与主应用 .confirm-dialog 完全同源） ── */
.nw-confirm {
  width: min(450px, 94vw);
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 13px;
  padding: 22px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-2xl);
  background: var(--elevated);
  box-shadow: var(--shadow);
  animation: nw-dialog-in 160ms ease-out;
}
.nw-confirm-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--warning) 10%, transparent);
  color: var(--warning);
}
.nw-confirm-copy h3 { margin: 1px 0 8px; font-size: 15px; font-weight: 600; }
.nw-confirm-copy p { margin: 0; color: var(--text-2); font-size: 12px; line-height: 1.65; }
.nw-confirm-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* ── 通用对话框（与主应用 dialog 风格一致） ── */
.nw-dialog {
  width: min(640px, 94vw);
  max-height: min(620px, 88vh);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-3xl);
  background: var(--elevated);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: nw-dialog-in 160ms ease-out;
}
@keyframes nw-dialog-in {
  from { opacity: 0; transform: translateY(-8px) scale(.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.nw-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--border);
}
.nw-dialog-header h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.nw-dialog-body { flex: 1; overflow-y: auto; padding: 20px 24px; }
.nw-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ── 主题切换开关 ── */
.nw-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
  border: none;
}
.nw-theme-toggle:hover { background: var(--surface-3); color: var(--text); }
.nw-theme-toggle svg { width: 18px; height: 18px; }

/* ── 主题切换开关 Switch（与主应用 .switch 完全同源） ── */
.nw-switch {
  position: relative;
  width: 34px;
  height: 19px;
  flex: 0 0 34px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface-3);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}
.nw-switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform 140ms ease, background 140ms ease;
}
.nw-switch.on { border-color: var(--accent); background: var(--accent); }
.nw-switch.on span { transform: translateX(15px); background: #12251d; }

/* ── kbd 键位 ── */
kbd {
  display: inline-flex;
  align-items: center;
  min-height: 19px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-color: var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1;
  white-space: nowrap;
}

/* ── 分隔线 ── */
.nw-divider { height: 1px; background: var(--border); border: none; margin: 16px 0; }
.nw-divider-strong { height: 1px; background: var(--border-strong); border: none; margin: 16px 0; }

/* ── 徽章 Badge ── */
.nw-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: var(--accent-soft);
  color: var(--accent);
}
.nw-badge-local { background: var(--accent-soft); color: var(--accent); }

/* ── 主行动按钮组 ── */
.nw-cta-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── 响应式 ── */
@media (max-width: 760px) {
  .nw-overlay { padding: 16px; }
  .nw-confirm { padding: 18px; }
  .nw-dialog { width: 100%; height: 96vh; max-height: 96vh; }
  .nw-dialog-body { padding: 16px; }
  .nw-dialog-header { padding: 16px 18px 12px; }
  .nw-toast-stack { right: 12px; bottom: 24px; }
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
