/* ================= 主题变量 ================= */
:root, html[data-theme="light"] {
  --bg: #f6f7f8;
  --bg-soft: #eef0f2;
  --card: #ffffff;
  --text: #1b1d21;
  --text-2: #6d7078;
  --link-c: #4d5256;          /* 书签文字色（小绿姬同款） */
  --border: #e3e5e9;
  --border-strong: #cfd2d8;
  --accent: #0e9f6e;
  --accent-weak: rgba(14, 159, 110, 0.12);
  --danger: #d43d51;
  --shadow: 0 4px 16px rgba(20, 24, 30, 0.08);
  --topbar: rgba(255, 255, 255, 0.82);
  --fav-s: 42%;
  --fav-l: 90%;
  --fav-t: #444;
}
html[data-theme="gray"] {
  --bg: #d7d8db;
  --bg-soft: #c9cacd;
  --card: #e9eaec;
  --text: #26282c;
  --text-2: #5c5f66;
  --link-c: #2c2f34;
  --border: #bfc1c6;
  --border-strong: #a8abb1;
  --accent: #0b8a5f;
  --accent-weak: rgba(11, 138, 95, 0.16);
  --danger: #b23348;
  --shadow: 0 4px 14px rgba(40, 44, 52, 0.14);
  --topbar: rgba(233, 234, 236, 0.88);
  --fav-s: 20%;
  --fav-l: 78%;
  --fav-t: #3a3d42;
}
html[data-theme="dark"] {
  --bg: #0c0d0f;
  --bg-soft: #141518;
  --card: #17181c;
  --text: #e8eaee;
  --text-2: #9aa1ac;
  --link-c: #cdd2d9;
  --border: #26282e;
  --border-strong: #363943;
  --accent: #2fbf8f;
  --accent-weak: rgba(47, 191, 143, 0.14);
  --danger: #e5637a;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  --topbar: rgba(18, 19, 22, 0.85);
  --fav-s: 32%;
  --fav-l: 26%;
  --fav-t: #e8eaee;
}

/* ================= 基础 ================= */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  transition: background-color 0.25s ease, color 0.25s ease;
}
button { font-family: inherit; }

/* ================= 顶栏 ================= */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--topbar);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 16px; font-weight: 650; letter-spacing: 0.02em; white-space: nowrap; }
.clock { flex: 1; text-align: center; color: var(--text-2); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 9px;
  min-width: 34px; height: 34px;
  padding: 0 9px;
  font-size: 15px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.wide { font-size: 13.5px; }
.icon-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 190px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 60;
}
.menu button {
  display: block; width: 100%;
  text-align: left;
  background: none; border: 0;
  color: var(--text);
  font-size: 13.5px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.menu button:hover { background: var(--bg-soft); }
.menu button.warn { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }

.edit-hint {
  position: sticky; top: 55px; z-index: 39;
  background: var(--accent-weak);
  color: var(--text);
  text-align: center;
  font-size: 12.5px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
}

/* ================= 主区 ================= */
.wrap { max-width: 1010px; margin: 0 auto; padding: 22px 20px 60px; }

.search-wrap { display: flex; justify-content: center; gap: 8px; margin-bottom: 20px; }
#search {
  width: min(560px, 100%);
  padding: 10px 16px;
  font-size: 14.5px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
#search::placeholder { color: var(--text-2); }
#search::-webkit-search-cancel-button { cursor: pointer; }
.engine-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--link-c);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}
.engine-btn:hover { border-color: var(--accent); color: var(--accent); }

.sec-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 8px; }
.sec-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  color: var(--text-2);
  letter-spacing: 0.08em;
}
.sec-hint { font-size: 12px; color: var(--text-2); opacity: 0.75; }

/* 常用图标条 */
.top-sites { margin-bottom: 18px; }
.pills { display: flex; flex-wrap: wrap; gap: 2px; }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  max-width: 220px;
  background: none;
  border: 0;
  color: var(--link-c);
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.pill:hover { background: var(--bg-soft); color: var(--accent); }
.pill .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill .pcount {
  font-size: 11px; color: var(--text-2);
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 0 7px;
  font-variant-numeric: tabular-nums;
}

/* ================= 书签区（小绿姬版式：左标题 + 文字超链接流） ================= */
.cats-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px 8px;
}

.cat {
  display: flex;
  gap: 12px;
  padding: 13px 10px;
}
.cat + .cat { border-top: 1px solid var(--border); }

.cat-head { flex: none; width: 100px; display: flex; align-items: flex-start; gap: 4px; }
.cat-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--link-c);
  line-height: 34px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hacts { display: none; gap: 1px; margin-top: 6px; }
.hacts button {
  border: 0; background: none; color: var(--text-2);
  width: 24px; height: 24px; border-radius: 6px;
  font-size: 13px; cursor: pointer;
}
.hacts button:hover { background: var(--bg-soft); color: var(--text); }

/* 链接流：行内排列，每项固定 138px（小绿姬同款格位） */
.grid { flex: 1; min-width: 0; }

.card {
  display: inline-flex; align-items: center; gap: 7px;
  width: 138px; height: 34px;
  vertical-align: top;
  color: var(--link-c);
  font-size: 15px;
  line-height: 34px;
  cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color 0.12s;
}
.card:hover { color: var(--accent); }
.card .cname { overflow: hidden; text-overflow: ellipsis; }

/* favicon：16px（小绿姬同款），失败时字母占位 */
.fav {
  flex: none;
  width: 16px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  overflow: hidden;
  background: none;
}
.fav img { width: 16px; height: 16px; display: block; }
.fav.letter {
  background: hsl(var(--h, 200) var(--fav-s) var(--fav-l));
  color: var(--fav-t);
  border-radius: 3px;
  font-size: 11px; font-weight: 650;
  line-height: 16px;
}
.pill .fav { width: 16px; height: 16px; }

/* 编辑模式：链接项变可操作块 */
body.edit-mode .hacts { display: inline-flex; }
body.edit-mode .card {
  position: relative;
  width: auto;
  min-width: 138px;
  max-width: 260px;
  padding: 0 58px 0 4px;
  margin: 0 6px 2px 0;
  border-radius: 6px;
  background: var(--bg-soft);
  line-height: 28px;
  height: 28px;
}
body.edit-mode .card:hover { color: var(--link-c); }
.card-actions {
  position: absolute; top: 0; right: 2px;
  display: none; gap: 0px;
}
body.edit-mode .card-actions { display: inline-flex; }
.ca {
  border: 0; background: none;
  color: var(--text-2);
  width: 20px; height: 28px;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.ca:hover { color: var(--text); }
.ca.del:hover { color: var(--danger); }

.add-cat {
  display: none;
  width: 100%;
  border: 0;
  background: none;
  color: var(--text-2);
  padding: 13px 10px;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  border-top: 1px solid var(--border);
}
.add-cat:hover { color: var(--accent); }
body.edit-mode .add-cat { display: block; }

.empty { text-align: center; color: var(--text-2); padding: 60px 0 20px; font-size: 14px; }

.foot {
  text-align: center;
  color: var(--text-2);
  font-size: 12px;
  opacity: 0.7;
  padding: 0 20px 26px;
}

/* ================= 弹窗 ================= */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.38);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  width: min(430px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px;
}
.modal h3 { margin: 0 0 16px; font-size: 15.5px; }
.modal .field { margin-bottom: 14px; }
.modal label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 5px; }
.modal input[type="text"], .modal input[type="url"], .modal select {
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
}
.modal input:focus, .modal select:focus { border-color: var(--accent); }
.modal .err { color: var(--danger); font-size: 12.5px; margin-top: 5px; min-height: 16px; }
.modal .modal-msg { font-size: 14px; margin-bottom: 4px; }
.modal .modal-sub { font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 16px;
  font-size: 13.5px;
  cursor: pointer;
}
.btn:hover { border-color: var(--border-strong); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ================= Toast ================= */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  z-index: 120;
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  border-radius: 10px;
  padding: 10px 18px;
  box-shadow: var(--shadow);
  max-width: min(520px, 90vw);
  text-align: center;
}

/* ================= 移动端 ================= */
@media (max-width: 720px) {
  .wrap { padding: 14px 10px 50px; }
  .cats-box { padding: 4px 4px; }
  .cat { flex-direction: column; gap: 2px; padding: 10px 8px; }
  .cat-head { width: auto; }
  .cat-head h2 { line-height: 30px; }
  .card { width: 32%; }
  .clock { display: none; }
  .edit-hint { position: static; font-size: 12px; }
  .search-wrap { flex-wrap: wrap; }
}

/* ================= 服务版增量 ================= */
.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-2); font-size: 12.5px;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.save-state {
  font-size: 11.5px; color: var(--text-2);
  display: inline-flex; align-items: center; gap: 5px;
}
.save-state .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-2); opacity: .5;
}
.save-state.saving .dot { background: #e6a700; animation: pulse 1s infinite; }
.save-state.saved .dot { background: var(--accent); opacity: 1; }
@keyframes pulse { 50% { opacity: .3; } }
.loading { text-align: center; color: var(--text-2); padding: 80px 0; font-size: 14px; }
.link-home {
  color: var(--text-2); text-decoration: none; font-size: 13px;
  border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 12px; background: var(--card);
}
.link-home:hover { border-color: var(--accent); color: var(--accent); }
