:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --line: #e2e5ea;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #2f6df6;
  --accent-soft: #e7effe;
  --danger: #d92d20;
  --ok: #12915b;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a20;
    --panel-2: #1e222a;
    --line: #2a2f39;
    --text: #e6e8ec;
    --muted: #939aa8;
    --accent: #5b8dff;
    --accent-soft: #1c2740;
    --danger: #f97066;
    --ok: #45c48a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 通用控件 ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field {
  width: 100%; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  outline: none;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- 登录 ---------- */

#login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
}
#login .card {
  width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow);
}
#login h1 { margin: 0 0 4px; font-size: 20px; }
#login p.sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
#login .row { display: flex; gap: 8px; }
#login .field { margin-bottom: 12px; }
.err { color: var(--danger); font-size: 13px; min-height: 20px; margin-top: 8px; }

/* ---------- 布局 ---------- */

header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: .2px; }
.brand .icon { width: 20px; height: 20px; color: var(--accent); }

.search { position: relative; flex: 1; max-width: 420px; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 34px; background: var(--panel-2); }

.quota { min-width: 140px; font-size: 12px; color: var(--muted); }
.quota .bar { height: 5px; border-radius: 3px; background: var(--panel-2); overflow: hidden; margin-top: 4px; }
.quota .bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .4s; }
.quota .bar span.warn { background: #f59e0b; }
.quota .bar span.full { background: var(--danger); }

main { max-width: 1120px; margin: 0 auto; padding: 16px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-bottom: 10px; font-size: 13px; }
.crumbs a { color: var(--muted); text-decoration: none; padding: 3px 7px; border-radius: 6px; cursor: pointer; }
.crumbs a:hover { background: var(--panel-2); color: var(--text); }
.crumbs a.here { color: var(--text); font-weight: 600; }
.crumbs .sep { color: var(--muted); opacity: .5; }

/* ---------- 文件表 ---------- */

.table { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tr {
  display: grid; grid-template-columns: 34px 1fr 100px 150px 36px;
  align-items: center; gap: 8px; padding: 0 10px;
  border-bottom: 1px solid var(--line);
}
.tr:last-child { border-bottom: none; }
.thead { color: var(--muted); font-size: 12px; height: 38px; background: var(--panel-2); user-select: none; }
.thead .sortable { cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.thead .sortable:hover { color: var(--text); }
.row { height: 48px; cursor: default; }
.row:hover { background: var(--panel-2); }
.row.sel { background: var(--accent-soft); }
.row.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }

.cell-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-name .icon { width: 20px; height: 20px; color: var(--muted); }
.cell-name .icon.folder { color: var(--accent); }
.cell-name .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.cell-name .label:hover { text-decoration: underline; }
.cell-name .badge {
  font-size: 11px; padding: 1px 6px; border-radius: 20px; flex: none;
  background: var(--accent-soft); color: var(--accent); border: 1px solid transparent;
}
.cell-dim { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.more { border: none; background: transparent; color: var(--muted); padding: 6px; border-radius: 6px; line-height: 0; }
.more:hover { background: var(--line); color: var(--text); }

.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty .icon { width: 40px; height: 40px; opacity: .4; margin-bottom: 10px; }

/* 拖放整页高亮 */
body.dragging::after {
  content: "松开即可上传";
  position: fixed; inset: 12px; z-index: 60; pointer-events: none;
  border: 2px dashed var(--accent); border-radius: 16px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  display: grid; place-items: center; font-size: 18px; font-weight: 600; color: var(--accent);
}

/* ---------- 菜单 ---------- */

.menu {
  position: fixed; z-index: 80; min-width: 172px; padding: 5px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
}
.menu button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border: none; background: transparent; border-radius: 7px;
  text-align: left; font-size: 13px;
}
.menu button:hover { background: var(--panel-2); }
.menu button.danger { color: var(--danger); }
.menu hr { border: none; border-top: 1px solid var(--line); margin: 5px 2px; }

/* ---------- 弹层 ---------- */

.mask {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(8, 10, 14, .55); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: 100%; max-width: 440px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 20px; max-height: 85dvh; overflow: auto;
}
.modal h3 { margin: 0 0 14px; font-size: 16px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal .hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.picker { border: 1px solid var(--line); border-radius: 8px; max-height: 280px; overflow: auto; }
.picker .p-row { display: flex; align-items: center; gap: 8px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.picker .p-row:last-child { border-bottom: none; }
.picker .p-row:hover { background: var(--panel-2); }
.picker .p-row .icon { color: var(--accent); }

/* 预览 */
.viewer { position: fixed; inset: 0; z-index: 95; background: rgba(8, 10, 14, .9); display: flex; flex-direction: column; }
.viewer .vhead { display: flex; align-items: center; gap: 10px; padding: 12px 16px; color: #eaecef; }
.viewer .vhead .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.viewer .vhead .btn { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .18); color: #eaecef; }
.viewer .vbody { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 16px 16px; }
.viewer img, .viewer video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.viewer iframe { width: 100%; height: 100%; border: none; border-radius: 8px; background: #fff; }
.viewer .edit-body { padding: 0 16px 16px; }
.edit-area {
  width: 100%; height: 100%; resize: none; outline: none;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 16px;
  font: 13px/1.7 ui-monospace, "Cascadia Code", Consolas, "Microsoft YaHei", monospace;
  tab-size: 4;
}
.edit-area:focus { border-color: var(--accent); }
.edit-area:disabled { opacity: .6; }

.viewer pre {
  width: 100%; height: 100%; margin: 0; overflow: auto; white-space: pre-wrap; word-break: break-word;
  background: var(--panel); color: var(--text); border-radius: 8px; padding: 16px;
  font: 13px/1.6 ui-monospace, "Cascadia Code", Consolas, monospace;
}

/* ---------- 上传队列 ---------- */

#uploads {
  position: fixed; right: 16px; bottom: 16px; z-index: 70; width: 340px; max-width: calc(100vw - 32px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden;
}
#uploads .uhead { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 600; }
#uploads .uhead .spacer { flex: 1; }
#uploads .ulist { max-height: 260px; overflow: auto; }
.uitem { padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 12px; }
.uitem:last-child { border-bottom: none; }
.uitem .top { display: flex; gap: 8px; align-items: center; }
.uitem .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uitem .st { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.uitem .st.err { color: var(--danger); }
.uitem .st.done { color: var(--ok); }
.uitem .bar { height: 4px; background: var(--panel-2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.uitem .bar span { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .2s; }

/* ---------- 提示条 ---------- */

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  z-index: 120; padding: 10px 16px; border-radius: 10px; font-size: 13px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); color: #fff; }

@media (max-width: 680px) {
  .tr { grid-template-columns: 30px 1fr 74px 36px; }
  .col-date { display: none; }
  .quota { display: none; }
  header { flex-wrap: wrap; }
  .search { max-width: none; order: 3; flex-basis: 100%; }
}
