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

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --bg: #f1f5f9;
  --bg-elevated: linear-gradient(160deg, #f8fafc 0%, #eef2ff 45%, #f1f5f9 100%);
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-secondary: #64748b;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --header-bg: rgba(255, 255, 255, 0.85);
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #60a5fa;
    --primary-hover: #93c5fd;
    --primary-soft: rgba(37, 99, 235, 0.2);
    --danger: #f87171;
    --danger-hover: #fca5a5;
    --bg: #0f172a;
    --bg-elevated: linear-gradient(165deg, #0f172a 0%, #1e1b4b 40%, #0f172a 100%);
    --card: #1e293b;
    --border: #334155;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 40px rgba(0, 0, 0, 0.35);
    --header-bg: rgba(30, 41, 59, 0.88);
  }

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

  .source-view {
    background: #0d1117;
    color: #c9d1d9;
  }

  .btn-small {
    background: #334155;
    color: var(--text);
    border-color: #475569;
  }
  .btn-small:hover {
    background: #475569;
  }
  .btn-small.active {
    background: var(--primary);
    color: #0f172a;
    border-color: var(--primary);
  }

  .btn-danger {
    background: rgba(248, 113, 113, 0.12);
    color: var(--danger);
    border-color: rgba(248, 113, 113, 0.35);
  }
  .btn-danger:hover {
    background: rgba(248, 113, 113, 0.2);
  }

  #preview-iframe {
    background: #fff;
  }

  .preview-title-strip:hover {
    border-color: #475569;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', 'PingFang SC', sans-serif;
  background: var(--bg-elevated);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Auth */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

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

.auth-box h1 {
  font-size: 24px;
  margin-bottom: 4px;
  text-align: center;
}

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

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .2s;
}

.auth-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.auth-panel { display: none; }
.auth-panel.active { display: block; }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--text);
}
.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  transition: border-color .2s;
}
.form-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.btn {
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  cursor: pointer;
  transition: background-color .2s, border-color .2s, color .2s, box-shadow .2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

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

.btn-small {
  padding: 6px 14px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-small:hover { background: var(--border); }
.btn-small.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-copy-link { color: var(--primary); border-color: var(--primary); }
.btn-copy-link:hover { background: var(--primary); color: #fff; }

.auth-message {
  margin-top: 12px;
  font-size: 14px;
  text-align: center;
  min-height: 20px;
}
.auth-message.error { color: var(--danger); }
.auth-message.success { color: #16a34a; }

/* Layout */
.layout { min-height: 100vh; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 32px;
  background: var(--header-bg);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.brand-text { min-width: 0; }

.header h1 { font-size: 1.125rem; font-weight: 600; letter-spacing: -0.02em; }
.header-tagline {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
}

.header h2 { font-size: 16px; font-weight: 500; }

.user-name {
  color: var(--text-secondary);
  font-size: 14px;
}

.main { max-width: 960px; margin: 0 auto; padding: 28px 32px 48px; }

/* Upload */
.toolbar { margin-bottom: 24px; }

.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 28px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background-color .2s, box-shadow .2s;
  background: var(--card);
  box-shadow: var(--shadow);
}

.upload-area:hover, .upload-area.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 4px 20px rgba(37, 99, 235, 0.12);
}

.upload-area:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

.upload-area svg {
  width: 44px;
  height: 44px;
  color: var(--primary);
  opacity: 0.85;
  margin-bottom: 10px;
}

.upload-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; letter-spacing: -0.01em; }

.upload-hint {
  font-size: 13px;
  color: var(--text-secondary);
}

/* File list */
.file-list-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.file-list-header h2 { font-size: 16px; flex: 1; }

.select-all-wrap { flex-shrink: 0; }

.file-count {
  font-size: 13px;
  color: var(--text-secondary);
}

/* File filter bar */
.file-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 9px 36px 9px 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--card);
  color: var(--text);
  transition: border-color .2s, box-shadow .2s;
}

#search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

#search-input::placeholder {
  color: var(--text-secondary);
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}

.search-clear:hover {
  background: var(--text-secondary);
  color: var(--card);
}

.filter-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.filter-chip:hover {
  border-color: var(--text-secondary);
  color: var(--text);
}

.filter-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.filter-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
}

@media (prefers-color-scheme: dark) {
  .search-clear {
    background: #475569;
    color: var(--text-secondary);
  }
  .search-clear:hover {
    background: var(--text-secondary);
    color: var(--card);
  }
  .filter-chip:hover {
    border-color: #64748b;
  }
}

@media (max-width: 640px) {
  .file-filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .search-input-wrap {
    min-width: 0;
  }
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px 0 8px;
  flex-wrap: wrap;
}
.pagination-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.pagination-btn:hover:not(:disabled) {
  background: var(--border);
}
.pagination-btn:disabled {
  opacity: .4;
  cursor: default;
}
.pagination-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.pagination-ellipsis {
  padding: 0 6px;
  color: var(--text-secondary);
  user-select: none;
}

/* Custom Checkbox */
.file-checkbox-wrap {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-user-select: none;
  user-select: none;
}
.file-checkbox-wrap input { position: absolute; opacity: 0; width: 0; height: 0; }
.file-checkbox-visual {
  width: 18px; height: 18px;
  border: 2px solid #cbd5e1;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
  position: relative;
}
.file-checkbox-wrap input:checked + .file-checkbox-visual {
  background: var(--primary);
  border-color: var(--primary);
}
.file-checkbox-wrap input:checked + .file-checkbox-visual::after {
  content: '';
  width: 5px; height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  margin-top: -2px;
}
.file-checkbox-wrap input:focus-visible + .file-checkbox-visual {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
@media (prefers-color-scheme: dark) {
  .file-checkbox-visual { border-color: #475569; }
}

.file-item.selected {
  background: rgba(37, 99, 235, 0.06);
  border-color: var(--primary);
}
@media (prefers-color-scheme: dark) {
  .file-item.selected {
    background: rgba(37, 99, 235, 0.15);
  }
}

/* Batch Toolbar */
.batch-toolbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}
@media (prefers-color-scheme: dark) {
  .batch-toolbar {
    background: rgba(30, 41, 59, 0.9);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  }
}
.batch-category-select {
  padding: 5px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: inherit;
  cursor: pointer;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: box-shadow .2s, border-color .2s, transform .15s ease;
}

.file-item:hover {
  box-shadow: var(--shadow);
  border-color: #cbd5e1;
}

@media (prefers-color-scheme: dark) {
  .file-item:hover {
    border-color: #475569;
  }
}

.file-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  cursor: pointer;
  min-width: 0;
  border-radius: var(--radius-sm);
  padding: 2px 4px 2px 0;
  margin: -2px 0;
}

.file-info:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.file-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.file-icon.html { background: linear-gradient(145deg, #fef3c7, #fde68a); color: #b45309; }
.file-icon.md { background: linear-gradient(145deg, #dbeafe, #bfdbfe); color: #1d4ed8; }

@media (prefers-color-scheme: dark) {
  .file-icon.html { background: rgba(251, 191, 36, 0.2); color: #fcd34d; }
  .file-icon.md { background: rgba(96, 165, 250, 0.2); color: #93c5fd; }
}

.file-meta { min-width: 0; }

.file-name {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-subline {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.file-snippet {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.file-snippet mark {
  background: #fff3b0;
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}
@media (prefers-color-scheme: dark) {
  .file-snippet mark {
    background: #5c4b00;
  }
}

.file-detail {
  font-size: 12px;
  color: var(--text-secondary);
}

.file-badge {
  display: inline-flex;
  align-items: center;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.7;
  white-space: nowrap;
}

.file-badge-type {
  background: var(--bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.file-badge-public {
  background: rgba(22, 163, 74, 0.1);
  color: #16a34a;
}

.file-badge-private {
  background: rgba(220, 38, 38, 0.08);
  color: var(--danger);
}

@media (prefers-color-scheme: dark) {
  .file-badge-public { background: rgba(22, 163, 74, 0.15); }
  .file-badge-private { background: rgba(248, 113, 113, 0.12); }
}

.file-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.file-actions .btn {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-danger {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}
.btn-danger:hover { background: #fee2e2; }

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

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: .5;
}

.empty-state-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  padding: 8px 20px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s;
}

.empty-state-cta:hover { background: var(--primary-hover); }
.empty-state-cta svg { width: 16px; height: 16px; }

/* Preview */
.preview-layout {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.preview-layout .header { flex-shrink: 0; }

.header.header-preview {
  padding: 6px max(12px, env(safe-area-inset-left, 0px)) 8px max(12px, env(safe-area-inset-right, 0px));
  align-items: stretch;
}

.header-preview {
  transition: max-height .32s ease, opacity .22s ease, padding .22s ease, border-width .22s ease;
  max-height: 200px;
  opacity: 1;
  overflow: visible;
}

.preview-topbar {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}

/* 仅标题行：点标题展开完整工具栏 */
.preview-title-strip {
  display: none;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.preview-layout.preview-toolbar-compact .preview-title-strip {
  display: flex;
}

.preview-title-strip:hover {
  border-color: #cbd5e1;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.preview-title-strip:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.preview-title-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.preview-title-strip-hint {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  opacity: 0.55;
  transition: transform .2s ease, opacity .2s ease;
}

.preview-title-strip:hover .preview-title-strip-hint {
  transform: translateY(2px);
  opacity: 0.8;
}

.preview-toolbar-expanded {
  display: block;
}

.preview-layout.preview-toolbar-compact .preview-toolbar-expanded {
  display: none !important;
}

.preview-expanded-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.preview-expanded-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.preview-expanded-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.header-preview #btn-back {
  position: relative;
}

.preview-heading-truncate {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.btn-preview-to-compact {
  padding: 4px 10px;
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn-preview-to-compact:hover {
  color: var(--text);
  border-color: var(--border);
}

.btn-header-fold {
  padding: 6px 10px;
  min-width: 36px;
  justify-content: center;
}

.btn-header-fold .icon-fold-chevron {
  width: 18px;
  height: 18px;
  display: block;
}

.btn-header-fold .icon-fold-chevron--down { display: none; }

.preview-layout.preview-header-collapsed .btn-header-fold .icon-fold-chevron--up {
  display: none;
}

.preview-layout.preview-header-collapsed .btn-header-fold .icon-fold-chevron--down {
  display: block;
}

.view-toggle { display: flex; gap: 4px; }

/* 收起：顶栏完全折叠不占高度，仅保留屏幕顶部悬浮「展开」 */
.preview-layout.preview-header-collapsed .header.header-preview {
  flex-shrink: 1;
  flex-grow: 0;
  flex-basis: 0;
  min-height: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin: 0;
  border-bottom-width: 0;
  border-bottom-color: transparent;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

.preview-expand-floating {
  display: none;
  position: fixed;
  top: max(6px, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
  border-top: none;
  background: var(--header-bg);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
}

.preview-expand-floating svg {
  width: 16px;
  height: 16px;
  opacity: 0.8;
}

.preview-expand-floating:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.preview-layout.preview-header-collapsed .preview-expand-floating {
  display: flex;
}

.preview-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#preview-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

.source-view {
  display: none;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 20px 32px;
  background: #1e1e1e;
  color: #d4d4d4;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 14px;
  line-height: 1.6;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.source-view.active { display: block; }

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 100;
  animation: slideIn .3s ease;
  border-left: 4px solid var(--primary);
  max-width: min(360px, calc(100vw - 40px));
}

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  .file-item { transition: none; }
  .upload-area { transition: none; }
  .header-preview { transition: none; }
}

.toast.error { border-left-color: var(--danger); }

@media (max-width: 600px) {
  .toast {
    top: auto;
    right: auto;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    border-left: none;
    border-radius: 20px;
    text-align: center;
  }
  .toast.error { border-left: none; }
}

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

/* List loading */
.file-list.is-loading {
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Skeleton */
.skeleton-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
}

.skeleton-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--border) 25%, rgba(0,0,0,.06) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  flex-shrink: 0;
}

.skeleton-lines { flex: 1; }

.skeleton-line {
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--border) 25%, rgba(0,0,0,.06) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  margin-bottom: 8px;
}

.skeleton-line:last-child { margin-bottom: 0; }
.skeleton-w60 { width: 60%; }
.skeleton-w40 { width: 40%; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Upload progress */
.upload-progress {
  margin-top: 10px;
  height: 24px;
  position: relative;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.upload-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #7c3aed);
  border-radius: 999px;
  width: 0%;
  transition: width .2s ease;
}

.upload-progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  mix-blend-mode: difference;
}

/* Preview spinner */
.preview-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--card);
  z-index: 5;
  color: var(--text-secondary);
  font-size: 14px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .skeleton-icon, .skeleton-line { animation: none; }
  .spinner { animation: none; }
}

/* Responsive */
@media (max-width: 768px) {
  .file-actions { flex-wrap: wrap; }
  .file-item { flex-wrap: wrap; }
}

@media (max-width: 640px) {
  .header { padding: 12px 16px; }
  .main { padding: 16px 16px 40px; }
  .auth-box { padding: 28px 20px; }
  .source-view { padding: 16px; }
  .brand-mark { width: 36px; height: 36px; font-size: 12px; }
  .upload-area { padding: 28px 18px; }
  .preview-expanded-left {
    width: 100%;
  }
  .preview-expanded-right {
    width: 100%;
    justify-content: flex-end;
  }
  .batch-toolbar {
    left: 12px;
    right: 12px;
    transform: none;
    flex-wrap: wrap;
    justify-content: center;
    bottom: 12px;
  }
}

/* Login */
.login-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-main {
  width: 100%;
  max-width: 400px;
}

.login-form {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-brand {
  text-align: center;
  margin-bottom: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.login-brand .brand-mark {
  width: 40px;
  height: 40px;
  font-size: 18px;
}

.login-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-field span {
  font-size: 13px;
  color: var(--text-secondary);
}

.login-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  background: var(--card);
  color: var(--text);
  transition: border-color .2s, box-shadow .2s;
}

.login-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

.login-error {
  background: rgba(220, 38, 38, 0.08);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.25);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
}

.login-submit {
  margin-top: 4px;
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 500;
  justify-content: center;
}

.login-submit:hover { background: var(--primary-hover); }
.login-submit:disabled { opacity: 0.6; cursor: not-allowed; }

@media (prefers-color-scheme: dark) {
  .login-error {
    background: rgba(248, 113, 113, 0.12);
    border-color: rgba(248, 113, 113, 0.35);
  }
  .login-submit { color: #0f172a; }
}

/* Header right (user + logout) */
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Settings dropdown */
.settings-dropdown {
  position: relative;
  display: inline-flex;
}

.btn-settings {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-settings svg {
  width: 16px;
  height: 16px;
  transition: transform .3s ease;
}

.settings-dropdown.open .btn-settings svg {
  transform: rotate(60deg);
}

.settings-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.15);
  z-index: 100;
  padding: 4px;
}

.settings-dropdown.open .settings-menu {
  display: block;
}

.settings-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}

.settings-menu-item:hover {
  background: var(--bg);
}

.settings-menu-item svg {
  width: 15px;
  height: 15px;
  opacity: 0.6;
  flex-shrink: 0;
}

.settings-menu-item:hover svg {
  opacity: 1;
}

.header-user {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 2px 8px;
  background: var(--bg);
  border-radius: 999px;
  border: 1px solid var(--border);
}

@media (prefers-color-scheme: dark) {
  .header-user {
    background: rgba(255, 255, 255, 0.05);
  }
}

/* Upload privacy checkbox row */
.upload-privacy {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.upload-privacy input {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary);
}

.upload-privacy:hover { color: var(--text); }

/* Lock badge */
.file-lock {
  display: inline-block;
  margin-right: 4px;
  font-size: 0.9em;
  filter: saturate(0.9);
}

/* Skills section */
.skills-section {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.skills-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.skills-header h2 { font-size: 16px; }

.skills-count { font-size: 13px; color: var(--text-secondary); }

.skills-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 14px;
  line-height: 1.6;
}

.skills-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skills-list.is-loading {
  color: var(--text-secondary);
  font-size: 13px;
  padding: 12px 0;
}

.skill-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.skill-card-info { flex: 1; min-width: 0; }

.skill-card-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 4px;
}

.skill-name { font-weight: 600; font-size: 15px; color: var(--text); }

.skill-version {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.skill-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0 0 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.skill-card-meta { font-size: 12px; color: var(--text-secondary); }

.skill-card-actions { display: flex; gap: 8px; flex-shrink: 0; }

.empty-state-sm { padding: 24px 16px; }
.empty-state-sm svg { width: 28px; height: 28px; }
.empty-state-sm p { font-size: 13px; }

/* Modal */
.modal-backdrop[hidden] { display: none; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.modal-panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  max-width: 720px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-header h2 { font-size: 16px; margin: 0; }

.modal-close {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 18px;
  line-height: 28px;
  justify-content: center;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-body h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 18px 0 8px;
}

.modal-body h3:first-child { margin-top: 0; }

.skill-modal-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  line-height: 1.6;
}

.skill-modal-meta code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
}

.skill-file-tree {
  list-style: none;
  padding: 10px 14px;
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.skill-file-tree li { padding: 2px 0; }

.skill-modal-source {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
  margin: 0;
}

.skill-modal-source code { font-family: inherit; }

.skill-install-rendered {
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
}

.skill-install-rendered h3 { margin-top: 0; }
.skill-install-rendered h4,
.skill-install-rendered h5 {
  font-size: 14px;
  font-weight: 600;
  margin: 16px 0 8px;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}

.skill-install-rendered h5 { font-size: 13px; color: var(--text-secondary); }

.skill-install-rendered p { margin: 0 0 10px; }

.skill-install-rendered ul,
.skill-install-rendered ol { margin: 0 0 12px; padding-left: 22px; }

.skill-install-rendered li { margin: 3px 0; }

.skill-install-rendered pre {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  margin: 0 0 12px;
}

.skill-install-rendered code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
}

.skill-install-rendered pre code { background: none; padding: 0; font-size: inherit; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.modal-footer .btn-primary { width: auto; }
.modal-footer .btn { flex-shrink: 0; }

/* Modal wide variant */
.modal-panel-wide {
  max-width: 860px;
}

/* Modal small variant (prompt / confirm / alert) */
.modal-panel-sm {
  max-width: 440px;
}

.dialog-message {
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
}

.dialog-field {
  margin-top: 12px;
}

.dialog-field[hidden] {
  display: none;
}

/* Version panel */
.version-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 320px;
  height: 100%;
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
  z-index: 20;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.version-panel.open {
  transform: translateX(0);
}

.version-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.version-panel-header h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.version-panel-body {
  overflow-y: auto;
  flex: 1;
  padding: 12px 0;
}

.version-item {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.version-item:last-child {
  border-bottom: none;
}

.version-item-current {
  background: var(--primary-soft);
}

.version-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.version-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.version-item-current .version-item-dot {
  background: var(--primary);
}

.version-item-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.version-item-current .version-item-label {
  color: var(--primary);
}

.version-item-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 16px;
  margin-bottom: 6px;
}

.version-item-actions {
  display: flex;
  gap: 6px;
  margin-left: 16px;
  flex-wrap: wrap;
}

.version-item-actions .btn {
  font-size: 11px;
  padding: 3px 10px;
}

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

.file-badge-version {
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
}

@media (prefers-color-scheme: dark) {
  .version-panel {
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.35);
  }

  .file-badge-version {
    background: rgba(96, 165, 250, 0.15);
  }

  .version-item-current {
    background: rgba(37, 99, 235, 0.12);
  }

  .version-item-dot {
    background: #475569;
  }

  .version-item-current .version-item-dot {
    background: var(--primary);
  }
}

@media (max-width: 640px) {
  .version-panel {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .version-panel {
    transition: none;
  }
}

/* MCP Config Modal */
.mcp-status {
  margin-bottom: 16px;
}

.mcp-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 14px;
}

.mcp-status-on {
  background: rgba(22, 163, 74, 0.1);
  color: #16a34a;
  border: 1px solid rgba(22, 163, 74, 0.25);
}

.mcp-status-off {
  background: rgba(220, 38, 38, 0.08);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.2);
}

.mcp-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mcp-status-on .mcp-status-dot { background: #16a34a; }
.mcp-status-off .mcp-status-dot { background: var(--danger); }

.mcp-info-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.mcp-info-row:last-child { border-bottom: none; }

.mcp-label {
  flex-shrink: 0;
  width: 64px;
  color: var(--text-secondary);
  font-weight: 500;
}

.mcp-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
  word-break: break-all;
  user-select: all;
}

.mcp-detail h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 20px 0 8px;
}

.mcp-config-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 10px;
  line-height: 1.6;
}

.mcp-config-hint code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
}

.mcp-config-block {
  position: relative;
}

.mcp-config-code {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  overflow-x: auto;
}

.mcp-config-code code { font-family: inherit; }

.mcp-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
}

@media (prefers-color-scheme: dark) {
  .mcp-status-on {
    background: rgba(22, 163, 74, 0.15);
    border-color: rgba(22, 163, 74, 0.35);
  }
  .mcp-status-off {
    background: rgba(248, 113, 113, 0.12);
    border-color: rgba(248, 113, 113, 0.3);
  }
}


/* --- Admin-only elements --- */
.admin-only { display: none; }

/* --- Settings menu divider --- */
.settings-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 8px;
}

.settings-menu-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 12px 2px;
  user-select: none;
}

/* --- Users table --- */
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.users-table th { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; }
.users-table td { font-size: 14px; }
.users-actions { display: flex; gap: 6px; }

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}
.role-admin { background: #dbeafe; color: #1e40af; }
.role-user { background: #f3f4f6; color: #6b7280; }
@media (prefers-color-scheme: dark) {
  .role-admin { background: #1e3a5f; color: #93c5fd; }
  .role-user { background: #374151; color: #9ca3af; }
}

/* --- Token list --- */
.token-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.token-info { display: flex; flex-direction: column; gap: 2px; }
.token-info strong { font-size: 14px; }
.token-prefix {
  display: inline-block;
  font-family: monospace;
  font-size: 12px;
  padding: 1px 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 3px;
  width: fit-content;
}
.token-time { font-size: 12px; color: var(--text-secondary); }
.btn-danger-outline {
  color: var(--danger);
  border: 1px solid var(--danger);
  background: transparent;
}
.btn-danger-outline:hover { background: var(--danger); color: white; }

/* --- Modal hint --- */
.modal-hint { font-size: 13px; color: var(--text-secondary); margin: 0; }

/* Star button */
.btn-star {
  font-size: 14px;
  color: var(--text-secondary);
  border-color: var(--border);
  min-width: 32px;
  justify-content: center;
}
.btn-star:hover { color: #f59e0b; border-color: #f59e0b; }
.btn-star.starred { color: #f59e0b; border-color: #f59e0b; background: rgba(245, 158, 11, 0.08); }

@media (prefers-color-scheme: dark) {
  .btn-star:hover { color: #fbbf24; border-color: #fbbf24; }
  .btn-star.starred { color: #fbbf24; border-color: #fbbf24; background: rgba(251, 191, 36, 0.12); }
}

/* Tag badge */
.file-badge-tag {
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
  border: 1px solid rgba(37, 99, 235, 0.2);
  cursor: pointer;
}
.file-badge-tag:hover { background: rgba(37, 99, 235, 0.15); }

@media (prefers-color-scheme: dark) {
  .file-badge-tag { background: rgba(96, 165, 250, 0.12); border-color: rgba(96, 165, 250, 0.25); }
  .file-badge-tag:hover { background: rgba(96, 165, 250, 0.2); }
}

/* Category badge */
.file-badge-category {
  background: rgba(124, 58, 237, 0.08);
  color: #7c3aed;
  border: 1px solid rgba(124, 58, 237, 0.2);
}

@media (prefers-color-scheme: dark) {
  .file-badge-category { background: rgba(167, 139, 250, 0.12); color: #a78bfa; border-color: rgba(167, 139, 250, 0.25); }
}

/* Filter dropdown */
.filter-dropdown { position: relative; display: inline-flex; }
.filter-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 160px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.15);
  z-index: 100;
  padding: 4px;
  max-height: 240px;
  overflow-y: auto;
}
.filter-dropdown.open .filter-dropdown-menu { display: block; }

.filter-dropdown-item {
  display: block;
  width: 100%;
  padding: 7px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.filter-dropdown-item:hover { background: var(--bg); }
.filter-dropdown-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }

/* Tag editor modal */
.tag-editor-selected { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; min-height: 28px; }
.tag-editor-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(37, 99, 235, 0.2);
}
.tag-editor-chip-remove { cursor: pointer; opacity: 0.6; font-size: 14px; line-height: 1; }
.tag-editor-chip-remove:hover { opacity: 1; }

.tag-editor-input-wrap { position: relative; }
#tag-editor-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--card);
  color: var(--text);
}
#tag-editor-input:focus { outline: none; border-color: var(--primary); }

/* Editor */
.editor-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--card);
}

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

.editor-gutter {
  width: 48px;
  padding: 12px 8px 12px 12px;
  text-align: right;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Menlo', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
  white-space: pre;
  user-select: none;
  opacity: 0.7;
}

.editor-textarea {
  flex: 1;
  padding: 12px 16px;
  border: none;
  outline: none;
  resize: none;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Menlo', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  background: var(--card);
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

.editor-statusbar {
  padding: 4px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg);
  border-top: 1px solid var(--border);
  text-align: right;
}

@media (prefers-color-scheme: dark) {
  .editor-container {
    background: #0d1117;
  }
  .editor-textarea {
    background: #0d1117;
    color: #c9d1d9;
  }
  .editor-gutter {
    background: #161b22;
    color: #484f58;
    border-right-color: #30363d;
  }
  .editor-statusbar {
    background: #161b22;
    border-top-color: #30363d;
  }
}

.tag-editor-suggestions {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  border-top: none;
  max-height: 160px;
  overflow-y: auto;
  z-index: 10;
  list-style: none;
  padding: 4px;
  margin: 0;
}
.tag-editor-suggestions.visible { display: block; }
.tag-editor-suggestions li { padding: 6px 12px; font-size: 13px; cursor: pointer; border-radius: var(--radius-sm); }
.tag-editor-suggestions li:hover { background: var(--bg); }
.tag-create-new { color: var(--primary); font-weight: 500; }

/* Category list */
.category-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
  font-size: 14px;
}
.category-list-item:hover { background: var(--bg); }
.category-list-item.selected { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.category-item-actions { display: flex; gap: 4px; }
.category-item-actions .btn { font-size: 11px; padding: 2px 8px; }

/* View badge */
.file-badge-views { color: var(--text-secondary); background: transparent; font-size: 11px; padding: 0 4px; }

/* Stats dialog */
.stats-summary { text-align: center; margin-bottom: 12px; }
.stats-total { font-size: 15px; }
.stats-total strong { font-size: 24px; color: var(--primary); margin: 0 4px; }
.stats-section { margin-bottom: 16px; }
.stats-section h4 { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; font-weight: 500; }
.stats-empty { color: var(--text-secondary); font-size: 13px; text-align: center; padding: 12px 0; }
.stats-chart { display: flex; align-items: flex-end; gap: 2px; height: 80px; border-bottom: 1px solid var(--border); padding-bottom: 18px; }
.stats-bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; min-width: 0; position: relative; }
.stats-bar { width: 100%; max-width: 20px; background: var(--primary); border-radius: 2px 2px 0 0; min-height: 2px; transition: height .3s; }
.stats-bar-val { font-size: 9px; color: var(--text-secondary); line-height: 1; margin-bottom: 2px; }
.stats-bar-label { font-size: 9px; color: var(--text-secondary); position: absolute; bottom: -16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* --- 内容模板市场 --- */
.ct-filter-bar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.ct-filter-bar .search-input-wrap { width: 100%; }
.ct-filter-bar .search-input-wrap input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-size: 14px; }
.ct-filter-bar .filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip { padding: 4px 12px; border-radius: 16px; border: 1px solid var(--border); background: transparent; color: var(--text-secondary); font-size: 12px; cursor: pointer; transition: all .2s; }
.filter-chip:hover { border-color: var(--primary); color: var(--primary); }
.filter-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.ct-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.ct-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 14px; cursor: pointer; transition: box-shadow .2s, border-color .2s; display: flex; flex-direction: column; gap: 6px; }
.ct-card:hover { box-shadow: 0 2px 8px var(--shadow); border-color: var(--primary); }
.ct-card-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ct-card-title { font-size: 14px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ct-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; line-height: 1.4; }
.ct-badge-html { background: #e0f2fe; color: #0369a1; }
.ct-badge-md { background: #dbeafe; color: #1d4ed8; }
.ct-badge-scene { background: var(--primary-light, #ede9fe); color: var(--primary); }
.ct-badge-tag { background: var(--bg-secondary, #f1f5f9); color: var(--text-secondary); }
.ct-card-desc { font-size: 12px; color: var(--text-secondary); line-height: 1.5; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin: 0; }
.ct-card-footer { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--text-secondary); margin-top: auto; }
.ct-use-count { color: var(--primary); font-weight: 500; }
.ct-owner-mark { color: var(--success, #10b981); font-weight: 500; }
.ct-loading, .ct-empty { text-align: center; padding: 40px; color: var(--text-secondary); font-size: 14px; grid-column: 1 / -1; }
.ct-pagination { display: flex; align-items: center; justify-content: center; gap: 12px; grid-column: 1 / -1; padding: 12px 0; }
.ct-page-info { font-size: 13px; color: var(--text-secondary); }
.ct-detail-meta { margin-bottom: 16px; }
.ct-meta-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ct-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.5; margin: 8px 0; }
.ct-meta-info { font-size: 12px; color: var(--text-secondary); }
@media (prefers-color-scheme: dark) {
  .ct-badge-html { background: #172554; color: #7dd3fc; }
  .ct-badge-md { background: #1e3a5f; color: #93c5fd; }
  .ct-badge-scene { background: #2e1065; color: #c4b5fd; }
  .ct-badge-tag { background: #1e293b; color: #94a3b8; }
}
