:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f7f9fd;
  --surface-hover: #eef3ff;
  --border: #e4e9f2;
  --text: #1b2334;
  --text-2: #4a556b;
  --muted: #8a94a8;
  --primary: #3568ee;
  --primary-2: #5a86ff;
  --primary-soft: #e9f0ff;
  --danger: #d94f5c;
  --danger-soft: #fdeef0;
  --shadow-sm: 0 1px 2px rgba(24, 40, 80, .05);
  --shadow: 0 2px 6px rgba(24, 40, 80, .05), 0 12px 32px rgba(24, 40, 80, .07);
  --shadow-lg: 0 24px 64px rgba(20, 34, 70, .18);
  --radius: 12px;
  --sidebar-w: 236px;
}
[data-theme="dark"] {
  --bg: #10141c;
  --surface: #1a202c;
  --surface-2: #222a38;
  --surface-hover: #26324a;
  --border: #2c3546;
  --text: #e8edf7;
  --text-2: #b3bfd2;
  --muted: #7e8ba3;
  --primary: #6b95ff;
  --primary-2: #8aabff;
  --primary-soft: #243559;
  --danger: #ff7b86;
  --danger-soft: #3a2229;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .2);
  --shadow: 0 2px 6px rgba(0, 0, 0, .22), 0 12px 32px rgba(0, 0, 0, .26);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .5);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
button { font: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
::-webkit-scrollbar-track { background: transparent; }

.layout { display: flex; min-height: 100vh; max-width: 1680px; margin: 0 auto; }

/* ---------- 侧栏 ---------- */
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 20px 18px 16px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; flex: 0 0 36px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff; font-weight: 800; font-size: 19px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(53, 104, 238, .28);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 15px; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text span { font-size: 11px; color: var(--muted); }
.brand .sidebar-close { display: none; margin-left: auto; }
.side-scroll { flex: 1; overflow-y: auto; padding: 6px 12px 18px; }
.side-label { font-size: 11px; color: var(--muted); letter-spacing: 1px; padding: 14px 10px 8px; font-weight: 600; }
.side-label-row { display: flex; justify-content: space-between; align-items: center; }
.cat-nav { display: flex; flex-direction: column; gap: 2px; }
.cat-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 9px; background: transparent;
  color: var(--text-2); text-align: left; transition: background .15s, color .15s;
}
.cat-item:hover { background: var(--surface-2); color: var(--text); }
.cat-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.cat-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; background: var(--primary); }
.cat-name { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cat-count { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cat-item.active .cat-count { color: var(--primary); }
.side-tools { display: flex; flex-direction: column; gap: 2px; }
.side-tool {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 9px; background: transparent;
  color: var(--text-2); text-align: left;
}
.side-tool svg { width: 16px; height: 16px; color: var(--muted); }
.side-tool:hover { background: var(--surface-2); color: var(--text); }
.side-tool:hover svg { color: var(--primary); }
.side-foot { border-top: 1px solid var(--border); padding: 12px 16px; }
.stat-line { font-size: 11px; color: var(--muted); margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.stat-line span { color: var(--text-2); font-weight: 600; }
.foot-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted);
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--surface-2); color: var(--primary); border-color: var(--border); }
.icon-btn.on { color: var(--primary); background: var(--primary-soft); }

/* ---------- 主区 ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 28px; background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; }
.search-box {
  position: relative; flex: 1; max-width: 620px; display: flex; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
  height: 42px; padding: 0 12px; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search-icon { color: var(--muted); width: 18px; height: 18px; flex: 0 0 18px; }
.search-box input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  color: var(--text); font-size: 14px; padding: 0 10px;
}
.search-box input::placeholder { color: var(--muted); }
.search-box input::-webkit-search-cancel-button { display: none; }
.kbd {
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted);
  border: 1px solid var(--border); border-radius: 5px; padding: 2px 6px; background: var(--surface-2);
  white-space: nowrap;
}
.clear-btn { display: none; border: 0; background: transparent; color: var(--muted); padding: 4px; margin-left: 4px; }
.clear-btn svg { width: 15px; height: 15px; }
.clear-btn.show { display: block; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 15px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); font-weight: 500; white-space: nowrap;
  transition: all .15s;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary {
  background: var(--primary); border-color: var(--primary); color: #fff;
  box-shadow: 0 4px 12px rgba(53, 104, 238, .22);
}
.btn-primary:hover { background: var(--primary-2); border-color: var(--primary-2); color: #fff; }
.btn-danger { color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.content { flex: 1; padding: 22px 28px 40px; max-width: 1500px; width: 100%; margin: 0 auto; }
.page-foot { padding: 14px 28px 22px; color: var(--muted); font-size: 11px; text-align: center; }
.page-foot .dot { margin: 0 6px; }
.page-foot .beian-link { color: inherit; text-decoration: none; }
.page-foot .beian-link:hover { text-decoration: underline; }

/* ---------- 分类区块 ---------- */
.section { margin-bottom: 30px; scroll-margin-top: 84px; }
.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 13px; }
.section-bar { width: 4px; height: 17px; border-radius: 3px; background: var(--primary); }
.section-title { font-size: 16px; font-weight: 700; letter-spacing: .2px; }
.section-count { font-size: 11px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; padding: 1px 8px; font-variant-numeric: tabular-nums; }
.section-actions { margin-left: auto; display: flex; gap: 6px; }
.mini-btn { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 4px 8px; border-radius: 6px; }
.mini-btn:hover { background: var(--surface-2); color: var(--primary); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(224px, 1fr)); gap: 11px; }

/* ---------- 网站卡片 ---------- */
.card {
  position: relative; display: flex; align-items: center; gap: 11px;
  min-height: 76px; padding: 12px 13px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm);
  transition: transform .16s, box-shadow .16s, border-color .16s;
  overflow: hidden;
}
.card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--primary) 42%, var(--border)); box-shadow: var(--shadow); }
.card-main { display: flex; align-items: center; gap: 11px; flex: 1; min-width: 0; }
.card-icon {
  width: 40px; height: 40px; flex: 0 0 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: #fff; overflow: hidden;
  background: var(--primary); user-select: none;
}
.card-icon .letter { display: block; line-height: 1; }
.card-icon img { width: 26px; height: 26px; object-fit: contain; display: none; }
.card-icon.has-img img { display: block; }
.card-icon.has-img .letter { display: none; }
.card-body { min-width: 0; flex: 1; }
.card-title { font-size: 13.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-host { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.card-desc { font-size: 11px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.card-sub { position: absolute; right: 10px; bottom: 6px; font-size: 10px; color: var(--muted); }
.card-more {
  position: absolute; top: 6px; right: 6px; width: 25px; height: 25px;
  border: 0; border-radius: 7px; background: var(--surface); color: var(--muted);
  display: none; align-items: center; justify-content: center; z-index: 2;
  box-shadow: var(--shadow-sm);
}
.card:hover .card-more, .card-more:focus { display: flex; }
.card-more:hover { color: var(--primary); background: var(--primary-soft); }
.card-more svg { width: 15px; height: 15px; }
.card-menu {
  position: absolute; top: 34px; right: 6px; z-index: 10; min-width: 124px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  box-shadow: var(--shadow); padding: 5px;
}
.card-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 9px;
  border: 0; background: transparent; color: var(--text-2); border-radius: 6px; font-size: 12.5px; text-align: left;
}
.card-menu button svg { width: 14px; height: 14px; }
.card-menu button:hover { background: var(--surface-2); color: var(--text); }
.card-menu button.danger { color: var(--danger); }
.card-menu button.danger:hover { background: var(--danger-soft); }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 70px 20px; color: var(--muted); gap: 10px; text-align: center;
}
.empty svg { width: 44px; height: 44px; opacity: .45; }
.empty strong { color: var(--text-2); font-size: 15px; }

/* ---------- 弹窗 ---------- */
#modalRoot:empty { display: none; }
.modal-mask {
  position: fixed; inset: 0; z-index: 100; background: rgba(18, 26, 44, .44);
  backdrop-filter: blur(3px); display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 16px 30px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 480px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg); animation: pop .18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-10px) scale(.985); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 4px; }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-desc { padding: 0 22px; color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.modal-body { padding: 18px 22px 4px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 9px; padding: 16px 22px 20px; }
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; font-weight: 600; }
.field label .req { color: var(--danger); }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2);
  color: var(--text); padding: 9px 11px; outline: 0; font: inherit; font-size: 13.5px;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field textarea { resize: vertical; min-height: 66px; }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline-add { display: flex; gap: 8px; }
.inline-add select { flex: 1; }
.color-row { display: flex; gap: 8px; flex-wrap: wrap; }
.color-chip { width: 26px; height: 26px; border-radius: 8px; border: 2px solid transparent; cursor: pointer; }
.color-chip.active { border-color: var(--text); }
.cat-manage-row {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px;
  border: 1px solid var(--border); border-radius: 9px; margin-bottom: 8px; background: var(--surface-2);
}
.cat-manage-row .cat-dot { width: 10px; height: 10px; flex-basis: 10px; }
.cat-manage-row .name { flex: 1; font-weight: 600; font-size: 13px; }
.cat-manage-row .num { color: var(--muted); font-size: 11px; }
.notice {
  background: var(--primary-soft); color: var(--primary); border-radius: 9px;
  padding: 10px 12px; font-size: 12.5px; margin-bottom: 14px; line-height: 1.6;
}
.notice.warn { background: var(--danger-soft); color: var(--danger); }

/* ---------- Toast ---------- */
#toastWrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--text); color: var(--surface); padding: 9px 16px; border-radius: 9px;
  font-size: 13px; box-shadow: var(--shadow); animation: toastIn .2s ease-out;
}
.toast.ok { background: #17795a; color: #fff; }
.toast.err { background: #c0394b; color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.mask { display: none; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .22s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .brand .sidebar-close { display: inline-flex; }
  .mask.show { display: block; position: fixed; inset: 0; background: rgba(15, 22, 40, .4); z-index: 25; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; gap: 9px; }
  .content { padding: 18px 16px 30px; }
  .top-add span { display: none; }
  .top-add { padding: 0 11px; }
  .kbd { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 9px; }
  .card { min-height: 70px; padding: 10px; }
  .card-icon { width: 34px; height: 34px; flex-basis: 34px; }
  .card-more { display: flex; }
}
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .field-row { grid-template-columns: 1fr; gap: 0; }
}

/* ---------- 批量管理（多选模式） ---------- */
.card .pick {
  position: absolute; top: 10px; right: 10px; width: 22px; height: 22px;
  border-radius: 7px; border: 2px solid var(--border); background: var(--surface);
  display: none; align-items: center; justify-content: center;
  color: #fff; z-index: 2; transition: all .12s;
}
.card .pick svg { width: 14px; height: 14px; stroke-width: 2.6; }
.card.selecting { cursor: pointer; }
.card.selecting .pick { display: flex; }
.card.selecting .card-main { pointer-events: none; }
.card.selecting .card-more { display: none; }
.card.selected { outline: 2px solid var(--primary); outline-offset: -2px; }
.card.selected .pick { background: var(--primary); border-color: var(--primary); }

.sel-bar {
  display: none; position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 60; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 14px; box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 32px);
}
.sel-bar.show { display: flex; flex-wrap: wrap; justify-content: center; }
.sel-count { font-weight: 600; color: var(--text); white-space: nowrap; }
.sel-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sel-actions .btn:disabled { opacity: .45; cursor: not-allowed; }
.batch-list {
  max-height: 260px; overflow: auto; border: 1px solid var(--border);
  border-radius: 8px; margin-top: 4px;
}
.batch-item {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 10px; border-bottom: 1px solid var(--border);
}
.batch-item:last-child { border-bottom: none; }
.batch-item .t { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch-item .h { color: var(--muted); font-size: 12px; white-space: nowrap; }
