*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4f6ef7;
  --primary-hover: #3a58e8;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --bg: #f5f6fa;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --sidebar-w: 210px;
  --header-h: 56px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---- Header ---- */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

/* ---- Layout ---- */
.layout {
  display: flex;
  padding-top: var(--header-h);
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 50;
}

.sidebar-section { margin-bottom: 8px; }

.sidebar-label {
  padding: 6px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-add-cat {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background .15s, color .15s;
}
.btn-add-cat:hover { background: #f3f4f6; color: var(--primary); }

.sidebar-nav {
  list-style: none;
  padding: 2px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-secondary);
  transition: background .12s, color .12s;
  position: relative;
  user-select: none;
}
.nav-item:hover { background: #f3f4f6; color: var(--text); }
.nav-item.active { background: #eef1fd; color: var(--primary); font-weight: 500; }
.nav-item svg { flex-shrink: 0; opacity: .7; }
.nav-item.active svg { opacity: 1; }

.nav-count {
  margin-left: auto;
  font-size: 11px;
  background: #f3f4f6;
  color: var(--text-secondary);
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}
.nav-item.active .nav-count { background: #d9e0fc; color: var(--primary); }

.nav-custom-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-secondary);
  transition: background .12s;
  position: relative;
}
.nav-custom-item:hover { background: #f3f4f6; color: var(--text); }
.nav-custom-item.active { background: #eef1fd; color: var(--primary); font-weight: 500; }
.nav-custom-item .nav-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-custom-item .nav-count { flex-shrink: 0; }
.nav-custom-delete { display: none; }

/* ---- 右键上下文菜单 ---- */
.ctx-menu {
  position: fixed;
  z-index: 500;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 130px;
  animation: fadeIn .1s;
}
.ctx-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: background .1s;
}
.ctx-menu-item:hover { background: #f3f4f6; }
.ctx-menu-item.danger { color: var(--danger); }
.ctx-menu-item.danger:hover { background: #fef2f2; }

.nav-empty { padding: 6px 10px; font-size: 12px; color: #bbb; }

.cat-search-wrap {
  padding: 4px 8px 6px;
}
.cat-search-wrap input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12.5px;
  outline: none;
  color: var(--text);
  background: #f9fafb;
  transition: border-color .15s, background .15s;
}
.cat-search-wrap input:focus {
  border-color: var(--primary);
  background: #fff;
}

/* ---- Main Wrap ---- */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 16px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.current-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  min-width: 220px;
}
.search-box svg { flex-shrink: 0; color: var(--text-secondary); }
.search-box input {
  border: none; outline: none;
  font-size: 14px; width: 100%;
  color: var(--text); background: transparent;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #f3f4f6; color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #e5e7eb; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ---- Grid ---- */
.main { padding: 16px 24px 40px; }

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

/* ---- File Card ---- */
.file-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  position: relative;
}
.file-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.card-thumb {
  width: 100%; height: 140px;
  background: #f3f4f6;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; position: relative;
}
.card-thumb img { width: 100%; height: 100%; object-fit: contain; background: #f3f4f6; }
.card-thumb .file-icon {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; color: var(--text-secondary);
}
.card-thumb .file-icon span {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  background: var(--border); padding: 2px 6px; border-radius: 4px;
}

.play-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.25);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .15s;
}
.file-card:hover .play-overlay { opacity: 1; }
.play-overlay svg { color: #fff; filter: drop-shadow(0 2px 4px rgba(0,0,0,.4)); }

.card-info { padding: 10px 12px; }
.card-name {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 6px;
}
.card-meta {
  font-size: 12px; color: var(--text-secondary);
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
}
.card-meta-left { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.card-actions {
  position: absolute; top: 8px; right: 8px;
  display: flex; gap: 4px;
  opacity: 0; transition: opacity .15s;
}
.file-card:hover .card-actions { opacity: 1; }
.action-btn {
  width: 28px; height: 28px; border-radius: 6px; border: none;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px); transition: background .15s;
}
.action-btn-delete { background: rgba(239,68,68,.85); color: #fff; }
.action-btn-delete:hover { background: var(--danger); }

.action-btn-download-corner {
  width: 28px; height: 28px; border-radius: 6px; border: none;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  background: #f3f4f6; color: var(--text-secondary);
  transition: background .15s, color .15s; flex-shrink: 0;
}
.action-btn-download-corner:hover { background: var(--primary); color: #fff; }

/* ---- Empty & Loading ---- */
.empty-state, .loading { text-align: center; padding: 80px 20px; color: var(--text-secondary); }
.empty-state p, .loading p { margin-top: 16px; font-size: 15px; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Pagination ---- */
.pagination {
  display: flex; justify-content: center;
  gap: 6px; margin-top: 32px; flex-wrap: wrap;
}
.page-btn {
  min-width: 36px; height: 36px; padding: 0 10px;
  border-radius: 8px; border: 1px solid var(--border);
  background: #fff; font-size: 14px; cursor: pointer; transition: all .15s;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: #fff; border-radius: 14px;
  width: 100%; max-width: 560px; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); animation: slideUp .2s;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-preview { max-width: 860px; }
.modal-small { max-width: 400px; }

.modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.preview-actions { display: flex; align-items: center; gap: 8px; }

.modal-close {
  width: 30px; height: 30px; border-radius: 6px; border: none;
  background: #f3f4f6; font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); transition: background .15s;
}
.modal-close:hover { background: #e5e7eb; }

.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0;
}

/* ---- Drop Zone ---- */
.drop-zone {
  border: 2px dashed var(--border); border-radius: 10px;
  padding: 40px 20px; text-align: center;
  transition: border-color .15s, background .15s; cursor: pointer;
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--primary); background: #f0f3ff; }
.drop-zone p { font-size: 14px; color: var(--text-secondary); margin-top: 12px; }
.drop-zone .hint { font-size: 12px; margin-top: 4px; }
.file-label { color: var(--primary); cursor: pointer; text-decoration: underline; }

/* ---- Upload Category ---- */
.upload-category-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
.upload-category-label { font-size: 13px; color: var(--text); flex-shrink: 0; }
.category-select-wrap { display: flex; align-items: center; gap: 8px; flex: 1; }
.category-select {
  flex: 1; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; color: var(--text);
  background: #fff; outline: none; cursor: pointer;
}
.category-select:focus { border-color: var(--primary); }
.btn-inline-add {
  padding: 7px 10px; border: 1px dashed var(--border);
  border-radius: 8px; background: #fff; font-size: 12px;
  color: var(--primary); cursor: pointer; white-space: nowrap;
  transition: border-color .15s, background .15s;
}
.btn-inline-add:hover { border-color: var(--primary); background: #f0f3ff; }

.new-cat-inline {
  display: flex; gap: 6px; align-items: center;
  margin-top: 8px;
}
.new-cat-inline input {
  flex: 1; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; outline: none;
}
.new-cat-inline input:focus { border-color: var(--primary); }

/* ---- Upload List ---- */
.upload-list { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.upload-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: #f9fafb; border-radius: 8px; font-size: 13px;
}
.upload-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item-size { color: var(--text-secondary); flex-shrink: 0; }
.upload-item-status { flex-shrink: 0; font-size: 12px; font-weight: 500; }
.status-pending { color: var(--text-secondary); }
.status-uploading { color: var(--primary); }
.status-done { color: #10b981; }
.status-error { color: var(--danger); }

/* ---- Preview ---- */
.preview-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 300px; background: #f3f4f6; border-radius: 8px; overflow: hidden;
}
.preview-body img { max-width: 100%; max-height: 70vh; object-fit: contain; border-radius: 6px; }
.preview-body video, .preview-body audio { width: 100%; max-height: 70vh; outline: none; }
.preview-no-support { text-align: center; padding: 40px; color: var(--text-secondary); }
.preview-no-support p { margin-top: 12px; font-size: 14px; }

/* ---- Toast ---- */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 999; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 18px; border-radius: 8px; font-size: 14px;
  color: #fff; box-shadow: var(--shadow-lg); animation: slideLeft .2s; min-width: 200px;
}
@keyframes slideLeft { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast-success { background: #10b981; }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }

/* ---- Responsive ---- */
@media (max-width: 700px) {
  .sidebar { display: none; }
  .main-wrap { margin-left: 0; }
  .main { padding: 12px 16px 40px; }
  .topbar { padding: 12px 16px 0; }
  .header { padding: 0 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
}
