/* ===========================================================
   导航页 · 样式（零依赖，浅色卡片风格）
   =========================================================== */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2328;
  --text-2: #626b78;
  --text-3: #9aa1ab;
  --border: #e6e8eb;
  --accent: #2b6cf6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 44px rgba(16, 24, 40, .14);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Hiragino Sans GB", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(58% 46% at 12% 0%, rgba(43, 108, 246, .07), transparent 62%),
    radial-gradient(48% 42% at 92% 3%, rgba(126, 87, 255, .06), transparent 62%);
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1120px;
  margin: 0 auto;
  padding: 26px 20px 56px;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 9px; }

.brand-dot {
  width: 22px; height: 22px;
  border-radius: 7px;
  background: linear-gradient(135deg, #2b6cf6, #7e57ff);
  box-shadow: 0 4px 12px rgba(43, 108, 246, .32);
}

.brand-name { font-size: 15px; font-weight: 600; letter-spacing: .3px; }

.actions { display: flex; gap: 8px; }

/* ---------------- 按钮 ---------------- */
.btn {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text-2);
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color .16s, color .16s, box-shadow .16s, background .16s;
  white-space: nowrap;
}
.btn:hover { border-color: #ccd3dd; color: var(--text); box-shadow: 0 1px 3px rgba(16, 24, 40, .07); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn.primary:hover { background: #1f5ee8; border-color: #1f5ee8; color: #fff; }
.btn.danger { color: #d93b3b; border-color: #f0d5d5; }
.btn.danger:hover { background: #fdf3f3; color: #d93b3b; border-color: #e8bcbc; }

.only-edit { display: none; }
body.edit-mode .only-edit { display: inline-flex; align-items: center; }

/* ---------------- 搜索区 ---------------- */
.search { max-width: 720px; margin: 30px auto 42px; }

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 9px 9px 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  transition: border-color .2s, box-shadow .2s;
}
.search-box:focus-within {
  border-color: #c3d4ff;
  box-shadow: 0 0 0 4px rgba(43, 108, 246, .10), var(--shadow);
}

.search-icon { width: 19px; height: 19px; flex: 0 0 19px; color: var(--text-3); }

.search-box input {
  flex: 1 1 auto;
  min-width: 0;
  height: 34px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
}
.search-box input::placeholder { color: var(--text-3); }

.search-submit {
  flex: 0 0 auto;
  height: 36px;
  padding: 0 20px;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .16s;
}
.search-submit:hover { background: #1f5ee8; }
.search-submit:active { transform: translateY(1px); }

.engines {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 14px;
}

.engine {
  padding: 6px 15px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: background .18s, color .18s, box-shadow .18s, border-color .18s;
}
.engine:hover { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.engine.active {
  background: #fff;
  border-color: #dbe5ff;
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ---------------- 分类 ---------------- */
.category { margin-bottom: 30px; }

.cat-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 4px 12px;
}

.cat-title { font-size: 16px; font-weight: 600; letter-spacing: .2px; }

.cat-count {
  padding: 1px 8px;
  border-radius: 999px;
  background: #eceef2;
  color: var(--text-3);
  font-size: 11.5px;
  line-height: 18px;
}

.cat-tools { margin-left: auto; display: flex; gap: 8px; }

.drag-handle {
  padding: 2px 1px;
  color: var(--text-3);
  font-size: 15px;
  line-height: 1;
  cursor: grab;
  user-select: none;
  letter-spacing: -2px;
}
.drag-handle:active { cursor: grabbing; }

.category.dragging { opacity: .4; }

/* ---------------- 网站网格 ---------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(228px, 1fr));
  gap: 12px;
  min-height: 8px;
}

.site {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
  transition: transform .16s cubic-bezier(.2, .7, .3, 1), box-shadow .18s, border-color .18s;
}
.site:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #dfe3e9; }
.site:active { transform: translateY(0); }

.site-icon {
  position: relative;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #f2f4f7;
  overflow: hidden;
}
.site-icon .fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  transition: opacity .2s;
}
/* 图标抓取成功后，淡出底层的首字母色块，避免字母/色块从图标边缘透出来 */
.site-icon.has-img .fallback { opacity: 0; }

.site-icon img {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .25s;
}
.site-icon img.ok { opacity: 1; }

.site-meta { display: flex; flex-direction: column; min-width: 0; }
.site-name {
  font-size: 14.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.site-desc {
  margin-top: 1px;
  color: var(--text-3);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 编辑态 */
body.edit-mode .site {
  border-style: dashed;
  border-color: #cfd6e0;
  cursor: grab;
}
body.edit-mode .site:hover { border-color: var(--accent); }

.site.dragging { opacity: .35; }
.site.drop-before { box-shadow: -4px 0 0 0 var(--accent); }
.site.drop-after  { box-shadow: 4px 0 0 0 var(--accent); }

.site-add {
  justify-content: flex-start;
  border-style: dashed;
  background: transparent;
  color: var(--text-3);
  font-family: inherit;
  cursor: pointer;
}
.site-add .plus {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #eef1f5;
  font-size: 20px;
  font-weight: 400;
}

.add-category {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 48px;
  border: 1px dashed #cfd6e0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: border-color .16s, color .16s, background .16s;
}
.add-category:hover { border-color: var(--accent); color: var(--accent); background: rgba(43, 108, 246, .03); }

/* ---------------- 页脚 ---------------- */
.foot {
  margin-top: 42px;
  text-align: center;
  color: var(--text-3);
  font-size: 12.5px;
}
.foot kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--text-2);
}

/* ---------------- 弹窗 ---------------- */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-root[hidden] { display: none; }

.modal-mask { position: absolute; inset: 0; background: rgba(16, 24, 40, .34); }

.modal {
  position: relative;
  width: 100%;
  max-width: 440px;
  padding: 22px;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  animation: pop .18s cubic-bezier(.2, .8, .3, 1);
}
@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.modal h3 { margin-bottom: 16px; font-size: 16px; font-weight: 600; }

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; color: var(--text-2); font-size: 12.5px; }
.field input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfbfc;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: 0;
  transition: border-color .16s, box-shadow .16s, background .16s;
}
.field input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(43, 108, 246, .10);
}
.field .hint { margin-top: 6px; color: var(--text-3); font-size: 12px; }

.modal-foot { display: flex; align-items: center; gap: 10px; margin-top: 20px; }
.modal-foot .spacer { flex: 1; }

/* ---------------- 提示条 ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  z-index: 200;
  max-width: 82vw;
  padding: 10px 18px;
  border-radius: 10px;
  background: #1f2328;
  color: #fff;
  font-size: 13.5px;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 响应式 ---------------- */
@media (max-width: 640px) {
  .app { padding: 18px 14px 44px; }
  .search { margin: 22px auto 30px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .site { padding: 10px 11px; gap: 10px; }
  .site-desc { display: none; }
  .search-submit { padding: 0 15px; }
  .cat-tools .btn { padding: 0 10px; }
}
