/* 响应式调整 */

@media (max-width: 1024px) and (min-width: 769px) {
    .favorites-grid {
        grid-template-columns: repeat(8, minmax(150px, 1fr));
    }

    .bookmark-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* PC 端：让 Logo + 搜索框整体更居中，分类和标签自然排在下面 */
@media (min-width: 769px) {
    .main-section {
        justify-content: center;      /* 垂直方向居中主内容块 */
        padding-top: 40px;           /* 顶部和底部各留一点空白，保证视觉舒适 */
        padding-bottom: 40px;
        min-height: auto;
    }
}

/* iPad Pro 等平板设备优化：确保内容完整显示 */
@media (min-width: 769px) and (max-width: 1366px) {
    .main-section {
        padding-top: 32px;
        padding-bottom: 32px;
        justify-content: center;      /* 平板也保持整体居中 */
    }

    .logo-wrap {
        margin-bottom: 28px;         /* Logo 与搜索框之间增加间距 */
    }

    .logo-wrap img {
        width: 260px;                /* Logo 稍微小一点，节省空间 */
        height: auto;
        max-height: 85px;            /* 限制最大高度 */
    }

    .search-panel {
        margin-top: 0;               /* 搜索框紧贴 Logo */
    }

    .favorites-section {
        margin-top: 0;
    }
    
    .category-nav {
        margin: 20px auto 16px;        /* 分类导航栏与搜索框和标签之间的间距 */
    }

    .favorites-grid {
        column-gap: 18px;           /* 水平方向 18px */
        row-gap: 10px;              /* iPad 竖直方向恢复为之前较紧凑的高度 */
        min-height: 96px;           /* 平板端保持固定高度 */
    }

    /* Footer 优化 */
    .page-footer {
        padding: 12px 24px 16px;     /* 减少 footer 的 padding */
        font-size: 11px;             /* 稍微小一点的字体 */
    }

    /* 确保页面内容不会超出视口 */
    body {
        min-height: 100vh;
        height: auto;
        overflow-x: hidden;          /* 防止横向滚动 */
    }
}

/* iPad Pro 横屏模式（1024px-1366px）进一步优化 */
@media (min-width: 1024px) and (max-width: 1366px) and (orientation: landscape) {
    .main-section {
        padding-top: 20px;           /* 横屏时进一步减少顶部间距 */
        padding-bottom: 12px;
    }

    .logo-wrap {
        margin-bottom: 24px;         /* 横屏时也保持适当间距 */
    }

    .logo-wrap img {
        width: 240px;                /* 横屏时 Logo 更小 */
        max-height: 75px;
    }

    .favorites-section {
        margin-top: 0;
    }
}

@media (max-width: 768px) {
    .top-bar {
        flex-wrap: wrap;
        gap: 8px;
        justify-content: space-between;
    }

    .top-left {
        flex: 1 1 auto;
        justify-content: flex-start;
    }

    .top-right {
        flex: 1 1 auto;
        justify-content: flex-end;
    }

    .logo-wrap {
        margin-left: 0;
        margin-top: 8px;
        margin-bottom: 24px; /* 手机端 Logo 与搜索框之间保持舒服的间距 */
        transform: none;
    }

    .logo-wrap img {
        width: 220px;
        height: 72px;
        border-radius: 10px;
    }

    .engine-dropdown {
        display: inline-flex; /* 在移动端显示下拉按钮 */
        align-items: center;
        margin-right: 8px;
        margin-left: 8px;
        position: relative; /* 确保下拉菜单能正确定位 */
    }

    /* 移动端：恢复与PC端一样的4列网格布局，但位置靠左 */
    .engine-dropdown-menu {
        position: absolute !important; /* 使用absolute定位，相对于父容器 */
        left: -16px !important; /* 向左偏移16px，让它更靠左（贴近浏览器左边） */
        right: auto !important;
        top: calc(100% + 6px) !important; /* 显示在按钮下方，与PC端一致 */
        bottom: auto !important;
        transform: none !important;
        min-width: 360px; /* 保持PC端的宽度 */
        max-width: calc(100vw - 32px); /* 最大不超过屏幕宽度减去左右边距 */
        width: auto !important;
        max-height: 60vh; /* 最大高度为视口高度的60% */
        overflow-y: auto;
        border-radius: 12px; /* 恢复圆角 */
        box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
        padding: 10px;
        margin: 0;
        z-index: 30;
    }


    .engine-dropdown-menu.show {
        grid-template-columns: repeat(4, minmax(0, 1fr)); /* 恢复4列，与PC端一致 */
        gap: 8px;
        display: grid !important;
    }

    .engine-dropdown-item {
        padding: 10px 6px; /* 恢复PC端的padding */
        border-radius: 10px;
        gap: 6px;
        min-height: auto; /* 移除固定高度 */
        transition: background-color var(--transition-fast);
    }

    .engine-dropdown-item:active {
        transform: none; /* 移除缩放效果 */
    }

    .engine-dropdown-item img {
        width: 26px !important; /* 恢复PC端的图标大小 */
        height: 26px !important;
        border-radius: 50%;
    }

    .engine-dropdown-item span {
        font-size: 12px; /* 恢复PC端的字体大小 */
        font-weight: normal;
        line-height: 1.3;
    }

    /* 移除移动端的拖拽指示条 */
    .engine-dropdown-menu::before {
        display: none;
    }

    .top-bar {
        padding: 12px 16px;
    }

    .search-panel {
        max-width: 100%;
        margin-top: 0;
    }

    .search-box-wrap {
        max-width: 100%;
    }

    .favorites-section {
        margin-top: 20px;
        min-height: 220px; /* 手机端保持足够高度，空分类不跳动 */
    }

    /* 当隐藏分类/标签时，仅隐藏模块，不改动主区域布局（移动端同样保持原位） */
    body.hide-categories .category-nav,
    body.hide-categories .favorites-section {
        display: none !important;
    }

    /* 手机端：每行 3 个，等分宽度 */
    .favorites-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        column-gap: 12px;
        row-gap: 12px;
        justify-content: center;
        max-width: 100%;
        min-height: 140px;
    }

    /* 手机端标签：自适应列宽，略增高度和圆角，视觉更舒适 */
    .favorite-card {
        width: 100%;
        height: 48px;
        padding: 10px 12px;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 10px;
        border-radius: 10px;
        box-sizing: border-box;
    }

    .favorite-card > div {
        width: 100%;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 10px;
    }

    /* 手机端图标：与PC端一致，20x20px */
    .favorite-icon {
        width: 20px;
        height: 20px;
        flex: 0 0 20px;
        border-radius: 4px;
    }

    .favorite-icon img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    /* 手机端文字区域：与PC端一致，左对齐，单行省略 */
    .favorite-text {
        flex: 1 1 auto;
        min-width: 0;
        text-align: left;
        overflow: hidden;
    }

    .favorite-name {
        font-size: 13px;
        font-weight: 400;
        line-height: 1.3;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--text-main);
        margin: 0;
    }

    /* 手机端：默认隐藏操作按钮 */
    .fav-actions {
        display: none;
    }

    /* 手机端：右键/长按时显示到卡片右上角；编辑模式保持兼容 */
    .favorite-card {
        position: relative;
    }

    .favorite-card.show-actions > div > .fav-actions,
    body.fav-editing .favorite-card > div > .fav-actions {
        display: flex !important;
        position: absolute;
        top: 6px;
        right: 6px;
        transform: none;
        width: auto;
        gap: 6px;
        justify-content: flex-end;
        align-items: flex-start;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-radius: 8px;
        padding: 4px 6px;
        z-index: 20;
    }

    /* 防止其它规则隐藏，确保显示状态可见 */
    .favorite-card.show-actions .fav-actions,
    body.fav-editing .fav-actions {
        display: flex !important;
    }

    body.theme-dark.fav-editing .fav-actions {
        background: rgba(17, 24, 39, 0.9);
        border-color: rgba(55, 65, 81, 0.8);
    }

    /* 手机端编辑/删除按钮：精致小巧 */
    body.fav-editing .fav-delete-btn,
    body.fav-editing .fav-edit-btn {
        width: 24px;
        height: 24px;
        border-radius: 999px;
    }

    body.fav-editing .fav-delete-icon {
        width: 14px;
        height: 14px;
    }
    
    /* 手机端分类导航：横向滚动 */
    .category-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 12px;
        margin: 20px auto 16px;
        justify-content: flex-start;
    }

    /* 手机端：编辑按钮上移一些并收紧间距 */
    #fav-edit-toggle {
        margin-top: -6px;
        margin-bottom: 10px !important;
    }
    
    .category-nav::-webkit-scrollbar {
        display: none;
    }
    
    .category-btn {
        font-size: 13px;
        padding: 6px 16px;
    }

    .page-footer {
        padding: 12px 16px 18px;
    }
}

@media (max-width: 480px) {
    /* 小屏幕：保持与PC端一致的布局，自适应列数 */
    .favorites-grid {
        grid-template-columns: repeat(auto-fill, 136px);
        column-gap: 18px;
        row-gap: 10px;
        justify-content: center;
        min-height: 96px;          /* 小屏幕下保持固定高度 */
    }

    /* 小屏幕卡片和图标保持与PC端一致 */
    .favorite-card {
        width: 140px;
        height: 40px;
        padding: 8px 12px;
    }

    .favorite-icon {
        width: 20px;
        height: 20px;
        flex: 0 0 20px;
    }

    .favorite-name {
        font-size: 13px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .bookmark-list {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }

    .auth-container {
        margin-top: 40px;
        border-radius: 16px;
        padding: 24px 18px 20px;
    }

    .dashboard-container {
        margin-top: 24px;
    }

    /* 小屏幕：保持4列布局，与PC端一致 */
    .engine-dropdown-menu {
        min-width: 320px; /* 小屏幕时稍微缩小最小宽度 */
    }
}


