:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #1f2329;
  --text-soft: #646a73;
  --border: #e3e6eb;
  --primary: #4f46e5;
  --primary-soft: #eef0ff;
  --danger: #e5484d;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.05);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: #16181d;
    --panel: #1f232b;
    --panel-2: #262b34;
    --text: #e6e8eb;
    --text-soft: #9aa1ab;
    --border: #2f353f;
    --primary: #7c83ff;
    --primary-soft: #2a2f45;
    --danger: #ff6369;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
  }
}
:root.dark {
  --bg: #16181d;
  --panel: #1f232b;
  --panel-2: #262b34;
  --text: #e6e8eb;
  --text-soft: #9aa1ab;
  --border: #2f353f;
  --primary: #7c83ff;
  --primary-soft: #2a2f45;
  --danger: #ff6369;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* 顶栏 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand .logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--primary); color: #fff; font-size: 15px;
}
.brand .title { font-weight: 600; font-size: 16px; }

/* 全局搜索框 */
.search-box {
  display: flex; align-items: center; gap: 6px;
  flex: 1 1 auto; max-width: 560px; margin: 0 18px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 10px;
}
.search-box:focus-within { border-color: var(--primary); }
.search-ico { font-size: 13px; opacity: .6; flex: 0 0 auto; }
#searchInput {
  flex: 1 1 auto; min-width: 0; border: none; outline: none;
  background: transparent; color: var(--text); font-size: 14px; font-family: inherit;
}
#searchInput::placeholder { color: var(--text-soft); opacity: .8; }
.search-clear {
  flex: 0 0 auto; border: none; background: transparent; color: var(--text-soft);
  cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 5px; border-radius: 6px;
}
.search-clear:hover { background: var(--panel); color: var(--text); }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.stat { font-size: 12px; color: var(--text-soft); }

/* 布局 */
.layout { flex: 1 1 auto; display: flex; min-height: 0; }
.sidebar {
  width: 240px; flex: 0 0 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 12px 10px;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: var(--text-soft); margin-bottom: 8px; padding: 0 4px;
}
.cat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1 1 auto; }

.cat-item {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  user-select: none; margin-bottom: 2px;
}
.cat-item:hover { background: var(--panel-2); }
.cat-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.cat-item .grip { cursor: grab; color: var(--text-soft); font-size: 12px; opacity: .5; }
.cat-item .name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item .badge {
  font-size: 11px; background: var(--panel-2); color: var(--text-soft);
  border-radius: 10px; padding: 1px 7px; min-width: 20px; text-align: center;
}
.cat-item.active .badge { background: var(--primary); color: #fff; }
.cat-item .acts { display: none; gap: 2px; }
.cat-item:hover .acts { display: flex; }
.cat-item.dragging { opacity: .4; }
.cat-item.dragover { box-shadow: inset 0 2px 0 var(--primary); }

.main { flex: 1 1 auto; padding: 18px 22px; overflow-y: auto; }
.main-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.main-head h2 { margin: 0; font-size: 18px; }
.count { font-size: 12px; color: var(--text-soft); }
.main-head .btn { margin-left: auto; }

/* 网址网格 */
.bm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.bm-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .08s ease, border-color .15s ease;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px;
  min-height: 96px;
}
.bm-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.bm-card .fav {
  width: 36px; height: 36px; border-radius: 8px; object-fit: contain;
  background: var(--panel-2);
}
.bm-card .fav-letter {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 16px;
}
.bm-card .bm-title {
  font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  word-break: break-all;
}
.bm-card .bm-cat {
  font-size: 11px; color: var(--text-soft);
  background: var(--panel-2); border-radius: 8px; padding: 1px 6px;
}
.bm-card .card-acts {
  position: absolute; top: 6px; right: 6px; display: none; gap: 4px;
}
.bm-card:hover .card-acts { display: flex; }
.bm-card .card-acts button { padding: 2px 6px; font-size: 12px; }
.bm-card.dragging { opacity: .4; }
.bm-card.dragover { box-shadow: 0 0 0 2px var(--primary); }

.empty-hint { color: var(--text-soft); text-align: center; padding: 60px 0; font-size: 14px; }

/* 按钮 */
.btn {
  border: 1px solid var(--border); background: var(--panel);
  color: var(--text); border-radius: 8px; padding: 6px 12px;
  font-size: 13px; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: rgba(229,72,77,.08); }

/* 弹窗 */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop[hidden] { display: none !important; }
.modal {
  background: var(--panel); border-radius: 12px; padding: 20px;
  width: 380px; max-width: 92vw; box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 14px; font-size: 16px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-size: 13px; }
.field > span { color: var(--text-soft); }
.field i { color: var(--danger); font-style: normal; font-size: 11px; }
.dup-hint { font-size: 12px; color: var(--danger); margin-top: 4px; }
.field input, .field select, .field textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* 提示条 */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #1f2329; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 80; box-shadow: var(--shadow); opacity: 0;
  transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--danger); }
.toast.ok { background: #2e9e5b; }

/* ---------- 口令登录遮罩（仅云端部署出现） ---------- */
.login-mask {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-mask[hidden] { display: none; }
.login-box {
  width: 100%; max-width: 340px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px 22px;
  display: flex; flex-direction: column; gap: 12px;
}
.login-title { font-size: 16px; font-weight: 600; color: var(--text); }
.login-tip { font-size: 12px; color: var(--text-soft); line-height: 1.6; }
.login-box input {
  width: 100%; padding: 9px 11px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel-2); color: var(--text); outline: none;
}
.login-box input:focus { border-color: var(--primary); }
.login-err { font-size: 12px; color: var(--danger); }
.login-box .btn { width: 100%; }
