/* files：文件页（工具条 / 范围切换 / 目录树）+ 文件预览弹窗。 */

.files-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}
.files-left { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; min-width: 0; }
.files-crumb { color: var(--muted); font-size: 12.5px; }
.files-crumb a { color: var(--amber); text-decoration: none; cursor: pointer; }

/* 工作区 / 共享目录切换 */
.scope-switch {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg); max-width: 100%;
}
.scope-btn {
  background: transparent;
  border: 1px solid transparent; border-radius: 6px;
  color: var(--muted);
  font-family: var(--sans); font-size: 12px; line-height: 20px;
  padding: 4px 10px; min-height: 30px; white-space: nowrap;
  cursor: pointer;
  transition: color 140ms ease, background 140ms ease, border-color 140ms ease;
}
.scope-btn:hover:not(:disabled) { color: var(--text); background: var(--panel-2); }
.scope-btn.active {
  color: var(--amber);
  border-color: var(--line);
  background: var(--panel);
  position: relative; z-index: 1;
}
.scope-btn:focus-visible { outline-offset: -2px; }
.scope-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ? 帮助提示（hover / 键盘聚焦 / 触屏点按均可弹出） */
.help {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px;
  border: 1px solid var(--line); border-radius: 50%;
  color: var(--muted);
  font-family: var(--mono); font-size: 11px;
  cursor: help; user-select: none;
}
.help:hover, .help:focus { color: var(--amber); border-color: var(--amber); outline: none; }
.help-tip {
  display: none;
  position: absolute; top: 24px; left: -12px; z-index: 30;
  width: min(340px, 72vw);
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 12.5px; line-height: 1.7; text-align: left;
  box-shadow: var(--shadow-sm);
  cursor: auto;
}
.help-tip b { color: var(--amber); font-weight: 600; }
.help-tip code {
  font-family: var(--mono); font-size: 11.5px;
  background: var(--code-bg); border-radius: 4px; padding: 1px 5px;
}
.help:hover .help-tip, .help:focus .help-tip, .help:focus-within .help-tip { display: block; }
.files-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.check { color: var(--muted); font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; }

/* 文件列表：名称 | 权限 | 大小 | 修改时间 | 操作 */
.files-head, .file-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px 88px 168px 156px;
  gap: 14px; align-items: center;
  padding: 0 10px;
}
.files-head {
  margin: 8px 20px 0;
  padding-top: 6px; padding-bottom: 6px;
  font-size: 11px; letter-spacing: 0;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
}
.files-head .num { text-align: right; }
.files-head .factions-head { text-align: right; }
.files-list { flex: 1; overflow-y: auto; padding: 0 20px 20px; }
.file-row {
  padding-top: 6px; padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--mono); font-size: 13px;
}
.file-row:hover { background: color-mix(in srgb, var(--amber) 6%, transparent); }
.file-row .fname {
  display: flex; align-items: center; gap: 7px;
  min-width: 0;
  padding-left: calc(var(--depth, 0) * 20px);
}
.file-row .farrow {
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
  width: 16px; text-align: center;
  color: var(--muted);
  cursor: pointer; user-select: none;
  transition: transform 0.15s ease, color 0.15s ease;
}
.file-row .farrow:hover, .file-row .farrow:focus { color: var(--amber); outline: none; }
.file-row .farrow.open { transform: rotate(90deg); color: var(--amber); }
/* 展开加载中：箭头原地换成小转圈 */
.file-row .farrow.busy {
  transform: none; cursor: progress;
  display: inline-flex; align-items: center; justify-content: center;
}
.file-row .farrow .spin { width: 9px; height: 9px; border-width: 2px; }
.file-row .fglyph { flex: none; width: 16px; text-align: center; color: var(--muted); }
.file-row .flabel {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: pointer;
}
.file-row .flabel:hover { color: var(--amber); text-decoration: underline; text-underline-offset: 3px; }
.file-row.dir .flabel { color: var(--amber); }
.file-row.empty-dir { border-bottom: none; }
.file-row .muted { color: var(--muted); font-style: normal; }
.file-row .fperm { color: var(--muted); font-size: 12px; letter-spacing: 0; }
.file-row .fsize { color: var(--muted); font-size: 12px; text-align: right; }
.file-row .ftime { color: var(--muted); font-size: 12px; }
.file-row .factions {
  display: flex; align-items: center; justify-content: flex-end; gap: 4px;
  min-width: 100px;
}
.file-act {
  width: 28px; height: 28px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  border: 1px solid transparent; border-radius: 6px;
  background: transparent; color: var(--muted);
}
.file-act:hover, .file-act:focus-visible {
  color: var(--amber); border-color: var(--line); background: var(--panel-2);
}
.file-act.danger:hover, .file-act.danger:focus-visible { color: var(--red); border-color: var(--red-line); }
.file-act:disabled { opacity: 0.4; cursor: progress; }
.files-empty { color: var(--muted); padding: 24px 10px; font-size: 13px; }
/* 目录读取中：直接用 base.css 的 .loading-block */

/* ---- 移动 / 删除文件 ---- */
.dlg-file-move { width: min(560px, 94vw); padding-bottom: 22px; overflow: hidden; }
.file-op-source, .file-move-target {
  display: grid; grid-template-columns: 72px minmax(0, 1fr); align-items: baseline; gap: 10px;
  color: var(--muted); font-size: 12px;
}
.file-op-source { margin-bottom: 16px; }
.file-op-source code, .file-move-target code {
  min-width: 0; color: var(--text); overflow-wrap: anywhere; font-size: 12px;
}
.file-move-nav {
  display: flex; align-items: center; gap: 14px;
  padding-bottom: 10px; border-bottom: 1px solid var(--line);
}
.file-move-crumb {
  flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap;
  color: var(--muted); font-size: 12px; scrollbar-width: none;
}
.file-move-crumb::-webkit-scrollbar { display: none; }
.file-move-crumb button {
  padding: 0; border: 0; background: transparent; color: var(--amber); font: inherit;
}
.file-move-dirs {
  height: 260px; overflow-y: auto;
  border-bottom: 1px solid var(--line);
}
.file-move-dir {
  width: 100%; height: 40px;
  display: flex; align-items: center; gap: 9px;
  padding: 0 8px; border: 0; border-bottom: 1px solid var(--line-soft);
  border-radius: 0; background: transparent; color: var(--text); text-align: left;
}
.file-move-dir:hover, .file-move-dir:focus-visible { background: var(--panel-2); color: var(--amber); outline: none; }
.file-move-dir .dir-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-move-dir .dir-arrow { color: var(--muted); }
.file-move-dir:disabled { color: var(--muted); opacity: 0.5; cursor: not-allowed; }
.file-move-dir:disabled:hover { background: transparent; color: var(--muted); }
.file-move-empty { margin: 0; padding: 24px 8px; color: var(--muted); font-size: 12px; }
.file-move-dirs .loading-block { min-height: 100%; }
.file-move-target { padding-top: 12px; }
.dlg-file-move .login-error, #dlg-file-delete .login-error { margin: 10px 0 0; }
#dlg-file-delete p { line-height: 1.65; overflow-wrap: anywhere; }

/* ---- 文件预览 / 编辑 ---- */
.dlg-file {
  width: min(960px, 94vw);
  height: min(82vh, 900px);
  padding: 0;
}
.fv { display: flex; flex-direction: column; height: 100%; }
.fv-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.fv-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; flex: 1; }
.fv-name {
  color: var(--amber); font-size: 14px; font-weight: 600;
  max-width: 60%; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fv-meta {
  color: var(--muted); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fv-actions { display: flex; align-items: center; gap: 8px; }
.fv-state {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 12px; margin-right: 4px;
}
.fv-body { flex: 1; min-height: 0; min-width: 0; display: flex; }
.fv-source {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  background: var(--code-bg); --fv-gutter-digits: 3;
}
.fv-codearea { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.fv-gutter {
  flex: none; position: relative; overflow: hidden; user-select: none;
  width: calc(var(--fv-gutter-digits) * 1ch + 24px);
  font: 13px/22px var(--mono); color: var(--muted);
  background: var(--code-head); border-right: 1px solid var(--code-line);
}
.fv-gutter span { position: absolute; left: 0; right: 0; padding-right: 12px; text-align: right; }
.fv-gutter .active { color: var(--amber); background: var(--panel-2); }
.fv-codepane { flex: 1; min-width: 0; position: relative; overflow: hidden; }
.fv-editor, .fv-highlight {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  color: var(--text);
  border: none; outline: none; resize: none;
  padding: 14px 16px;
  font: 13px/22px var(--mono); font-variant-ligatures: none;
  letter-spacing: normal; tab-size: 4; white-space: pre; overflow-wrap: normal;
  text-align: left; direction: ltr;
}
.fv-highlight { overflow: hidden; pointer-events: none; background: transparent; }
.fv-codepane .fv-editor {
  background: transparent; color: transparent; caret-color: var(--text);
  overflow: auto; resize: none; outline: none;
}
.fv-editor::selection { color: transparent; background: color-mix(in srgb, var(--amber) 28%, transparent); }
.fv-current-line { position: absolute; left: 0; right: 0; background: var(--code-head); pointer-events: none; }
.fv-source-status {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  padding: 6px 12px; border-top: 1px solid var(--code-line);
  background: var(--code-head); color: var(--muted); font-size: 11px;
}
/* Prism 的 tag 等类名也被页面组件使用；着色不能改变字宽、行高或盒模型，
 * 否则可见代码会偏离负责输入的 textarea。先隔离 token，再只赋予颜色。 */
.fv-highlight .token { all: unset; }
.fv-highlight .token.comment, .fv-highlight .token.prolog,
.fv-highlight .token.doctype, .fv-highlight .token.cdata { color: var(--muted); }
.fv-highlight .token.keyword, .fv-highlight .token.tag,
.fv-highlight .token.boolean, .fv-highlight .token.important { color: var(--syntax-keyword); }
.fv-highlight .token.string, .fv-highlight .token.char,
.fv-highlight .token.attr-value, .fv-highlight .token.inserted { color: var(--green); }
.fv-highlight .token.number, .fv-highlight .token.constant,
.fv-highlight .token.symbol, .fv-highlight .token.attr-name { color: var(--amber); }
.fv-highlight .token.function, .fv-highlight .token.class-name,
.fv-highlight .token.property, .fv-highlight .token.selector { color: var(--syntax-function); }
.fv-highlight .token.operator, .fv-highlight .token.punctuation { color: var(--muted); }
.fv-highlight .token.deleted { color: var(--red); }
@media (forced-colors: active) {
  .fv-highlight { visibility: hidden; }
  .fv-codepane .fv-editor { color: CanvasText; caret-color: CanvasText; }
  .fv-editor::selection { color: HighlightText; background: Highlight; }
}
.fv-imgwrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  overflow: auto;
  background:
    repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%) 0 0 / 24px 24px;
  padding: 16px;
}
.fv-imgwrap img { max-width: 100%; max-height: 100%; box-shadow: var(--shadow-sm); }
.fv-notice {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  color: var(--muted); font-size: 13px;
  padding: 24px; text-align: center;
}
.fv-notice .spin { width: 30px; height: 30px; border-width: 3px; }
.fv-actions .dlg-x { margin: 0; }
/* HTML 预览把这排撑得很满；宽度不够时让动作区自己折行，别把标题挤没 */
.fv-actions { flex-wrap: wrap; justify-content: flex-end; }
.fv-actions .scope-btn { height: 26px; padding: 0 10px; font-size: 12px; }
.fv-auto { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* HTML 渲染预览：iframe 居中，视口档位靠 max-width 收窄模拟平板/手机 */
.fv-framewrap {
  flex: 1; min-width: 0;
  display: flex; justify-content: center;
  overflow: auto;
  background: var(--panel-2);
}
.fv-frame {
  flex: 1; min-width: 0; width: 100%; height: 100%;
  border: 0; background: #fff; /* 原型自己不画底色时，白底才是它在浏览器里的样子 */
}
.fv-framewrap[data-vp="tablet"], .fv-framewrap[data-vp="phone"] { padding: 12px 0; }
.fv-framewrap[data-vp="tablet"] .fv-frame,
.fv-framewrap[data-vp="phone"] .fv-frame {
  flex: none; height: 100%;
  border-radius: 10px; box-shadow: var(--shadow-sm);
}
.fv-framewrap[data-vp="tablet"] .fv-frame { width: min(834px, 100%); }
.fv-framewrap[data-vp="phone"] .fv-frame { width: min(390px, 100%); }

/* Markdown 渲染预览：正文限宽居中，排版直接借用对话流的 .msg.agent */
.fv-mdwrap {
  flex: 1; min-width: 0;
  overflow: auto;
  background: var(--bg);
  padding: 20px 24px 40px;
}
.fv-md { max-width: 780px; margin: 0 auto; font-size: 14px; }

/* 全屏：铺满窗口看整页布局 */
.dlg-file.fv-max {
  width: 100vw; height: 100dvh;
  max-width: 100vw; max-height: 100dvh;
  margin: 0; border: none; border-radius: 0;
}

/* ---- 窄屏：工具条两行化、面包屑横滚、行高加大、列只留名称+大小、预览全屏 ---- */
@media (max-width: 760px) {
  .files-bar { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 12px; }
  .files-left { flex-wrap: nowrap; gap: 10px; }
  .files-crumb {
    flex: 1; min-width: 0;
    overflow-x: auto; white-space: nowrap;
    scrollbar-width: none;
  }
  .files-crumb::-webkit-scrollbar { display: none; }
  .files-actions { justify-content: flex-end; }
  .files-actions .check { margin-right: auto; }

  .files-head, .file-row { grid-template-columns: minmax(0, 1fr) 54px 148px; gap: 8px; }
  .files-head span:nth-child(2), .files-head span:nth-child(4),
  .file-row .fperm, .file-row .ftime { display: none; }
  .files-head { margin: 4px 12px 0; }
  .files-list { padding: 0 12px 14px; }
  .file-row { padding-top: 10px; padding-bottom: 10px; } /* 触控行高 ≈40px */
  .file-row .factions { min-width: 148px; gap: 2px; }

  .dlg-file-move { width: 94vw; padding: 20px 18px; }
  .file-move-nav { align-items: stretch; flex-direction: column; gap: 10px; }
  .file-move-nav .scope-switch { align-self: flex-start; }
  .file-move-dirs { height: min(42dvh, 300px); }

  .dlg-file {
    width: 100vw; height: 100dvh;
    max-width: 100vw; max-height: 100dvh;
    margin: 0; border: none; border-radius: 0;
  }
  /* 窄屏本来就满屏了，视口模拟和全屏按钮都没有意义，腾出位置给模式切换 */
  .fv-vps, #fv-full { display: none !important; }
  .fv-head { padding: 10px 12px; }
  .fv-title { flex-basis: 100%; }
  .fv-actions { gap: 6px; width: 100%; }
  .fv-mdwrap { padding: 14px 14px 30px; }
}

/* 上传进度条 */
.upload-progress {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 20px; border-bottom: 1px solid var(--line-soft);
}
.upload-progress-track {
  flex: 1; height: 6px; border-radius: 3px;
  background: var(--panel-2); overflow: hidden;
}
#upload-progress-fill {
  display: block; height: 100%; width: 0;
  background: var(--amber); transition: width 0.15s ease;
}
#upload-progress-text { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* 拖拽上传高亮 */
#tab-files { position: relative; }
#tab-files.drag-over { outline: 2px dashed var(--amber); outline-offset: -6px; }
#tab-files.drag-over::after {
  content: "松开以上传文件";
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: var(--amber);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  pointer-events: none;
}

/* 新建文件夹 / 重命名 输入框 */
#dlg-file-name { width: min(420px, 94vw); }
.file-name-field { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.file-name-field label { font-size: 13px; color: var(--muted); }
.file-name-field input {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); color: var(--text); font-family: var(--mono);
}
.file-name-field input:focus-visible { outline: none; border-color: var(--amber); }
#dlg-file-name .login-error { margin: 10px 0 0; }
