/* ═══════════════════════════════════════════
   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;
}

/* ═══════════════════════════════════════════
   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; 
}

/* ═══════════════════════════════════════════
   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;
}

.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 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: var(--text-inverse); 
  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; position: relative; }
  .app-bar .left { padding-right: 100px; }
  .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 10px; font-size: 0.76rem; }

  /* 移动端：用户芯片上移到顶栏第一行右侧 */
  .app-bar .actions .user-chip {
    position: absolute;
    top: 10px;
    right: 14px;
    margin: 0;
    z-index: 10;
  }
  
  #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-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 { 
    height: calc(50vh - 40px); 
    min-height: 280px; 
  }
  
  .preview-pane { 
    height: calc(50vh - 40px); 
    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 .tooltip {
    display: none !important;
  }
}

@media (max-width: 480px) {
  .app-bar .actions .btn span { display: none; }
  .editor-pane { min-height: 220px; }
  .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);
}

/* ═══════════════════════════════════════════
   登录 / 注册 网关页
   ═══════════════════════════════════════════ */
#gatePage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-header);
  min-height: 100vh;
}
.gate-box { width: 90%; max-width: 380px; }
.gate-sub { color: var(--text-tertiary); font-size: 0.85rem; margin-bottom: 20px; }
.gate-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.gate-tab {
  flex: 1; padding: 10px; border: 1px solid var(--border-primary);
  background: transparent; color: var(--text-secondary);
  border-radius: var(--radius-md); cursor: pointer; font-size: 0.9rem;
}
.gate-tab.active { background: var(--accent-gradient); color: var(--text-inverse); border-color: transparent; }
.gate-form input {
  width: 100%; padding: 14px 16px; margin-bottom: 12px;
  border: 2px solid var(--border-primary); border-radius: var(--radius-md);
  background: var(--bg-input); color: var(--text-primary);
  box-sizing: border-box; outline: none; font-size: 1rem;
}
.gate-form input:focus { border-color: var(--accent); }
/* 验证码行：输入框 + 获取验证码按钮同行 */
.gate-code-row {
  display: flex; gap: 10px; margin-bottom: 12px; align-items: stretch;
  /* 避免整行被父级 input 100% 宽度影响 */
  width: 100%; box-sizing: border-box;
}
.gate-code-row input {
  flex: 1 1 auto; min-width: 0; width: auto; margin-bottom: 0;
}
.auth-box .gate-code-btn {
  flex: 0 0 auto; width: auto; min-width: 96px; white-space: nowrap;
  padding: 0 12px; border: 2px solid var(--border-primary);
  border-radius: var(--radius-md); background: var(--bg-input);
  color: var(--accent); font-size: 0.8rem; cursor: pointer;
  box-shadow: none; margin: 0; transition: all var(--transition-fast);
  display: flex; align-items: center; justify-content: center;
}
.auth-box .gate-code-btn:hover:not(:disabled) { border-color: var(--accent); }
.auth-box .gate-code-btn:disabled { color: var(--text-tertiary); cursor: not-allowed; opacity: 0.7; }
.gate-submit {
  width: 100%; padding: 14px; 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);
}
.gate-submit:hover { transform: translateY(-1px); }
.gate-error { color: #f85149; font-size: 0.82rem; min-height: 1.2em; margin-top: 6px; text-align: center; }
.gate-links {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; margin-top: 14px; flex-wrap: nowrap;
}
.auth-box .gate-link {
  width: auto; margin-top: 0; padding: 0; border: none; border-radius: 0;
  background: transparent; color: var(--text-link); box-shadow: none;
  font-size: 0.85rem; font-weight: 400; line-height: 1.2;
  text-decoration: underline; text-underline-offset: 2px;
  transition: color var(--transition-fast);
  flex: 0 0 auto;
}
.auth-box .gate-link:hover {
  transform: none; box-shadow: none; color: var(--accent-hover);
}
.gate-divider { color: var(--text-tertiary); font-size: 0.85rem; user-select: none; }
.gate-tip {
  color: var(--text-tertiary); font-size: 0.82rem; margin-bottom: 10px;
  text-align: center; line-height: 1.4;
}

/* ═══════════════════════════════════════════
   顶栏用户芯片
   ═══════════════════════════════════════════ */
.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--bg-input); border: 1px solid var(--border-primary);
  cursor: pointer; max-width: 160px;
}
.uc-avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-light); display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; flex-shrink: 0; overflow: hidden;
}
.uc-avatar img { width: 100%; height: 100%; object-fit: cover; }
.uc-name {
  font-size: 0.82rem; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ═══════════════════════════════════════════
   个人中心弹窗
   ═══════════════════════════════════════════ */
.profile-box { max-width: 520px; padding: 0; overflow: hidden; }
.profile-head {
  display: flex; align-items: center; gap: 14px;
  padding: 22px 24px; border-bottom: 1px solid var(--border-secondary);
  position: relative;
}
.profile-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent-light); display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; flex-shrink: 0; overflow: hidden;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-id { flex: 1; min-width: 0; }
.profile-name { font-size: 1.05rem; font-weight: 600; color: var(--text-primary); }
.profile-uname { font-size: 0.8rem; color: var(--text-tertiary); }
.profile-close {
  position: absolute; top: 14px; right: 16px; border: none; background: transparent;
  font-size: 1.1rem; color: var(--text-tertiary); cursor: pointer;
}
.profile-tabs { display: flex; border-bottom: 1px solid var(--border-secondary); padding: 0 8px; overflow-x: auto; }
.profile-tab {
  flex: 1; padding: 12px 6px; border: none; background: transparent;
  color: var(--text-secondary); cursor: pointer; font-size: 0.85rem;
  white-space: nowrap; border-bottom: 2px solid transparent;
}
.profile-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.profile-body { padding: 22px 24px; max-height: 60vh; overflow-y: auto; }
.profile-pane { display: none; }
.profile-pane.active { display: block; }
.profile-pane label { display: block; font-size: 0.8rem; color: var(--text-secondary); margin: 14px 0 6px; }
.profile-pane input {
  width: 100%; padding: 11px 14px; border: 2px solid var(--border-primary);
  border-radius: var(--radius-md); background: var(--bg-input); color: var(--text-primary);
  box-sizing: border-box; outline: none; font-size: 0.95rem;
}
.profile-pane input:focus { border-color: var(--accent); }
.profile-pane .btn { margin-top: 16px; }
.pf-msg { font-size: 0.82rem; margin-top: 10px; min-height: 1em; }
.pf-tip { font-size: 0.85rem; color: var(--text-tertiary); line-height: 1.6; }
.pf-tip.warn { color: #f0883e; }
.pf-avatar-row { display: flex; align-items: center; gap: 12px; margin: 6px 0 16px; }
.pf-avatar-preview {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent-light); display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; overflow: hidden; border: 2px solid var(--border-secondary);
}
.pf-avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.pf-avatar-row .btn { margin-top: 0; }
.profile-stats { list-style: none; padding: 0; margin: 0; }
.profile-stats li {
  display: flex; justify-content: space-between; padding: 12px 4px;
  border-bottom: 1px solid var(--border-secondary); font-size: 0.9rem;
}
.profile-stats li span { color: var(--text-secondary); }
.profile-stats li b { color: var(--text-primary); font-weight: 600; }
.danger-block { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--border-primary); }
.pf-hr { border: none; border-top: 1px solid var(--border-secondary); margin: 20px 0; }
.btn-danger { background: linear-gradient(135deg, #f85149, #da3633); color: #fff; }
.btn-danger:hover { transform: translateY(-1px); }

.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;
}
