/* 编辑操作统一尺寸、线条与状态；危险操作在悬停或聚焦时强调。 */
.ui-icon { display: inline-block; flex-shrink: 0; vertical-align: middle; pointer-events: none; }
.edit-mode-hint { display: none; align-items: center; gap: 12px; padding-top: 18px; color: var(--text-secondary); font-size: 12px; }
body.edit-mode .edit-mode-hint { display: flex; }
.edit-mode-label { display: inline-flex; align-items: center; flex-shrink: 0; gap: 7px; font-weight: 600; color: var(--accent); }
.edit-mode-label::before { content: ''; width: 6px; height: 6px; background: currentColor; border-radius: 50%; }
body.edit-mode main.container { padding-top: 18px; }

.cat-action-btn, .sub-tab-edit, .sub-tab-delete, .card-delete {
  width: 30px;
  height: 30px;
  min-height: 30px;
  flex: 0 0 30px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  line-height: 1;
  box-shadow: none;
  transition: color .15s, background .15s, border-color .15s;
}
.cat-action-btn:hover, .sub-tab-edit:hover { color: var(--accent); background: var(--accent-bg); border-color: var(--accent-light); transform: none; }
.card-delete:hover, .card-delete:focus-visible, .sub-tab-delete:hover, .sub-tab-delete:focus-visible,
.cat-action-btn.cat-action-danger:hover, .cat-action-btn.cat-action-danger:focus-visible {
  color: #bd4141;
  border-color: #d89494;
  background: #fff0ee;
  transform: none;
}
html.dark .card-delete:hover, html.dark .card-delete:focus-visible,
html.dark .sub-tab-delete:hover, html.dark .sub-tab-delete:focus-visible,
html.dark .cat-action-btn.cat-action-danger:hover, html.dark .cat-action-btn.cat-action-danger:focus-visible {
  color: #ffaaa1;
  border-color: #895a57;
  background: #432c2b;
}
.cat-action-btn:disabled, .sub-tab-edit:disabled, .sub-tab-delete:disabled, .card-delete:disabled { opacity: .45; cursor: wait; }
.cat-actions { align-items: center; gap: 6px; }
.cat-action-btn.is-hidden { opacity: 1; color: var(--accent); }
.cat-action-btn.sidebar-rename-btn { flex-basis: 30px; width: 30px; height: 30px; margin-right: -12px; }

/* 拖柄都使用六点图标，并与点击操作保留独立触控区域。 */
.sidebar-drag-handle, .cat-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 24px;
  width: 24px;
  min-width: 24px;
  height: 32px;
  min-height: 32px;
  margin-right: 4px;
  color: var(--text-muted);
  opacity: 1;
}
.sidebar-drag-handle:hover, .cat-drag-handle:hover { color: var(--accent); }
.engine-drag-handle { margin-right: 5px; opacity: .75; }
.engine-btn { display: inline-flex; align-items: center; justify-content: center; max-width: 100%; padding: 6px 12px; }
.engine-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.edit-mode .engine-drag-handle { display: inline-flex; align-items: center; }
body.edit-mode .engine-btn { display: inline-flex; align-items: center; }
body.edit-mode .engine-drag-handle .ui-icon { width: 14px; height: 16px; }

/* 小目录标签与操作构成一个完整分组，减少散落图标带来的杂乱。 */
body.edit-mode .sub-tabs { padding: 8px; gap: 8px; background: transparent; }
body.edit-mode .sub-tab-item { padding: 3px; gap: 3px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; }
body.edit-mode .sub-tab-item:has(.sub-tab.active) { border-color: var(--accent-light); }
body.edit-mode .sub-tab-item .sub-tab { padding: 6px 11px; }
body.edit-mode .sub-tab-edit, body.edit-mode .sub-tab-delete { border-color: transparent; background: transparent; }
body.edit-mode .sub-tab-edit:hover { background: var(--accent-bg); }
body.edit-mode .sub-tab-delete:hover { background: #fff0ee; }
html.dark body.edit-mode .sub-tab-delete:hover { background: #432c2b; }
.sub-tab-drag-handle { display: inline-flex; align-items: center; justify-content: center; width: 18px; flex-shrink: 0; color: var(--text-muted); cursor: grab; }
.sub-tab-drag-handle .ui-icon { width: 14px; height: 18px; }
body.edit-mode .sub-tab-add { display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 6px 11px; font-size: 12px; font-weight: 500; border-radius: 10px; min-height: 38px; }

/* 编辑态保留静态卡片；悬停边框和拖动反馈即可提示可操作。 */
body.edit-mode .link-card:not(.card-add):not(.drag-active):not(.drag-ghost) { animation: none; }
body.edit-mode .link-card:not(.card-add) { padding-right: 50px; }
.card-delete { top: 10px; right: 10px; }
.card-add { border-width: 1px; border-radius: var(--radius); color: var(--text-secondary); width: 100%; }
.card-add .add-icon { display: inline-flex; font-size: inherit; }
.card-add .add-icon .ui-icon { width: 21px; height: 21px; }
.card-add .add-text { color: var(--text-secondary); }
.add-cat-section { display: block; width: 100%; border-width: 1px !important; }
.add-cat-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; }
.sidebar-add-cat { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: transparent; font-style: normal; font-family: inherit; }

/* 隐藏状态只淡化内容，操作按钮保持清晰，状态文字不遮住按钮。 */
.cat-hidden { opacity: 1; border-style: dashed; }
.cat-hidden::after { display: none; }
.cat-hidden .category-name::after { content: '已隐藏'; display: inline-block; margin-left: 10px; padding: 2px 7px; border-radius: 5px; background: var(--accent-bg); color: var(--accent); font-size: 11px; font-weight: 500; vertical-align: middle; }
.cat-hidden .links-grid { opacity: .55; }

.admin-fab, body.edit-mode .admin-fab { width: auto; height: 44px; padding: 0 18px; gap: 8px; border-radius: 12px; font-size: 14px; font-weight: 600; letter-spacing: 0; box-shadow: var(--shadow-lg); }
.admin-fab:hover { transform: translateY(-1px); }
.sort-toast { max-width: calc(100vw - 48px); padding: 10px 16px; font-size: 13px; }
.sort-toast-success { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); border-left: 3px solid var(--accent); }
/* 多条提示在右下角依次排列，互不覆盖；错误提示可点击关闭。 */
.toast-stack { position: fixed; right: 24px; bottom: 88px; z-index: 10000; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; max-width: calc(100vw - 48px); pointer-events: none; }
.toast-stack .sort-toast { position: relative; right: auto; bottom: auto; display: flex; align-items: center; gap: 10px; }
.toast-stack .sort-toast-error { pointer-events: auto; cursor: pointer; }
.toast-close { flex: 0 0 auto; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 6px; background: rgba(255,255,255,.18); color: inherit; font-size: 16px; line-height: 22px; cursor: pointer; }
.toast-close:hover { background: rgba(255,255,255,.3); }
/* 编辑网址时显示当前图标，并可手动重新获取。 */
.edit-icon-row[hidden] { display: none; }
.edit-icon-label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.edit-icon-line { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.edit-icon-preview { display: inline-flex; }
.edit-icon-preview .card-icon, .edit-icon-preview .card-icon-placeholder { width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; }
.edit-icon-preview .card-icon { object-fit: contain; }
.edit-icon-preview .card-icon-placeholder { display: flex; align-items: center; justify-content: center; background: var(--accent-solid); color: var(--on-accent); font-size: 15px; font-weight: 700; }
.edit-icon-line .category-name-hint { margin: 0; }
.edit-icon-line .category-name-hint.is-error { color: #bd4141; }
html.dark .edit-icon-line .category-name-hint.is-error { color: #ffa49c; }
.toast-close:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 32px; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-secondary); }
.btn:hover { color: var(--accent); background: var(--accent-bg); }
.btn-primary { border-color: transparent; background: var(--accent-solid); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-solid); color: var(--on-accent); }
.btn-danger { color: #bd4141; background: transparent; }
.btn-danger:hover { color: #bd4141; background: #fff0ee; border-color: #d89494; }
html.dark .btn-danger { color: #ffaaa1; }
html.dark .btn-danger:hover { color: #ffaaa1; background: #432c2b; border-color: #895a57; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.form-group input[readonly] { background: var(--bg); color: var(--text-secondary); }
.form-group input[type="checkbox"] { width: auto; margin-right: 5px; accent-color: var(--accent-solid); }
.admin-table .btn { margin: 2px; white-space: nowrap; }

@media (max-width: 768px) {
  .content { width: 100%; }
  .edit-mode-hint { align-items: flex-start; gap: 8px; font-size: 11px; }
  body.edit-mode .category-title { flex-wrap: wrap; gap: 8px; }
  body.edit-mode .category-name { flex: 1; }
  body.edit-mode .cat-actions { flex-basis: 100%; justify-content: flex-end; padding-top: 4px; }
  body.edit-mode .sub-tabs { flex-wrap: nowrap; max-width: 100%; overflow-x: auto; padding-bottom: 10px; scrollbar-width: thin; }
  body.edit-mode .sub-tab-item, body.edit-mode .sub-tab-all, body.edit-mode .sub-tab-add { flex-shrink: 0; }
  .cat-action-btn, .sub-tab-edit, .sub-tab-delete { width: 34px; height: 34px; min-height: 34px; flex-basis: 34px; }
  body.edit-mode .links-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
  .admin-fab, body.edit-mode .admin-fab { bottom: 18px; right: 16px; }
  .toast-stack { right: 16px; bottom: 76px; max-width: calc(100vw - 32px); }
}
@media (max-width: 480px) {
  .search-engines { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .engine-btn { min-height: 34px; padding: 6px 4px; font-size: 12px; }
  .engine-drag-handle { margin-right: 3px; }
  body.edit-mode .engine-drag-handle .ui-icon { width: 12px; }
}
@media (max-width: 360px) {
  .search-engines { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* 保留内容密度，减少空页头；手机保留明确的分类跳转入口。 */
.search-header { padding-top: 42px; padding-bottom: 32px; }
.site-title { margin-bottom: 24px; }
.load-error { display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--text-secondary); padding: 16px; font-size: 13px; }
.load-error[hidden] { display: none; }
.search-order-control { display: none; margin: 12px auto 0; padding: 6px 10px; border-radius: 7px; color: var(--text-secondary); background: transparent; border: 1px solid var(--border); font-size: 12px; }
body.edit-mode .search-order-control { display: block; }
.mobile-category-jump { display: none; }
.card-order, .sub-tab-order { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 8px; color: var(--text-secondary); background: var(--bg-card); flex-shrink: 0; }
.card-order { position: absolute; top: 46px; right: 10px; z-index: 10; }
.card-order:hover, .sub-tab-order:hover { color: var(--accent); background: var(--accent-bg); }
body.edit-mode .sub-tab-order { border-color: transparent; background: transparent; }
body.category-sort-saving .card-order, body.category-sort-saving .sub-tab-order { pointer-events: none; opacity: .45; }
.category-title:focus { outline: none; }
.category-section { scroll-margin-top: 70px; }
@media (max-width: 768px) {
  .search-header { padding: 28px 0 24px; }
  .mobile-category-jump { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20; padding-top: 10px; padding-bottom: 10px; background: var(--bg); border-bottom: 1px solid var(--border); }
  .mobile-category-jump label { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }
  .mobile-category-jump select { min-width: 0; flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-card); color: var(--text); font: inherit; font-size: 14px; }
  .card-order, .sub-tab-order { width: 34px; height: 34px; }
  .load-error { flex-wrap: wrap; }
}
/* 两个卡片操作纵向排列时留足空间，短标题或无简介也不会裁掉按钮。 */
body.edit-mode .link-card:not(.card-add) { min-height: 90px; }

/* 首屏先为搜索选项、侧栏和内容区预留位置，数据到达后页面不再整体往下跳。
   只在选项尚未显示时预留（按常用 8 个选项的行数），显示后按实际高度；加载失败不留空白。 */
.search-engines { align-content: start; }
.search-engines:empty { min-height: 33px; }
.search-engines.search-engines-failed { min-height: 0; }
.sidebar:empty { visibility: hidden; }
.content > .loading { min-height: 100vh; }
@media (max-width: 600px) {
  .search-engines:empty { min-height: 72px; }
}
@media (max-width: 480px) {
  .search-engines:empty { min-height: 74px; }
}
@media (max-width: 360px) {
  .search-engines:empty { min-height: 114px; }
}
