:root {
  --bg: #f5f7fc;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --surface-3: #e9edf7;
  --text: #1c2030;
  --text-2: #495066;
  --muted: #858ca1;
  --border: #e5e9f2;
  --accent: #4d6bf5;
  --accent-2: #7258e8;
  --accent-soft: #edf0ff;
  --danger: #e04b5f;
  --success: #18a06a;
  --shadow: 0 6px 22px rgba(31, 45, 90, .07);
  --shadow-lg: 0 16px 44px rgba(31, 45, 90, .14);
  --radius: 16px;
}

html[data-theme="dark"] {
  --bg: #0d1017;
  --surface: #171b25;
  --surface-2: #1e2330;
  --surface-3: #272d3d;
  --text: #eef0f7;
  --text-2: #b9c0d2;
  --muted: #838da5;
  --border: #2a3142;
  --accent: #8298ff;
  --accent-2: #a48cff;
  --accent-soft: #232c4d;
  --danger: #ff7185;
  --success: #47d39b;
  --shadow: 0 6px 22px rgba(0, 0, 0, .28);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, .42);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; max-width: 100%; overflow-x: hidden; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  width: 100%;
  height: 520px;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(45% 60% at 20% 25%, rgba(109, 132, 255, .16), transparent 70%),
    radial-gradient(40% 55% at 78% 15%, rgba(154, 110, 235, .13), transparent 72%);
}
html[data-theme="dark"] body::before { opacity: .55; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.wrap { width: calc(100% - 40px); max-width: 1160px; margin: 0 auto; }

/* ---------- 顶栏 ---------- */
.topbar { padding: 30px 0 10px; }
.topbar-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  font-size: 21px; color: #fff; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px rgba(80, 100, 240, .28);
}
.brand h1 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -.4px; }
.brand p { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; margin-left: auto; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; flex: none;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); font-size: 17px; box-shadow: var(--shadow);
  transition: transform .18s ease, border-color .18s ease, color .18s ease;
}
.icon-btn:hover { transform: translateY(-2px); border-color: var(--accent); color: var(--accent); }

.searchbar { margin: 22px 0 6px; position: relative; max-width: 560px; }
.searchbar svg { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.searchbar input {
  width: 100%; height: 52px; padding: 0 82px 0 50px; border-radius: 16px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  outline: none; box-shadow: var(--shadow); font-size: 15px;
  transition: border-color .2s, box-shadow .2s;
}
.searchbar input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }
.searchbar input::placeholder { color: var(--muted); }
.search-kbd {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  font-size: 11px; color: var(--muted); border: 1px solid var(--border);
  background: var(--surface-2); padding: 2px 8px; border-radius: 6px; pointer-events: none;
}
.status-line { display: flex; align-items: center; gap: 8px; margin: 10px 0 20px; font-size: 12.5px; color: var(--muted); min-width: 0; }
.status-line > span:last-child { min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-line .dot { flex: none; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px rgba(24,160,106,.14); }
.dot.local { background: #e2a03a; box-shadow: 0 0 0 3px rgba(226,160,58,.14); }

/* ---------- 分组 ---------- */
.group { margin-bottom: 38px; }
.group-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.group-emoji {
  width: 38px; height: 38px; flex: none; border-radius: 12px; display: grid; place-items: center;
  font-size: 19px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.group-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.group-title h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
.count {
  font-size: 11.5px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border-radius: 999px; padding: 2px 9px;
}
.group-desc { width: 100%; font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.group-rule { flex: 1; height: 1px; background: var(--border); min-width: 20px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 14px; }
.site-card {
  position: relative; display: flex; flex-direction: column; gap: 10px;
  min-height: 132px; padding: 16px 16px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform .2s cubic-bezier(.2,.8,.2,1), box-shadow .2s, border-color .2s;
  overflow: hidden;
}
.site-card::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity: 0; transition: opacity .2s;
}
.site-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: transparent; }
.site-card:hover::after { opacity: 1; }
.site-top { display: flex; align-items: flex-start; gap: 11px; }
.site-ico {
  flex: none; display: grid; place-items: center; border-radius: 13px; overflow: hidden;
  font-weight: 700; font-size: 20px;
}
.site-ico img { width: 100%; height: 100%; object-fit: cover; }
.ico-emoji { font-size: 23px; line-height: 1; }
.ico-letter { font-size: 19px; font-weight: 800; }
.site-name { font-size: 14.5px; font-weight: 650; line-height: 1.35; word-break: break-word; }
.site-tag {
  display: inline-block; margin-top: 4px; font-size: 10.5px; color: var(--muted);
  background: var(--surface-2); padding: 1px 8px; border-radius: 999px;
}
.site-desc {
  font-size: 12.5px; color: var(--text-2); line-height: 1.5; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.site-foot {
  margin-top: auto; display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--muted);
}
.site-foot .host { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-foot .arrow { margin-left: auto; font-size: 15px; transition: transform .2s, color .2s; }
.site-card:hover .site-foot .arrow { transform: translate(3px, -3px); color: var(--accent); }
.empty {
  grid-column: 1 / -1; text-align: center; padding: 44px 20px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface);
}
.empty .big { font-size: 30px; display: block; margin-bottom: 8px; }

footer {
  padding: 16px 0 40px; text-align: center; font-size: 12px; color: var(--muted);
}
footer a { color: var(--accent); }

/* ---------- 通用组件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 15px; border-radius: 11px; font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  transition: all .18s ease; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent; box-shadow: 0 6px 16px rgba(80, 100, 240, .25);
}
.btn.primary:hover { filter: brightness(1.06); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12px; border-radius: 9px; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: #20263a; color: #fff; padding: 11px 20px; border-radius: 12px;
  font-size: 13.5px; box-shadow: 0 12px 30px rgba(0,0,0,.22); opacity: 0;
  pointer-events: none; transition: all .25s ease; z-index: 99; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #b8374c; }

/* ---------- 后台 ---------- */
.admin-head {
  display: flex; align-items: center; gap: 12px; padding: 22px 0 18px; flex-wrap: wrap;
}
.admin-head h1 { margin: 0; font-size: 20px; font-weight: 700; }
.admin-head .sub { font-size: 12.5px; color: var(--muted); }
.admin-head .spacer { flex: 1; }
.admin-toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; padding: 12px; margin-bottom: 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
}
.admin-toolbar .badge {
  margin-left: auto; align-self: center; font-size: 12px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 7px;
}
.unsaved { color: #e2a03a !important; font-weight: 600; }

.login-card {
  max-width: 430px; margin: 8vh auto; padding: 32px 28px; text-align: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow-lg);
}
.login-card .lock { font-size: 38px; }
.login-card h2 { margin: 12px 0 6px; font-size: 20px; }
.login-card p { margin: 0 0 22px; font-size: 13px; color: var(--muted); line-height: 1.7; }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field input, .field textarea, .field select {
  width: 100%; padding: 10px 12px; border-radius: 10px; outline: none;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 14px;
  transition: border-color .18s, box-shadow .18s;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 74px; }
.field .hint { font-size: 11.5px; color: var(--muted); }

.group-block {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden;
}
.gb-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; flex-wrap: wrap; }
.gb-head .emoji-input {
  width: 46px; height: 38px; text-align: center; font-size: 18px; padding: 4px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.gb-head .name-input {
  flex: 1; min-width: 140px; height: 38px; padding: 0 12px; font-weight: 650; font-size: 15px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); outline: none;
}
.gb-head .name-input:focus { border-color: var(--accent); }
.gb-head .desc-input {
  width: 100%; padding: 8px 12px; font-size: 12.5px; margin-top: 2px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); outline: none;
}
.gb-tools { display: flex; gap: 5px; }
.mini-btn {
  width: 30px; height: 30px; display: grid; place-items: center; font-size: 13px;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
}
.mini-btn:hover { border-color: var(--accent); color: var(--accent); }
.mini-btn.del:hover { border-color: var(--danger); color: var(--danger); }

.item-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.item-row:hover { background: var(--surface-2); }
.item-main { min-width: 0; flex: 1; }
.item-main .n { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-main .u { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-ops { display: flex; gap: 5px; flex: none; }
.gb-foot { padding: 10px 16px; border-top: 1px solid var(--border); }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 20, 35, .48); z-index: 60;
  display: none; align-items: center; justify-content: center; padding: 18px;
  backdrop-filter: blur(3px);
}
.modal-mask.open { display: flex; }
.modal {
  width: min(460px, 100%); max-height: 88vh; overflow: auto;
  background: var(--surface); border-radius: 18px; padding: 22px;
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.modal h3 { margin: 0 0 16px; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- 响应式 ---------- */
@media (max-width: 760px) {
  .wrap { width: calc(100% - 26px); }
  .topbar { padding-top: 18px; }
  .brand-mark { width: 40px; height: 40px; border-radius: 12px; font-size: 19px; }
  .brand h1 { font-size: 18px; }
  .brand p { display: none; }
  .icon-btn { width: 36px; height: 36px; font-size: 15px; }
  .searchbar { margin-top: 16px; max-width: none; }
  .searchbar input { height: 46px; padding-left: 44px; border-radius: 13px; }
  .searchbar svg { left: 15px; }
  .search-kbd { display: none; }
  .status-line { margin-bottom: 16px; }
  .group { margin-bottom: 28px; }
  .group-head { gap: 9px; margin-bottom: 12px; }
  .group-emoji { width: 33px; height: 33px; font-size: 17px; border-radius: 10px; }
  .group-title h2 { font-size: 16px; }
  .group-rule { display: none; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .site-card { min-height: 118px; padding: 12px; gap: 8px; border-radius: 13px; }
  .site-top { gap: 9px; }
  .site-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .site-desc { font-size: 11.5px; -webkit-line-clamp: 1; }
  .site-tag { display: none; }
  .site-foot { font-size: 10.5px; }
  .admin-head { flex-wrap: nowrap; gap: 8px; }
  .admin-head > div { min-width: 0; flex: 1; }
  .admin-head h1 { font-size: 17px; white-space: nowrap; }
  .admin-head .sub { display: none; }
  .admin-head .spacer { display: none; }
  .admin-head .icon-btn:last-child { margin-left: auto; }
  .admin-toolbar { padding: 10px; }
  .admin-toolbar .badge { width: 100%; margin-left: 0; padding-top: 4px; }
  .item-row { flex-wrap: wrap; padding: 10px 12px; }
  .item-ops { width: 100%; justify-content: flex-end; }
  .form-grid { grid-template-columns: 1fr; }
  .login-card { margin: 5vh auto; padding: 26px 20px; }
  .gb-head { padding: 12px; }
  .modal { padding: 18px; }
}
@media (max-width: 380px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .site-card { padding: 10px; }
  .site-ico { width: 36px !important; height: 36px !important; border-radius: 10px; }
}
