:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f0f3f8;
  --text: #1c2430;
  --muted: #687385;
  --border: #dde3ec;
  --accent: #2481cc;
  --accent-2: #1a6eb0;
  --accent-soft: rgba(36, 129, 204, 0.12);
  --danger: #d14343;
  --danger-soft: rgba(209, 67, 67, 0.12);
  --ok: #2e9d5b;
  --warn-bg: #fff6e0;
  --warn-text: #7a5300;
  --shadow: 0 8px 30px rgba(20, 30, 50, 0.12);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --panel: #1a2029;
    --panel-2: #222a35;
    --text: #e3e8ef;
    --muted: #8f9bab;
    --border: #2d3644;
    --accent: #3d9be0;
    --accent-2: #5aaeea;
    --accent-soft: rgba(61, 155, 224, 0.16);
    --danger: #ef6b6b;
    --danger-soft: rgba(239, 107, 107, 0.16);
    --warn-bg: #3a3017;
    --warn-text: #f2d48a;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { min-height: 100vh; }
button, input { font: inherit; color: inherit; }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.92em; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }
.spacer { flex: 1; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pre-line { white-space: pre-line; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.plain { margin: 6px 0; padding-left: 18px; }
.plain li { margin: 4px 0; word-break: break-all; }

.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- 按钮与输入 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.input, .field input, .filter {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); outline: none;
}
.input:focus, .field input:focus, .filter:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.field input { color: var(--text); font-size: 14px; }
.filter { width: 180px; }

.notice { margin: 10px 16px 0; padding: 10px 14px; border-radius: 8px; background: var(--panel-2); color: var(--muted); }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.login-card .notice { margin: 0; }

/* ---------- 登录 ---------- */
.login { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.login-card { width: min(380px, 100%); padding: 32px 28px; display: grid; gap: 16px; }
.login-card .muted { margin: -8px 0 0; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; }
.brand.big { font-size: 22px; }
.logo {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #37aee2, #1e96c8); color: #fff; font-size: 12px; font-weight: 700; letter-spacing: 0.5px;
}
.brand.big .logo { width: 38px; height: 38px; font-size: 14px; }

/* ---------- 主界面 ---------- */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.usage { font-size: 13px; }
.user { color: var(--muted); }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 12px 16px 8px; }
.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; min-width: 0; font-size: 15px; }
.breadcrumb button {
  border: 0; background: none; padding: 4px 6px; border-radius: 6px; cursor: pointer; color: var(--accent);
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.breadcrumb button:hover { background: var(--accent-soft); }
.breadcrumb button[aria-current] { color: var(--text); font-weight: 600; cursor: default; background: none; }
.breadcrumb .sep { color: var(--muted); }

.selection-bar {
  display: flex; align-items: center; gap: 8px; margin: 0 16px 8px; padding: 6px 10px;
  border-radius: 8px; background: var(--accent-soft);
}

.listing { flex: 1; margin: 0 16px 16px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.files { width: 100%; border-collapse: collapse; table-layout: fixed; }
.files th, .files td { padding: 0 10px; height: 44px; border-bottom: 1px solid var(--border); text-align: left; }
.files thead th { height: 38px; background: var(--panel-2); font-weight: 500; color: var(--muted); font-size: 13px; }
.files tbody tr:last-child td { border-bottom: 0; }
.files tbody tr:hover { background: var(--panel-2); }
.files tbody tr.selected { background: var(--accent-soft); }
.col-check { width: 42px; }
.col-size { width: 110px; color: var(--muted); }
.col-time { width: 160px; color: var(--muted); }
.col-actions { width: 130px; text-align: right !important; white-space: nowrap; }
.sort { border: 0; background: none; padding: 0; cursor: pointer; color: inherit; font: inherit; }
.sort[data-dir="1"]::after { content: " ▲"; font-size: 10px; }
.sort[data-dir="-1"]::after { content: " ▼"; font-size: 10px; }

.name-link {
  display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; border: 0; background: none;
  padding: 0; cursor: pointer; text-align: left; color: var(--text);
}
.name-link span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-link:hover span:last-child { color: var(--accent); text-decoration: underline; }

.icon {
  flex: none; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 6px;
  font-size: 9px; font-weight: 700; text-transform: uppercase; color: #fff; background: #8592a6; overflow: hidden;
}
.icon.dir { background: #f0b429; position: relative; }
.icon.dir::before { content: ""; position: absolute; left: 4px; top: 6px; width: 10px; height: 4px; background: #d99a12; border-radius: 2px 2px 0 0; }
.icon.image { background: #8e5bd8; }
.icon.video { background: #e0546b; }
.icon.audio { background: #e08a2c; }
.icon.text { background: #4f8fd6; }
.icon.archive { background: #6d7a8c; }
.icon.pdf { background: #d6453d; }

.icon-btn {
  border: 0; background: none; color: var(--accent); cursor: pointer; padding: 6px 8px; border-radius: 6px;
  text-decoration: none; font-size: 13px;
}
.icon-btn:hover { background: var(--accent-soft); }

.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.listing .notice { margin: 10px; }

.menu {
  position: fixed; z-index: 50; min-width: 150px; padding: 6px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); display: grid;
}
.menu button { border: 0; background: none; text-align: left; padding: 8px 12px; border-radius: 6px; cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--panel-2); outline: none; }
.menu button.danger { color: var(--danger); }

.drop-overlay {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; pointer-events: none;
  background: rgba(36, 129, 204, 0.14); border: 3px dashed var(--accent);
}
.drop-overlay div { padding: 16px 26px; border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); font-size: 16px; }

/* ---------- 上传队列 ---------- */
.uploads {
  position: fixed; right: 16px; bottom: 16px; z-index: 30; width: min(420px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; max-height: 60vh;
}
.uploads header { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; border-bottom: 1px solid var(--border); }
.uploads.collapsed ul { display: none; }
.uploads.collapsed header { border-bottom: 0; }
.uploads ul { list-style: none; margin: 0; padding: 4px 0; overflow: auto; }
.upload-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 8px 14px; }
.upload-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item .meta { grid-column: 1; font-size: 12px; color: var(--muted); }
.upload-item .actions { grid-row: 1 / span 2; grid-column: 2; align-self: center; }
.upload-item.error .meta { color: var(--danger); }
.upload-item.done .meta { color: var(--ok); }
.progress { grid-column: 1; height: 4px; border-radius: 2px; background: var(--panel-2); overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.upload-item.done .progress div { background: var(--ok); }
.upload-item.error .progress div { background: var(--danger); }

/* ---------- 对话框 ---------- */
.dialog {
  width: min(440px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--panel); color: var(--text); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(10, 15, 25, 0.5); }
.dialog form { display: grid; gap: 14px; padding: 22px; }
.dialog h2 { margin: 0; font-size: 17px; }
.dialog h3 { margin: 18px 0 6px; font-size: 14px; }
.dialog p { margin: 0; word-break: break-word; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog.wide { width: min(760px, calc(100vw - 32px)); }
.dialog > header { display: flex; align-items: center; gap: 8px; padding: 12px 14px 12px 20px; border-bottom: 1px solid var(--border); }
.dialog > header h2 { font-size: 16px; }
.rclone-body { padding: 14px 20px 20px; max-height: 75vh; overflow: auto; }
.rclone-body > .field { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.code { position: relative; }
.code pre {
  margin: 0; padding: 12px 14px; padding-right: 70px; border-radius: 8px; background: var(--panel-2);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; white-space: pre-wrap; word-break: break-all;
}
.code .btn { position: absolute; top: 8px; right: 8px; }

.preview { width: min(1100px, calc(100vw - 24px)); }
.preview-body { display: grid; place-items: center; min-height: 200px; max-height: 80vh; overflow: auto; padding: 12px; background: var(--panel-2); }
.preview-body img, .preview-body video { max-width: 100%; max-height: 76vh; display: block; }
.preview-body audio { width: min(520px, 100%); }
.text-preview {
  justify-self: stretch; align-self: start; margin: 0; padding: 12px; white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; background: var(--panel); border-radius: 8px;
}
.preview-empty { display: grid; gap: 10px; justify-items: center; text-align: center; padding: 30px; }
.preview-empty p { margin: 0; }

/* ---------- 提示 ---------- */
.toasts { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; }
.toast {
  padding: 10px 16px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: var(--shadow);
  max-width: min(560px, calc(100vw - 32px)); word-break: break-word; animation: toast-in 0.18s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

@media (max-width: 760px) {
  .col-time { display: none; }
  .filter { width: 100%; order: 10; }
  .usage, .user { display: none; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .col-size { display: none; }
  .col-actions { width: 96px; }
  .toolbar .btn { padding: 0 10px; }
  .listing { margin: 0 8px 8px; }
}
