:root {
  --bg: #f4f7fc;
  --surface: #ffffff;
  --border: #e2e8f2;
  --text: #1b2436;
  --muted: #6b7891;
  --primary: #2f5bd7;
  --primary-dark: #2348b4;
  --danger: #c73b45;
  --success: #1f8a5b;
  --shadow: 0 8px 28px rgba(28, 48, 92, .08);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

[hidden] { display: none !important; }

.muted { color: var(--muted); }
.pad { padding: 0 20px 8px; margin: 0; }
.right { text-align: right; }

.brand-mark {
  width: 52px; height: 52px; border-radius: 14px;
  background: linear-gradient(135deg, #2f5bd7, #4a86f7);
  color: #fff; font-weight: 700; font-size: 18px; letter-spacing: .5px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(47, 91, 215, .28);
}
.brand-mark.small { width: 38px; height: 38px; border-radius: 10px; font-size: 13px; }

/* 登录 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px; padding: 36px 34px 28px;
  box-shadow: var(--shadow); text-align: center;
}
.login-card .brand-mark { margin: 0 auto 18px; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-card .muted { font-size: 12px; margin: 0 0 26px; }
.login-card form { text-align: left; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; }
.login-card input { width: 100%; }
.hint { margin: 22px 0 0; font-size: 12px; color: var(--muted); }
.form-error { color: var(--danger); font-size: 12px; margin: 10px 0 0; }

input[type="text"], input[type="password"], input[type="search"], select {
  height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); font-size: 14px; outline: none;
  font-family: inherit;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 91, 215, .12); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* 按钮 */
.btn {
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 13px; font-family: inherit;
  cursor: pointer; white-space: nowrap; transition: .15s ease;
}
.btn:hover:not(:disabled) { border-color: #b9c7e4; background: #f7f9fd; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { background: #eef2fa; color: var(--text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #a92f38; }
.btn.block { width: 100%; margin-top: 22px; height: 40px; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12px; }

/* 顶栏 */
.topbar {
  height: 68px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; gap: 16px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.app-title { font-weight: 700; font-size: 15px; }
.app-sub { font-size: 11px; color: var(--muted); }
.user-chip { font-size: 12px; color: var(--muted); text-align: right; line-height: 1.35; }
.user-chip strong { display: block; color: var(--text); font-size: 13px; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px;
  background: #eaf0ff; color: var(--primary); margin-right: 4px;
}
.badge.off { background: #eef1f5; color: #98a2b3; }

.container { max-width: 1280px; margin: 0 auto; padding: 24px 28px 60px; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tab {
  border: 0; background: transparent; padding: 8px 16px; border-radius: 8px;
  font-size: 14px; color: var(--muted); cursor: pointer; font-family: inherit;
}
.tab.active { background: #fff; color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.panel.drag-over { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(47, 91, 215, .14); }
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.section-title { font-size: 16px; margin: 0; }
.search { width: 190px; }

.breadcrumb { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 13px; }
.crumb { color: var(--primary); cursor: pointer; border: 0; background: transparent; font-family: inherit; font-size: 13px; padding: 2px 4px; }
.crumb:hover { text-decoration: underline; }
.crumb.current { color: var(--text); font-weight: 600; cursor: default; }
.sep { color: #c3ccdb; }

.drop-hint { padding: 10px 20px; font-size: 12px; color: var(--muted); background: #fcfdff; border-bottom: 1px solid var(--border); }

.upload-progress { padding: 12px 20px; background: #f7faff; border-bottom: 1px solid var(--border); }
.upload-row { display: flex; align-items: center; gap: 12px; margin: 5px 0; font-size: 12px; }
.up-name { width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { flex: 1; height: 6px; background: #e5ebf7; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--primary); transition: width .15s; }
.up-pct { width: 46px; text-align: right; color: var(--muted); }
.upload-row.done .up-pct { color: var(--success); }
.upload-row.failed .up-pct { color: var(--danger); }

/* 表格 */
.table-wrap { overflow-x: auto; }
.file-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.file-table th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 12px;
  background: #fbfcfe; padding: 10px 20px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.file-table td { padding: 11px 20px; border-bottom: 1px solid #f0f3f9; vertical-align: middle; }
.file-table tr:last-child td { border-bottom: 0; }
.file-table tbody tr:hover { background: #f8faff; }
/* 最后一列（操作按钮）常驻右侧：列多、屏幕窄时不用横向滚动也点得到 */
.file-table th:last-child,
.file-table td:last-child {
  position: sticky; right: 0; z-index: 1;
  background: var(--surface);
  box-shadow: -8px 0 10px -8px rgba(28, 48, 92, .16);
}
.file-table thead th:last-child { background: #fbfcfe; }
.file-table tbody tr:hover td:last-child { background: #f8faff; }
.build-tag {
  margin-left: 8px; padding: 1px 6px; border-radius: 6px;
  background: #eef3ff; color: #6b7891; font-size: 11px;
}
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.name-link { color: var(--text); text-decoration: none; cursor: pointer; word-break: break-all; }
.name-link:hover { color: var(--primary); text-decoration: underline; }
.icon-box { width: 26px; height: 26px; flex: 0 0 26px; border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.icon-box.dir { background: #fff3d9; color: #b7791f; }
.icon-box.file { background: #eaf0ff; color: var(--primary); }
.icon-box svg { width: 16px; height: 16px; }
.cell-muted { color: var(--muted); white-space: nowrap; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* 拖拽排序：手柄、拖动中的行、插入位置指示线 */
.name-cell[draggable="true"] { cursor: grab; }
.name-cell[draggable="true"]:active { cursor: grabbing; }
.drag-handle {
  width: 16px; height: 22px; flex: 0 0 16px; color: #aab6ca; cursor: grab;
  display: flex; align-items: center; justify-content: center;
}
.drag-handle:hover { color: var(--primary); }
.drag-handle:active { cursor: grabbing; }
.drag-handle svg { width: 14px; height: 14px; }
.file-table tbody tr.dragging { opacity: .45; background: #eef3ff; }
.file-table tbody tr.drop-before td { box-shadow: inset 0 3px 0 0 var(--primary); }
.file-table tbody tr.drop-after td { box-shadow: inset 0 -3px 0 0 var(--primary); }
.empty { text-align: center; padding: 46px 20px; color: var(--muted); font-size: 13px; }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(20, 32, 56, .42); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 460px; box-shadow: 0 20px 60px rgba(15, 28, 55, .25); max-height: 88vh; display: flex; flex-direction: column; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-x { border: 0; background: transparent; font-size: 22px; color: var(--muted); cursor: pointer; line-height: 1; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.form-row { margin-bottom: 14px; }
.form-row > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.form-row input[type="text"], .form-row input[type="password"], .form-row select { width: 100%; }
.input-line { display: flex; gap: 8px; align-items: center; }
.input-line input { flex: 1; min-width: 0; }
.input-line .btn { flex: none; white-space: nowrap; }
.check-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.check-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
/* 移动到：目标文件夹选择器 */
.folder-picker { max-height: 42vh; overflow-y: auto; background: #fbfcfe; border: 1px solid var(--border); border-radius: 10px; padding: 6px; }
.folder-option { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.folder-option:hover { background: #eef3ff; }
.folder-option.disabled { opacity: .48; cursor: not-allowed; }
.folder-option input { flex: none; margin: 0; }
.folder-option .icon-box { width: 20px; height: 20px; flex: 0 0 20px; border-radius: 5px; }
.folder-option .icon-box svg { width: 13px; height: 13px; }
.folder-name { font-weight: 600; white-space: nowrap; }
.folder-full { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-tag { margin-left: auto; color: var(--danger); font-size: 11px; white-space: nowrap; }
.new-folder-box { margin-top: 16px; }
.new-folder-box label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.new-folder-box input { width: 100%; }
.modal-note { font-size: 12px; color: var(--muted); margin: 0 0 14px; }
.preview-text { background: #f7f9fc; border: 1px solid var(--border); border-radius: 8px; padding: 14px; font-family: Consolas, "Courier New", monospace; font-size: 12px; white-space: pre-wrap; word-break: break-all; max-height: 56vh; overflow: auto; margin: 0; }
.preview-media { text-align: center; }
.preview-media img { max-width: 100%; max-height: 60vh; }
.preview-media iframe, .preview-media video { width: 100%; height: 60vh; border: 0; background: #f4f6fa; }
.file-detail { background: #f7f9fc; border: 1px solid var(--border); border-radius: 10px; padding: 6px 14px; }
.file-detail-row { display: flex; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; line-height: 1.5; }
.file-detail-row:last-child { border-bottom: 0; }
.file-detail-row > span { flex: 0 0 72px; color: var(--muted); }
.file-detail-row > strong { font-weight: 500; color: var(--text); word-break: break-all; }
.viewer-hint { line-height: 1.7; margin: 14px 0 12px; }
.log-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.log-table th, .log-table td { padding: 7px 8px; border-bottom: 1px solid #f0f3f9; text-align: left; }

/* 提示 */
.toast-root { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: #1f2b45; color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 13px; box-shadow: 0 8px 24px rgba(15, 28, 55, .22); max-width: 360px; animation: slide-in .18s ease; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.offline { position: fixed; top: 0; left: 0; right: 0; z-index: 90; background: #b7791f; color: #fff; text-align: center; padding: 8px; font-size: 13px; }

/* 知识库访问令牌 */
.token-fresh { background: #f0f7ff; border: 1px solid #cfe3ff; border-radius: 10px; padding: 12px 14px; margin: 14px 0; }
.token-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.token-code { display: block; font-family: ui-monospace, Consolas, monospace; font-size: 12px; line-height: 1.6;
  background: #f7f9fc; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  white-space: pre-wrap; word-break: break-all; margin: 6px 0 8px; }
.token-actions { display: flex; align-items: center; gap: 12px; margin: 14px 0 10px; }
.token-guide { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); }
.token-guide .hint { line-height: 1.7; margin-top: 8px; }
.mono { font-family: ui-monospace, Consolas, monospace; }

/* 成员可见范围 */
.scope-all { margin: 6px 0 12px; font-weight: 600; }
.scope-list { max-height: 44vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 6px; background: #fbfcfe; }
.scope-list.muted-block { opacity: .5; }
.scope-item { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.scope-item:hover { background: #f0f5ff; }
.scope-name { font-size: 13px; }

@media (max-width: 860px) {
  .topbar { padding: 0 14px; height: auto; min-height: 64px; flex-wrap: wrap; }
  .app-sub, .user-chip { display: none; }
  .container { padding: 16px 12px 40px; }
  .toolbar { padding: 14px; }
  .search { width: 100%; }
  .file-table th, .file-table td { padding: 10px 12px; }
  .file-table th:nth-child(3), .file-table td:nth-child(3) { display: none; }
  .up-name { width: 120px; }
}
