:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e6ea;
  --border-strong: #d3d8de;
  --text: #1f2733;
  --text-2: #5b6673;
  --text-3: #98a1ab;
  --primary: #2563eb;
  --primary-soft: #eaf0ff;
  --danger: #dc2626;
  --danger-soft: #fdeceb;
  --ok: #15803d;
  --warn: #b45309;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 12px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
}

* { box-sizing: border-box; }

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

body {
  font: 14px/1.5 "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

/* ---------------- 布局 ---------------- */
.app {
  display: grid;
  grid-template-columns: 246px 1fr;
  grid-template-rows: 52px 1fr 28px;
  grid-template-areas: "brand topbar" "side main" "side status";
  height: 100vh;
}

.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  letter-spacing: .2px;
}
.brand .logo {
  width: 24px; height: 24px; border-radius: 7px;
  background: linear-gradient(135deg, #2563eb, #4f8cff);
  display: grid; place-items: center; color: #fff; font-size: 13px;
}
.brand small { color: var(--text-3); font-weight: 400; font-size: 11px; margin-left: 2px; }

.topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.searchbox { position: relative; width: 320px; max-width: 42vw; }
.searchbox input {
  width: 100%; height: 32px; padding: 0 30px 0 30px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface-2); outline: none;
}
.searchbox input:focus { border-color: var(--primary); background: #fff; }
.searchbox .ico { position: absolute; left: 10px; top: 7px; color: var(--text-3); }
.searchbox .clr {
  position: absolute; right: 8px; top: 5px; border: 0; background: none;
  cursor: pointer; color: var(--text-3); display: none;
}
.searchbox.on .clr { display: block; }

.spacer { flex: 1; }

.btn {
  height: 32px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap; transition: .12s;
}
.btn:hover { background: var(--surface-2); border-color: #c3cad3; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1d4fd7; }
.btn.danger { color: var(--danger); border-color: #f0c3c0; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef1f5; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn svg { flex: none; }

.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.seg button {
  height: 30px; padding: 0 9px; border: 0; background: var(--surface); cursor: pointer;
  color: var(--text-2); display: grid; place-items: center;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--primary-soft); color: var(--primary); }

.whoami {
  font-size: 12.5px; color: var(--text-2); white-space: nowrap;
  padding: 3px 9px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px;
}
.whoami:empty { display: none; }

/* ---------------- 侧栏 ---------------- */
.side {
  grid-area: side;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.side-head {
  padding: 10px 12px 6px;
  font-size: 11px; font-weight: 600; letter-spacing: .6px;
  color: var(--text-3); text-transform: uppercase;
}
.tree { flex: 1; overflow: auto; padding: 0 6px 10px; }

.node {
  display: flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 6px; border-radius: 6px;
  cursor: pointer; user-select: none; color: var(--text-2);
  white-space: nowrap;
}
.node:hover { background: #f0f2f5; }
.node.on { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.node .caret {
  width: 14px; height: 14px; flex: none; display: grid; place-items: center;
  color: var(--text-3); font-size: 9px; transition: transform .12s;
}
.node .caret.open { transform: rotate(90deg); }
.node .caret.empty { visibility: hidden; }
.node .lbl { overflow: hidden; text-overflow: ellipsis; }
.node .ico { flex: none; color: #eab308; }

.tree-children { margin-left: 11px; border-left: 1px dashed var(--border-strong); padding-left: 3px; }
.side-foot { border-top: 1px solid var(--border); padding: 9px 12px; font-size: 12px; color: var(--text-3); }
.side-foot .bar { height: 5px; border-radius: 3px; background: #eceff3; overflow: hidden; margin: 6px 0 5px; }
.side-foot .bar i { display: block; height: 100%; background: linear-gradient(90deg, #4f8cff, #2563eb); }

/* ---------------- 主区 ---------------- */
.main { grid-area: main; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }

.crumbs {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 9px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
  min-height: 40px;
}
.crumbs a {
  padding: 3px 7px; border-radius: 6px; color: var(--text-2);
  text-decoration: none; cursor: pointer;
}
.crumbs a:hover { background: #eef1f5; color: var(--text); }
.crumbs a.cur { color: var(--text); font-weight: 600; background: #f0f2f5; }
.crumbs .sep { color: var(--text-3); font-size: 11px; }

.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 9px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.toolbar .divider { width: 1px; height: 20px; background: var(--border); margin: 0 2px; }

.panel { flex: 1; overflow: auto; padding: 12px 14px 40px; position: relative; }

/* 列表视图 */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.rows { width: 100%; border-collapse: collapse; }
.rows th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--text-2);
  background: var(--surface-2); padding: 8px 10px; border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none; white-space: nowrap;
}
.rows th.no-sort { cursor: default; }
.rows th .arw { color: var(--primary); margin-left: 3px; font-size: 10px; }
.rows td { padding: 0 10px; height: 38px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
.rows tr:last-child td { border-bottom: 0; }
.rows tr:hover td { background: #f7f9fc; }
.rows tr.sel td { background: var(--primary-soft); }
.rows .nm { display: flex; align-items: center; gap: 9px; min-width: 0; }
.rows .nm .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .nm.dir .txt { font-weight: 500; }
.rows .c-sel { width: 34px; }
.rows .c-size { width: 96px; color: var(--text-2); }
.rows .c-time { width: 150px; color: var(--text-2); }
.rows .c-kind { width: 84px; color: var(--text-3); }
.rows .c-act { width: 96px; text-align: right; }
.rows .c-act button {
  border: 0; background: none; cursor: pointer; color: var(--text-3);
  padding: 3px 4px; border-radius: 5px;
}
.rows .c-act button:hover { background: #e8ecf2; color: var(--text); }

/* 网格视图 */
.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
}
.card {
  position: relative; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); padding: 10px; cursor: default; transition: .12s;
}
.card:hover { border-color: #c3cad3; box-shadow: var(--shadow); }
.card.sel { border-color: var(--primary); background: var(--primary-soft); }
.card .thumb {
  height: 96px; border-radius: 7px; background: var(--surface-2);
  display: grid; place-items: center; overflow: hidden; margin-bottom: 8px;
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .cname {
  font-size: 12.5px; line-height: 1.35; height: 34px; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  word-break: break-all;
}
.card .cmeta { font-size: 11px; color: var(--text-3); margin-top: 3px; display: flex; justify-content: space-between; }
.card .pick { position: absolute; top: 8px; left: 8px; opacity: 0; }
.card:hover .pick, .card.sel .pick { opacity: 1; }
.card .menu-btn {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px;
  border: 0; border-radius: 6px; background: rgba(255,255,255,.9);
  cursor: pointer; color: var(--text-2); opacity: 0;
}
.card:hover .menu-btn { opacity: 1; }
.card .menu-btn:hover { background: #eef1f5; }

input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }

/* 空态 / 加载 */
.empty { text-align: center; padding: 70px 20px; color: var(--text-3); }
.empty .big { font-size: 34px; margin-bottom: 10px; opacity: .55; }
.empty .hint { font-size: 12.5px; margin-top: 6px; }
.loading { padding: 40px; text-align: center; color: var(--text-3); }
.spin {
  width: 20px; height: 20px; border: 2px solid var(--border-strong);
  border-top-color: var(--primary); border-radius: 50%;
  display: inline-block; animation: sp .7s linear infinite;
}
@keyframes sp { to { transform: rotate(360deg); } }

/* 拖拽层 */
.dropmask {
  position: fixed; inset: 0; background: rgba(37, 99, 235, .07);
  border: 3px dashed var(--primary); border-radius: 12px;
  display: none; place-items: center; z-index: 60; pointer-events: none;
}
.dropmask.on { display: grid; }
.dropmask .box {
  background: var(--surface); padding: 20px 34px; border-radius: 12px;
  box-shadow: var(--shadow-lg); font-weight: 500; color: var(--primary);
}

/* 状态栏 */
.status {
  grid-area: status; display: flex; align-items: center; gap: 14px;
  padding: 0 14px; background: var(--surface); border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-3);
}
.status .path {
  font-family: Consolas, "Courier New", monospace; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; max-width: 46vw;
}

/* ---------------- 对话框 ---------------- */
.mask {
  position: fixed; inset: 0; background: rgba(23, 30, 40, .38);
  display: none; place-items: center; z-index: 80; padding: 24px;
}
.mask.on { display: grid; }
.dlg {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 12px;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.dlg.wide { max-width: 880px; }
.dlg h3 { margin: 0; padding: 15px 18px 0; font-size: 15px; }
.dlg .body { padding: 14px 18px 4px; }
.dlg .body p.msg { margin: 0 0 12px; color: var(--text-2); }
.dlg .body .warn { color: var(--danger); font-weight: 600; }
.dlg input[type=text], .dlg select {
  width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--border-strong);
  border-radius: var(--radius); outline: none;
}
.dlg input[type=text]:focus { border-color: var(--primary); }
.dlg textarea {
  width: 100%; height: 56vh; padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius); outline: none; resize: vertical;
  font: 13px/1.6 Consolas, "Courier New", monospace;
}
.dlg .foot { padding: 14px 18px 16px; display: flex; justify-content: flex-end; gap: 8px; }

/* ---------------- 右键菜单 ---------------- */
.ctx {
  position: fixed; z-index: 90; min-width: 176px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; box-shadow: var(--shadow-lg); display: none;
}
.ctx.on { display: block; }
.ctx button {
  width: 100%; text-align: left; border: 0; background: none; cursor: pointer;
  padding: 7px 10px; border-radius: 6px; display: flex; align-items: center; gap: 8px;
}
.ctx button:hover { background: #eef1f5; }
.ctx button.danger { color: var(--danger); }
.ctx button.danger:hover { background: var(--danger-soft); }
.ctx hr { border: 0; border-top: 1px solid var(--border); margin: 5px 3px; }
.ctx .k { margin-left: auto; font-size: 11px; color: var(--text-3); }

/* ---------------- 提示 / 进度 ---------------- */
.toasts {
  position: fixed; right: 18px; bottom: 44px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  background: #1f2733; color: #fff; padding: 9px 14px; border-radius: 8px;
  box-shadow: var(--shadow-lg); font-size: 13px; max-width: 420px;
  animation: slide .16s ease-out;
}
.toast.err { background: #b91c1c; }
.toast.ok { background: #15803d; }
@keyframes slide { from { opacity: 0; transform: translateY(6px); } }

.progress {
  position: fixed; left: 50%; bottom: 46px; transform: translateX(-50%);
  z-index: 100; width: min(420px, 80vw); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  box-shadow: var(--shadow-lg); display: none;
}
.progress.on { display: block; }
.progress .t { font-size: 13px; display: flex; justify-content: space-between; margin-bottom: 7px; }
.progress .bar { height: 6px; background: #eceff3; border-radius: 3px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .15s; }

.pv { text-align: center; }
.pv img, .pv video { max-width: 100%; max-height: 68vh; border-radius: 8px; background: #f0f2f5; }
.pv audio { width: 100%; }
.pv iframe { width: 100%; height: 68vh; border: 1px solid var(--border); border-radius: 8px; }
.pv .meta { font-size: 12px; color: var(--text-3); margin-top: 10px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cfd5dd; border-radius: 6px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #b4bcc7; background-clip: padding-box; }
