:root {
  --bg: #f4f6fa;
  --bg-soft: #e9edf5;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #101827;
  --text-soft: #47536b;
  --muted: #7a8699;
  --border: #e3e8f0;
  --border-strong: #cfd7e6;
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-soft: #e8f0ff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #059669;
  --shadow: 0 1px 2px rgba(16, 24, 39, .05), 0 8px 24px -12px rgba(16, 24, 39, .18);
  --radius: 14px;
  --radius-sm: 10px;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --panel: #151a22;
  --panel-2: #1b212b;
  --text: #e6edf3;
  --text-soft: #b3bcc9;
  --muted: #8b95a5;
  --border: #262d38;
  --border-strong: #333c48;
  --brand: #4f8cff;
  --brand-hover: #6c9dff;
  --brand-soft: #16233a;
  --danger: #f87171;
  --danger-soft: #2b1a1a;
  --ok: #34d399;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -16px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }

/* hidden 属性必须优先于任何 display 规则，否则登录页会盖住后台 */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

button { font: inherit; color: inherit; }

input { font: inherit; }

.icon { width: 18px; height: 18px; flex: none; stroke-width: 1.9; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 15px;
  letter-spacing: .2px;
  white-space: nowrap;
}

.brand-badge {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  color: #fff;
}

.search {
  position: relative;
  flex: 1;
  max-width: 420px;
  margin-left: auto;
}

.search .icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.search input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

/* ---------- 布局 ---------- */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 22px 24px 72px;
}

.crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.crumbs button {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.crumbs button:hover { background: var(--bg-soft); color: var(--text); }
.crumbs .sep { color: var(--border-strong); }
.crumbs .current { color: var(--text); font-weight: 600; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 12px;
  flex-wrap: wrap;
}

.meta { color: var(--muted); font-size: 13px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: background .15s, border-color .15s, transform .1s, color .15s;
}

.btn:hover { border-color: var(--border-strong); background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--bg-soft); }

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 10px;
}

/* ---------- 卡片与列表 ---------- */
.section-title {
  margin: 18px 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--muted);
  text-transform: uppercase;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}

.folder-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  transition: border-color .15s, transform .12s, box-shadow .15s;
}

.folder-card:hover {
  border-color: var(--brand);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.folder-card .icon { color: var(--brand); }

.folder-name {
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-top: 1px solid var(--border);
}

.row:first-child { border-top: 0; }
.row:hover { background: var(--panel-2); }

.row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
}

.row-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 520;
}

.row-sub { color: var(--muted); font-size: 12px; }
.row-size { color: var(--muted); font-size: 12px; width: 92px; text-align: right; flex: none; }
.row-time { color: var(--muted); font-size: 12px; width: 108px; flex: none; }
.row-actions { display: flex; gap: 6px; flex: none; }

.kind-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--bg-soft); color: var(--text-soft); }
.kind-image .kind-icon { background: #dbeafe; color: #2563eb; }
.kind-video .kind-icon { background: #ede9fe; color: #7c3aed; }
.kind-audio .kind-icon { background: #dcfce7; color: #16a34a; }
.kind-pdf .kind-icon, .kind-doc .kind-icon { background: #fee2e2; color: #dc2626; }
.kind-archive .kind-icon { background: #fef3c7; color: #b45309; }
.kind-text .kind-icon, .kind-code .kind-icon { background: var(--bg-soft); color: var(--text-soft); }
.kind-folder .kind-icon { background: var(--brand-soft); color: var(--brand); }

[data-theme="dark"] .kind-image .kind-icon { background: #12233f; color: #6c9dff; }
[data-theme="dark"] .kind-video .kind-icon { background: #221a3f; color: #a78bfa; }
[data-theme="dark"] .kind-audio .kind-icon { background: #12291f; color: #4ade80; }
[data-theme="dark"] .kind-pdf .kind-icon, [data-theme="dark"] .kind-doc .kind-icon { background: #2b1616; color: #f87171; }
[data-theme="dark"] .kind-archive .kind-icon { background: #2a2110; color: #fbbf24; }

.empty {
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 64px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty .icon { width: 34px; height: 34px; opacity: .6; }

/* ---------- 上传区 ---------- */
.dropzone {
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 34px 20px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text-soft);
  text-align: center;
  transition: border-color .15s, background .15s;
}

.dropzone.hot {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--text);
}

.dropzone .big-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--brand-soft);
  color: var(--brand);
}

.dropzone .hint { color: var(--muted); font-size: 12.5px; }

.queue { margin-top: 14px; display: grid; gap: 8px; }

.queue-item {
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.q-head { display: flex; align-items: center; gap: 10px; }
.q-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-size { color: var(--muted); font-size: 12px; flex: none; }
.q-state { font-size: 12px; flex: none; }
.q-state.ok { color: var(--ok); }
.q-state.err { color: var(--danger); }
.q-size-wrap { margin-top: 7px; }

.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), #7c3aed);
  transition: width .18s ease;
}

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  padding: 28px;
  background: rgba(9, 12, 18, .62);
  backdrop-filter: blur(6px);
  overflow: auto;
}

.modal.open { display: grid; place-items: center; }

.modal-card {
  width: min(920px, 100%);
  max-height: calc(100vh - 56px);
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.modal-body { padding: 18px; overflow: auto; }

.preview-stage { display: grid; place-items: center; }

.preview-stage img,
.preview-stage video {
  max-width: 100%;
  max-height: 66vh;
  border-radius: 10px;
  background: #000;
}

.preview-stage audio { width: 100%; }

.preview-stage pre {
  margin: 0;
  width: 100%;
  max-height: 60vh;
  overflow: auto;
  padding: 14px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; color: var(--muted); }

.field input {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  outline: none;
}

.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 13px 16px;
  border-top: 1px solid var(--border);
}

/* ---------- 登录 ---------- */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 24px; }

.login-card {
  width: min(390px, 100%);
  padding: 26px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.login-card h1 { margin: 14px 0 6px; font-size: 19px; }
.login-card p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }

.login-error {
  margin-bottom: 12px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

/* ---------- 提示 ---------- */
#toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  display: grid;
  gap: 8px;
  justify-items: end;
}

.toast {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: pop .18s ease;
}

.toast.ok { border-color: color-mix(in srgb, var(--ok) 55%, transparent); }
.toast.err { border-color: color-mix(in srgb, var(--danger) 55%, transparent); color: var(--danger); }

@keyframes pop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.spin { animation: spin .9s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .container { padding: 16px 14px 64px; }
  .row-time { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .search { max-width: none; }
  .modal { padding: 0; }
  .modal-card { max-height: 100vh; height: 100vh; border-radius: 0; border: 0; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
