/* ============================================================
   收藏夹 — 苹果风 · 暖色调
   ============================================================ */

:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f5f0e8;
  --border: #ece4d8;
  --border-strong: #ddd2c0;

  --text: #2f2a24;
  --text-2: #6f6559;
  --text-3: #a39585;

  --accent: #d97b45;
  --accent-strong: #c96a37;
  --accent-soft: #f7e8db;

  --ok: #5a9e6f;
  --ok-soft: #e4f1e8;
  --dead: #c4453c;
  --dead-soft: #fae7e4;
  --unknown: #b3a896;
  --unknown-soft: #efebe3;

  --shadow-sm: 0 1px 2px rgba(93, 66, 44, 0.05), 0 2px 8px rgba(93, 66, 44, 0.05);
  --shadow-md: 0 4px 12px rgba(93, 66, 44, 0.08), 0 10px 30px rgba(93, 66, 44, 0.08);
  --shadow-lg: 0 12px 40px rgba(60, 42, 28, 0.18);

  --radius: 16px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { display: block; }

[hidden] { display: none !important; }

/* ------------------------------------------------------------ 通用组件 */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(217, 123, 69, 0.35);
}
.btn-primary:hover { background: var(--accent-strong); }

.btn-ghost {
  background: var(--surface);
  color: var(--text-2);
  border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: var(--dead);
  color: #fff;
}
.btn-danger:hover { background: #a9362f; }

.btn-block { width: 100%; justify-content: center; }

.icon-btn {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-3);
  line-height: 1;
  padding: 4px 8px;
  border-radius: 8px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field input, .field select, .field textarea {
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 123, 69, 0.18);
}

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-error { background: var(--dead-soft); color: var(--dead); }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-3);
  padding: 6px 10px;
  border-radius: 999px;
  display: flex;
  align-items: center;
}
.seg-btn.active { background: var(--surface); color: var(--accent-strong); box-shadow: var(--shadow-sm); }

/* ------------------------------------------------------------ 顶部栏 */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 24px;
  background: rgba(250, 247, 242, 0.85);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-dot {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #f0b584, var(--accent));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), var(--shadow-sm);
}
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: 0.2px; }

.search-box {
  flex: 1;
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 123, 69, 0.15);
}
.search-icon { color: var(--text-3); flex-shrink: 0; }
.search-box input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
}
.search-box input::placeholder { color: var(--text-3); }

.topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.user-menu { position: relative; }
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #d9a06a, var(--accent));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.avatar::-webkit-details-marker { display: none; }
.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 6px;
  display: none;
}
.user-menu[open] .user-dropdown { display: block; }
.user-dropdown a {
  display: block;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
.user-dropdown a:hover { background: var(--surface-2); text-decoration: none; }

/* ------------------------------------------------------------ 布局 */

.layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: calc(100vh - 62px);
}

/* ------------------------------------------------------------ 侧栏 */

.sidebar {
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  overflow-y: auto;
  position: sticky;
  top: 62px;
  height: calc(100vh - 62px);
}

.sidebar-section { margin-top: 22px; }
.sidebar-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-3);
  padding: 0 8px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.mini-btn {
  border: none;
  background: none;
  color: var(--text-3);
  font-size: 15px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
}
.mini-btn:hover { background: var(--surface); color: var(--accent-strong); }

.cat-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 8px 0;
  border-top: 1px solid var(--border);
}
.btn-sm { padding: 5px 12px; font-size: 12.5px; }

.tree { display: flex; flex-direction: column; gap: 2px; }

.tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  width: 100%;
  border: none;
  background: none;
  text-align: left;
}
.tree-item:hover { background: var(--surface); color: var(--text); }
.tree-item.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.tree-item .caret {
  width: 14px; flex-shrink: 0;
  color: var(--text-3);
  transition: transform 0.15s;
}
.tree-item .caret.collapsed { transform: rotate(-90deg); }
.tree-item .count { margin-left: auto; font-size: 12px; color: var(--text-3); }
.tree-children { display: flex; flex-direction: column; gap: 2px; }
.tree-children.indent { margin-left: 16px; padding-left: 6px; border-left: 1px solid var(--border); }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px; }
.tag-chip {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  border-radius: 999px;
  padding: 4px 11px;
}
.tag-chip:hover { border-color: var(--accent); color: var(--accent-strong); }
.tag-chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); font-weight: 600; }

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: none;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-2);
  text-align: left;
}
.status-row:hover { background: var(--surface); color: var(--text); }
.status-row.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.status-unknown { background: var(--unknown); }
.status-ok { background: var(--ok); }
.status-dead { background: var(--dead); }

/* ------------------------------------------------------------ 内容区 */

.content { padding: 26px 30px 60px; min-width: 0; }

.content-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 20px;
}
.content-head h2 { font-size: 24px; font-weight: 700; letter-spacing: -0.2px; }
.content-count { color: var(--text-3); font-size: 14px; }

/* 卡片视图 */
.bookmark-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.card.dead-card { opacity: 0.78; }
.card.dead-card .card-thumb::after {
  content: "链接已失效";
  position: absolute;
  inset: auto 0 0 0;
  padding: 6px 10px;
  background: rgba(196, 69, 60, 0.92);
  color: #fff;
  font-size: 12px;
  text-align: center;
}

.card-thumb {
  height: 118px;
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
}
.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-thumb .thumb-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  background: linear-gradient(135deg, #f3e9da, #ead9c2);
}

.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title-row { display: flex; align-items: center; gap: 8px; }
.card-favicon {
  width: 20px; height: 20px; border-radius: 5px; flex-shrink: 0;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card-favicon img { width: 100%; height: 100%; object-fit: contain; }
.card-title {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-host { font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-notes {
  font-size: 12.5px;
  color: var(--text-2);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  min-height: 2.4em;
}
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; }
.tag {
  font-size: 11px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 8px;
}
.card-menu {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px; height: 28px;
  border-radius: 8px;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--border);
  color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  opacity: 0;
  transition: opacity 0.12s;
  box-shadow: var(--shadow-sm);
}
.card:hover .card-menu { opacity: 1; }
.card-menu:hover { color: var(--text); }

/* 列表视图 */
.bookmark-list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  transition: box-shadow 0.15s;
  position: relative;
}
.row:hover { box-shadow: var(--shadow-sm); }
.row .row-thumb { width: 68px; height: 42px; border-radius: 8px; overflow: hidden; background: var(--surface-2); flex-shrink: 0; }
.row .row-thumb img { width: 100%; height: 100%; object-fit: cover; }
.row .row-thumb .thumb-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 18px; background: linear-gradient(135deg, #f3e9da, #ead9c2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 12.5px; color: var(--text-3); display: flex; align-items: center; gap: 8px; }
.row-sub .sep { color: var(--border-strong); }
.row-tags { display: flex; gap: 4px; }
.row-tags .tag { font-size: 10.5px; }
.row-status { flex-shrink: 0; }
.row-menu {
  border: none;
  background: none;
  color: var(--text-3);
  font-size: 16px;
  padding: 6px;
  border-radius: 8px;
  opacity: 0;
}
.row:hover .row-menu { opacity: 1; }
.row-menu:hover { color: var(--text); background: var(--surface-2); }

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 90px 20px;
  color: var(--text-3);
}
.empty-icon { font-size: 42px; margin-bottom: 14px; }

/* ------------------------------------------------------------ 弹窗 */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(47, 42, 36, 0.4);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 460px;
  padding: 24px;
  animation: pop 0.18s ease;
}
.modal-sm { max-width: 360px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { font-size: 18px; font-weight: 700; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.modal-actions-spacer { flex: 1; }
.confirm-text { color: var(--text-2); margin: 8px 0 20px; }

@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------ Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  animation: pop 0.2s ease;
}

/* ------------------------------------------------------------ 登录页 */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1200px 600px at 20% -10%, #f7e6d2 0%, transparent 60%),
    radial-gradient(900px 500px at 90% 110%, #f0d9c0 0%, transparent 55%),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 40px 34px;
  width: 100%;
  max-width: 380px;
}
.login-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.login-card h1 { text-align: center; font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.login-sub { text-align: center; color: var(--text-3); font-size: 14px; margin-bottom: 26px; }

/* ------------------------------------------------------------ Bookmarklet 页 */

.bm-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 24px;
}
.bm-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  padding: 36px;
  margin-bottom: 20px;
}
.bm-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.bm-card h2 { font-size: 17px; font-weight: 600; margin: 22px 0 10px; }
.bm-card p, .bm-card li { color: var(--text-2); font-size: 14.5px; }
.bm-card ol { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.bm-steps { margin: 14px 0; }
.bm-step { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 16px; }
.bm-num {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong);
  font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 2px;
}
.bm-step p { margin-top: 3px; }

.drag-hint {
  text-align: center;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 26px;
  margin: 18px 0;
  background: var(--bg);
}
.drag-hint .bm-bookmarklet {
  display: inline-block;
  margin-top: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 10px 22px;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(217, 123, 69, 0.35);
  cursor: grab;
  font-size: 14px;
}
.drag-hint .bm-bookmarklet:hover { background: var(--accent-strong); text-decoration: none; }
.drag-hint .hint-tip { font-size: 13px; color: var(--text-3); margin-top: 10px; }

.bm-foot { color: var(--text-3); font-size: 12.5px; text-align: center; }

/* ------------------------------------------------------------ 响应式 */

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
  }
  .sidebar-section { margin-top: 0; }
  .sidebar-section--status { display: none; }
  .content { padding: 20px 16px 60px; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  .search-box { order: 3; max-width: none; flex-basis: 100%; }
  .topbar-actions { gap: 8px; }
  #check-dead-btn span, #check-dead-btn { font-size: 0; gap: 0; padding: 8px 10px; }
}

@media (max-width: 520px) {
  .bookmark-grid { grid-template-columns: 1fr; }
  .row .row-thumb { display: none; }
  .brand-name { font-size: 15px; }
}
