/* public/admin/styles.css
   v7 — 全局样式表
   - 移动优先,FireFox Android 验证基线
   - 状态条 / 工具栏用 position:fixed + bottom:var(--kb-over)
   - drawer / sheet 用 position:fixed + transform 滑入
   - safe-area-inset 处理刘海屏
*/

:root {
  --kb-over: 0px;
  --toolbar-h: 56px;
  --status-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #fff;
  --fg: #111;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --warn-bg: #fef3c7;
  --warn-fg: #78350f;
  --warn-border: #fbbf24;
  --success: #16a34a;
  --surface: #f9fafb;
  --surface-2: #f3f4f6;
  --code-bg: #1f2937;
  --code-fg: #d1d5db;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
               "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1;
  background: var(--bg);
  color: var(--fg);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  /* v8.24 — 简化:只 touch-action: none (只锁触屏手势,不影响桌面 wheel)
     之前还加 overflow:hidden + position:fixed 把桌面 wheel 滚动也锁了
     → Windows Firefox 上滚轮失效 */
  touch-action: none;
}

/* v8.5 — 用固定像素定位取代 flex 链 */

:root {
  --banner-h: 88px;
  --editor-header-h: 56px;
  --toolbar-h: 56px;
  --status-h: 56px;
  --kb-over: 0px;
}

.banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--banner-h);
  z-index: 5;
  background: var(--warn-bg);
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--warn-border);
  color: var(--warn-fg);
  user-select: none;
  overflow: hidden;
  touch-action: none;
}
.banner strong { font-weight: 600; }
.banner small { opacity: 0.6; }

#app {
  position: fixed;
  top: var(--banner-h); left: 0; right: 0;
  bottom: 0;
  overflow: hidden;
  touch-action: none;
}

#app-root {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  overflow: hidden;
  touch-action: none;
}

/* =============== List view ================================================= */

/* v8.26 — list-view 用 position:absolute 取代 flex 撑高
   之前 flex: 1 + min-height: 0 在某些浏览器 (特别是 Firefox) 计算高度为 0
   → 整个 list-view 没高度 → overflow-y:auto 失效 → 永远不能滚
   现在 top: var(--list-header-h) 跳过 header+search, bottom 留 96px 给 status+toolbar */
:root {
  --list-header-h: 106px;  /* list-header 56 + search 50 */
}

.list-view {
  position: absolute;
  top: var(--list-header-h);
  left: 0; right: 0;
  bottom: 96px;  /* status 56 + toolbar 40 缓冲 */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 0 24px 0;
  touch-action: pan-y;
  background: var(--bg);
}

.list-header {
  padding: 12px 16px 8px;
  display: flex; align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0;
  z-index: 5;
}
.list-header h1 {
  margin: 0; font-size: 18px; font-weight: 600;
  flex: 1;
}
.list-header .icon-btn {
  width: 36px; height: 36px;
}

.search-bar {
  padding: 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 53px;
  z-index: 4;
}
.search-bar input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
}
.search-bar input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

.list-section {
  padding: 12px 16px 4px;
}
.list-section h2 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.article-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}
.article-card:active { background: var(--surface-2); }
.article-card.dirty { border-left: 3px solid var(--warn-border); }
/* v8.40 — hidden 卡片整体灰化 + 左边暗灰条,跟 dirty 的黄色条区分 */
.article-card.hidden {
  opacity: 0.62;
  background: var(--surface-2);
  border-left: 3px solid var(--border-strong);
}
.article-card.hidden .title { color: var(--muted); text-decoration: line-through; }
.badge.hidden-badge {
  background: #e5e7eb;
  color: #374151;
  border: 1px solid #d1d5db;
}
.article-card .title {
  font-weight: 500;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}
.article-card .meta {
  font-size: 12px;
  color: var(--muted);
  display: flex; gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.article-card .meta .dot { width: 3px; height: 3px; background: var(--border-strong); border-radius: 50%; }
.article-card .badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  background: var(--surface-2);
  border-radius: 4px;
  color: var(--muted);
}
.article-card .badge.warn { background: var(--warn-bg); color: var(--warn-fg); border: 1px solid var(--warn-border); }
.article-card .badge.pinned { background: #fef3c7; color: #92400e; }

/* v8.20 — 卡片顶部:缩略图 + 标题区 */
.card-top {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.card-thumb {
  width: 56px; height: 56px;
  flex-shrink: 0;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.card-main {
  flex: 1;
  min-width: 0;
}
.card-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}
.cat-chip {
  font-size: 11px;
  padding: 1px 6px;
  background: #e0e7ff;
  color: #3730a3;
  border-radius: 8px;
}
.card-desc {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 标签 chips */
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.tag-chip {
  font-size: 11px;
  padding: 1px 6px;
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 8px;
}

/* 卡片底部操作按钮 */
.card-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  margin-top: 2px;
}
.icon-btn-sm {
  width: 32px; height: 28px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.icon-btn-sm:hover { background: var(--surface-2); }
.icon-btn-sm.active { background: var(--primary); color: #fff; }
.icon-btn-sm.danger:hover { background: #fee2e2; color: var(--danger); }

/* 页面文件卡 (v8.20) */
.page-card {
  display: flex;
  gap: 10px;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  align-items: center;
  transition: background 0.12s;
}
.page-card:active { background: var(--surface-2); }
.page-card.dirty { border-left: 3px solid var(--warn-border); }
.page-icon {
  width: 40px; height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 18px;
}
.page-info { flex: 1; min-width: 0; }
.page-info .title {
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 2px;
}
.page-info .meta {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  gap: 6px;
  align-items: center;
}

/* 列表 section 标题 (v8.20 加图标) */
.list-section h2 {
  display: flex;
  align-items: center;
  gap: 6px;
}
.section-icon { font-size: 14px; }
.pages-section h2 { color: #6d28d9; }
.published-section h2 { color: #6b7280; }

.list-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + var(--kb-over) + var(--safe-bottom));
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 28px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  cursor: pointer;
  z-index: 14;
  -webkit-tap-highlight-color: transparent;
  transition: bottom 0.12s ease;
}
.fab:active { background: var(--primary-hover); }

/* =============== Editor view ============================================== */

/* .editor-view 现在只是 React Fragment 的占位 div,无样式需求 */
.editor-header {
  position: fixed;
  top: var(--banner-h); left: 0; right: 0;
  height: var(--editor-header-h);
  z-index: 6;
  display: flex; align-items: center; gap: 4px;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  touch-action: none;
}
.editor-header .title-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 16px;
  font-weight: 500;
  padding: 4px 8px;
  outline: none;
  min-width: 0;
}
.editor-header .title-input::placeholder { color: var(--muted); }
.icon-btn {
  width: 40px; height: 40px;
  border: none; background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.primary { color: var(--primary); font-weight: 600; font-size: 14px; width: auto; padding: 0 12px; }
.icon-btn.danger { color: var(--danger); }

.editor-area {
  position: fixed;
  top: calc(var(--banner-h) + var(--editor-header-h));
  bottom: calc(var(--toolbar-h) + var(--status-h) + var(--kb-over));
  left: 0; right: 0;
  padding: 8px;
  background: var(--surface);
  overflow: hidden;
}

/* mountEditor 把 textarea 直接挂到 .editor-mount 容器里 */
.editor-mount {
  position: absolute;
  top: 8px; left: 8px; right: 8px; bottom: 8px;
  overflow: hidden;
}

/* v8 — 纯 textarea 编辑器 (替代 ByteMD/CodeMirror)
   原生 textarea 的 cursor/IME/scroll 浏览器保证可靠。
   touch-action: pan-y 让 textarea 接管垂直滚动;
   overscroll-behavior: contain 让滚到边界时不传给祖先。*/
.simple-editor {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "Consolas",
               "PingFang SC", "Noto Sans SC", monospace;
  font-size: 15px;
  line-height: 1.6;
  padding: 12px 14px;
  resize: none;
  outline: none;
  caret-color: var(--primary);
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.simple-editor:focus {
  border-color: var(--primary);
}
.simple-editor::placeholder {
  color: var(--muted);
}

/* =============== Toolbar ================================================== */

.toolbar {
  position: fixed;
  left: 0; right: 0;
  bottom: var(--kb-over);
  display: flex; gap: 2px; padding: 6px 4px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 12;
  transition: bottom 0.12s ease;
  padding-bottom: calc(6px + var(--safe-bottom));
  /* v8.39 — touch-action: none 会锁死 Firefox Android 的横向 pan,
     改成 manipulation 让浏览器原生处理 tap + 横向 pan,按钮 onClick 不受影响 */
  touch-action: manipulation;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.toolbar button {
  flex-shrink: 0;
  min-width: 44px; height: 40px; padding: 0 10px;
  border: none; background: none; border-radius: 6px;
  cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  color: var(--fg);
}
.toolbar button:active { background: var(--surface-2); }
.toolbar .divider { width: 1px; background: var(--border); margin: 8px 4px; flex-shrink: 0; }
.toolbar .meta-btn { font-size: 13px; font-weight: 500; color: var(--primary); }

/* =============== Status bar =============================================== */

.status {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--toolbar-h) + var(--kb-over));
  background: var(--code-bg); color: var(--code-fg);
  font-size: 11px; padding: 6px 12px;
  font-family: ui-monospace, monospace;
  border-top: 1px solid #374151;
  white-space: pre-wrap;
  max-height: 80px;
  overflow-y: auto;
  z-index: 11;
  touch-action: none;
  transition: bottom 0.12s ease;
}
.status .ok { color: #86efac; }
.status .err { color: #fca5a5; }
.status .warn { color: #fcd34d; }

/* =============== Drawer / Sheet (bottom) ================================== */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  z-index: 21;
  transform: translateY(100%);
  transition: transform 0.22s ease;
  max-height: 90vh;
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
}
.drawer.open { transform: translateY(0); }
.drawer-handle {
  width: 40px; height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 8px auto;
  flex-shrink: 0;
}
.drawer-header {
  padding: 0 16px 8px;
  display: flex; align-items: center;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-header h2 { margin: 0; font-size: 16px; font-weight: 600; flex: 1; }
.drawer-body {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  -webkit-overflow-scrolling: touch;
}
.drawer-footer {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px;
  flex-shrink: 0;
}

/* =============== Form fields ============================================== */

.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 4px;
}
.field input[type="text"],
.field input[type="url"],
.field input[type="datetime-local"],
.field textarea,
.field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: 2px solid var(--primary);
  border-color: var(--primary);
}
.field textarea { min-height: 60px; resize: vertical; }

.field-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0;
}
.field-row label { margin: 0; flex: 1; }
.field-row .toggle {
  position: relative;
  width: 44px; height: 24px;
  background: var(--border-strong);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.field-row .toggle.on { background: var(--primary); }
.field-row .toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.field-row .toggle.on::after { transform: translateX(20px); }

.chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  min-height: 36px;
}
.chips .item {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  background: var(--surface-2);
  border-radius: 12px;
  font-size: 13px;
}
.chips .item button {
  border: none; background: transparent;
  color: var(--muted); cursor: pointer;
  padding: 0; margin-left: 2px;
  font-size: 16px; line-height: 1;
}
.chips input {
  border: none; outline: none; flex: 1;
  min-width: 80px;
  font-size: 14px;
  background: transparent;
}

/* =============== Buttons ================================================== */

.btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex: 1;
}
.btn:active { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:active { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); }

/* =============== Toast ==================================================== */

.toast {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%) translateY(-200%);
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  font-size: 13px;
  z-index: 30;
  max-width: calc(100% - 32px);
  transition: transform 0.22s ease;
}
.toast.open { transform: translateX(-50%) translateY(0); }
.toast.success { background: #16a34a; }
.toast.error { background: var(--danger); }

/* =============== Loading splash ========================================== */

.splash {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 100;
  flex-direction: column;
  gap: 12px;
}
.splash.hide { display: none; }
.splash .spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.splash .msg { color: var(--muted); font-size: 13px; max-width: 80%; text-align: center; }

/* =============== Preview sheet ============================================= */

.drawer-preview { max-height: 92vh; }

.preview-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px 24px;
}

.preview-loading,
.preview-error {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
  font-size: 13px;
}
.preview-error { color: var(--danger); }

.preview-frontmatter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}
.pv-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--fg);
}
.pv-date {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.pv-desc {
  font-size: 13px;
  color: var(--fg);
  margin: 6px 0;
  line-height: 1.5;
}
.pv-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.pv-tag {
  background: var(--surface-2);
  color: var(--fg);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 12px;
}

/* markdown 渲染 (内联样式避开 external CSS) */
.markdown-body {
  font-size: 15px;
  line-height: 1.7;
  color: var(--fg);
  word-wrap: break-word;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-weight: 600;
  margin: 1.4em 0 0.5em;
  line-height: 1.3;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.2em;
}
.markdown-body h1 { font-size: 1.6em; border-bottom-width: 2px; }
.markdown-body h2 { font-size: 1.35em; }
.markdown-body h3 { font-size: 1.15em; border-bottom: none; }
.markdown-body h4 { font-size: 1em; border-bottom: none; }
.markdown-body p { margin: 0.6em 0; }
.markdown-body a { color: var(--primary); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body strong { font-weight: 600; }
.markdown-body em { font-style: italic; }
.markdown-body code {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.88em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.markdown-body pre {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 12px 14px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
  margin: 0.8em 0;
}
.markdown-body pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}
.markdown-body blockquote {
  border-left: 3px solid var(--border-strong);
  margin: 0.8em 0;
  padding: 0.2em 0 0.2em 1em;
  color: var(--muted);
  background: var(--surface);
  border-radius: 0 4px 4px 0;
}
.markdown-body ul,
.markdown-body ol {
  margin: 0.6em 0;
  padding-left: 1.6em;
}
.markdown-body li { margin: 0.2em 0; }
.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}
.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.5em 0;
}
.markdown-body table {
  border-collapse: collapse;
  margin: 0.8em 0;
  width: 100%;
  font-size: 14px;
}
.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.markdown-body th { background: var(--surface); font-weight: 600; }