:root {
  --bg: #0f1115;
  --bg-2: #161a22;
  --bg-3: #1d2230;
  --line: #2a3040;
  --text: #e8ecf3;
  --muted: #8f9bb3;
  --primary: #4f8cff;
  --primary-2: #3a6fd8;
  --danger: #ff5d6c;
  --ok: #3ddc97;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* hidden 属性必须真正生效（否则 .login/.app 的 display 会覆盖它） */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", -apple-system, "PingFang SC", sans-serif;
  font-size: 14px;
}

button, input, textarea { font-family: inherit; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

/* ---------- 登录 ---------- */
.login {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(900px 500px at 20% 0%, rgba(79, 140, 255, 0.16), transparent 60%),
    radial-gradient(700px 400px at 100% 100%, rgba(61, 220, 151, 0.10), transparent 60%),
    var(--bg);
  z-index: 50;
}

.login-card {
  width: min(420px, 92vw);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 30px 28px;
  box-shadow: var(--shadow);
}

.login-card h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: 0.5px; }
.login-card .muted { margin: 0 0 22px; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

input[type="password"], input[type="text"], .input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  outline: none;
}
input:focus, .input:focus, .textarea:focus { border-color: var(--primary); }

.msg { min-height: 18px; margin: 12px 0 0; font-size: 13px; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  user-select: none;
  white-space: nowrap;
}
.btn:hover { background: #252c3d; border-color: #38415a; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { background: rgba(255, 93, 108, 0.12); border-color: rgba(255, 93, 108, 0.45); color: #ffb3ba; }
.btn.danger:hover { background: rgba(255, 93, 108, 0.22); }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 3px 8px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.file-btn { position: relative; overflow: hidden; }

/* ---------- 布局 ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  background: rgba(22, 26, 34, 0.9);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}

.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 10px var(--ok); }

.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
}
.tab:hover { color: var(--text); background: var(--bg-3); }
.tab.active { color: var(--text); background: var(--bg-3); border-color: var(--line); }

main { padding: 22px; flex: 1; display: flex; flex-direction: column; }

.tab-panel { display: none; flex: 1; }
.tab-panel.active { display: block; }
#tab-files.active { display: flex; flex-direction: column; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar.small { margin-bottom: 8px; }

/* ---------- 文件 ---------- */
.volume-select {
  width: auto;
  min-width: 120px;
  padding: 6px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  cursor: pointer;
}
.volume-select:focus { border-color: var(--primary); }

.breadcrumb { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 14px; }
.breadcrumb .crumb-link { color: var(--primary); cursor: pointer; background: none; border: none; padding: 2px 4px; font-size: 14px; }
.breadcrumb .crumb-link:hover { text-decoration: underline; }
.breadcrumb .sep { color: var(--muted); }

.drop-zone { flex: 1; display: flex; flex-direction: column; position: relative; }
.drop-zone.drag::after {
  content: "松开鼠标上传到当前目录";
  position: absolute;
  inset: 0;
  border: 2px dashed var(--primary);
  border-radius: var(--radius);
  background: rgba(79, 140, 255, 0.10);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--primary);
  z-index: 5;
  pointer-events: none;
}

.file-list {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  overflow: auto;
  min-height: 240px;
}

.file-row {
  display: grid;
  grid-template-columns: 34px minmax(120px, 1fr) 110px 170px 130px;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(42, 48, 64, 0.7);
  cursor: default;
}
.file-row:last-child { border-bottom: none; }
.file-row:hover { background: rgba(255, 255, 255, 0.03); }
.file-row .name { display: flex; align-items: center; gap: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer; }
.file-row .name:hover { color: var(--primary); }
.file-row .icon { font-size: 18px; width: 22px; text-align: center; }
.file-row .size, .file-row .mtime { color: var(--muted); font-size: 12px; }
.file-row .actions { display: flex; gap: 6px; justify-content: flex-end; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.hint { text-align: center; color: var(--muted); font-size: 12px; margin: 10px 0 0; }

.upload-progress { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.upload-label { flex: 0 1 auto; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.upload-item { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.upload-item .bar { flex: 1; height: 5px; border-radius: 3px; background: var(--bg-3); overflow: hidden; }
.upload-item .bar i { display: block; height: 100%; width: 0; background: var(--primary); transition: width 0.2s; }
.upload-item.done .bar i { background: var(--ok); }
.upload-item.fail { color: var(--danger); }

/* ---------- KV ---------- */
.kv-layout { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }

.kv-side {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  padding: 12px;
  min-height: 320px;
}
.ns-list { display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow: auto; }
.ns-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  border: 1px solid transparent;
}
.ns-item:hover { background: var(--bg-3); color: var(--text); }
.ns-item.active { background: rgba(79, 140, 255, 0.14); border-color: rgba(79, 140, 255, 0.4); color: var(--text); }
.ns-item .count { font-size: 11px; background: var(--bg-3); padding: 1px 7px; border-radius: 10px; }
.ns-item .ns-badge { font-size: 10px; color: var(--muted); background: var(--bg-3); padding: 1px 6px; border-radius: 8px; white-space: nowrap; }

.kv-main { min-width: 0; }
.crumb { font-size: 14px; font-weight: 600; }

.record-list {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  overflow: auto;
  max-height: 44vh;
}
.record-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 120px 170px 70px;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(42, 48, 64, 0.7);
  cursor: pointer;
  font-size: 13px;
}
.record-row:hover { background: rgba(255, 255, 255, 0.03); }
.record-row .rkey { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.record-row .rmeta { color: var(--muted); font-size: 12px; }

.record-editor {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  padding: 14px;
}
.editor-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.editor-head input { max-width: 320px; }
.textarea {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 12px;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 13px;
  line-height: 1.55;
  outline: none;
}

/* ---------- 状态 ---------- */
.vol-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 2px; }
.vol-table th, .vol-table td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.vol-table th { color: var(--muted); font-weight: 500; }
.vol-table tr:last-child td { border-bottom: none; }

.status-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.stat .value { font-size: 22px; font-weight: 700; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.detail { display: grid; grid-template-columns: 160px 1fr; gap: 8px 14px; font-size: 13px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; word-break: break-all; }
.detail code { background: var(--bg-3); padding: 1px 6px; border-radius: 5px; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
}
.modal-card {
  width: min(460px, 92vw);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 16px; font-size: 16px; }
.modal-card select.input { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  padding: 12px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: 380px;
  font-size: 13px;
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }

@media (max-width: 760px) {
  main { padding: 12px; }
  .topbar { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .tabs { order: 3; width: 100%; }
  .file-row { grid-template-columns: 30px 1fr 90px; }
  .file-row .mtime, .file-row .actions { display: none; }
  .kv-layout { grid-template-columns: 1fr; }
  .record-row { grid-template-columns: 1fr 110px; }
  .record-row .rmeta:last-child { display: none; }
}
