/* ---------- 主题变量 ---------- */
:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #15181e;
  --muted: #6b7280;
  --line: #e5e8ee;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, .10);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
  --wrap: 1180px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #161b22;
  --text: #e6edf3;
  --muted: #8b949e;
  --line: #262d36;
  --accent: #58a6ff;
  --accent-soft: rgba(88, 166, 255, .14);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 16px rgba(0, 0, 0, .40);
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 20px; }

/* ---------- 头部 ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-top: 16px;
  padding-bottom: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.avatar {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: 12px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.brand-text { min-width: 0; }
.brand-text h1 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: .2px; }
.brand-text p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.header-actions { display: flex; align-items: center; gap: 10px; }

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  width: 300px;
  max-width: 46vw;
}
.search-icon {
  position: absolute;
  left: 11px;
  width: 17px;
  height: 17px;
  color: var(--muted);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  padding: 9px 42px 9px 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-box kbd {
  position: absolute;
  right: 10px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--panel);
  color: var(--muted);
  font: 600 11px/1.6 ui-monospace, Menlo, Consolas, monospace;
  pointer-events: none;
}

.icon-btn {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.icon-btn:hover { border-color: var(--accent); }

/* 右上角按钮的「保存」态：编辑中高亮成主按钮 */
.icon-btn.is-save {
  width: auto;
  flex: 0 0 auto;
  padding: 0 14px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

/* ---------- 主体 ---------- */
.main { flex: 1; padding-top: 26px; padding-bottom: 52px; }

.group { margin-bottom: 30px; }

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: .4px;
}
.group-icon { font-size: 15px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  transition: transform .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card:active { transform: translateY(0); }

.icon {
  position: relative;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--accent-soft);
}
.icon-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}
.icon img {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.card-meta { min-width: 0; }
.card-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-desc {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- 编辑模式 ---------- */
.adminbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 22px;
  padding: 10px 14px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.admin-status { font-size: 12.5px; color: var(--muted); }
.admin-status.is-error { color: #e5484d; font-weight: 600; }
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  padding: 6px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-danger { color: #e5484d; border-color: rgba(229, 72, 77, .4); }
.btn-danger:hover { background: rgba(229, 72, 77, .1); border-color: #e5484d; }
.btn.is-quiet { color: var(--muted, var(--text)); opacity: .75; }
.btn.is-quiet:hover { opacity: 1; }

.card.is-editing { position: relative; padding-right: 60px; cursor: pointer; }
.card.is-editing:hover { transform: none; border-color: var(--accent); }

.card-ctrl {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
}
.mini-btn {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}
.mini-btn:hover { color: var(--text); border-color: var(--accent); }
.mini-btn.is-del:hover { color: #e5484d; border-color: #e5484d; }

.group-ctrl { display: inline-flex; gap: 4px; margin-left: 8px; }

.grid-add {
  display: grid;
  place-items: center;
  min-height: 62px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.grid-add:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; }
.modal-mask { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }

.modal-card {
  position: relative;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 20px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.modal-card h3 { margin: 0 0 14px; font-size: 16px; }

.modal-field { display: block; margin-bottom: 11px; }
.modal-field span { display: block; margin-bottom: 4px; font-size: 12px; color: var(--muted); }
.modal-field input,
.modal-field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.modal-field select { appearance: none; cursor: pointer; }
.modal-field input:focus,
.modal-field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.icon-picker {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 3px;
  margin-top: 7px;
  max-height: 168px;
  overflow: auto;
  padding: 2px;
}
.icon-opt {
  padding: 3px 0;
  font-size: 17px;
  line-height: 1.25;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}
.icon-opt:hover { border-color: var(--line); background: var(--accent-soft); }
.icon-opt.is-on { border-color: var(--accent); background: var(--accent-soft); }
.icon-opt.is-clear { font-size: 12px; color: var(--muted); }

.modal-error {
  margin: 0 0 10px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(229, 72, 77, .1);
  color: #e5484d;
  font-size: 12.5px;
}

.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.modal-actions .spacer { flex: 1; }

/* ---------- 保存结果提示 ---------- */
.toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  padding: 8px 18px;
  border-radius: 10px;
  background: rgba(20, 24, 30, .88);
  color: #fff;
  font-size: 13.5px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  transition: opacity .25s;
}
.toast.is-error { background: rgba(180, 40, 45, .92); }

/* ---------- 页脚 ---------- */
.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 16px;
  padding-bottom: 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
}

/* ---------- 移动端 ---------- */
@media (max-width: 640px) {
  .header-inner { padding-top: 12px; padding-bottom: 12px; }
  .header-actions { width: 100%; }
  .search-box { width: 100%; max-width: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
}
