/* ═══════════════════════════════════════════
   Modern Theme System with Advanced UI Design
   ═══════════════════════════════════════════ */

:root {
  /* Light Theme - Clean & Professional */
  --bg-primary: #fafafa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f5f5f7;
  --bg-sidebar: #f8f9fa;
  --bg-toolbar: #ffffff;
  --bg-header: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #f0f4ff;
  --bg-active: #667eea;
  --bg-badge: #667eea;
  --bg-toast: #1a1a2e;
  --bg-modal: #ffffff;
  --bg-preview: #ffffff;
  --bg-code: #f8f9fa;
  --bg-pre: #1e1e2e;
  
  --text-primary: #1a1a2e;
  --text-secondary: #4a5568;
  --text-tertiary: #718096;
  --text-inverse: #ffffff;
  --text-link: #667eea;
  --text-code: #e53e3e;
  
  --accent: #667eea;
  --accent-hover: #5a67d8;
  --accent-light: rgba(102, 126, 234, 0.1);
  --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  
  --border-primary: #e2e8f0;
  --border-secondary: #edf2f7;
  --border-focus: #667eea;
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.12);
  --shadow-glow: 0 0 20px rgba(102, 126, 234, 0.3);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  
  --preview-header-bg: #f7fafc;
  --preview-blockquote-bg: #f0f4ff;
  --preview-table-header-bg: #f7fafc;
  --preview-code-bg: #f8f9fa;
  --preview-table-border: #e2e8f0;
  --search-highlight: #f0f4ff;
  --search-highlight-text: #667eea;
}

[data-theme="dark"] {
  /* Dark Theme - VS Code Inspired */
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #0d1117;
  --bg-sidebar: #0d1117;
  --bg-toolbar: #161b22;
  --bg-header: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  --bg-card: #161b22;
  --bg-input: #0d1117;
  --bg-hover: #1a2332;
  --bg-active: #58a6ff;
  --bg-badge: #58a6ff;
  --bg-toast: #161b22;
  --bg-modal: #161b22;
  --bg-preview: #0d1117;
  --bg-code: #1a2332;
  --bg-pre: #1e1e2e;
  
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-tertiary: #6e7681;
  --text-inverse: #0d1117;
  --text-link: #58a6ff;
  --text-code: #ff7b72;
  
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --accent-light: rgba(88, 166, 255, 0.1);
  --accent-gradient: linear-gradient(135deg, #58a6ff 0%, #a371f7 100%);
  
  --border-primary: #30363d;
  --border-secondary: #21262d;
  --border-focus: #58a6ff;
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(88, 166, 255, 0.2);
  
  --preview-header-bg: #161b22;
  --preview-blockquote-bg: #1a2332;
  --preview-table-header-bg: #161b22;
  --preview-code-bg: #1a2332;
  --preview-table-border: #30363d;
  --search-highlight: #1a2332;
  --search-highlight-text: #58a6ff;
}

/* ═══════════════════════════════════════════
   Base Reset & Typography
   ═══════════════════════════════════════════ */
*, *::before, *::after { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background var(--transition-normal), color var(--transition-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

/* ═══════════════════════════════════════════
   Authentication Overlay
   ═══════════════════════════════════════════ */
#authOverlay {
  position: fixed; inset: 0; 
  background: var(--bg-header);
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(10px);
}

#authOverlay.hidden { display: none; }

.auth-box {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 90%; max-width: 380px;
  text-align: center;
  color: var(--text-primary);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-primary);
  transition: all var(--transition-normal);
}

.auth-box:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.auth-box h2 { 
  font-size: 1.4rem; 
  margin-bottom: 8px; 
  font-weight: 600;
  letter-spacing: -0.01em;
}

.auth-box p { 
  font-size: 0.85rem; 
  color: var(--text-tertiary); 
  margin-bottom: 24px; 
}

.auth-box input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border-primary);
  border-radius: var(--radius-md);
  font-size: 1rem;
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  box-sizing: border-box;
  transition: all var(--transition-fast);
}

.auth-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.auth-box button {
  width: 100%;
  padding: 14px;
  margin-top: 16px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent-gradient);
  color: var(--text-inverse);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-md);
}

.auth-box button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.auth-box button:active {
  transform: translateY(0);
}

.auth-error {
  color: #f85149;
  font-size: 0.8rem;
  margin-top: 12px;
  min-height: 1.2em;
  font-weight: 500;
}

/* ═══════════════════════════════════════════
   Application Header
   ═══════════════════════════════════════════ */
.app-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-header);
  color: #ffffff;
  position: sticky; top: 0; z-index: 200;
  gap: 12px; flex-wrap: wrap;
  box-shadow: var(--shadow-lg);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.app-bar .left { display: flex; align-items: center; gap: 12px; }

.app-bar .left .menu-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--text-inverse);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px 10px;
  display: none;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.app-bar .left .menu-btn:hover {
  background: rgba(255,255,255,0.2);
  transform: translateY(-1px);
}

.app-bar h1 { 
  font-size: 1.15rem; 
  font-weight: 700; 
  white-space: nowrap; 
  display: flex; 
  align-items: center; 
  gap: 8px;
  letter-spacing: -0.02em;
}

.app-bar h1 .hl { 
  background: rgba(255,255,255,0.2);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.app-bar .actions { 
  display: flex; 
  gap: 8px; 
  align-items: center; 
  flex-wrap: wrap; 
}

/* 移动端：图标紧凑排一行 */
@media (max-width: 820px) {
  .app-bar .actions { 
    gap: 4px; 
    flex-wrap: nowrap; 
  }
  .app-bar .actions .btn { 
    padding: 5px 6px; 
    font-size: 0.76rem; 
    flex-shrink: 0; 
  }
}

/* ═══════════════════════════════════════════
   Buttons
   ═══════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: rgba(255,255,255,0.1);
  color: #ffffff !important;
  backdrop-filter: blur(10px);
}

.btn:hover {
  background: rgba(255,255,255,0.2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary { 
  background: var(--accent-gradient);
  border: none;
  color: var(--text-inverse);
}

.btn-primary:hover {
  box-shadow: var(--shadow-glow);
}

.btn-outline { 
  background: transparent; 
  color: var(--text-secondary); 
  border: 1px solid var(--border-primary); 
}

.btn-outline:hover { 
  border-color: var(--accent); 
  color: var(--accent); 
  background: var(--accent-light);
}

.btn-sm { padding: 4px 10px; font-size: 0.72rem; }

.btn-success { 
  background: linear-gradient(135deg, #48bb78, #38a169); 
  color: var(--text-inverse);
  border: none;
}

.btn-success:hover {
  box-shadow: 0 0 15px rgba(72, 187, 120, 0.4);
}

.btn-danger { 
  background: linear-gradient(135deg, #f56565, #e53e3e); 
  color: var(--text-inverse);
  border: none;
}

.btn-danger:hover {
  box-shadow: 0 0 15px rgba(245, 101, 101, 0.4);
}

.btn-warning { 
  background: linear-gradient(135deg, #ed8936, #dd6b20); 
  color: var(--text-inverse);
  border: none;
}

.btn-warning:hover {
  box-shadow: 0 0 15px rgba(237, 137, 54, 0.4);
}

/* ═══════════════════════════════════════════
   Theme Toggle Button
   ═══════════════════════════════════════════ */
.theme-toggle {
  background: rgba(255,255,255,0.1) !important;
  border: 1px solid rgba(255,255,255,0.2) !important;
  color: var(--text-inverse) !important;
  font-size: 1rem !important;
  padding: 6px 10px !important;
  cursor: pointer;
  transition: all var(--transition-fast) !important;
  border-radius: var(--radius-sm) !important;
  line-height: 1;
  backdrop-filter: blur(10px);
}

.theme-toggle:hover {
  background: rgba(255,255,255,0.2) !important;
  transform: translateY(-1px) !important;
  box-shadow: var(--shadow-md) !important;
}

/* ═══════════════════════════════════════════
   Read Mode Button
   ═══════════════════════════════════════════ */
.btn-readmode { 
  background: linear-gradient(135deg, #805ad5, #6b46c1) !important; 
  color: var(--text-inverse) !important;
  border: none !important;
}

.btn-readmode:hover {
  box-shadow: 0 0 15px rgba(128, 90, 213, 0.4) !important;
}

.btn-readmode.active { 
  background: linear-gradient(135deg, #ed8936, #dd6b20) !important; 
}

/* ═══════════════════════════════════════════
   Main Layout
   ═══════════════════════════════════════════ */
.main-layout {
  display: flex; 
  height: calc(100vh - 64px); 
  position: relative;
  background: var(--bg-primary);
}

/* ═══════════════════════════════════════════
   Sidebar
   ═══════════════════════════════════════════ */
.sidebar {
  width: 280px; 
  min-width: 280px; 
  background: var(--bg-sidebar); 
  border-right: 1px solid var(--border-primary);
  display: flex; 
  flex-direction: column; 
  overflow: hidden;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; 
  border-bottom: 1px solid var(--border-secondary);
  background: var(--bg-toolbar);
}

.sidebar-header h3 { 
  font-size: 0.85rem; 
  color: var(--text-tertiary); 
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-header .actions { display: flex; gap: 6px; }

.sidebar-header .actions button {
  background: var(--accent-light);
  border: 1px solid var(--border-primary);
  color: var(--accent);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: all var(--transition-fast);
}

.sidebar-header .actions button:hover { 
  background: var(--accent);
  color: var(--text-inverse);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.sidebar-search { 
  padding: 12px 18px; 
  border-bottom: 1px solid var(--border-secondary);
  background: var(--bg-toolbar);
}

.sidebar-search input {
  width: 100%; 
  padding: 10px 14px; 
  border: 1px solid var(--border-primary); 
  border-radius: var(--radius-md);
  font-size: 0.82rem; 
  background: var(--bg-input); 
  color: var(--text-primary); 
  outline: none;
  transition: all var(--transition-fast);
}

.sidebar-search input:focus { 
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.sidebar-tree {
  flex: 1; 
  overflow-y: auto; 
  padding: 8px 0; 
  font-size: 0.85rem;
  background: var(--bg-sidebar);
}

.sidebar-tree::-webkit-scrollbar { width: 6px; }
.sidebar-tree::-webkit-scrollbar-track { background: transparent; }
.sidebar-tree::-webkit-scrollbar-thumb { 
  background: var(--border-primary); 
  border-radius: 3px; 
}
.sidebar-tree::-webkit-scrollbar-thumb:hover { 
  background: var(--text-tertiary); 
}

.tree-item {
  display: flex; align-items: center; padding: 8px 14px; margin: 2px 10px;
  border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast);
  gap: 8px; user-select: none; position: relative;
  border: 1px solid transparent;
}

.tree-item:hover { 
  background: var(--bg-hover);
  border-color: var(--border-secondary);
}

.tree-item.active { 
  background: var(--accent-light); 
  color: var(--accent); 
  font-weight: 600;
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.tree-item .icon { 
  font-size: 0.9rem; 
  width: 20px; 
  text-align: center; 
  flex-shrink: 0; 
}

.tree-item .name { 
  flex: 1; 
  overflow: hidden; 
  text-overflow: ellipsis; 
  white-space: nowrap;
  font-size: 0.82rem;
}

/* 玄骐 2026-10-25: 文件最后修改时间 — 灰色小字靠右, hover 时完整时间放 title 属性 */
.tree-item .file-date {
  flex-shrink: 0;
  font-size: 0.68rem;
  color: var(--text-tertiary, #8b95a7);
  font-variant-numeric: tabular-nums;
  margin-right: 4px;
}
.tree-item:hover .file-date,
.tree-item.active .file-date {
  color: var(--text-secondary, #9aa4b5);
}

.tree-item .item-actions { 
  display: none; 
  gap: 4px; 
  flex-shrink: 0; 
}

.tree-item:hover .item-actions { 
  display: flex; 
}

.tree-item .item-actions button {
  background: transparent; 
  border: 1px solid var(--border-primary);
  font-size: 0.7rem;
  cursor: pointer; 
  padding: 2px 6px; 
  border-radius: var(--radius-sm); 
  color: var(--text-tertiary); 
  line-height: 1;
  transition: all var(--transition-fast);
}

.tree-item .item-actions button:hover { 
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}

.tree-item.active .item-actions button { 
  color: var(--accent); 
}

.tree-item.active .item-actions button:hover { 
  background: var(--accent);
  color: var(--text-inverse);
}

.tree-item .arrow {
  font-size: 0.7rem; 
  width: 16px; 
  text-align: center; 
  flex-shrink: 0;
  transition: transform var(--transition-fast); 
  color: var(--text-tertiary);
}

.tree-item .arrow.expanded { 
  transform: rotate(90deg); 
}

.tree-item.active .arrow { 
  color: var(--accent); 
}

.tree-children { 
  padding-left: 24px; 
}

.tree-empty {
  text-align: center; 
  color: var(--text-tertiary); 
  padding: 32px 20px; 
  font-size: 0.82rem; 
  line-height: 1.6;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  margin: 16px;
  border: 1px dashed var(--border-primary);
}

/* ═══════════════════════════════════════════
   Content Area
   ═══════════════════════════════════════════ */
.content-area { 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  min-width: 0;
  background: var(--bg-primary);
}

/* ═══════════════════════════════════════════
   Toolbar
   ═══════════════════════════════════════════ */
.toolbar-wrap {
  background: var(--bg-toolbar); 
  border-bottom: 1px solid var(--border-primary); 
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.toolbar {
  display: flex; align-items: center; gap: 4px; padding: 8px 16px;
  flex-wrap: wrap;
}

.toolbar .sep { 
  display: inline-flex; 
  width: 1px; 
  height: 24px; 
  background: var(--border-primary); 
  margin: 0 6px; 
  flex-shrink: 0; 
}

.toolbar button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; 
  border: 1px solid transparent; 
  border-radius: var(--radius-sm);
  background: transparent; 
  color: var(--text-secondary); 
  font-size: 0.9rem;
  cursor: pointer; 
  transition: all var(--transition-fast); 
  flex-shrink: 0; 
  position: relative;
}

.toolbar button:hover { 
  background: var(--bg-hover);
  border-color: var(--border-secondary);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.toolbar button:active { 
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(0.95);
}

.toolbar .tb-label { 
  font-size: 0.72rem; 
  font-weight: 600; 
  padding: 0 8px;
}

.toolbar .tb-wide { 
  width: auto; 
  padding: 0 10px; 
  gap: 4px; 
  font-size: 0.78rem; 
  font-weight: 550; 
}

.toolbar button .tooltip {
  display: none; 
  position: absolute; 
  top: -32px; 
  left: 50%; 
  transform: translateX(-50%);
  background: var(--bg-toast); 
  color: var(--text-inverse); 
  font-size: 0.68rem; 
  padding: 4px 10px;
  border-radius: var(--radius-sm); 
  white-space: nowrap; 
  pointer-events: none;
  box-shadow: var(--shadow-md);
  z-index: 100;
}

.toolbar button:hover .tooltip { 
  display: block; 
}

/* ═══════════════════════════════════════════
   Editor & Preview
   ═══════════════════════════════════════════ */
.editor-wrapper { 
  display: flex; 
  flex: 1; 
  gap: 0; 
  min-height: 0; 
  background: var(--bg-primary);
}

.editor-wrapper.readmode .editor-pane { display: none; }
.editor-wrapper.readmode .preview-pane { flex: 1; }
.editor-wrapper.readmode ~ .mobile-tabs,
body.read-mode .mobile-tabs { display: none !important; }

.editor-pane, .preview-pane {
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  min-width: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  margin: 8px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-normal);
}

.editor-pane:hover, .preview-pane:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.pane-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; 
  background: var(--preview-header-bg); 
  border-bottom: 1px solid var(--border-secondary);
  font-size: 0.78rem; 
  font-weight: 600; 
  color: var(--text-tertiary); 
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.pane-header .badge {
  font-size: 0.68rem; 
  background: var(--accent-gradient); 
  color: var(--text-inverse); 
  padding: 3px 12px;
  border-radius: 16px; 
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.CodeMirror { 
  flex: 1; 
  height: auto !important; 
  font-size: 14px; 
  line-height: 1.7;
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
}

.CodeMirror-scroll { min-height: 100%; }

.preview-content {
  flex: 1; 
  overflow-y: auto; 
  padding: 24px 28px; 
  background: var(--preview-bg);
  line-height: 1.7; 
  color: var(--text-primary);
  transition: all var(--transition-normal);
}

.preview-content h1, .preview-content h2, .preview-content h3 { 
  margin-top: 1.4em; 
  margin-bottom: 0.5em; 
  font-weight: 600; 
  border-bottom: 1px solid var(--border-secondary); 
  padding-bottom: 0.3em;
  letter-spacing: -0.02em;
}

.preview-content h1 { font-size: 1.7rem; }
.preview-content h2 { font-size: 1.4rem; }
.preview-content h3 { font-size: 1.15rem; border-bottom: none; }

.preview-content p { 
  margin-bottom: 1em; 
  line-height: 1.7;
  color: var(--text-secondary);
}

.preview-content ul, .preview-content ol { 
  padding-left: 1.8em; 
  margin-bottom: 1em; 
}

.preview-content li { 
  margin-bottom: 0.4em; 
  line-height: 1.6;
}

.preview-content code {
  background: var(--preview-code-bg);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.88em;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  color: var(--text-code);
  border: 1px solid var(--border-primary);
}

.preview-content mark {
  background: #fff3a3;
  color: inherit;
  padding: 1px 3px;
  border-radius: 3px;
}

[data-theme="dark"] .preview-content mark {
  background: #7a5c00;
  color: #fff;
}

.preview-content pre { 
  background: var(--bg-pre); 
  color: #cdd6f4; 
  padding: 18px; 
  border-radius: var(--radius-md); 
  overflow-x: auto; 
  margin: 1.2em 0; 
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255,255,255,0.1);
}

.preview-content pre code { 
  background: transparent; 
  padding: 0; 
  color: inherit; 
  border: none;
}

.preview-content blockquote { 
  border-left: 4px solid var(--accent); 
  padding: 12px 18px; 
  margin: 1.2em 0; 
  background: var(--preview-blockquote-bg); 
  color: var(--text-secondary); 
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-style: italic;
}

.preview-content table { 
  width: 100%; 
  border-collapse: separate; 
  border-spacing: 0;
  margin: 1.2em 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.preview-content th, .preview-content td { 
  border: 1px solid var(--preview-table-border); 
  padding: 10px 14px; 
  text-align: left;
}

.preview-content th { 
  background: var(--preview-table-header-bg); 
  font-weight: 600;
  color: var(--text-primary);
}

.preview-content img { 
  max-width: 100%; 
  border-radius: var(--radius-md); 
  margin: 1.2em 0;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-fast);
}

.preview-content img:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-lg);
}

.preview-content hr { 
  border: none; 
  border-top: 2px solid var(--border-secondary); 
  margin: 2em 0; 
}

.preview-content a { 
  color: var(--text-link); 
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: all var(--transition-fast);
}

.preview-content a:hover { 
  text-decoration: none;
  border-bottom-color: var(--text-link);
}

.preview-content .task-list-item { 
  list-style: none; 
  margin-left: -1.8em; 
}

.preview-content .task-list-item input { 
  margin-right: 8px; 
}

.preview-content.readmode p, .preview-content.readmode li, .preview-content.readmode h1,
.preview-content.readmode h2, .preview-content.readmode h3, .preview-content.readmode blockquote,
.preview-content.readmode pre, .preview-content.readmode td, .preview-content.readmode th { 
  user-select: text; 
  -webkit-user-select: text; 
}

/* ═══════════════════════════════════════════
   Empty State
   ═══════════════════════════════════════════ */
.empty-state { 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  justify-content: center; 
  height: 100%; 
  color: var(--text-tertiary); 
  text-align: center; 
  gap: 12px; 
  padding: 20px;
}

.empty-state .icon { 
  font-size: 3rem; 
  opacity: 0.4; 
}

.empty-state p { 
  font-size: 0.92rem; 
  line-height: 1.5;
}

/* ═══════════════════════════════════════════
   Toast Notifications
   ═══════════════════════════════════════════ */
.toast {
  position: fixed; 
  bottom: 32px; 
  left: 50%; 
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-toast); 
  color: #ffffff;
  padding: 12px 28px; 
  border-radius: var(--radius-lg);
  font-size: 0.88rem; 
  box-shadow: var(--shadow-xl);
  opacity: 0; 
  transition: all var(--transition-slow); 
  pointer-events: none; 
  z-index: 999;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
}

.toast.show { 
  opacity: 1; 
  transform: translateX(-50%) translateY(0);
}

/* ═══════════════════════════════════════════
   Modals
   ═══════════════════════════════════════════ */
.modal-overlay {
  display: none; 
  position: fixed; 
  inset: 0; 
  background: rgba(0,0,0,0.5);
  z-index: 300; 
  align-items: center; 
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-overlay.show { 
  display: flex; 
}

.modal-box {
  background: var(--bg-modal); 
  border-radius: var(--radius-xl); 
  padding: 32px; 
  width: 90%; 
  max-width: 420px;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-primary);
  transition: all var(--transition-normal);
}

.modal-box:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.modal-box h3 { 
  font-size: 1.15rem; 
  margin-bottom: 16px;
  color: var(--text-primary);
  font-weight: 600;
}

.modal-box input, .modal-box select {
  width: 100%; 
  padding: 12px 16px; 
  border: 1px solid var(--border-primary); 
  border-radius: var(--radius-md);
  font-size: 0.92rem; 
  outline: none; 
  margin-bottom: 16px;
  background: var(--bg-input);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.modal-box input:focus, .modal-box select:focus { 
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.modal-box .modal-actions { 
  display: flex; 
  gap: 10px; 
  justify-content: flex-end; 
}

/* 文件夹选择器样式 */
.modal-folder-select {
  width: 100%; 
  padding: 10px 14px; 
  border: 1px solid var(--border-primary); 
  border-radius: var(--radius-md);
  font-size: 0.88rem; 
  outline: none; 
  margin-bottom: 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.modal-folder-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* Modal 内的按钮样式覆盖 — 白色背景上需要更高的对比度和合适的尺寸 */
.modal-box .btn {
  padding: 8px 16px;
  font-size: 0.85rem;
  border-radius: var(--radius-md);
}

.modal-box .btn-outline {
  background: var(--bg-input);
  color: var(--text-primary) !important;
  border: 1px solid var(--border-primary);
}

.modal-box .btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.modal-box .btn-primary {
  background: var(--accent);
  border: none;
  color: var(--text-inverse);
}

.modal-box .btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
}

/* ═══════════════════════════════════════════
   Search Overlay
   ═══════════════════════════════════════════ */
.search-overlay {
  display: none; 
  position: fixed; 
  inset: 0; 
  background: rgba(0,0,0,0.4);
  z-index: 250; 
  align-items: flex-start; 
  justify-content: center; 
  padding-top: 100px;
  backdrop-filter: blur(6px);
}

.search-overlay.show { 
  display: flex; 
}

.search-panel {
  background: var(--bg-modal); 
  border-radius: var(--radius-xl); 
  padding: 24px; 
  width: 90%; 
  max-width: 600px;
  max-height: 70vh; 
  overflow-y: auto; 
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-primary);
  transition: all var(--transition-normal);
}

.search-panel:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.search-panel input {
  width: 100%; 
  padding: 14px 18px; 
  border: 2px solid var(--accent); 
  border-radius: var(--radius-lg);
  font-size: 1.05rem; 
  outline: none;
  background: var(--bg-input);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.search-panel input:focus {
  box-shadow: 0 0 0 4px var(--accent-light);
}

.search-result-item {
  padding: 14px 18px; 
  border-bottom: 1px solid var(--border-secondary); 
  cursor: pointer; 
  border-radius: var(--radius-md);
  margin-top: 8px;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.search-result-item:hover { 
  background: var(--search-highlight);
  border-color: var(--border-primary);
  transform: translateX(4px);
}

.search-result-item .file-path { 
  font-size: 0.76rem; 
  color: var(--text-tertiary); 
  margin-bottom: 4px; 
}

.search-result-item .file-title { 
  font-size: 0.95rem; 
  font-weight: 600; 
  color: var(--text-primary); 
}

.search-result-item .match-snippet { 
  font-size: 0.84rem; 
  color: var(--text-secondary); 
  margin-top: 6px; 
}

.search-result-item .match-snippet em { 
  color: var(--search-highlight-text); 
  font-style: normal; 
  background: var(--search-highlight); 
  padding: 1px 4px; 
  border-radius: 3px; 
}

.search-empty { 
  text-align: center; 
  padding: 40px; 
  color: var(--text-tertiary); 
  font-size: 0.95rem; 
}

/* ═══════════════════════════════════════════
   Mobile Tabs
   ═══════════════════════════════════════════ */
.mobile-tabs { 
  display: none; 
  background: var(--bg-toolbar); 
  border-bottom: 1px solid var(--border-primary); 
}

.mobile-tabs button {
  flex: 1; 
  border: none; 
  background: transparent; 
  padding: 10px 0;
  font-size: 0.84rem; 
  font-weight: 500; 
  color: var(--text-secondary);
  cursor: pointer; 
  border-bottom: 2px solid transparent; 
  transition: all var(--transition-fast);
}

.mobile-tabs button.active { 
  color: var(--accent); 
  border-bottom-color: var(--accent); 
  background: var(--accent-light);
}

/* ═══════════════════════════════════════════
   File Info Bar
   ═══════════════════════════════════════════ */
.file-info {
  display: flex; align-items: center; gap: 8px; 
  font-size: 0.76rem; 
  color: var(--text-secondary);
}

.file-info .folder-tag {
  background: var(--accent-light);
  padding: 2px 10px; 
  border-radius: 12px; 
  font-size: 0.68rem;
  color: var(--accent);
  font-weight: 500;
  border: 1px solid var(--accent);
}

/* ═══════════════════════════════════════════
   Responsive Design
   ═══════════════════════════════════════════ */
@media (max-width: 820px) {
  .app-bar { padding: 10px 14px; }
  .app-bar .left .menu-btn { display: inline-flex; }
  .app-bar h1 { font-size: 0.95rem; }
  .app-bar .actions .btn span { display: none; }
  .app-bar .actions .btn { padding: 5px 6px; font-size: 0.76rem; }
  .app-bar .actions { flex-wrap: nowrap; gap: 4px; }
  
  #exportMdBtn, #exportHtmlBtn { display: none !important; }
  

  .sidebar {
    position: fixed; 
    left: -300px; 
    top: 95px; 
    bottom: 0; 
    width: 300px;
    box-shadow: var(--shadow-xl);
    z-index: 160;
  }
  
  .sidebar.open { 
    left: 0; 
  }

  /* 手机端：侧边栏顶部搜索框不被编辑器遮挡 */
  .sidebar {
    top: 52px !important;
    bottom: 0;
    z-index: 300;
  }
  
  .sidebar-backdrop {
    display: none; 
    position: fixed; 
    inset: 0; 
    background: rgba(0,0,0,0.4);
    z-index: 150;
  }
  
  .sidebar-backdrop.show { 
    display: block; 
  }

  .editor-wrapper { 
    flex-direction: column; 
  }
  
  .editor-pane {
    /* 浏览器：100dvh 自动收缩（Chrome 108+/Safari 15.4+） */
    /* APK WebView：100dvh 不变，JS 监听 resize 强行重设（见 app.js 键盘适配） */
    height: calc(100dvh - 100px);
    min-height: 280px;
  }

  .preview-pane {
    height: calc(100dvh - 100px);
    min-height: 280px;
  }
  
  .preview-content { 
    padding: 16px 20px; 
  }
  
  .CodeMirror { 
    font-size: 13px; 
  }
  
  .mobile-tabs { 
    display: flex; 
  }
  
  .editor-pane, .preview-pane { 
    display: none; 
  }
  
  .editor-pane.active { 
    display: flex; 
  }
  .preview-pane.active { 
    display: flex; 
  }
  
  .toolbar-wrap { 
    top: 0; 
  }

  /* 工具栏：按钮换行排列，隐藏分隔线 */
  .toolbar-wrap {
    position: sticky;
    top: 52px;
    z-index: 190;
  }
  .toolbar {
    gap: 3px;
    padding: 6px 10px;
  }
  .toolbar .sep {
    display: none;
  }
  /* 手机端：隐藏撤销/重做按钮 */
  .toolbar button[data-cmd="undo"],
  .toolbar button[data-cmd="redo"] {
    display: none !important;
  }
  /* 手机端编辑模式：隐藏预览面板，编辑器占满空间 */
  .editor-wrapper.hide-preview .editor-pane {
    height: auto !important;
    min-height: 0;
  }
  .editor-wrapper.hide-preview .preview-pane {
    display: none !important;
  }
  /* 键盘弹起时整个 wrapper 跟随动态视口 */
  .editor-wrapper.hide-preview {
    max-height: calc(100dvh - 100px);
  }
  .toolbar button .tooltip {
    display: none !important;
  }
}

@media (max-width: 480px) {
  .app-bar .actions .btn span { display: none; }
  .editor-pane { min-height: 220px !important; }
  .preview-pane { min-height: 220px; }
  
  .auth-box {
    padding: 32px 24px;
  }
  
  .modal-box {
    padding: 24px 20px;
  }
  
  .search-panel {
    padding: 20px 16px;
  }
}

/* ═══════════════════════════════════════════
   Backup / Sync Modal Styles
   ═══════════════════════════════════════════ */
.modal-lg {
  max-width: 560px;
}

.sync-status {
  padding: 12px 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-secondary);
  margin-bottom: 12px;
}

.backup-list {
  max-height: 320px;
  overflow-y: auto;
}

.backup-list-title {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  font-weight: 500;
}

.backup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  margin-bottom: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.backup-item:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.backup-item-info {
  flex: 1;
  min-width: 0;
}

.backup-item-time {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 500;
}

.backup-item-meta {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.backup-item-actions {
  display: flex;
  gap: 6px;
  margin-left: 10px;
  flex-shrink: 0;
}

.backup-item-actions button {
  border: none;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-restore {
  background: var(--accent);
  color: white;
}

.btn-restore:hover {
  opacity: 0.85;
}

.btn-delete {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-secondary) !important;
}

.btn-delete:hover {
  color: #e74c3c;
  border-color: #e74c3c !important;
}

.restore-empty {
  text-align: center;
  padding: 30px 0;
  color: var(--text-tertiary);
  font-size: 0.88rem;
}

/* 同步中状态 */
.sync-loading {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.sync-loading::after {
  content: '...';
  animation: dots 1.5s infinite;
}

@keyframes dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

/* 恢复确认提示 */
.restore-confirm {
  padding: 12px;
  background: rgba(255, 165, 0, 0.08);
  border: 1px solid rgba(255, 165, 0, 0.3);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* ===================== 分享 Modal ===================== */
.share-modal-box {
  max-width: 640px;
  width: 90%;
}

/* modal-header 通用样式：让标题左、关闭按钮右 */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: -8px 0 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-primary);
}
.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--text-primary);
}

/* modal-close 圆形图标按钮 */
.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.4rem;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}
.modal-close:hover {
  background: var(--bg-secondary);
  color: var(--accent);
}
.modal-close:active {
  transform: scale(0.92);
}

.share-note-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
}
.share-note-icon { font-size: 1.3rem; }
.share-note-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  word-break: break-all;
}

.share-create-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
}
.share-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.share-expiry-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.share-expiry-opt {
  flex: 1;
  min-width: 80px;
  position: relative;
  cursor: pointer;
}
.share-expiry-opt input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.share-expiry-opt span {
  display: block;
  padding: 10px 16px;
  text-align: center;
  background: var(--bg-primary);
  border: 2px solid var(--border-primary);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.share-expiry-opt input[type="radio"]:checked + span {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}
.share-expiry-opt:hover span {
  border-color: var(--accent);
}
.btn-share-create {
  padding: 10px 20px;
  background: var(--accent);
  color: white !important;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  align-self: flex-start;
}
.btn-share-create:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.share-divider {
  height: 1px;
  background: var(--border-primary);
  margin: 24px 0 16px;
}

.share-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.btn-share-refresh {
  padding: 4px 12px;
  background: transparent;
  color: var(--accent) !important;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-share-refresh:hover {
  background: var(--accent);
  color: white !important;
}

.share-list {
  max-height: 400px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.share-loading,
.share-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.share-row {
  padding: 12px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.share-row-expired { opacity: 0.6; }

.share-row-note {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-primary);
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border-primary);
}
.share-row-note-icon {
  font-size: 0.95rem;
}
.share-row-note-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-row-url code {
  display: block;
  padding: 8px 10px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--text-primary);
  word-break: break-all;
  border: 1px solid var(--border-primary);
}

.share-row-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.share-badge {
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}
.share-badge-active {
  background: rgba(34, 197, 94, 0.15);
  color: #16a34a;
}
.share-badge-expired {
  background: rgba(239, 68, 68, 0.15);
  color: #dc2626;
}
[data-theme="dark"] .share-badge-active {
  background: rgba(34, 197, 94, 0.25);
  color: #4ade80;
}
[data-theme="dark"] .share-badge-expired {
  background: rgba(239, 68, 68, 0.25);
  color: #f87171;
}

.share-row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.share-row-actions button {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
}
.btn-share-copy {
  background: var(--accent);
  color: white !important;
  border-color: var(--accent);
}
.btn-share-copy:hover { background: var(--accent-hover); }
.btn-share-open {
  background: transparent;
  color: var(--text-primary) !important;
  border-color: var(--border-primary);
}
.btn-share-open:hover { background: var(--bg-primary); }
.btn-share-revoke {
  background: transparent;
  color: #dc2626 !important;
  border-color: rgba(239, 68, 68, 0.4);
}
.btn-share-revoke:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: #dc2626;
}

@media (max-width: 640px) {
  .share-modal-box {
    max-width: 100%;
    width: 100%;
    margin: 0;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    max-height: 90vh;
    overflow-y: auto;
  }
  .share-row-actions { width: 100%; }
  .share-row-actions button { flex: 1; }
}
