/* ============ 基础与主题变量 ============ */
:root {
  --bg: #f4f6fb;
  --bg-soft: #eef1f8;
  --card: #ffffff;
  --card-2: #f8fafc;
  --text: #1e293b;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --border: #e5eaf2;
  --primary: #4f46e5;
  --primary-2: #4338ca;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --shadow: 0 6px 24px rgba(15, 23, 42, .08);
  --radius: 14px;
  --sidebar-w: 230px;
}
[data-theme="dark"] {
  --bg: #0f172a;
  --bg-soft: #172033;
  --card: #1e293b;
  --card-2: #243247;
  --text: #e2e8f0;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --border: #2d3a52;
  --primary: #6366f1;
  --primary-2: #4f46e5;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; }
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; }
input[type="date"], input[type="month"] { color-scheme: light; }
[data-theme="dark"] input[type="date"], [data-theme="dark"] input[type="month"] { color-scheme: dark; }

/* ============ 通用按钮 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 8px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: background .15s, opacity .15s, transform .05s;
  background: var(--card); color: var(--text);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .88; }
.btn-ghost { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-ghost:hover { background: var(--bg-soft); color: var(--text); }
.btn-outline { border-color: var(--border); background: var(--card); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  background: none; border: none; cursor: pointer; font-size: 17px;
  padding: 6px 8px; border-radius: 8px; color: var(--text-2);
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
a.icon-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; vertical-align: middle; }

/* ============ 登录页 ============ */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #9333ea 100%);
  padding: 20px;
}
.login-card {
  background: #fff; color: #1e293b; border-radius: 20px; padding: 40px 36px;
  width: 100%; max-width: 380px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-logo { font-size: 52px; }
.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.login-sub { color: #64748b; margin: 0 0 24px; font-size: 13px; }
.login-card input { width: 100%; margin-bottom: 12px; text-align: center; }
.login-err { color: #dc2626; font-size: 13px; min-height: 20px; margin-top: 8px; }

/* ============ 布局 ============ */
#app-view { display: flex; min-height: 100vh; }
#app-view[hidden], .mobile-topbar[hidden] { display: none; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--card);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 700; font-size: 16px;
}
.brand-icon { font-size: 24px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--text-2); font-size: 14px; margin-bottom: 2px;
}
.sidebar-nav a:hover { background: var(--bg-soft); color: var(--text); }
.sidebar-nav a.active { background: var(--primary); color: #fff; }
.nav-ico { font-size: 17px; width: 22px; text-align: center; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.main { flex: 1; padding: 24px; min-width: 0; max-width: 1200px; margin: 0 auto; width: 100%; }
.mobile-topbar { display: none; }

/* ============ 卡片 / 面板 ============ */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.view-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.view-header h2 { margin: 0; font-size: 20px; }
.view-header .spacer { flex: 1; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input[type="text"], .toolbar input[type="search"] { min-width: 180px; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.empty {
  text-align: center; color: var(--text-3); padding: 60px 20px;
}
.empty .big { font-size: 44px; margin-bottom: 8px; }

/* ============ 文件视图 ============ */
.breadcrumb { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 14px; margin-bottom: 12px; }
.breadcrumb a { color: var(--text-2); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { color: var(--text-3); }
.breadcrumb .current { font-weight: 600; }

.folder-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px;
}
.folder-card {
  display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px;
  background: var(--card-2); border: 1px solid var(--border); cursor: pointer;
}
.folder-card:hover { border-color: var(--primary); }
.folder-card .fi { font-size: 22px; }
.folder-card .fn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.folder-card .fd { font-size: 12px; color: var(--text-3); }

.file-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px;
}
.file-card {
  position: relative; background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; cursor: pointer; transition: box-shadow .15s, border-color .15s;
}
.file-card:hover { box-shadow: var(--shadow); border-color: var(--primary); }
.file-card.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); }
.file-thumb {
  height: 110px; display: flex; align-items: center; justify-content: center;
  background: var(--card-2); font-size: 42px; position: relative;
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-card .file-check {
  position: absolute; top: 8px; left: 8px; width: 18px; height: 18px; accent-color: var(--primary);
  z-index: 2; cursor: pointer;
}
.file-card .star {
  position: absolute; top: 6px; right: 8px; z-index: 2; font-size: 17px;
  background: rgba(255,255,255,.85); border-radius: 8px; padding: 2px 5px; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.file-card .star.on { color: #f59e0b; }
.file-info { padding: 8px 10px 10px; }
.file-info .fname {
  font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.35;
}
.file-info .fmeta { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.file-actions {
  display: none; position: absolute; right: 8px; bottom: 8px; gap: 4px; z-index: 2;
}
.file-card:hover .file-actions { display: flex; }
.file-actions .icon-btn {
  background: rgba(255,255,255,.9); border-radius: 8px; font-size: 15px; padding: 4px 7px;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}

.batch-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 40;
  background: var(--text); color: #fff; border-radius: 14px; padding: 10px 16px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.batch-bar .count { font-weight: 600; margin-right: 4px; }
.batch-bar .btn { background: rgba(255,255,255,.15); color: #fff; }
.batch-bar .btn:hover { background: rgba(255,255,255,.28); }
.batch-bar .btn-danger { background: rgba(220,38,38,.85); }

/* ============ 列表视图（笔记/书签/记账/RSS/日志/回收站） ============ */
.list-table { width: 100%; border-collapse: collapse; }
.list-table th {
  text-align: left; font-size: 12px; color: var(--text-3); font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.list-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.list-table tr:hover td { background: var(--card-2); }
.list-table .row-check { width: 32px; accent-color: var(--primary); }

.chip {
  display: inline-block; background: var(--bg-soft); color: var(--text-2);
  border-radius: 999px; padding: 2px 10px; font-size: 12px; margin: 2px 2px 2px 0;
}
.chip.primary { background: rgba(79,70,229,.12); color: var(--primary); }
.tag-input-wrap { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ============ 统计 ============ */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
}
.stat-card .num { font-size: 24px; font-weight: 700; margin-top: 2px; }
.stat-card .lbl { color: var(--text-2); font-size: 12px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding: 10px 4px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar { width: 70%; max-width: 34px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-col .bdate { font-size: 10px; color: var(--text-3); }

/* ============ 笔记编辑器 ============ */
.note-editor { display: flex; flex-direction: column; gap: 12px; }
.note-title-input {
  font-size: 20px; font-weight: 700; border: none; background: transparent;
  border-bottom: 2px solid var(--border); border-radius: 0; padding: 8px 2px;
}
.note-title-input:focus { border-bottom-color: var(--primary); }
.note-body-area {
  min-height: 55vh; line-height: 1.75; font-size: 15px; padding: 16px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--card);
}
.note-body-area:focus { border-color: var(--primary); }
.note-meta-row { display: flex; gap: 10px; flex-wrap: wrap; }
.backlinks-panel { background: var(--card-2); border-radius: 10px; padding: 12px; }
.backlinks-panel h4 { margin: 0 0 8px; font-size: 13px; color: var(--text-2); }

/* ============ RSS ============ */
.feed-item {
  display: flex; gap: 12px; padding: 14px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.feed-item:hover { background: var(--card-2); }
.feed-item.unread .fi-title { font-weight: 700; }
.feed-item .fi-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-item .fi-meta { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.feed-item .fi-star { font-size: 16px; color: var(--text-3); cursor: pointer; }
.feed-item .fi-star.on { color: #f59e0b; }
.feed-summary { font-size: 13px; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 3px; }

/* ============ 弹窗 ============ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn .15s;
}
.modal {
  background: var(--card); border-radius: 16px; width: 100%; max-width: 560px;
  max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 80px rgba(0,0,0,.35); animation: popIn .15s;
}
.modal.wide { max-width: 900px; }
.modal-header {
  display: flex; align-items: center; gap: 10px; padding: 16px 20px;
  border-bottom: 1px solid var(--border); font-size: 16px; font-weight: 600;
}
.modal-header .spacer { flex: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.modal .form-row { margin-bottom: 14px; }
.modal label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 5px; }
.modal input[type="text"], .modal input[type="password"], .modal input[type="number"], .modal input[type="date"], .modal input[type="month"], .modal select, .modal textarea { width: 100%; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* 预览 */
.preview-frame { width: 100%; height: 60vh; border: none; background: var(--card); border-radius: 10px; }
.preview-img { max-width: 100%; max-height: 65vh; margin: 0 auto; display: block; border-radius: 10px; }
.preview-video { width: 100%; max-height: 60vh; }
.preview-text {
  width: 100%; min-height: 50vh; font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px; line-height: 1.6; background: var(--card-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; white-space: pre-wrap; word-break: break-word;
}

/* ============ Toast ============ */
#toast-root { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: slideIn .2s; max-width: 320px;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ============ 拖拽上传 ============ */
#drop-overlay {
  position: fixed; inset: 0; z-index: 150; background: rgba(79,70,229,.15);
  border: 3px dashed var(--primary); display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: var(--primary); pointer-events: none;
}

#drop-overlay[hidden] { display: none; }


/* ============ 加载 / 动画 ============ */
.view-loading { text-align: center; color: var(--text-3); padding: 60px 0; }
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: rot .8s linear infinite; vertical-align: -3px; }
@keyframes rot { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { transform: scale(.96); opacity: 0; } }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } }

/* ============ 移动端 ============ */
@media (max-width: 820px) {
  .sidebar { display: none; position: fixed; z-index: 90; width: 240px; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .sidebar.open { display: flex; }
  .mobile-topbar {
    display: flex; align-items: center; gap: 8px; padding: 10px 14px;
    background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50;
  }
  .mobile-title { flex: 1; font-weight: 700; }
  #app-view { flex-direction: column; }
  .main { padding: 14px; }
  #drop-overlay { font-size: 16px; }
}

/* ============ PDF 在线预览 ============ */
.pdf-toolbar {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  flex-wrap: nowrap; margin-bottom: 10px; padding: 6px 10px;
  background: var(--card-2, #f5f6f8); border: 1px solid var(--border); border-radius: 10px;
}
.pdf-toolbar .icon-btn { min-width: 34px; height: 32px; padding: 0 8px; font-size: 15px; }
.pdf-toolbar .icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.pdf-pageinfo { font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 52px; text-align: center; font-size: 14px; }
.pdf-zoom-label { font-size: 13px; min-width: 44px; text-align: center; color: var(--muted, #777); font-variant-numeric: tabular-nums; }
.pdf-toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 2px; }
.pdf-container {
  height: 62vh; min-height: 320px; overflow-y: auto; overflow-x: hidden;
  background: var(--card-2, #eef0f3); border-radius: 10px; padding: 14px 8px;
}
.pdf-loading { text-align: center; color: var(--muted, #777); padding: 40px 10px; font-size: 14px; }
.pdf-page-wrap { text-align: center; margin-bottom: 14px; }
.pdf-page {
  display: block; margin: 0 auto; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.18);
  max-width: 100%; height: auto;
}
.pdf-page-wrap .pdf-loading-mini { color: var(--muted, #777); font-size: 12px; padding: 20px; }

/* 暗色适配 */
[data-theme="dark"] .pdf-container { background: #1c1f24; }
[data-theme="dark"] .pdf-toolbar { background: #23262c; }

/* 窄屏（手机）紧凑工具栏 */
@media (max-width: 480px) {
  .pdf-toolbar { gap: 4px; padding: 6px 6px; }
  .pdf-toolbar .icon-btn { min-width: 30px; padding: 0 6px; }
  .pdf-pageinfo { min-width: 42px; }
  .pdf-zoom-label { min-width: 34px; }
  .pdf-toolbar-sep { margin: 0; }
  .pdf-container { padding: 10px 4px; }
}
