/* ======================================================= */
/* 1. 全局初始化与基础设置 */
/* ======================================================= */
* {  
  margin: 0;  
  padding: 0;  
  box-sizing: border-box;  
}  

body {  
  background: #f2f2f7;  
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', Helvetica, Arial, sans-serif;  
  color: #1c1c1e;  
  min-height: 100vh;  
  padding: 40px 24px;  
  display: flex;  
  justify-content: center;  
  overflow-y: auto;
}  

.content-layout {  
  max-width: 800px;
  width: 100%;  
}  

.favorites-main {  
  width: 100%;  
  display: flex;  
  flex-direction: column;  
  gap: 16px;
}  

.section-block {  
  width: 100%;  
}  

/* ======================================================= */
/* 2. 大板块头部折叠控制 */
/* ======================================================= */
.main-header {  
  display: flex;  
  align-items: center;  
  justify-content: space-between;  
  margin-bottom: 16px;  
  padding-bottom: 12px;  
  border-bottom: 1px solid rgba(60, 60, 67, 0.1);  
}  

.main-header h1 {  
  font-size: 1.5rem;  
  font-weight: 700;  
  letter-spacing: -0.5px;  
  color: #000;  
}  

.clickable-header {  
  cursor: pointer;  
  user-select: none;  
}

.clickable-header::after {  
  content: '▼';  
  font-size: 0.85rem;  
  color: #8e8e93;  
  transition: transform 0.2s cubic-bezier(0.25, 1, 0.5, 1);  
}  

.section-block.is-collapsed .clickable-header::after {  
  transform: rotate(-90deg);  
}  

.section-content-wrapper {  
  overflow: hidden;  
  max-height: 8000px;
  transition: max-height 0.3s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.2s, margin 0.2s;  
  opacity: 1;  
  margin-bottom: 24px;
}  

.section-block.is-collapsed .section-content-wrapper {  
  max-height: 0 !important;  
  opacity: 0;  
  pointer-events: none;  
  margin-bottom: 0px;
}  

/* ======================================================= */
/* 3. 个人收藏：网格布局 */
/* ======================================================= */
.favorites-grid {  
  display: grid;  
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));  
  gap: 24px 16px;  
  margin-bottom: 16px;  
}  

.fav-item {  
  display: flex;  
  flex-direction: column;  
  align-items: center;  
  text-align: center;  
  text-decoration: none;  
  color: #1c1c1e;  
  background: none;  
  border: none;  
  outline: none;  
  cursor: pointer;  
  transition: transform 0.2s cubic-bezier(0.25, 1, 0.5, 1);  
}  

.fav-item:hover { transform: translateY(-4px); }  
.fav-item:active { transform: scale(0.95); }  

.fav-icon {  
  width: 64px;  
  height: 64px;  
  border-radius: 16px;  
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);  
  display: flex;  
  align-items: center;  
  justify-content: center;  
  margin-bottom: 8px;  
  position: relative;  
  overflow: hidden;
}  

/* 文件夹样式 */
.fav-item.is-folder .fav-icon {  
  background: linear-gradient(135deg, #ffdd75, #ffb834) !important;  
  box-shadow: 0 6px 12px rgba(230, 160, 30, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);  
}  

.fav-item.is-folder .fav-icon::before {  
  content: '';  
  position: absolute;  
  top: -4px;  
  left: 6px;  
  width: 20px;  
  height: 6px;  
  background: #ffb834;  
  border-radius: 4px 4px 0 0;  
}  

/* 多彩果冻渐变色 - 仅用于未加载到真实图标的书签 */
.fav-icon:not(.has-favicon) {
  background: linear-gradient(135deg, #007aff, #0056cc);
}
.fav-icon:not(.has-favicon) .fav-icon-fallback span {
  font-size: 26px;
  font-weight: 700;
  color: white !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  display: block;
}

/* 为不同位置的图标分配不同渐变色 */
.fav-item:nth-child(8n+1) .fav-icon:not(.has-favicon) { background: linear-gradient(135deg, #007aff, #0056cc); }
.fav-item:nth-child(8n+2) .fav-icon:not(.has-favicon) { background: linear-gradient(135deg, #ff9500, #ff7b00); }
.fav-item:nth-child(8n+3) .fav-icon:not(.has-favicon) { background: linear-gradient(135deg, #ff3b30, #e0241b); }
.fav-item:nth-child(8n+4) .fav-icon:not(.has-favicon) { background: linear-gradient(135deg, #34c759, #249d43); }
.fav-item:nth-child(8n+5) .fav-icon:not(.has-favicon) { background: linear-gradient(135deg, #af52de, #9137c0); }
.fav-item:nth-child(8n+6) .fav-icon:not(.has-favicon) { background: linear-gradient(135deg, #ff2d55, #e0163d); }
.fav-item:nth-child(8n+7) .fav-icon:not(.has-favicon) { background: linear-gradient(135deg, #5ac8fa, #1da1db); }
.fav-item:nth-child(8n+8) .fav-icon:not(.has-favicon) { background: linear-gradient(135deg, #8e8e93, #636366); }

.fav-title {  
  font-size: 0.75rem;  
  font-weight: 500;  
  line-height: 1.3;  
  max-width: 80px;  
  word-break: break-word;  
  color: #2c2c2e;  
  display: -webkit-box;  
  -webkit-line-clamp: 2;  
  -webkit-box-orient: vertical;  
  overflow: hidden;  
}  

/* 成功加载真实图标的样式 */
.fav-icon.has-favicon {
  background: #ffffff !important;
  border: 1px solid rgba(0, 0, 0, 0.05);
  padding: 12px;
  display: flex !important;
  align-items: center;
  justify-content: center;
}

.fav-icon.has-favicon img {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
  border-radius: 4px;
  display: block !important;
}

/* 降级文字图标容器 */
.fav-icon-fallback {
  width: 100%;
  height: 100%;
  display: flex !important;
  align-items: center;
  justify-content: center;
}

/* 文件夹展开抽屉 */
.folder-expanded-container {  
  grid-column: 1 / -1;  
  background: rgba(255, 255, 255, 0.45);  
  backdrop-filter: blur(25px);  
  -webkit-backdrop-filter: blur(25px);  
  border: 1px solid rgba(255, 255, 255, 0.5);  
  border-radius: 24px;  
  padding: 24px;  
  margin: -8px 0 16px 0;  
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 10px 25px rgba(0, 0, 0, 0.04);  
  display: none;  
  animation: fadeInSafari 0.25s cubic-bezier(0.25, 1, 0.5, 1);  
}  

.folder-expanded-container.is-active { display: block; }  

.folder-expanded-header {  
  font-size: 0.95rem;  
  font-weight: 600;  
  color: #3a3a3c;  
  margin-bottom: 16px;  
  display: flex;  
  align-items: center;  
  gap: 6px;  
}  

@keyframes fadeInSafari {  
  from { opacity: 0; transform: translateY(-10px); }  
  to { opacity: 1; transform: translateY(0); }  
}  

/* ======================================================= */
/* 4. 书签菜单样式 */
/* ======================================================= */
.folder-item { margin-bottom: 6px; }  

.folder-name {  
  font-weight: 600;  
  font-size: 0.9rem;  
  color: #1c1c1e;  
  padding: 10px 14px;  
  display: flex;  
  align-items: center;  
  justify-content: space-between;  
  border-radius: 12px;  
  background: rgba(255, 255, 255, 0.6);  
  cursor: pointer;  
  user-select: none;  
  transition: background 0.2s, transform 0.1s;  
}  

.folder-name:hover { background: rgba(255, 255, 255, 0.9); }  
.folder-name:active { transform: scale(0.99); }  

.folder-name::after {  
  content: '▼';  
  font-size: 0.65rem;  
  color: #8e8e93;  
  transition: transform 0.2s ease;  
}  

.folder-item.is-collapsed .folder-name::after {  
  transform: rotate(-90deg);  
}  

.bookmark-list {  
  list-style: none;  
  padding-left: 14px;  
  margin-top: 4px;  
  overflow: hidden;  
  max-height: 4000px;  
  transition: max-height 0.25s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.2s;  
  opacity: 1;  
}  

.folder-item.is-collapsed .bookmark-list {  
  max-height: 0 !important;  
  opacity: 0;  
  pointer-events: none;  
}  

.root-bookmark-item {
  list-style: none;
  margin-bottom: 2px;
}

.bookmark-link {  
  display: block;  
  padding: 9px 12px;  
  font-size: 0.85rem;  
  color: #007aff;  
  text-decoration: none;  
  border-radius: 8px;  
  transition: background 0.2s;  
  white-space: nowrap;  
  overflow: hidden;  
  text-overflow: ellipsis;  
}  

.bookmark-link:hover { background: rgba(0, 122, 255, 0.08); }  

/* 菜单中的 favicon 图标 */
.menu-favicon {
  width: 16px !important;
  height: 16px !important;
  object-fit: contain !important;
  margin-right: 8px;
  vertical-align: text-bottom;
  border-radius: 3px;
  display: inline-block !important;
}

.menu-favicon-fallback {
  font-size: 0.85rem;
  margin-right: 6px;
  display: inline-block;
}

/* ======================================================= */
/* 5. 其他状态 */
/* ======================================================= */
.loading-text, .error-text { padding: 30px; text-align: center; color: #8e8e93; font-size: 0.9rem; }  
hr { border: none; border-top: 1px solid rgba(60, 60, 67, 0.1); margin: 12px 0; }  

/* ======================================================= */
/* 6. 移动端自适应 */
/* ======================================================= */
@media (max-width: 850px) {  
  body { padding: 24px 12px; }  
  .favorites-grid { grid-template-columns: repeat(4, 1fr); gap: 20px 8px; }  
  .fav-icon { width: 56px; height: 56px; border-radius: 14px; margin-bottom: 6px; }  
  .fav-icon:not(.has-favicon) .fav-icon-fallback span { font-size: 22px !important; }
  .fav-item.is-folder .fav-icon::before { top: -3px; left: 5px; width: 16px; height: 5px; }  
  .fav-title { font-size: 0.7rem; max-width: 100%; padding: 0 2px; }  
  .folder-expanded-container { padding: 16px 12px; border-radius: 18px; }  
}

/* ======================================================= */
/* 7. 错误反馈面板 */
/* ======================================================= */
.error-panel {
  grid-column: 1 / -1;
  background: #ffffff;
  border: 1px solid rgba(255, 59, 48, 0.15);
  border-radius: 20px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 10px 25px rgba(255, 59, 48, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  animation: fadeInSafari 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

.error-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.error-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ff3b30;
  margin-bottom: 8px;
}

.error-details {
  font-family: monospace;
  font-size: 0.8rem;
  background: #fdf2f2;
  color: #d73a49;
  padding: 8px 12px;
  border-radius: 8px;
  display: inline-block;
  max-width: 100%;
  word-break: break-all;
  margin-bottom: 12px;
}

.retry-btn {
  background: linear-gradient(180deg, #ffffff, #f2f2f7);
  border: 1px solid rgba(60, 60, 67, 0.2);
  color: #1c1c1e;
  padding: 10px 24px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
  transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1);
}

.retry-btn:hover {
  background: #007aff;
  border-color: #0056cc;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

.retry-btn:active {
  transform: scale(0.97);
}

/* ======================================================= */
/* 8. 动画锁 */
/* ======================================================= */
.no-transition,
.no-transition *,
.no-transition::before,
.no-transition::after {
  transition: none !important;
  animation: none !important;
}

/* ======================================================= */
/* 文件夹预览图标（2x2 网格，类似 iOS App 文件夹） */
/* ======================================================= */

.folder-preview-icon {
  background: rgba(255, 255, 255, 0.95) !important;
  padding: 6px !important;
}

.folder-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 3px;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}

.folder-preview-item {
  background: linear-gradient(135deg, #f5f5f7, #e5e5ea);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.folder-preview-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.folder-preview-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  background: linear-gradient(135deg, #007aff, #0056cc);
  color: white;
}

/* 不同位置不同颜色 */
.folder-preview-item:nth-child(1) .folder-preview-fallback { background: linear-gradient(135deg, #007aff, #0056cc); }
.folder-preview-item:nth-child(2) .folder-preview-fallback { background: linear-gradient(135deg, #ff9500, #ff7b00); }
.folder-preview-item:nth-child(3) .folder-preview-fallback { background: linear-gradient(135deg, #34c759, #249d43); }
.folder-preview-item:nth-child(4) .folder-preview-fallback { background: linear-gradient(135deg, #af52de, #9137c0); }

.folder-preview-empty {
  background: rgba(0, 0, 0, 0.05);
}

.folder-preview-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 16px;
  pointer-events: none;
  z-index: 2;
}

/* 空文件夹图标样式 */
.folder-icon-empty {
  background: linear-gradient(135deg, #ffdd75, #ffb834) !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

.folder-icon-empty span {
  font-size: 32px;
}

/* 移动端适配 */
@media (max-width: 850px) {
  .folder-preview-fallback {
    font-size: 14px;
  }
  .folder-preview-grid {
    gap: 2px;
  }
}
