:root {
  --bg: #f6f8fb;
  --text: #101828;
  --muted: #98a2b3;
  --line: rgba(16, 24, 40, 0.07);
  --line-strong: rgba(16, 24, 40, 0.12);
  --card: rgba(255, 255, 255, 0.7);
  --card-hover: rgba(255, 255, 255, 0.94);
  --accent: #3b6cff;
  --accent-soft: rgba(59, 108, 255, 0.12);
  --danger: #e5484d;
  --page: 1080px;
  --radius: 16px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei',
    sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(760px 440px at 6% -10%, #dbe8ff 0%, rgba(219, 232, 255, 0) 62%),
    radial-gradient(700px 420px at 98% 2%, #efe4ff 0%, rgba(239, 228, 255, 0) 60%),
    radial-gradient(820px 480px at 58% 108%, #d9f5eb 0%, rgba(217, 245, 235, 0) 62%),
    var(--bg);
  background-attachment: fixed;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(var(--page), calc(100vw - 48px));
  margin: 16px auto 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.74);
  backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: 0 8px 30px rgba(16, 24, 40, 0.07);
}

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

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: linear-gradient(140deg, #4f8cff, #8b5cf6);
  box-shadow: 0 5px 14px rgba(79, 140, 255, 0.35);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.pill {
  min-width: 20px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

.search {
  position: relative;
  flex: 1;
  max-width: 360px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  display: inline-flex;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.86);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.search input::placeholder {
  color: #a7b0be;
}

.search input:focus {
  border-color: rgba(59, 108, 255, 0.45);
  background: #fff;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.btn {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.84);
  color: #344054;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s;
}

.btn:hover {
  background: #fff;
  border-color: rgba(16, 24, 40, 0.18);
  box-shadow: 0 6px 16px rgba(16, 24, 40, 0.07);
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.btn.primary {
  border-color: transparent;
  background: linear-gradient(140deg, #4f8cff, #7c5cff);
  box-shadow: 0 8px 20px rgba(90, 120, 255, 0.32);
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover {
  box-shadow: 0 10px 24px rgba(90, 120, 255, 0.42);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn.ghost:hover {
  background: rgba(16, 24, 40, 0.05);
  border-color: transparent;
  box-shadow: none;
  color: #344054;
}

.btn.danger {
  border-color: transparent;
  background: var(--danger);
  color: #fff;
  font-weight: 600;
}

.btn.danger:hover {
  background: #d13b40;
}

.btn.block {
  width: 100%;
  height: 40px;
}

/* ---------- 主体 ---------- */
#board {
  width: min(var(--page), calc(100vw - 48px));
  margin: 0 auto;
  padding: 30px 0 90px;
}

.hint,
.empty {
  margin: 6px 2px;
  color: #a7b0be;
  font-size: 13px;
}

.group {
  margin-bottom: 26px;
  border-radius: var(--radius);
}

.group.dragging,
.card.dragging {
  opacity: 0.45;
}

.group.drop-target {
  box-shadow: 0 0 0 2px rgba(59, 108, 255, 0.35);
}

.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 0 2px;
  cursor: grab;
}

.group-head:active {
  cursor: grabbing;
}

.grip {
  color: #c3cad6;
  font-size: 12px;
  letter-spacing: -2px;
  user-select: none;
}

.group-head h2 {
  margin: 0;
  color: #475467;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.group-head .count {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.group-actions {
  display: flex;
  gap: 2px;
  margin-left: auto;
  opacity: 0;
  transition: opacity 0.15s;
}

.group-head:hover .group-actions,
.group-head:focus-within .group-actions {
  opacity: 1;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  border-color: var(--line-strong);
  background: #fff;
  color: #344054;
}

.icon-btn.danger:hover {
  border-color: rgba(229, 72, 77, 0.3);
  background: rgba(229, 72, 77, 0.08);
  color: var(--danger);
}

/* ---------- 卡片网格 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(198px, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  backdrop-filter: blur(16px) saturate(1.35);
  box-shadow: 0 2px 12px rgba(16, 24, 40, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.75);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.card:hover {
  border-color: var(--line-strong);
  background: var(--card-hover);
  box-shadow: 0 16px 34px rgba(16, 24, 40, 0.11);
  transform: translateY(-2px);
}

.card::before,
.card::after {
  content: '';
  position: absolute;
  top: 10px;
  bottom: 10px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.12s;
}

.card::before {
  left: -7px;
}

.card::after {
  right: -7px;
}

.card.drop-before::before,
.card.drop-after::after {
  opacity: 1;
}

.card-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
  color: inherit;
  text-decoration: none;
}

.site-icon {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 6px;
  border-radius: 13px;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.08);
  object-fit: contain;
}

.site-icon.letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 13px;
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

/* 服务端还在后台抓图标：色块呼吸一下，抓到后淡入替换 */
.site-icon.letter.pending {
  animation: icon-pending 1.4s ease-in-out infinite;
}

img.site-icon {
  animation: icon-appear 0.28s ease-out both;
}

@keyframes icon-pending {
  50% {
    opacity: 0.55;
    transform: scale(0.94);
  }
}

@keyframes icon-appear {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
}

@media (prefers-reduced-motion: reduce) {
  .site-icon.letter.pending,
  img.site-icon {
    animation: none;
  }
}

.card-meta {
  min-width: 0;
}

.card-meta .name {
  display: block;
  font-size: 13.5px;
  font-weight: 620;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta .host {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 2px 10px rgba(16, 24, 40, 0.12);
  opacity: 0;
  transition: opacity 0.15s;
}

.card:hover .card-actions,
.card:focus-within .card-actions {
  opacity: 1;
}

.card-actions .icon-btn {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  font-size: 12px;
}

/* ---------- 弹窗 ---------- */
.dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(20px);
  color: var(--text);
  box-shadow: 0 30px 70px rgba(16, 24, 40, 0.22);
}

.dialog::backdrop {
  background: rgba(16, 24, 40, 0.28);
  backdrop-filter: blur(3px);
}

.dialog form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
}

.dialog h2 {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 650;
}

.dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #667085;
  font-size: 12px;
}

.dialog input,
.dialog select {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.dialog input:focus,
.dialog select:focus {
  border-color: rgba(59, 108, 255, 0.45);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.dialog-text {
  margin: 0;
  color: #667085;
  font-size: 13px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 12px;
}

/* ---------- 提示条 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  max-width: min(460px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: 12px;
  background: #101828;
  box-shadow: 0 16px 40px rgba(16, 24, 40, 0.28);
  color: #f9fafb;
  font-size: 13px;
}

.toast.error {
  background: #b42318;
}

/* ---------- 登录页 ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(340px, 100%);
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(20px) saturate(1.3);
  box-shadow: 0 26px 60px rgba(16, 24, 40, 0.14);
  text-align: center;
}

.login-card .brand-mark {
  align-self: center;
  width: 40px;
  height: 40px;
  border-radius: 13px;
  font-size: 18px;
}

.login-card h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
}

.login-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.login-card input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: #fff;
  outline: none;
}

.login-card input:focus {
  border-color: rgba(59, 108, 255, 0.45);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- 小屏 ---------- */
@media (max-width: 720px) {
  .topbar {
    top: 8px;
    width: calc(100vw - 24px);
    margin-top: 8px;
    flex-wrap: wrap;
    padding: 10px;
    gap: 8px;
  }

  .search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }

  .toolbar .btn {
    padding: 0 10px;
  }

  #board {
    width: calc(100vw - 24px);
    padding: 20px 0 80px;
  }

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

  .card {
    gap: 10px;
    padding: 10px 12px;
  }

  .site-icon {
    width: 38px;
    height: 38px;
    padding: 5px;
    border-radius: 11px;
  }

  .site-icon.letter {
    font-size: 16px;
  }

  /* 触屏没有悬停，操作入口常驻 */
  .card-actions,
  .group-actions {
    opacity: 1;
  }

  .card-actions {
    position: static;
    background: transparent;
    box-shadow: none;
    padding: 0;
  }
}

@media (hover: none) {
  .card-actions,
  .group-actions {
    opacity: 1;
  }
}