@layer components {
/* ============================================================
   FavsHub Mobile Responsive Styles
   Breakpoints: 1024px (tablet), 768px (phone), 480px (small phone)

   结构：
   1. 共享移动端元素样式（媒体查询外，桌面端通过 display:none 隐藏）
   2. @media (min-width:1025px) — 桌面端隐藏移动元素
   3. @media (max-width:1024px) — 平板特有
   4. @media (max-width:768px)  — 手机特有（侧边栏抽屉、布局重置等）
   5. @media (max-width:480px)  — 小屏微调
   6. 文件夹浮动导航（所有尺寸通用）
   7. 回到顶部按钮避让底栏（@layer 外，未分层覆盖未分层）
   ============================================================ */

/* ════════════════════════════════════════════
   1. 共享移动端元素样式
   ════════════════════════════════════════════ */

/* --- 顶部栏 --- */
.mobile-header-bar {
  display: flex; align-items: center; justify-content: space-between;
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  height: 56px; padding: 0 12px;
  box-sizing: border-box; max-width: 100vw;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
}

/* 防止移动端水平滚动溢出 */
@media (max-width: 1024px) {
  html, body { overflow-x: hidden; }
}
.mobile-header-bar .sidebar-brand-card { padding: 0; gap: 0.6rem; }
.mobile-header-bar .sidebar-brand-logo { width: 38px; height: 38px; padding: 7px; border-radius: 10px; }
.mobile-header-bar .sidebar-brand-title { font-size: 16px; }
.mobile-header-bar .sidebar-brand-subtitle { font-size: 10px; }
.mobile-header-actions { display: flex; align-items: center; gap: 4px; }
.mobile-header-actions .btn-favorite,
.mobile-header-actions .btn-primary,
.mobile-header-actions .btn-secondary {
  padding: 4px 8px; font-size: 12px; border-radius: 10px; gap: 4px;
}
.mobile-header-actions .btn-favorite i,
.mobile-header-actions .btn-primary i,
.mobile-header-actions .btn-secondary i { font-size: 13px; }
.mobile-header-actions .mobile-sort-select {
  padding: 4px 8px; font-size: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card-bg, var(--bg));
  color: var(--text-primary); outline: none; cursor: pointer;
  max-width: 72px; appearance: auto;
}

/* --- 汉堡按钮 --- */
.mobile-hamburger-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: none; border-radius: 10px;
  background: transparent; color: var(--text-primary);
  cursor: pointer; padding: 0;
  transition: background-color 120ms cubic-bezier(0.22, 1, 0.36, 1), transform 120ms cubic-bezier(0.22, 1, 0.36, 1);
}
.mobile-hamburger-btn:hover { background: var(--surface-hover); }
.mobile-hamburger-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.mobile-hamburger-btn:active { background: var(--surface-hover); transform: scale(0.95); }
.mobile-hamburger-btn svg { width: 22px; height: 22px; pointer-events: none; }

/* --- 底部导航 --- */
.mobile-bottom-nav {
  display: flex; align-items: center; justify-content: center;
  position: fixed; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%);
  z-index: 9998; gap: 4px;
  background: var(--surface-raised);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 6px 12px; box-shadow: var(--shadow-md);
}
.mobile-nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 6px 12px; border: none; background: transparent;
  color: var(--text-secondary); text-decoration: none; cursor: pointer;
  transition: color 120ms cubic-bezier(0.22, 1, 0.36, 1), background-color 120ms cubic-bezier(0.22, 1, 0.36, 1), transform 120ms cubic-bezier(0.22, 1, 0.36, 1);
  -webkit-tap-highlight-color: transparent;
  font-family: inherit; border-radius: 10px;
}
.mobile-nav-item.active, .mobile-nav-item:active {
  color: var(--primary); background: var(--primary-light);
}
.mobile-nav-item:active { transform: scale(0.96); }
.mobile-nav-item:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.mobile-nav-icon { font-size: 20px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.mobile-nav-icon i { font-size: 20px; }
.mobile-nav-label { font-size: 10px; font-weight: 500; line-height: 1; white-space: nowrap; }

/* --- 搜索弹窗 --- */
.mobile-search-backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--overlay); z-index: 10002;
  opacity: 0; pointer-events: none;
  transition: opacity 240ms cubic-bezier(0.22, 1, 0.36, 1);
}
.mobile-search-backdrop.active { opacity: 1; pointer-events: auto; }

.mobile-search-bottomsheet {
  position: fixed; bottom: 56px; left: 0; right: 0; z-index: 10003;
  max-height: 80vh; background: var(--surface-raised);
  border-radius: 14px 14px 0 0; display: none; flex-direction: column;
  box-shadow: var(--shadow-lg);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.mobile-search-bottomsheet.active { display: flex; }

.mobile-search-sheet-close {
  position: absolute; top: 10px; right: 10px;
  width: 36px; height: 36px; border: none;
  background: var(--surface-hover); color: var(--text-primary);
  cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  padding: 0; z-index: 99999; pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}
.mobile-search-sheet-close:active { background: var(--surface-active); transform: scale(0.95); }
.mobile-search-sheet-close:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.mobile-search-sheet-close svg { width: 20px; height: 20px; pointer-events: none; }

.mobile-search-sheet-body { flex: 1; overflow-y: auto; padding: 16px; padding-bottom: 60px; }


/* ════════════════════════════════════════════
   2. 桌面端：隐藏移动元素
   ════════════════════════════════════════════ */
@media (min-width: 1025px) {
  .mobile-header-bar,
  .mobile-sidebar-overlay,
  .mobile-bottom-nav { display: none; }
}


/* ════════════════════════════════════════════
   3. 平板及以下（≤1024px）— 侧边栏抽屉 + 顶底避让
   与 useMobile MOBILE_BP=1024 对齐，避免 769–1024 双导航
   ════════════════════════════════════════════ */
@media (max-width: 1024px) {
  /* 提示词页工具栏移动端隐藏 */
  .main-toolbar { display: none; }
  /* 主内容区留出顶部（MobileHeader 56px）和底部空间（底栏 + safe-area） */
  main.flex-1, .main-content { padding-top: 60px !important; padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
  /* 回到顶部按钮避让底栏：见文件末尾第 7 节——必须放在 @layer 外才能
     覆盖 main-bundle.css 顶层（未分层）的 bottom:0; z-index:999999 */
  /* 搜索引擎下拉底部面板：见文件末尾第 8 节——同样必须在 @layer 外，
     否则会被 main-bundle.css 未分层的 .search-engine-dropdown 基规则打败 */

  /* --- 侧边栏变抽屉（平板 + 手机统一） --- */
  aside.custom-width, aside.sidebar {
    display: flex; position: fixed; top: 0; left: 0; bottom: 0;
    width: 280px; min-width: 280px; max-width: 85vw; z-index: 10001;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none; overflow-y: auto; overflow-x: hidden;
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  aside.custom-width.mobile-drawer-open,
  aside.sidebar.mobile-drawer-open {
    transform: translateX(0); box-shadow: var(--shadow-lg);
  }

  /* --- 遮罩层 --- */
  .mobile-sidebar-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: var(--overlay); z-index: 10000;
    opacity: 0; transition: opacity 240ms cubic-bezier(0.22, 1, 0.36, 1);
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-sidebar-overlay.active { display: block; opacity: 1; }

  /* --- 隐藏桌面端控件 --- */
  #toggle-sidebar { display: none; }

  /* --- 布局重置 --- */
  #sidebar-container { width: 0; flex-shrink: 0; overflow: visible; margin-left: 0; }
  .home-shell, .prompts-root { overflow: visible; }
  #sidebar-container.collapsed aside.custom-width,
  #sidebar-container.collapsed aside.sidebar { display: flex; margin-left: 0; }
  main.flex-1 { width: 100%; margin-left: 0; padding: 60px 1rem 1rem; padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
  .main-content { width: 100%; }
  .main-area { padding: 60px 1rem 1rem; padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }

  #sidebar-container.mobile-drawer-open main.flex-1,
  #sidebar-container.mobile-drawer-open .main-content { pointer-events: none; }

  /* --- 首页：隐藏欢迎区 + 桌面搜索 --- */
  #welcome-message, .welcome-search-container, .home-shell .search-container { display: none; }
  .bookmarks-container { width: 100%; padding: 0.75rem; margin: 1rem auto; border-radius: 8px; }
  .folder-group { padding: 1rem; margin-bottom: 1rem; border-radius: 12px; }
  .folder-group-title { font-size: 1rem; margin-bottom: 0.75rem; padding-bottom: 0.4rem; }
  .folder-bookmarks-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .folder-bookmarks-grid .bookmark-card { max-width: 100%; }

  /* --- 提示词页 --- */
  .search-box { display: none; }
  .prompts-grid { grid-template-columns: 1fr; gap: 12px; }
  .filter-bar { flex-wrap: wrap; font-size: 11px; }
  .prompt-card { padding: 14px; gap: 10px; }
  .prompt-actions { opacity: 1; }

  /* --- 模态框 --- */
  .modal-content { max-width: calc(100vw - 24px); margin: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
  .modal-large, .modal-xlarge { max-width: calc(100vw - 24px); }
  .modal-body { padding: 16px; }
  .modal-footer { flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
  .modal-footer .btn { flex: 1 1 auto; min-width: 0; text-align: center; justify-content: center; }
  .form-row { grid-template-columns: 1fr; }

  /* --- 搜索弹窗内部 --- */
  .mobile-search-sheet-body .search-suggestions-wrapper { position: static; box-shadow: none; }
  .mobile-search-sheet-body .search-form { width: 100%; max-width: 100%; }
  .mobile-search-sheet-body .search-box { width: 100%; display: flex; }
}


/* ════════════════════════════════════════════
   4. 手机（≤768px）— 更紧布局
   ════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* --- 头部按钮额外调整（768px 独有） --- */
  .mobile-header-actions .btn-favorite,
  .mobile-header-actions .btn-primary,
  .mobile-header-actions .btn-secondary { padding: 5px 8px; }

  main.flex-1 { padding: 60px 1rem 1rem; padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
  .main-area { padding: 60px 1rem 1rem; padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }

  .folder-bookmarks-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
}


/* ════════════════════════════════════════════
   5. 小屏手机（≤480px）
   ════════════════════════════════════════════ */
@media (max-width: 480px) {
  main.flex-1, .main-area { padding: 52px 0.75rem 0.75rem; padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
  .mobile-header-bar { height: 50px; padding: 0 10px; }
  .mobile-header-bar .sidebar-brand-logo { width: 34px; height: 34px; padding: 6px; border-radius: 8px; }
  .mobile-header-bar .sidebar-brand-title { font-size: 15px; }
  .mobile-hamburger-btn svg { width: 20px; height: 20px; }
  .bookmarks-container { padding: 0.5rem; margin: 0.5rem auto; border-radius: 6px; }
  .btn-favorite { font-size: 12px; padding: 0.45rem 0.7rem; }
  .prompt-card { padding: 12px; border-radius: 10px; gap: 8px; }
  .prompt-title { font-size: 14px; }
  .prompt-desc { font-size: 12px; }
  .prompt-meta-footer { padding-top: 8px; flex-wrap: wrap; gap: 6px; }
  .modal-content { max-width: calc(100vw - 16px); margin: 8px; border-radius: 12px; }
  .modal-header { padding: 12px 16px; }
  .modal-header h2 { font-size: 16px; }
  aside.custom-width, aside.sidebar { width: 260px; min-width: 260px; }
  .folder-bookmarks-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr)) !important;
    gap: 0.5rem;
  }
}

/* 兜底：防止 auto-fill 窄屏自动退化成 1 列 */
@media (max-width: 610px) {
  .folder-bookmarks-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem;
  }
}


/* ════════════════════════════════════════════
   6. 文件夹浮动导航（所有尺寸通用）
   ════════════════════════════════════════════ */
.mobile-folder-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--overlay); z-index: 10000;
  -webkit-tap-highlight-color: transparent;
}
.mobile-folder-float {
  position: fixed; right: 12px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 4px;
  max-height: min(70vh, calc(100vh - 140px));
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  box-shadow: var(--shadow-md);
  z-index: 10001;
  scrollbar-width: thin;
}
.mobile-folder-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 10px; border-radius: 10px; cursor: pointer;
  transition: background-color 120ms cubic-bezier(0.22, 1, 0.36, 1), transform 120ms cubic-bezier(0.22, 1, 0.36, 1);
  text-decoration: none;
  flex-shrink: 0;
  border: none; background: transparent; font-family: inherit;
}
.mobile-folder-item:hover { background: var(--surface-hover); }
.mobile-folder-item:active { background: var(--surface-hover); transform: scale(0.96); }
.mobile-folder-item:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.mobile-folder-item.active { background: var(--primary-light, var(--primary-medium)); color: var(--primary); }
.mobile-folder-icon { font-size: 22px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.mobile-folder-icon i { font-size: 20px; }
.mobile-folder-icon.sub i { font-size: 15px; }
.mobile-folder-lock { font-size: 12px; color: var(--text-tertiary); display: flex; align-items: center; }
.mobile-folder-name {
  font-size: 10px; color: var(--text-primary);
  text-align: center; white-space: nowrap;
  max-width: 72px; overflow: hidden; text-overflow: ellipsis;
}
.mobile-folder-item.active .mobile-folder-name { color: var(--primary); }
.mobile-folder-sub {
  display: flex; flex-direction: column; gap: 2px; padding-left: 4px;
  flex-shrink: 0;
}
.mobile-folder-item.sub { padding: 6px 8px; }
.mobile-folder-icon.sub { font-size: 16px; }

/* Folder float animation */
.folder-float-enter-active,
.folder-float-leave-active { transition: opacity 180ms cubic-bezier(0.22, 1, 0.36, 1), transform 180ms cubic-bezier(0.22, 1, 0.36, 1); }
.folder-float-enter-from,
.folder-float-leave-to { opacity: 0; transform: translateY(8px); }

/* Sub folder animation */
.folder-sub-enter-active,
.folder-sub-leave-active { transition: opacity 180ms cubic-bezier(0.22, 1, 0.36, 1), max-height 180ms cubic-bezier(0.22, 1, 0.36, 1); overflow: hidden; }
.folder-sub-enter-from,
.folder-sub-leave-to { opacity: 0; max-height: 0; }
.folder-sub-enter-to,
.folder-sub-leave-from { max-height: 500px; }

}

/* ════════════════════════════════════════════
   Non-layered mobile overrides (higher priority than promptpro-bundle.css)
   ════════════════════════════════════════════ */
@media (max-width: 1024px) {
  /* Hide toolbar buttons already shown in MobileHeader */
  .main-toolbar .btn-favorite,
  .main-toolbar .sort-select,
  .main-toolbar .btn-primary { display: none !important; }

  /* Center and full-width search box */
  .main-toolbar {
    justify-content: center !important;
  }
  .main-toolbar .search-box {
    width: 100% !important;
    max-width: 360px !important;
  }
}

/* ════════════════════════════════════════════
   7. 回到顶部按钮避让底栏（顶层规则，不入 @layer）
   main-bundle.css 的 #back-to-top-container 是顶层（未分层）规则
   bottom:0; z-index:999999；未分层规则优先级高于任何 @layer 内规则，
   因此覆盖必须同样写在 @layer 外（见上文件头注释 6→7 编号）
   ════════════════════════════════════════════ */
@media (max-width: 1024px) {
  #back-to-top-container {
    z-index: 10004;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
}

/* ════════════════════════════════════════════
   8. 移动端搜索引擎下拉：底部面板（顶层规则，不入 @layer）
   main-bundle.css 的 .search-engine-dropdown 是未分层基规则
   （position:absolute; top:100%），未分层规则优先级高于任何 @layer
   内规则 → 覆盖必须同样写在 @layer 外，否则下拉退化成内联面板被压扁
   ════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .mobile-search-sheet-body .search-engine-dropdown {
    position: fixed; left: 16px; right: 16px; width: auto;
    bottom: 0; top: auto; max-height: 50vh; overflow-y: auto;
    z-index: 100004; margin-top: 0; border-radius: 14px 14px 0 0;
  }
  .engine-dialog-overlay { z-index: 100005; }
}
