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

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --bg: #f8fafc;
  --bg-white: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --sidebar-width: 260px;
  --header-height: 56px;
  --transition: 0.2s ease;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Auth Pages (Login/Register) === */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.auth-card {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  text-align: center;
}

.auth-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 14px;
}

.form-group { margin-bottom: 20px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: var(--text);
  font-size: 13px;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  transition: border-color var(--transition);
  outline: none;
}

.form-group input:focus {
  border-color: var(--primary);
  background: var(--bg-white);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 13px;
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--border-light); color: var(--text); }

.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 13px;
}
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

.auth-link {
  text-align: center;
  margin-top: 20px;
  color: var(--text-secondary);
  font-size: 13px;
}

/* === App Layout === */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
}

.sidebar-header .logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-header .logo svg {
  width: 24px;
  height: 24px;
}

/* Sidebar collapse toggle button */
.sidebar-collapse-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: #94a3b8;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.sidebar-collapse-btn:hover { background: #f1f5f9; color: #475569; }

/* === Collapsed Sidebar (desktop) === */
.app-layout.sidebar-collapsed .sidebar {
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-right: none;
  transition: width 0.25s ease, min-width 0.25s ease;
}
.app-layout:not(.sidebar-collapsed) .sidebar {
  transition: width 0.25s ease, min-width 0.25s ease;
}

/* Expand strip on left edge when collapsed */
.sidebar-expand-strip {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  z-index: 50;
  cursor: pointer;
  transition: width 0.15s, background 0.15s;
}
.sidebar-expand-strip:hover {
  width: 8px;
  background: #e2e8f0;
}
.app-layout.sidebar-collapsed .sidebar-expand-strip {
  display: block;
}

/* Mobile: never collapse sidebar via desktop toggle */
@media (max-width: 768px) {
  .sidebar-collapse-btn { display: none; }
  .sidebar-expand-strip { display: none !important; }
  .app-layout.sidebar-collapsed .sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    overflow: visible;
  }
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.nav-section { margin-bottom: 8px; }
.nav-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 8px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  transition: all var(--transition);
  position: relative;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--border-light);
  text-decoration: none;
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}

.nav-item .count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--border-light);
  padding: 1px 6px;
  border-radius: 10px;
}

.nav-item.active .count {
  background: var(--primary);
  color: white;
}

.nav-item .folder-icon { font-size: 15px; }

.sidebar-doc-list {
  max-height: 50vh;
  overflow-y: auto;
  margin-left: 4px;
}

.nav-doc-item {
  font-size: 12px !important;
  padding: 5px 12px !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item .delete-folder {
  opacity: 0;
  margin-left: 4px;
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all var(--transition);
}
.nav-item:hover .delete-folder { opacity: 1; }
.nav-item .delete-folder:hover { background: #fef2f2; }

/* 文件夹拖拽排序 */
.nav-item.drag-handle {
  cursor: grab;
}
.nav-item.dragging {
  opacity: 0.4;
  cursor: grabbing;
}
.nav-item.drag-over {
  border-top: 2px solid var(--primary);
  margin-top: -2px;
}
.nav-item .drag-indicator {
  opacity: 0;
  font-size: 12px;
  color: var(--text-muted);
  transition: opacity var(--transition);
  flex-shrink: 0;
}
.nav-item:hover .drag-indicator { opacity: 0.5; }
#folderList.sorting .nav-item { cursor: grabbing; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === Main Content === */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.main-header {
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.main-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-box {
  position: relative;
  min-width: 240px;
}

.search-box input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bg);
  outline: none;
  transition: border-color var(--transition);
  -webkit-appearance: textfield;
  appearance: textfield;
}

.search-box input::-webkit-search-decoration,
.search-box input::-webkit-search-cancel-button,
.search-box input::-webkit-search-results-button,
.search-box input::-webkit-search-results-decoration {
  -webkit-appearance: none;
}

.search-box input:focus {
  border-color: var(--primary);
  background: var(--bg-white);
}

.search-box .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
}

.main-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* === Doc List === */
.doc-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.doc-list-header .breadcrumb {
  font-size: 13px;
  color: var(--text-secondary);
}

.doc-table {
  width: 100%;
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.doc-table table {
  width: 100%;
  border-collapse: collapse;
}

.doc-table th {
  text-align: left;
  padding: 12px 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--border-light);
  border-bottom: 1px solid var(--border);
}

.doc-table td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
  vertical-align: middle;
}

.doc-table tr:last-child td { border-bottom: none; }
.doc-table tr:hover td { background: var(--border-light); }

.doc-title {
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.doc-title a { color: var(--text); text-decoration: none; }
.doc-title a:hover { color: var(--primary); }

.doc-title .doc-icon {
  width: 28px;
  height: 28px;
  background: var(--primary-light);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.doc-folder { color: var(--text-muted); font-size: 12px; }
.doc-time { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.doc-actions { text-align: right; white-space: nowrap; }

.doc-actions .btn-icon {
  opacity: 0.6;
  font-size: 12px;
}

.doc-table tr:hover .doc-actions .btn-icon { opacity: 1; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 16px; font-weight: 500; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 13px; margin-bottom: 20px; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

.pagination .btn-sm { min-width: 36px; }

/* === Editor Page === */
.editor-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
}

.editor-toolbar .doc-title-input {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
  border: none;
  outline: none;
  color: var(--text);
  background: transparent;
  padding: 4px 0;
}

.editor-toolbar .doc-title-input::placeholder { color: var(--text-muted); }

.editor-toolbar select {
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bg-white);
  color: var(--text);
  outline: none;
  cursor: pointer;
}

.editor-container {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.editor-pane:first-child { border-right: 1px solid var(--border); }

.pane-header {
  padding: 10px 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--border-light);
  border-bottom: 1px solid var(--border);
}

.editor-pane textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 20px;
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg-white);
}

.preview-pane {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg-white);
}

/* === Markdown Preview Styles === */
.markdown-body {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text);
  max-width: 860px;
}

.markdown-body h1 { font-size: 28px; font-weight: 700; margin: 24px 0 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.markdown-body h2 { font-size: 22px; font-weight: 600; margin: 24px 0 12px; }
.markdown-body h3 { font-size: 18px; font-weight: 600; margin: 20px 0 10px; }
.markdown-body h4 { font-size: 16px; font-weight: 600; margin: 16px 0 8px; }
.markdown-body p { margin-bottom: 12px; }
.markdown-body ul, .markdown-body ol { padding-left: 24px; margin-bottom: 12px; }
.markdown-body li { margin-bottom: 4px; }
.markdown-body code {
  background: var(--border-light);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
  font-size: 13px;
  color: #e11d48;
}
.markdown-body pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 16px 20px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin-bottom: 16px;
}
.markdown-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 13px;
}
.markdown-body blockquote {
  border-left: 4px solid var(--primary);
  padding: 8px 16px;
  margin: 12px 0;
  background: var(--primary-light);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
}
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}
.markdown-body th, .markdown-body td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}
.markdown-body th { background: var(--border-light); font-weight: 600; }
.markdown-body img { max-width: 100%; border-radius: var(--radius); }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.markdown-body a { color: var(--primary); }

/* === Viewer Page === */
.viewer-layout {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.viewer-content {
  max-width: 900px;
  margin: 0 auto;
}

.viewer-header {
  margin-bottom: 32px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.viewer-header h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.viewer-meta {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.viewer-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* === Doc TOC (vertical list with hierarchy indent) === */
.doc-toc {
  padding: 16px 20px;
  margin-bottom: 24px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.toc-heading {
  font-size: 13px;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 10px;
}
.toc-link {
  display: block;
  padding: 3px 0 3px 0;
  font-size: 13px;
  color: #64748b;
  text-decoration: none;
  border-radius: 4px;
  line-height: 1.6;
  transition: color 0.15s;
}
.toc-link:hover { color: var(--primary); }
.toc-link.active { color: var(--primary); font-weight: 500; }
.toc-link.toc-lv1 { font-weight: 600; padding-left: 0; }
.toc-link.toc-lv2 { padding-left: 18px; font-size: 12px; }
.toc-link.toc-lv3 { padding-left: 36px; font-size: 12px; color: #94a3b8; }

/* === Doc Pager (prev/next) === */
.doc-pager {
  display: flex;
  gap: 16px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.doc-pager-item {
  flex: 1;
  min-width: 0;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.doc-pager-item:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}
.doc-pager-item.disabled {
  opacity: 0.4;
  pointer-events: none;
}
.doc-pager-label {
  display: block;
  font-size: 11px;
  color: #94a3b8;
  margin-bottom: 4px;
}
.doc-pager-title {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-pager-next {
  text-align: right;
}

/* === Toast / Notification === */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease;
  max-width: 360px;
}

.toast-success { background: #166534; color: white; }
.toast-error { background: #991b1b; color: white; }
.toast-info { background: var(--primary); color: white; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.modal h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal .form-group { margin-bottom: 16px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* === Modal Header / Body / Footer === */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h3 { margin-bottom: 0; }

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 20px;
  color: #94a3b8;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.modal-close:hover {
  background: #f1f5f9;
  color: #475569;
}

.modal-body { margin-bottom: 4px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* === Confirm Delete Modal (dynamic, reusable) === */
.confirm-overlay {
  opacity: 0;
  transition: opacity 0.2s ease;
}
.confirm-overlay.show { opacity: 1; }

.confirm-modal {
  max-width: 400px;
  padding: 28px 24px 20px;
  text-align: center;
  transform: scale(0.92) translateY(8px);
  opacity: 0;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}
.confirm-overlay.show .confirm-modal {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.confirm-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 26px;
}
.confirm-icon-danger {
  background: #fef2f2;
  color: var(--danger);
}
.confirm-icon-warning {
  background: #fffbeb;
  color: #f59e0b;
}
.confirm-icon-info {
  background: var(--primary-light);
  color: var(--primary);
}

.confirm-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.confirm-message {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 4px;
}

.confirm-actions {
  justify-content: center;
  margin-top: 24px;
  gap: 12px;
}
.confirm-actions .btn { min-width: 96px; }

/* === Loading === */
.loading { text-align: center; padding: 40px; color: var(--text-muted); }
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === Mobile: Hamburger Button === */
.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text);
  padding: 4px 8px;
  border-radius: 6px;
  transition: background var(--transition);
  flex-shrink: 0;
  line-height: 1;
}
.mobile-menu-btn:hover { background: var(--border-light); }

/* === Sidebar Overlay (mobile) === */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sidebar-overlay.show {
  display: block;
  opacity: 1;
}

/* === Responsive === */
@media (max-width: 768px) {
  /* === Sidebar → Drawer === */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 16px rgba(0,0,0,0.12);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* === Show hamburger button === */
  .mobile-menu-btn { display: inline-flex; align-items: center; justify-content: center; }

  /* === Main Header === */
  .main-header {
    padding: 0 12px;
    gap: 8px;
    height: auto;
    min-height: var(--header-height);
    flex-wrap: wrap;
  }
  .main-header h2 {
    font-size: 15px;
  }

  /* === Header Actions === */
  .header-actions {
    gap: 6px;
    flex-wrap: wrap;
    width: 100%;
    justify-content: flex-end;
  }
  .header-actions .btn-sm {
    padding: 6px 10px;
    font-size: 12px;
  }
  .search-box {
    min-width: 0;
    flex: 1 1 100%;
    max-width: 100%;
    order: 3;
    margin-top: 6px;
  }
  .search-box input {
    font-size: 16px; /* prevent iOS zoom on focus */
  }

  /* === Main Body === */
  .main-body {
    padding: 12px;
  }

  /* === Doc Table → Card-like === */
  .doc-table {
    border-radius: var(--radius);
  }
  .doc-table th:nth-child(2),
  .doc-table td:nth-child(2) {
    display: none; /* hide folder column */
  }
  .doc-table th, .doc-table td {
    padding: 10px 12px;
  }
  .doc-table th:last-child,
  .doc-table td:last-child {
    padding-right: 12px;
  }

  /* === Auth Pages === */
  .auth-card {
    padding: 28px 20px;
    max-width: 100%;
    margin: 0 12px;
  }

  /* === Editor === */
  .editor-toolbar {
    padding: 10px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .editor-toolbar .doc-title-input {
    font-size: 16px;
    min-width: 0;
    flex: 1 1 100%;
    order: 2;
  }
  .editor-toolbar .btn-sm,
  .editor-toolbar select {
    font-size: 12px;
  }
  .editor-toolbar select {
    padding: 6px 8px;
  }
  .editor-container {
    flex-direction: column;
  }
  .editor-pane:first-child {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .editor-pane {
    min-height: 200px;
  }
  .editor-pane:first-child {
    height: 45%;
  }
  .editor-pane:last-child {
    height: 55%;
  }
  .editor-pane textarea {
    font-size: 16px; /* prevent iOS zoom */
    padding: 14px;
  }
  .pane-header {
    padding: 8px 14px;
    font-size: 11px;
  }

  /* === Viewer === */
  .viewer-layout {
    padding: 16px;
  }
  .viewer-header h1 {
    font-size: 22px;
  }
  .viewer-meta {
    flex-wrap: wrap;
    gap: 8px 12px;
    font-size: 12px;
  }
  .viewer-actions {
    flex-wrap: wrap;
    gap: 6px;
  }
  /* Doc pager mobile */
  .doc-pager { flex-direction: column; }
  .doc-pager-item { padding: 12px 16px; }
  .doc-pager-next { text-align: left; }

  /* === Markdown Body === */
  .markdown-body {
    font-size: 14px;
  }
  .markdown-body h1 { font-size: 22px; }
  .markdown-body h2 { font-size: 19px; }
  .markdown-body h3 { font-size: 16px; }
  .markdown-body pre {
    padding: 12px;
    font-size: 12px;
    -webkit-overflow-scrolling: touch;
  }

  /* === Modal === */
  .modal-overlay {
    padding: 16px;
    align-items: flex-end;
  }
  .modal {
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .modal[style*="width:540px"],
  .modal[style*="width: 540px"] {
    width: 100% !important;
  }

  /* === Confirm Modal === */
  .confirm-modal {
    max-width: 100%;
  }
  .confirm-overlay {
    padding: 16px;
    align-items: flex-end;
  }

  /* === Toast === */
  .toast {
    top: 12px;
    right: 12px;
    left: 12px;
    max-width: none;
    font-size: 12px;
    padding: 10px 14px;
  }

  /* === Upload Area === */
  .upload-area {
    padding: 24px 12px;
  }

  /* === Footer === */
  .app-footer {
    padding: 10px 12px 16px;
    font-size: 11px;
  }

  /* === Admin Page === */
  .admin-content {
    padding: 12px;
  }
  .admin-content h2 {
    font-size: 16px;
    margin-bottom: 12px;
  }
  .admin-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .admin-tab {
    padding: 8px 14px !important;
    font-size: 13px !important;
    white-space: nowrap;
  }
  .admin-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .admin-table table {
    min-width: 600px;
  }
}

/* === Small phones (≤420px) === */
@media (max-width: 420px) {
  .main-header h2 {
    font-size: 14px;
  }
  .header-actions {
    gap: 4px;
  }
  .header-actions .btn-sm {
    padding: 5px 8px;
    font-size: 11px;
  }
  .search-box {
    max-width: 100%;
  }
  .doc-table th, .doc-table td {
    padding: 8px 10px;
    font-size: 12px;
  }
  .doc-title .doc-icon {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }
  .viewer-header h1 {
    font-size: 19px;
  }
  .sidebar-header .logo {
    font-size: 15px;
  }
}

/* === Upload area === */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 16px;
}

.upload-area:hover, .upload-area.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-area .upload-icon { font-size: 36px; margin-bottom: 12px; }
.upload-area p { color: var(--text-secondary); font-size: 13px; }
.upload-area .hint { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.upload-result { margin-top: 16px; }

/* === Footer === */
.app-footer {
  text-align: center;
  padding: 12px 24px 24px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: auto;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
