/* ============================================================
   CSS Design System — from UX 架构设计 v1.0 & design-spec.md
   ============================================================ */

:root {
  /* Light Theme */
  --bg-primary: #FFFFFF;
  --bg-secondary: #F7F8FA;
  --bg-tertiary: #F0F1F3;
  --text-primary: #1A1A2E;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --border-color: #E5E7EB;
  --accent-color: #534AB7;
  --accent-hover: #4339A0;
  --accent-light: rgba(83, 74, 183, 0.08);
  --danger-color: #EF4444;
  --success-color: #10B981;
  --warning-color: #F59E0B;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);

  /* Typography */
  --font-sans: 'Inter', -apple-system, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  /* Layout */
  --sidebar-width: 200px;
  --context-panel-width: 240px;
  --titlebar-height: 40px;
  --navbar-height: 44px;
  --statusbar-height: 28px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

[data-theme="dark"] {
  --bg-primary: #1A1A2E;
  --bg-secondary: #16213E;
  --bg-tertiary: #0F3460;
  --text-primary: #E5E7EB;
  --text-secondary: #9CA3AF;
  --text-tertiary: #6B7280;
  --border-color: #2D2D44;
  --accent-light: rgba(83, 74, 183, 0.15);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.5);
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* ============================================================
   App Shell
   ============================================================ */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Auth Overlay ── */
.auth-overlay {
  position: fixed; inset: 0; z-index: 3000;
  background: var(--bg-primary);
  display: flex; align-items: center; justify-content: center;
}
.auth-card {
  width: 380px; background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-8) var(--space-6);
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  text-align: center; margin-bottom: var(--space-6);
}
.auth-logo-icon {
  width: 48px; height: 48px; background: var(--accent-color);
  border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; font-weight: 700; margin-bottom: var(--space-2);
}
.auth-title { font-size: var(--text-lg); font-weight: 700; text-align: center; margin-bottom: var(--space-1); }
.auth-subtitle { font-size: var(--text-xs); color: var(--text-tertiary); text-align: center; margin-bottom: var(--space-6); }
.auth-field { margin-bottom: var(--space-3); }
.auth-field label { display: block; font-size: var(--text-xs); font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.auth-field input {
  width: 100%; height: 40px; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: 0 var(--space-3);
  background: var(--bg-primary); color: var(--text-primary);
  font-size: var(--text-sm); outline: none; transition: border-color 0.2s;
}
.auth-field input:focus { border-color: var(--accent-color); }
.auth-error { color: var(--danger-color); font-size: var(--text-xs); margin-bottom: var(--space-3); min-height: 18px; }
.auth-btn {
  width: 100%; height: 40px; background: var(--accent-color);
  color: #fff; border: none; border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-weight: 600; cursor: pointer;
  transition: all 0.15s;
}
.auth-btn:hover { background: var(--accent-hover); }
.auth-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-switch { text-align: center; margin-top: var(--space-4); font-size: var(--text-xs); color: var(--text-tertiary); }
.auth-switch a, .auth-switch-link { color: var(--accent-color); cursor: pointer; text-decoration: none; font-weight: 500; }
.auth-switch a:hover, .auth-switch-link:hover { text-decoration: underline; }
.auth-status { text-align: center; margin-top: var(--space-2); font-size: var(--text-xs); color: var(--success-color); min-height: 18px; }

/* Title Bar */
.titlebar {
  height: var(--titlebar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-3);
  -webkit-app-region: drag;
  flex-shrink: 0;
}
.titlebar-brand { display: flex; align-items: center; gap: var(--space-2); -webkit-app-region: no-drag; }
.titlebar-logo { width: 18px; height: 18px; background: var(--accent-color); border-radius: 4px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 10px; font-weight: 700; }
.titlebar-title { font-size: var(--text-xs); font-weight: 600; color: var(--text-secondary); }
.titlebar-right { display: flex; align-items: center; gap: var(--space-2); -webkit-app-region: no-drag; }
.titlebar-user { font-size: var(--text-xs); color: var(--text-tertiary); }
.titlebar-logout { font-size: var(--text-xs); color: var(--text-tertiary); cursor: pointer; border: none; background: none; padding: 2px 8px; border-radius: var(--radius-sm); }
.titlebar-logout:hover { color: var(--danger-color); background: var(--bg-tertiary); }
.window-controls { display: flex; gap: 2px; -webkit-app-region: no-drag; }
.window-btn { width: 36px; height: 28px; border: none; background: transparent; color: var(--text-secondary); cursor: pointer; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 14px; transition: all 0.15s; }
.window-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.window-btn.close:hover { background: var(--danger-color); color: #fff; }

/* Navbar */
.navbar { height: var(--navbar-height); background: var(--bg-primary); border-bottom: 1px solid var(--border-color); display: flex; align-items: stretch; padding: 0 var(--space-6); gap: 0; flex-shrink: 0; position: relative; }
.nav-tab { display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-4); cursor: pointer; color: var(--text-secondary); font-size: var(--text-sm); font-weight: 500; border: none; background: none; border-bottom: 2px solid transparent; transition: all 0.2s ease; position: relative; }
.nav-tab:hover { color: var(--text-primary); background: var(--bg-secondary); }
.nav-tab.active { color: var(--accent-color); border-bottom-color: var(--accent-color); }
.nav-tab .tab-icon { font-size: 16px; }
.nav-tab .tab-badge { background: var(--accent-color); color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 10px; font-weight: 600; }
.nav-search { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.nav-search input { width: 200px; height: 28px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); background: var(--bg-secondary); color: var(--text-primary); padding: 0 var(--space-3); font-size: var(--text-xs); outline: none; transition: all 0.2s; }
.nav-search input:focus { border-color: var(--accent-color); width: 280px; }
.nav-search kbd { background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 3px; padding: 1px 5px; font-size: 10px; color: var(--text-tertiary); font-family: var(--font-mono); }
.theme-toggle-btn { width: 28px; height: 28px; border: none; background: none; cursor: pointer; border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 16px; display: flex; align-items: center; justify-content: center; transition: all 0.15s; }
.theme-toggle-btn:hover { background: var(--bg-tertiary); }

/* Main Layout — Three Columns */
.main-layout { display: flex; flex: 1; overflow: hidden; }

/* Left Sidebar */
.sidebar { width: var(--sidebar-width); min-width: var(--sidebar-width); background: var(--bg-secondary); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; overflow-y: auto; flex-shrink: 0; }
.sidebar-section { padding: var(--space-3) var(--space-2); border-bottom: 1px solid var(--border-color); }
.sidebar-section-title { font-size: 10px; font-weight: 600; text-transform: uppercase; color: var(--text-tertiary); letter-spacing: 0.5px; padding: 0 var(--space-2); margin-bottom: var(--space-2); }
.sidebar-item { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-2); border-radius: var(--radius-sm); cursor: pointer; color: var(--text-secondary); font-size: var(--text-sm); transition: all 0.15s; }
.sidebar-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.sidebar-item.active { background: var(--accent-light); color: var(--accent-color); font-weight: 600; }
.sidebar-item .item-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-item .item-count { margin-left: auto; font-size: var(--text-xs); color: var(--text-tertiary); background: var(--bg-tertiary); padding: 1px 6px; border-radius: 10px; }
.sidebar-item .item-delete { display: none; margin-left: 2px; font-size: 12px; color: var(--text-tertiary); cursor: pointer; padding: 0 3px; border-radius: 3px; }
.sidebar-item:hover .item-delete { display: inline; }
.sidebar-item .item-delete:hover { color: var(--danger-color); background: var(--bg-tertiary); }

/* Add Category */
.sidebar-add-category { display: flex; gap: 4px; padding: var(--space-2); margin-top: var(--space-1); }
.sidebar-add-category input {
  flex: 1; height: 26px; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: 0 6px; font-size: var(--text-xs);
  background: var(--bg-primary); color: var(--text-primary); outline: none;
}
.sidebar-add-category input:focus { border-color: var(--accent-color); }
.sidebar-add-category button {
  height: 26px; width: 32px; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); background: var(--bg-primary);
  color: var(--accent-color); font-size: 16px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.sidebar-add-category button:hover { background: var(--accent-light); }
.sidebar-quick-actions { display: flex; flex-direction: column; gap: 2px; padding: var(--space-3) var(--space-2); border-bottom: 1px solid var(--border-color); }
.quick-action-btn { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-2); border-radius: var(--radius-sm); cursor: pointer; color: var(--accent-color); font-size: var(--text-sm); font-weight: 500; border: none; background: none; width: 100%; text-align: left; transition: all 0.15s; }
.quick-action-btn:hover { background: var(--accent-light); }
.quick-action-btn .qa-icon { font-size: 16px; }

/* Main Content */
.main-content { flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; }
.tab-content { display: none; padding: var(--space-6); height: 100%; }
.tab-content.active { display: block; }
.tab-content.fade-in { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* Context Panel */
.context-panel { width: var(--context-panel-width); min-width: var(--context-panel-width); background: var(--bg-secondary); border-left: 1px solid var(--border-color); overflow-y: auto; flex-shrink: 0; }
.context-panel-inner { padding: var(--space-4) var(--space-3); }
.context-panel-title { font-size: 10px; font-weight: 600; text-transform: uppercase; color: var(--text-tertiary); letter-spacing: 0.5px; margin-bottom: var(--space-3); }
.context-card { background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: var(--space-3); margin-bottom: var(--space-2); cursor: pointer; transition: all 0.15s; }
.context-card:hover { border-color: var(--accent-color); box-shadow: var(--shadow-sm); }
.context-card-title { font-size: var(--text-sm); font-weight: 600; color: var(--text-primary); margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.context-card-meta { font-size: var(--text-xs); color: var(--text-tertiary); }

/* Status Bar */
.statusbar { height: var(--statusbar-height); background: var(--bg-secondary); border-top: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; padding: 0 var(--space-4); flex-shrink: 0; }
.status-left, .status-right { display: flex; align-items: center; gap: var(--space-3); font-size: 11px; color: var(--text-tertiary); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success-color); }
.status-dot.syncing { background: var(--warning-color); animation: pulse 1s infinite; }
.status-dot.error { background: var(--danger-color); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: 0.3 } }

/* ============================================================
   Common Components
   ============================================================ */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-6); }
.page-title { font-size: 1.25rem; font-weight: 700; }
.btn { display: inline-flex; align-items: center; gap: var(--space-2); padding: 6px 14px; border-radius: var(--radius-sm); font-size: var(--text-sm); font-weight: 500; cursor: pointer; border: 1px solid var(--border-color); background: var(--bg-primary); color: var(--text-primary); transition: all 0.15s; }
.btn:hover { background: var(--bg-secondary); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent-color); color: #fff; border-color: var(--accent-color); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-sm { padding: 4px 10px; font-size: var(--text-xs); }
.btn-icon { padding: 4px 8px; font-size: 16px; }
.btn-danger { color: var(--danger-color); border-color: var(--danger-color); }
.btn-danger:hover { background: var(--danger-color); color: #fff; }

/* Loading spinner */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border-color); border-top-color: var(--accent-color); border-radius: 50%; animation: spin 0.6s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Cards */
.card { background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: var(--space-4); }
.card-title { font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--space-3); color: var(--text-primary); }

/* Empty State */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--space-8); text-align: center; color: var(--text-tertiary); }
.empty-state-icon { font-size: 40px; margin-bottom: var(--space-3); opacity: 0.6; }
.empty-state-title { font-size: var(--text-lg); font-weight: 600; margin-bottom: var(--space-2); color: var(--text-secondary); }
.empty-state-desc { font-size: var(--text-sm); margin-bottom: var(--space-4); line-height: 1.5; }
.empty-state kbd { background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 3px; padding: 2px 6px; font-family: var(--font-mono); font-size: 11px; }

/* ============================================================
   Today Dashboard
   ============================================================ */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); margin-bottom: var(--space-4); }
.todo-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--border-color); }
.todo-item:last-child { border-bottom: none; }
.todo-check { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-color); cursor: pointer; flex-shrink: 0; transition: all 0.15s; background: none; position: relative; }
.todo-check:hover { border-color: var(--accent-color); }
.todo-check.done { background: var(--success-color); border-color: var(--success-color); }
.todo-check.done::after { content: '✓'; position: absolute; top: -1px; left: 3px; color: #fff; font-size: 10px; font-weight: 700; }
.todo-text { flex: 1; font-size: var(--text-sm); }
.todo-text.done { text-decoration: line-through; color: var(--text-tertiary); }
.todo-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.todo-item:hover .todo-actions { opacity: 1; }
.todo-add { display: flex; gap: var(--space-2); align-items: center; margin-top: var(--space-3); }
.todo-add input { flex: 1; border: 1px dashed var(--border-color); border-radius: var(--radius-sm); padding: 6px 10px; font-size: var(--text-sm); background: transparent; color: var(--text-primary); outline: none; }
.todo-add input:focus { border-color: var(--accent-color); border-style: solid; }

.reminder-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--border-color); font-size: var(--text-sm); }
.reminder-item:last-child { border-bottom: none; }
.reminder-item.done { opacity: 0.5; }
.reminder-item.done .reminder-title { text-decoration: line-through; }
.reminder-time { font-size: var(--text-xs); color: var(--accent-color); font-weight: 600; min-width: 65px; }
.reminder-type-badge { font-size: 9px; padding: 1px 5px; border-radius: 3px; background: var(--bg-tertiary); color: var(--text-tertiary); white-space: nowrap; }
.reminder-title { flex: 1; }
.reminder-status-badge { font-size: 9px; padding: 1px 6px; border-radius: 8px; font-weight: 600; white-space: nowrap; }
.reminder-status-badge.pending { background: #FEF3C7; color: #92400E; }
.reminder-status-badge.viewed { background: var(--accent-light); color: var(--accent-color); }
.reminder-status-badge.done { background: #D1FAE5; color: #065F46; }
.reminder-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.reminder-item:hover .reminder-actions { opacity: 1; }
.reminder-add { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-top: var(--space-3); }
.reminder-add input[type="text"] { flex: 1; min-width: 120px; border: 1px dashed var(--border-color); border-radius: var(--radius-sm); padding: 6px 10px; font-size: var(--text-sm); background: transparent; color: var(--text-primary); outline: none; }
.reminder-add input[type="text"]:focus { border-color: var(--accent-color); border-style: solid; }
.reminder-add input[type="datetime-local"] { border: 1px dashed var(--border-color); border-radius: var(--radius-sm); padding: 5px 8px; font-size: var(--text-xs); background: transparent; color: var(--text-primary); outline: none; }
.reminder-add input[type="datetime-local"]:focus { border-color: var(--accent-color); border-style: solid; }
.reminder-add input[type="datetime-local"]::-webkit-calendar-picker-indicator { filter: invert(1); cursor: pointer; }
.reminder-add select { border: 1px dashed var(--border-color); border-radius: var(--radius-sm); padding: 5px 6px; font-size: var(--text-xs); background: var(--bg-primary); color: var(--text-primary); outline: none; cursor: pointer; }
.reminder-add select:focus { border-color: var(--accent-color); border-style: solid; }
.reminder-add select option { background: var(--bg-primary); color: var(--text-primary); }
.reminder-type-toggle { display: flex; gap: 0; border: 1px solid var(--border-color); border-radius: var(--radius-sm); overflow: hidden; }
.reminder-type-toggle button { padding: 4px 12px; font-size: var(--text-xs); border: none; background: none; color: var(--text-secondary); cursor: pointer; transition: all 0.15s; }
.reminder-type-toggle button.active { background: var(--accent-color); color: #fff; }
.reminder-type-toggle button:hover:not(.active) { background: var(--bg-tertiary); }
.reminder-edit-input { border: 1px solid var(--accent-color); border-radius: 3px; padding: 2px 6px; font-size: var(--text-sm); font-family: var(--font-sans); background: var(--bg-primary); color: var(--text-primary); outline: none; }
.reminder-edit-input.small { width: 80px; font-size: var(--text-xs); }
.reminder-edit-input[type="datetime-local"]::-webkit-calendar-picker-indicator,
.reminder-edit-input[type="time"]::-webkit-calendar-picker-indicator { filter: invert(1); cursor: pointer; }
.reminder-edit-input.small option, .reminder-edit-input.small optgroup { background: var(--bg-primary); color: var(--text-primary); }
.reminder-add-row { display: flex; gap: var(--space-2); align-items: center; width: 100%; }
.reminder-filter-bar { display: flex; gap: var(--space-1); margin-bottom: var(--space-3); }
.reminder-filter-btn { font-size: var(--text-xs); padding: 2px 10px; border-radius: 10px; border: 1px solid var(--border-color); background: none; color: var(--text-secondary); cursor: pointer; transition: all 0.15s; }
.reminder-filter-btn:hover { background: var(--bg-tertiary); }
.reminder-filter-btn.active { background: var(--accent-color); color: #fff; border-color: var(--accent-color); }

.note-mini-card { display: flex; flex-direction: column; gap: 2px; padding: var(--space-2) 0; border-bottom: 1px solid var(--border-color); cursor: pointer; transition: all 0.15s; }
.note-mini-card:last-child { border-bottom: none; }
.note-mini-card:hover { color: var(--accent-color); }
.note-mini-title { font-size: var(--text-sm); font-weight: 500; }
.note-mini-time { font-size: var(--text-xs); color: var(--text-tertiary); }

.stats-row { display: flex; gap: var(--space-4); margin-top: var(--space-4); }
.stat-card { flex: 1; text-align: center; padding: var(--space-3); background: var(--bg-secondary); border-radius: var(--radius-md); }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--accent-color); }
.stat-label { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: 2px; }

/* ============================================================
   Notes Module
   ============================================================ */
.notes-layout { display: flex; height: 100%; gap: 0; }
.note-list-panel { width: 260px; min-width: 260px; border-right: 1px solid var(--border-color); overflow-y: auto; padding: var(--space-3); background: var(--bg-secondary); }
.note-editor-panel { flex: 1; display: flex; flex-direction: column; }
.note-list-item { padding: var(--space-3); border-radius: var(--radius-sm); cursor: pointer; margin-bottom: var(--space-1); transition: all 0.15s; }
.note-list-item:hover { background: var(--bg-tertiary); }
.note-list-item.active { background: var(--accent-light); border-left: 3px solid var(--accent-color); }
.note-list-title { font-size: var(--text-sm); font-weight: 600; margin-bottom: 2px; cursor: text; }
.note-list-title .title-edit-input {
  width: 100%; border: 1px solid var(--accent-color);
  border-radius: 3px; padding: 2px 6px; font-size: var(--text-sm);
  font-weight: 600; font-family: var(--font-sans);
  background: var(--bg-primary); color: var(--text-primary);
  outline: none; box-sizing: border-box;
}
.note-list-preview { font-size: var(--text-xs); color: var(--text-tertiary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-list-meta { display: flex; gap: var(--space-2); align-items: center; font-size: 10px; color: var(--text-tertiary); margin-top: var(--space-1); flex-wrap: wrap; }
.note-tag { background: var(--accent-light); color: var(--accent-color); padding: 1px 6px; border-radius: 3px; font-size: 10px; }

/* ============================================================
   Enhanced Editor Toolbar — Rich Text & Markdown
   ============================================================ */

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  align-items: center;
  user-select: none;
  min-height: 34px;
}

/* ── Toolbar Groups ── */
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 0 2px;
}

/* ── Standard Toolbar Button ── */
.toolbar-btn {
  width: 28px;
  height: 26px;
  border: none;
  background: none;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
  position: relative;
  flex-shrink: 0;
  font-family: var(--font-sans);
}
.toolbar-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}
.toolbar-btn.active {
  color: var(--accent-color);
  background: var(--accent-light);
}
.toolbar-btn:active {
  transform: scale(0.95);
}

/* ── Toolbar Button with Label (wider) ── */
.toolbar-btn-label {
  width: auto;
  padding: 0 8px;
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
}

/* ── Divider ── */
.toolbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border-color);
  margin: 0 3px;
  flex-shrink: 0;
}

/* ── Select Dropdowns ── */
.toolbar-select {
  height: 26px;
  padding: 0 4px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 11px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  font-family: var(--font-sans);
  flex-shrink: 0;
}
.toolbar-select:focus {
  border-color: var(--accent-color);
}
.toolbar-select.text-type {
  min-width: 80px;
}
.toolbar-select.font-family {
  min-width: 110px;
}
.toolbar-select.font-size {
  min-width: 58px;
}
.toolbar-select.line-spacing {
  min-width: 62px;
}

/* ── Category Select ── */
.toolbar-category-select {
  height: 26px;
  padding: 0 6px;
  margin: 1px 2px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 11px;
  outline: none;
  cursor: pointer;
  max-width: 110px;
  flex-shrink: 0;
}
.toolbar-category-select:focus { border-color: var(--accent-color); }

/* ── Color Palette ── */
.toolbar-color-group {
  position: relative;
  display: flex;
  align-items: center;
}
.toolbar-color-btn {
  width: 26px;
  height: 24px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  transition: all 0.12s;
  flex-shrink: 0;
}
.toolbar-color-btn:hover {
  border-color: var(--accent-color);
  transform: scale(1.08);
}
.toolbar-color-btn .color-current {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 2px;
}
.toolbar-color-btn.text-color .color-current {
  background: var(--text-primary);
}
.toolbar-color-btn.highlight-color .color-current {
  background: transparent;
}
.toolbar-color-indicator {
  width: 14px;
  height: 3px;
  border-radius: 1px;
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
}

/* Color Picker Popup */
.color-picker-popup {
  position: absolute;
  top: 32px;
  left: 0;
  z-index: 500;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  display: none;
  min-width: 168px;
}
.color-picker-popup.show {
  display: block;
}
.color-presets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  margin-bottom: 6px;
}
.color-preset {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.12s;
}
.color-preset:hover {
  border-color: var(--accent-color);
  transform: scale(1.15);
}
.color-preset.selected {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px var(--accent-light);
}
.color-picker-custom {
  display: flex;
  align-items: center;
  gap: 4px;
}
.color-picker-custom input[type="color"] {
  width: 28px;
  height: 24px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  background: none;
}
.color-picker-custom input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}
.color-picker-custom input[type="color"]::-webkit-color-swatch {
  border-radius: 2px;
  border: none;
}
.color-picker-label {
  font-size: 10px;
  color: var(--text-tertiary);
  flex: 1;
  text-align: right;
}

/* ============================================================
   Editor Area — Rich Text
   ============================================================ */

.editor-area {
  flex: 1;
  padding: var(--space-6);
  font-family: 'SimSun', 'Noto Serif SC', var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.8;
  color: var(--text-primary);
  outline: none;
  overflow-y: auto;
  word-wrap: break-word;
  tab-size: 4;
}
.editor-area:empty::before {
  content: '开始书写... (支持 Markdown 语法)';
  color: var(--text-tertiary);
}
.editor-area h1 {
  font-size: 1.75em;
  font-weight: 700;
  margin: 0.6em 0 0.3em;
  line-height: 1.4;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.2em;
}
.editor-area h2 {
  font-size: 1.4em;
  font-weight: 600;
  margin: 0.5em 0 0.25em;
  line-height: 1.45;
}
.editor-area h3 {
  font-size: 1.15em;
  font-weight: 600;
  margin: 0.4em 0 0.2em;
  line-height: 1.5;
}
.editor-area h4 {
  font-size: 1.05em;
  font-weight: 600;
  margin: 0.35em 0 0.15em;
}
.editor-area h5, .editor-area h6 {
  font-size: 1em;
  font-weight: 600;
  margin: 0.3em 0 0.1em;
}
.editor-area p {
  margin: 0.3em 0;
  line-height: 1.8;
}
.editor-area div {
  line-height: 1.8;
}
.editor-area strong, .editor-area b {
  font-weight: 700;
}
.editor-area em, .editor-area i {
  font-style: italic;
}
.editor-area u {
  text-decoration: underline;
}
.editor-area s, .editor-area strike {
  text-decoration: line-through;
}
.editor-area code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.editor-area pre {
  background: var(--bg-tertiary);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.85em;
  overflow-x: auto;
  margin: var(--space-3) 0;
  line-height: 1.5;
}
.editor-area blockquote {
  border-left: 3px solid var(--accent-color);
  padding: 4px 0 4px 16px;
  margin: 8px 0;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.editor-area ul, .editor-area ol {
  padding-left: 24px;
  margin: 4px 0;
}
.editor-area li {
  margin: 2px 0;
  line-height: 1.8;
}
.editor-area hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 16px 0;
}
.editor-area a {
  color: var(--accent-color);
  text-decoration: underline;
  cursor: pointer;
}
.editor-area .todo-ref {
  color: var(--accent-color);
  cursor: pointer;
  border-bottom: 1px dashed var(--accent-color);
}
.editor-area img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

/* ── Alignment classes for execCommand ── */
.editor-area [style*="text-align:left"],
.editor-area .text-left { text-align: left; }
.editor-area [style*="text-align:center"],
.editor-area .text-center { text-align: center; }
.editor-area [style*="text-align:right"],
.editor-area .text-right { text-align: right; }
.editor-area [style*="text-align:justify"],
.editor-area .text-justify { text-align: justify; }

/* ── Indent padding ── */
.editor-area [style*="padding-left"] {
  /* execCommand('indent') adds padding-left */
}

/* ============================================================
   Ask / Q&A Module
   ============================================================ */
.ask-layout { display: flex; flex-direction: column; height: 100%; max-width: 700px; margin: 0 auto; }
.ask-messages { flex: 1; overflow-y: auto; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); }
.ask-message { display: flex; gap: var(--space-3); max-width: 90%; }
.ask-message.user { align-self: flex-end; flex-direction: row-reverse; }
.ask-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.ask-avatar.ai { background: var(--accent-light); }
.ask-avatar.user { background: var(--bg-tertiary); }
.ask-bubble { padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); font-size: var(--text-sm); line-height: 1.6; white-space: pre-wrap; }
.ask-message.ai .ask-bubble { background: var(--bg-secondary); }
.ask-message.user .ask-bubble { background: var(--accent-color); color: #fff; }
.ask-sources { margin-top: var(--space-2); padding: var(--space-2) var(--space-3); background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--radius-sm); font-size: var(--text-xs); }
.ask-source-item { display: flex; align-items: center; gap: var(--space-2); padding: 3px 0; cursor: pointer; color: var(--accent-color); }
.ask-source-item:hover { text-decoration: underline; }
.ask-input-area { padding: var(--space-4); border-top: 1px solid var(--border-color); }
.ask-input-row { display: flex; gap: var(--space-2); margin-bottom: var(--space-2); }
.ask-input-area textarea { flex: 1; min-height: 44px; max-height: 120px; width: 100%; border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: var(--space-2) var(--space-3); background: var(--bg-secondary); color: var(--text-primary); font-family: var(--font-sans); font-size: var(--text-sm); resize: none; outline: none; box-sizing: border-box; }
.ask-input-area textarea:focus { border-color: var(--accent-color); }
.ask-input-actions { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); }

/* Conversation top bar */
.ask-topbar { padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--border-color); display: flex; align-items: center; gap: var(--space-2); position: relative; }
.conv-dropdown { display: none; position: absolute; top: 100%; left: var(--space-4); z-index: 100; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--radius-md); box-shadow: var(--shadow-md); min-width: 240px; max-height: 300px; overflow-y: auto; }
.conv-dropdown.show { display: block; }
.conv-dropdown-header { display: flex; align-items: center; justify-content: space-between; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border-color); }
.conv-item { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); cursor: pointer; font-size: var(--text-sm); border-bottom: 1px solid var(--border-color); transition: background 0.15s; }
.conv-item:hover { background: var(--bg-secondary); }
.conv-item.active { background: var(--accent-light); }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { font-size: 10px; color: var(--text-tertiary); white-space: nowrap; }
.conv-delete { width: 20px; height: 20px; border: none; background: none; cursor: pointer; font-size: 12px; color: var(--text-tertiary); border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; }
.conv-delete:hover { background: var(--danger-light); color: var(--danger-color); }

/* RAG control bar */
.ask-rag-bar { padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--border-color); display: flex; align-items: center; gap: var(--space-1); }
.rag-cat-panel { display: flex; align-items: center; gap: var(--space-1); position: relative; margin-left: var(--space-2); }
.rag-cat-dropdown { display: none; position: absolute; top: 100%; left: 0; z-index: 100; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--radius-md); box-shadow: var(--shadow-md); min-width: 180px; max-height: 240px; overflow-y: auto; }
.rag-cat-dropdown.show { display: block; }
.rag-cat-option { padding: 6px 12px; font-size: 12px; cursor: pointer; border-bottom: 1px solid var(--border-color); }
.rag-cat-option:hover { background: var(--bg-secondary); }
.rag-cat-option.active { background: var(--accent-light); color: var(--accent-color); }
.rag-cat-tag { display: inline-block; padding: 1px 6px; background: var(--accent-light); color: var(--accent-color); border-radius: var(--radius-sm); font-size: 10px; margin-right: 2px; }

/* Document bar */
.ask-doc-bar { padding: var(--space-2) var(--space-4); display: flex; align-items: center; gap: var(--space-2); border-bottom: 1px solid var(--border-color); }
.doc-tag { display: inline-flex; align-items: center; gap: 2px; padding: 2px 8px; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-sm); font-size: 11px; }
.doc-tag-remove { border: none; background: none; cursor: pointer; font-size: 10px; color: var(--text-tertiary); padding: 0 2px; }
.doc-tag-remove:hover { color: var(--danger-color); }

/* Message actions */
.msg-actions { display: flex; gap: var(--space-1); margin-top: var(--space-2); }
.msg-action-btn { padding: 2px 8px; border: 1px solid var(--border-color); background: var(--bg-primary); border-radius: var(--radius-sm); font-size: 10px; color: var(--text-secondary); cursor: pointer; transition: all 0.15s; }
.msg-action-btn:hover { background: var(--bg-secondary); border-color: var(--accent-color); color: var(--accent-color); }

/* ============================================================
   Settings Module
   ============================================================ */
.settings-section { margin-bottom: var(--space-6); }
.settings-section-title { font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--space-3); color: var(--text-secondary); }
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) 0; border-bottom: 1px solid var(--border-color); }
.setting-label { font-size: var(--text-sm); }
.setting-desc { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: 2px; }
.setting-control select { padding: 6px 10px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); background: var(--bg-secondary); color: var(--text-primary); font-size: var(--text-sm); outline: none; }

/* Toggle Switch */
.toggle { width: 40px; height: 22px; border-radius: 11px; background: var(--border-color); cursor: pointer; position: relative; transition: all 0.2s; }
.toggle.on { background: var(--accent-color); }
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: all 0.2s; }
.toggle.on::after { left: 20px; }

/* ============================================================
   Quick Capture Modal
   ============================================================ */
.modal-overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,0.3); display: flex; align-items: flex-start; justify-content: center; padding-top: 15vh; animation: overlayIn 0.15s ease; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
.quick-capture { width: 480px; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; animation: modalIn 0.2s ease; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(-10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.qc-header { display: flex; align-items: center; justify-content: space-between; padding: var(--space-2) var(--space-3); background: var(--bg-secondary); border-bottom: 1px solid var(--border-color); }
.qc-header-title { font-size: var(--text-xs); font-weight: 600; color: var(--text-secondary); }
.qc-close { width: 24px; height: 24px; border: none; background: none; cursor: pointer; border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 14px; display: flex; align-items: center; justify-content: center; }
.qc-close:hover { background: var(--bg-tertiary); }
.qc-body { padding: var(--space-4); }
.qc-body textarea { width: 100%; min-height: 120px; border: none; outline: none; font-family: var(--font-sans); font-size: var(--text-base); color: var(--text-primary); resize: vertical; line-height: 1.6; background: transparent; }
.qc-body textarea::placeholder { color: var(--text-tertiary); }
.qc-footer { display: flex; align-items: center; justify-content: space-between; padding: var(--space-2) var(--space-4) var(--space-3); }
.qc-hint { font-size: var(--text-xs); color: var(--text-tertiary); }
.qc-hint kbd { background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 3px; padding: 1px 5px; font-family: var(--font-mono); font-size: 10px; }
.qc-actions { display: flex; gap: var(--space-2); }

/* ============================================================
   Toast
   ============================================================ */
.toast-container { position: fixed; bottom: 60px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: var(--space-2); }
.toast { background: var(--text-primary); color: var(--bg-primary); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-sm); box-shadow: var(--shadow-md); animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards; max-width: 320px; }
.toast.error { background: var(--danger-color); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(20px); } }

/* ============================================================
   Scrollbar
   ============================================================ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* Welcome Guide Modal */
.guide-overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; }
.guide-card { width: 420px; background: var(--bg-primary); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: var(--space-6); text-align: center; }
.guide-icon { font-size: 48px; margin-bottom: var(--space-4); }
.guide-title { font-size: 1.25rem; font-weight: 700; margin-bottom: var(--space-3); }
.guide-steps { text-align: left; margin: var(--space-4) 0; }
.guide-step { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) 0; }
.guide-step-num { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-light); color: var(--accent-color); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--text-sm); flex-shrink: 0; }
.guide-step-text { font-size: var(--text-sm); }
.guide-step-text kbd { background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 3px; padding: 1px 5px; font-family: var(--font-mono); font-size: 11px; }
