/* ==========================================================================
   FileHub - 私有文件管理与便签平台
   ========================================================================== */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --surface-3: #f1f2f5;
  --border: #e4e6eb;
  --border-strong: #d3d6dd;
  --text: #1d2129;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --warning: #d97706;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --header-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
}

[data-theme='dark'] {
  --bg: #14161a;
  --surface: #1c1f25;
  --surface-2: #22262d;
  --surface-3: #2a2f37;
  --border: #2e333b;
  --border-strong: #3c424c;
  --text: #e8eaed;
  --text-2: #9aa1ac;
  --text-3: #6b7280;
  --primary: #6366f1;
  --primary-hover: #7c7ff5;
  --primary-soft: #262a3d;
  --danger: #f87171;
  --danger-soft: #2c1f1f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--primary); text-decoration: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------------ 登录 */

#auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 100;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px 32px;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 19px;
  font-weight: 650;
  margin-bottom: 6px;
}
.auth-logo .mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  display: grid; place-items: center;
  color: #fff;
}
.auth-sub { color: var(--text-2); font-size: 13px; margin-bottom: 24px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 550; margin-bottom: 6px; }
.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 550;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover { background: #fee2e2; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; padding: 11px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.error-msg {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.error-msg.show { display: block; }

/* ------------------------------------------------------------------ 布局 */

#app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; }
.brand .mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  display: grid; place-items: center; color: #fff;
}

.tabs { display: flex; gap: 4px; background: var(--surface-3); padding: 3px; border-radius: 10px; }
.tab {
  padding: 6px 16px; border-radius: 8px; font-weight: 550; color: var(--text-2);
  display: flex; align-items: center; gap: 6px;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.topbar-spacer { flex: 1; }

.search-box {
  position: relative;
  width: 240px;
}
.search-box input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface-2);
  outline: none;
}
.search-box input:focus { border-color: var(--primary); background: var(--surface); }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); }

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--text-2);
  border: 1px solid transparent;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

.menu-wrap { position: relative; }
.dropdown {
  position: absolute;
  right: 0; top: calc(100% + 8px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  padding: 6px;
  display: none;
  z-index: 50;
}
.dropdown.show { display: block; }
.dropdown-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 8px 10px; border-radius: 7px;
  color: var(--text); text-align: left; font-size: 13.5px;
}
.dropdown-item:hover { background: var(--surface-3); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-sep { height: 1px; background: var(--border); margin: 5px 0; }

main { flex: 1; padding: 20px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ------------------------------------------------------------------ 工具栏 */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  font-size: 14px;
  margin-bottom: 14px;
  min-height: 26px;
}
.breadcrumb button { color: var(--text-2); padding: 3px 7px; border-radius: 6px; }
.breadcrumb button:hover { background: var(--surface-3); color: var(--text); }
.breadcrumb .current { font-weight: 600; padding: 3px 7px; }
.breadcrumb .sep { color: var(--text-3); }

.select {
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
}

.selection-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--primary-soft);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  margin-bottom: 14px;
  color: var(--primary);
  font-weight: 550;
}
.selection-bar.show { display: flex; }

/* ------------------------------------------------------------------ 文件网格 */

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .1s;
  position: relative;
  user-select: none;
}
.card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.card.selected { border-color: var(--primary); background: var(--primary-soft); }
.card.dragging { opacity: .4; }

.card-thumb {
  height: 76px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  display: grid;
  place-items: center;
  margin-bottom: 10px;
  overflow: hidden;
  color: var(--text-2);
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }

.card-name {
  font-weight: 550;
  font-size: 13.5px;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 38px;
}
.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: 12px;
  margin-top: 6px;
}
.card-actions {
  position: absolute;
  top: 8px; right: 8px;
  display: flex; gap: 4px;
  opacity: 0;
  transition: opacity .15s;
}
.card:hover .card-actions { opacity: 1; }
.card-actions button {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
}
.card-actions button:hover { color: var(--primary); border-color: var(--primary); }
.card-actions button.danger:hover { color: var(--danger); border-color: var(--danger); }
.card-check {
  position: absolute; top: 8px; left: 8px;
  width: 20px; height: 20px; border-radius: 6px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  display: none; place-items: center;
}
.select-mode .card-check { display: grid; }
.card.selected .card-check { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 列表视图 */
.file-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.file-row {
  display: grid;
  grid-template-columns: 32px 1fr 110px 150px 96px;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.file-row:last-child { border-bottom: none; }
.file-row:hover { background: var(--surface-2); }
.file-row.selected { background: var(--primary-soft); }
.file-row .name { font-weight: 550; word-break: break-all; display: flex; align-items: center; gap: 9px; }
.file-row .meta { color: var(--text-2); font-size: 13px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-actions button {
  width: 28px; height: 28px; border-radius: 7px;
  display: grid; place-items: center; color: var(--text-2);
}
.row-actions button:hover { background: var(--surface-3); color: var(--primary); }
.row-actions button.danger:hover { color: var(--danger); }

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-2);
}
.empty svg { color: var(--text-3); margin-bottom: 12px; }
.empty .title { font-size: 15px; font-weight: 550; color: var(--text); margin-bottom: 4px; }

/* ------------------------------------------------------------------ 拖拽上传 */

.dropzone-mask {
  position: fixed;
  inset: 0;
  background: rgba(79, 70, 229, .10);
  border: 3px dashed var(--primary);
  z-index: 90;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.dropzone-mask.show { display: flex; }
.dropzone-mask .inner {
  background: var(--surface);
  padding: 28px 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: 17px;
  font-weight: 600;
  color: var(--primary);
  display: flex; align-items: center; gap: 12px;
}

.upload-panel {
  position: fixed;
  right: 20px; bottom: 20px;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 80;
  display: none;
  overflow: hidden;
}
.upload-panel.show { display: block; }
.upload-panel header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 13.5px;
}
.upload-list { max-height: 280px; overflow-y: auto; padding: 8px; }
.upload-item { padding: 8px; border-radius: var(--radius-sm); }
.upload-item + .upload-item { border-top: 1px solid var(--border); }
.upload-item .row { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; margin-bottom: 5px; }
.upload-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item .status { color: var(--text-2); white-space: nowrap; }
.progress { height: 5px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); width: 0; transition: width .2s; }
.progress.done > div { background: var(--success); }
.progress.error > div { background: var(--danger); }

/* ------------------------------------------------------------------ 便签 */

.notes-layout { display: grid; grid-template-columns: 210px 1fr; gap: 18px; align-items: start; }

.side-cats { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
.cat-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  width: 100%; text-align: left; color: var(--text);
}
.cat-item:hover { background: var(--surface-3); }
.cat-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.cat-item .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.cat-item .count { margin-left: auto; color: var(--text-3); font-size: 12px; }
.cat-item.active .count { color: var(--primary); }

.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }

.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
  display: flex; flex-direction: column;
}
.note-card:hover { box-shadow: var(--shadow); border-color: var(--primary); }
.note-card[data-color='yellow'] { border-left-color: #f59e0b; background: #fffdf5; }
.note-card[data-color='green']  { border-left-color: #16a34a; background: #f6fdf8; }
.note-card[data-color='blue']   { border-left-color: #3b82f6; background: #f5f9ff; }
.note-card[data-color='pink']   { border-left-color: #ec4899; background: #fef7fa; }
.note-card[data-color='purple'] { border-left-color: #8b5cf6; background: #faf7ff; }
[data-theme='dark'] .note-card[data-color='yellow'] { background: var(--surface); }
[data-theme='dark'] .note-card[data-color='green']  { background: var(--surface); }
[data-theme='dark'] .note-card[data-color='blue']   { background: var(--surface); }
[data-theme='dark'] .note-card[data-color='pink']   { background: var(--surface); }
[data-theme='dark'] .note-card[data-color='purple'] { background: var(--surface); }

.note-title { font-weight: 600; margin-bottom: 6px; word-break: break-all; }
.note-excerpt {
  color: var(--text-2);
  font-size: 13px;
  flex: 1;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
}
.note-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--border);
  color: var(--text-3); font-size: 12px;
}
.note-foot .acts { display: flex; gap: 2px; }
.note-foot .acts button { width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; color: var(--text-3); }
.note-foot .acts button:hover { background: var(--surface-3); color: var(--primary); }
.note-foot .acts button.danger:hover { color: var(--danger); }
.pin-badge { color: var(--warning); }

/* ------------------------------------------------------------------ 弹层 */

.modal-mask {
  position: fixed; inset: 0;
  background: rgba(15, 18, 25, .45);
  z-index: 70;
  display: none;
  align-items: center; justify-content: center;
  padding: 24px;
  backdrop-filter: blur(2px);
}
.modal-mask.show { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 460px;
  max-height: 100%;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal.wide { max-width: 760px; height: 100%; max-height: 640px; }
.modal header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 15px;
  display: flex; align-items: center; justify-content: space-between;
}
.modal .body { padding: 20px; overflow-y: auto; flex: 1; }
.modal footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* 便签编辑器 */
.note-editor { display: flex; flex-direction: column; height: 100%; }
.editor-title {
  width: 100%; border: none; outline: none;
  font-size: 19px; font-weight: 650;
  padding: 0 0 10px; background: transparent;
}
.editor-toolbar {
  display: flex; gap: 2px; flex-wrap: wrap;
  padding: 8px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.editor-toolbar button {
  min-width: 30px; height: 30px; padding: 0 7px;
  border-radius: 6px; color: var(--text-2);
  display: grid; place-items: center; font-size: 13px;
}
.editor-toolbar button:hover { background: var(--surface-3); color: var(--text); }
.editor-toolbar button.active { background: var(--primary-soft); color: var(--primary); }
.editor-toolbar .divider { width: 1px; background: var(--border); margin: 4px 5px; }
.color-dots { display: flex; gap: 6px; align-items: center; margin-left: auto; padding-right: 4px; }
.color-dots button { width: 18px; height: 18px; border-radius: 50%; border: 2px solid transparent; }
.color-dots button.active { border-color: var(--text); }

.editor-area {
  flex: 1; outline: none; overflow-y: auto;
  font-size: 14.5px; line-height: 1.75; min-height: 180px;
}
.editor-area:empty:before { content: attr(data-placeholder); color: var(--text-3); }
.editor-area h1, .editor-area h2, .editor-area h3 { margin: .7em 0 .4em; }
.editor-area p { margin: .5em 0; }
.editor-area ul, .editor-area ol { padding-left: 22px; margin: .5em 0; }
.editor-area pre {
  background: var(--surface-3); padding: 10px 12px; border-radius: var(--radius-sm);
  overflow-x: auto; font-family: ui-monospace, Consolas, monospace; font-size: 13px;
}
.editor-area code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.editor-area blockquote {
  border-left: 3px solid var(--border-strong);
  margin: .6em 0; padding-left: 12px; color: var(--text-2);
}
.editor-area img { max-width: 100%; border-radius: 6px; }
.editor-area a { text-decoration: underline; }
.editor-area table { border-collapse: collapse; }
.editor-area td, .editor-area th { border: 1px solid var(--border-strong); padding: 5px 9px; }

.editor-foot {
  display: flex; align-items: center; gap: 12px;
  padding-top: 12px; margin-top: 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.editor-foot .saved-tip { color: var(--text-3); font-size: 12.5px; }

/* 预览弹层 */
.preview-body { text-align: center; }
.preview-body img, .preview-body video { max-width: 100%; max-height: 68vh; border-radius: var(--radius-sm); }
.preview-body pre {
  text-align: left; background: var(--surface-3); padding: 14px;
  border-radius: var(--radius-sm); overflow: auto; max-height: 68vh;
  font-family: ui-monospace, Consolas, monospace; font-size: 13px; white-space: pre-wrap; word-break: break-all;
}

/* ------------------------------------------------------------------ Toast */

#toast-container {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13.5px;
  display: flex; align-items: center; gap: 8px;
  animation: toast-in .22s ease;
  max-width: 90vw;
}
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stat-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px; font-size: 12.5px; color: var(--text-2);
}
.pill b { color: var(--text); }

.hidden { display: none !important; }

/* ------------------------------------------------------------------ 响应式 */

@media (max-width: 860px) {
  .notes-layout { grid-template-columns: 1fr; }
  .side-cats { display: flex; gap: 6px; overflow-x: auto; }
  .side-cats .cat-item { width: auto; white-space: nowrap; }
  .search-box { width: 150px; }
  main { padding: 14px; }
  .file-row { grid-template-columns: 28px 1fr 84px 84px; }
  .file-row .col-time { display: none; }
  .topbar { padding: 0 12px; gap: 10px; }
  .brand span { display: none; }
  .upload-panel { right: 10px; left: 10px; width: auto; }
}

@media (max-width: 560px) {
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .notes-grid { grid-template-columns: 1fr; }
  .modal.wide { padding: 0; max-height: 100%; }
}
