:root {
  --bg: #FAFAFA;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: rgba(0, 0, 0, 0.04);
  --text: #1A1A1A;
  --text-secondary: #666666;
  --border: #E0E0E0;
  --danger: #c33;
  --danger-bg: rgba(204, 51, 51, 0.08);
  --success: #2e7d32;
  --success-bg: rgba(46, 125, 50, 0.12);
  --highlight: rgba(255, 220, 120, 0.55);

  --backdrop: rgba(0, 0, 0, 0.4);
  --border-strong: rgba(0, 0, 0, 0.08);
  --underline: rgba(0, 0, 0, 0.25);
  --shadow-color: rgba(0, 0, 0, 0.04);
  --shadow-color-strong: rgba(0, 0, 0, 0.18);
  --grid-line: rgba(0, 0, 0, 0.05);
  --surface-elevated: rgba(255, 255, 255, 0.92);

  --font-display: serif;
  --font-body: sans-serif;
  --font-mono: monospace;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --sidebar-w: 280px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --bg-secondary: #1E1E1E;
    --bg-tertiary: rgba(255, 255, 255, 0.06);
    --text: #ECECEC;
    --text-secondary: #9A9A9A;
    --border: #2A2A2A;
    --danger: #E58585;
    --danger-bg: rgba(229, 133, 133, 0.12);
    --success: #6FCF97;
    --success-bg: rgba(111, 207, 151, 0.14);
    --highlight: rgba(255, 220, 120, 0.28);

    --backdrop: rgba(0, 0, 0, 0.65);
    --border-strong: rgba(255, 255, 255, 0.1);
    --underline: rgba(255, 255, 255, 0.3);
    --shadow-color: rgba(0, 0, 0, 0.6);
    --shadow-color-strong: rgba(0, 0, 0, 0.8);
    --grid-line: rgba(255, 255, 255, 0.04);
    --surface-elevated: rgba(30, 30, 30, 0.92);
  }
}
:root[data-theme="dark"] {
  --bg: #121212;
  --bg-secondary: #1E1E1E;
  --bg-tertiary: rgba(255, 255, 255, 0.06);
  --text: #ECECEC;
  --text-secondary: #9A9A9A;
  --border: #2A2A2A;
  --danger: #E58585;
  --danger-bg: rgba(229, 133, 133, 0.12);
  --success: #6FCF97;
  --success-bg: rgba(111, 207, 151, 0.14);
  --highlight: rgba(255, 220, 120, 0.28);

  --backdrop: rgba(0, 0, 0, 0.65);
  --border-strong: rgba(255, 255, 255, 0.1);
  --underline: rgba(255, 255, 255, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.6);
  --shadow-color-strong: rgba(0, 0, 0, 0.8);
  --grid-line: rgba(255, 255, 255, 0.04);
  --surface-elevated: rgba(30, 30, 30, 0.92);
}
@media (max-width: 768px) {
  :root { --sidebar-w: 60px; }
}
body:has(.sidebar[data-state="collapsed"]) {
  --sidebar-w: 60px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
html.modal-open, body.modal-open {
  overflow: hidden;
  overscroll-behavior: none;
}
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.hidden { display: none !important; }
.bg-grid {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}
.app-shell, .toast { position: relative; z-index: 1; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  letter-spacing: -0.005em;
}
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--text); color: var(--bg); }
.font-display { font-family: var(--font-display); font-weight: 400; letter-spacing: -0.02em; }
.font-body    { font-family: var(--font-body); font-weight: 400; }
.font-mono    { font-family: var(--font-mono); font-weight: 500; letter-spacing: 0.2em; text-transform: uppercase; }
.font-cn      { font-family: 'Noto Serif SC', var(--font-display); font-weight: 400; }
.container { max-width: 900px; margin: 0 auto; padding: 0 48px; }
@media (max-width: 768px) { .container { padding: 0 24px; } }
.page { display: block; }
.page-header { padding-top: 48px; padding-bottom: 32px; border-bottom: 1px solid var(--border); margin-bottom: 32px; }
.page-header h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(36px, 5vw, 56px); margin: 8px 0 12px; letter-spacing: -0.02em; }
.page-header p  { color: var(--text-secondary); font-size: 16px; margin: 0; }
.app-shell { display: flex; height: 100dvh; overflow: hidden; }
[data-tooltip] {
  position: relative;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  right: -2px;
  padding: 5px 10px;
  background: var(--text);
  color: var(--bg-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0s linear;
  z-index: 100;
}
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
  transition: opacity 0.08s var(--ease-out) 0.3s;
}
[data-tooltip].tooltip-above::after {
  top: auto;
  bottom: calc(100% + 8px);
}
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  color: var(--text);
  border: 1px solid var(--bg-tertiary);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 10px 18px;
  z-index: 110;
  animation: toast-in 0.2s var(--ease-out);
}
.toast-action {
  margin-left: 14px; background: none; border: 1px solid var(--text-secondary);
  color: var(--text); font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.06em; padding: 3px 9px; cursor: pointer;
  transition: background 0.15s var(--ease-out), color 0.15s var(--ease-out);
}
.toast-action:hover { background: var(--text); color: var(--bg-secondary); }
.app-footer {
  text-align: center;
  padding: 32px 0 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
@keyframes popover-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes btn-spin { to { transform: rotate(360deg); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes syncing-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.is-syncing #topbar-right,
.is-syncing #corpus-sidebar-list {
  animation: syncing-pulse 1.2s ease-in-out infinite;
  transition: opacity 0.18s var(--ease-out);
}