:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2129; --muted: #6b7280; --line: #e5e7eb;
  --primary: #2563eb; --primary-text: #fff; --danger: #dc2626; --hover: #f1f5f9;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111317; --panel: #1a1d23; --text: #e5e7eb; --muted: #9ca3af; --line: #2d323b;
    --primary: #3b82f6; --hover: #22262e; --danger: #f87171; }
}
* { box-sizing: border-box; }
/* hidden 属性必须始终生效：否则 .grid{display:grid} 这类样式会盖过它，导致该隐藏的元素仍显示 */
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
button, .button { font: inherit; padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--text); cursor: pointer; display: inline-block; }
button:hover, .button:hover { background: var(--hover); }
button.primary, .button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.link { border: none; background: none; color: var(--primary); padding: 2px 6px; }
button.link.danger { color: var(--danger); }
input, select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); width: 100%; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .spacer { flex: 1; }
.error { color: var(--danger); }

.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.topbar nav { display: flex; gap: 4px; }
.tab { border: none; background: none; }
.tab.active { background: var(--hover); font-weight: 600; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.crumbs { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
.crumbs a { color: var(--primary); text-decoration: none; padding: 2px 4px; }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
.list th, .list td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.list tbody tr:hover { background: var(--hover); }
.list tbody tr:last-child td { border-bottom: none; }
.list td.name { white-space: normal; word-break: break-all; }
.list .num { text-align: right; }
.list .ops { text-align: right; }
.list a.dir { color: var(--primary); cursor: pointer; text-decoration: none; font-weight: 500; }
.list .empty { text-align: center; color: var(--muted); padding: 24px; }
.tag { font-size: 12px; padding: 1px 6px; border-radius: 4px; background: var(--hover); color: var(--muted); }
.tag.bad { color: var(--danger); }

#uploads .up { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; font-size: 13px; }
#uploads progress { flex: 1; max-width: 300px; }

dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text);
  width: min(520px, calc(100vw - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog label { display: block; margin: 10px 0; }
dialog h3 { margin-top: 0; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text);
  color: var(--bg); padding: 8px 16px; border-radius: 6px; z-index: 10; }

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 28px;
  width: min(360px, 100%); }
.login-card h1 { margin: 0 0 16px; font-size: 20px; }
.login-card label { display: block; margin-bottom: 12px; }
.login-card button { width: 100%; margin-top: 8px; }

@media (max-width: 640px) {
  .list th:nth-child(3), .list td:nth-child(3) { display: none; }
}
button.primary.danger-bg { background: var(--danger); border-color: var(--danger); }
a.link-a { color: var(--primary); padding: 2px 6px; text-decoration: none; }
.tag.ok { color: #16a34a; }
.check-body { max-height: 50vh; overflow-y: auto; }
.check-body ul { margin: 4px 0 12px; padding-left: 20px; }
.check-body li { word-break: break-all; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px 20px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin-bottom: 12px; }
.kv .k { color: var(--muted); }
.kv .v { word-break: break-all; }
.kv .warn { color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 16px; align-items: end; }
.form-grid label { display: block; }
pre.cmd { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; overflow-x: auto; font-size: 13px; white-space: pre-wrap; }
.notice { background: var(--hover); border-radius: 6px; padding: 10px 12px; margin-top: 12px; }
img.qr { width: 200px; height: 200px; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 6px; }
button.danger-text { color: var(--danger); }
.login-card .small a { color: var(--primary); }
/* 拖拽上传：整个标签页区域都可以松手，拖入时显示虚线框和目标目录 */
#tab-files, #tab-r2 { position: relative; min-height: calc(100vh - 120px); }
section.dropping::after {
  content: attr(data-drop-tip); position: absolute; inset: -8px; z-index: 5; pointer-events: none;
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px;
  border: 2px dashed var(--primary); border-radius: 10px; background: rgba(37, 99, 235, .08);
  color: var(--primary); font-size: 18px; font-weight: 600; word-break: break-all;
}
.drop-hint { color: var(--muted); font-size: 12px; }
@media (max-width: 640px) { .drop-hint { display: none; } }
/* 空间占用信息栏 */
.usage { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-bottom: 12px; padding: 8px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.usage b.warn { color: #d97706; } .usage b.bad { color: var(--danger); }
.meter { display: inline-block; width: 140px; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--primary); }
.meter.warn > span { background: #d97706; } .meter.bad > span { background: var(--danger); }
/* 列表 / 网格切换 */
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.seg button.active { background: var(--hover); font-weight: 600; }
/* 网格视图 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; padding: 12px;
  min-height: 240px; align-content: start; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; outline: none; }
.tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px 8px;
  border: 1px solid transparent; border-radius: 8px; cursor: pointer; user-select: none; text-align: center; min-width: 0; }
.tile:hover { background: var(--hover); }
.tile:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.tile.sel { background: rgba(37, 99, 235, .12); border-color: var(--primary); }
.tile .thumb { width: 72px; height: 72px; display: flex; align-items: center; justify-content: center; font-size: 44px; line-height: 1; }
.tile .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.tile .tname { font-size: 13px; width: 100%; word-break: break-all; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile.dir .tname { font-weight: 500; }
.tile .tmeta { font-size: 11px; color: var(--muted); }
.tile .more { position: absolute; top: 4px; right: 4px; padding: 0 6px; line-height: 20px; border: none; background: none;
  color: var(--muted); font-weight: 700; visibility: hidden; }
.tile:hover .more, .tile.sel .more, .tile:focus-within .more { visibility: visible; }
.tile .more:hover { background: var(--line); }
@media (hover: none) { .tile .more { visibility: visible; } }
.grid-empty { grid-column: 1 / -1; text-align: center; padding: 40px 0; }
/* 右键菜单 */
.ctx { position: fixed; z-index: 20; min-width: 150px; padding: 4px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); }
.ctx button { display: block; width: 100%; text-align: left; border: none; border-radius: 5px; padding: 6px 12px; background: none; }
.ctx button:hover, .ctx button:focus { background: var(--hover); outline: none; }
.ctx button.danger { color: var(--danger); }
.ctx .sep { height: 1px; margin: 4px 6px; background: var(--line); }
@media (max-width: 640px) { .meter { width: 90px; } .grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); } }
/* 不可用的按钮（R2 本地备份目录只读时的"新建目录 / 上传"） */
button:disabled, .button.disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
/* 设置 → R2：本地备份目录保护 */
.lock-panel { border: 1px solid var(--line); border-left: 3px solid #16a34a; border-radius: 6px; padding: 10px 12px; margin-top: 16px; }
.lock-panel.open { border-left-color: #d97706; }
.lock-panel p { margin: 6px 0 0; }
.lock-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tag.warn { color: #d97706; }
/* 文件列表：受保护的 R2 本地备份目录置顶分组 */
tr.pinned td { background: var(--hover); }
tr.pinned-last td { border-bottom: 2px solid var(--line); }
.tile.pinned { background: var(--hover); }
/* 目录大小统计（v0.8.8） */
.dirstat { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: -6px 0 12px; font-size: 13px; color: var(--muted); }
.dirstat button { font-size: 12px; padding: 2px 8px; }
.list th.sortable { cursor: pointer; user-select: none; }
.list th.sortable:hover { color: var(--primary); }
.list td .cnt { color: var(--muted); font-size: 12px; margin-left: 4px; }
dialog.wide { width: min(860px, calc(100vw - 32px)); }
.top-wrap { max-height: 60vh; overflow-y: auto; }
.top-wrap td.name a { color: var(--primary); text-decoration: none; }
tr.flash td, .tile.flash { animation: flash 2s ease-out; }
@keyframes flash { from { background: rgba(37, 99, 235, .25); } to { background: transparent; } }
