/**
 * cards.css — Category sections, bookmark cards, and default grid.
 * Split from style.css with rule order preserved.
 */
/* ==================== 主内容区域 ==================== */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px 20px 40px;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--sidebar-transition), transform 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
    will-change: margin-left;
}

#main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
}

#grid-container.grid-container {
    flex: 1;
    width: 100%;
}

.grid-container {
    max-width: 62rem;
    margin: 0 auto;
}

/* ==================== 分类区块（连续滚动） ==================== */
.category-section {
    margin-bottom: 24px;
    scroll-margin-top: 30px;
}

.category-section-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px; /* 微调略小更显精致 */
    font-weight: 700;
    color: var(--text);
    padding: 6px 14px;
    margin-bottom: 16px;
    margin-left: 4px;
    position: sticky;
    top: 0;
    z-index: 10;
    border-radius: 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    
    /* 🔒 固定大小设计（配合 1图标+5个字限制，给卡片向上弹出释放充裕空间） */
    max-width: 160px; /* 固定的最大宽度 */
    height: 32px; /* 固定的高度 */
    box-sizing: border-box;
    overflow: hidden; /* 强制裁剪溢出 */
}

/* 分类名文字样式（确保截断） */
.category-section-title .cat-title-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100px;
}

.category-section-title .cat-icon {
    font-size: 20px;
}

/* 💡 页面管理模式下的分类标题高亮与悬浮效果 */
.manage-clickable-cat {
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.manage-clickable-cat:hover {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #fff !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(57, 157, 255, 0.4);
}

.manage-clickable-cat:hover .edit-pencil-icon {
    opacity: 1 !important;
    color: #fff !important;
    transform: scale(1.2);
}

/* ==================== 分类按钮样式（保留用于管理弹窗内） ==================== */
.tab-btn {
    white-space: nowrap;
    padding: 8px 22px;
    border-radius: 25px;
    border: 1px solid var(--glass-border);
    background: var(--glass);
    color: var(--text);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 16px;
    font-weight: bold;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: scale(1.05);
}

.tab-btn.active.warning-btn {
    background: #f39c12;
    border-color: #e67e22;
    box-shadow: 0 4px 15px rgba(230, 126, 34, 0.4);
}

/* ==================== 分段选择器（Segmented Control）样式 ==================== */
.segmented-control {
    display: flex;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 8px;
    padding: 3px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

body.light-theme .segmented-control {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.03);
}

.seg-btn {
    flex: 1;
    border: none;
    outline: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    background: transparent;
    color: rgba(255, 255, 255, 0.65);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
}

body.light-theme .seg-btn {
    color: rgba(44, 62, 80, 0.65);
}

.seg-btn.active {
    background: var(--primary) !important;
    color: #ffffff !important;
    box-shadow: 0 2px 6px rgba(57, 157, 255, 0.3);
    font-weight: bold;
}

.tab-btn.hidden-item {
    opacity: 0.4;
    text-decoration: line-through;
}

/* ==================== 分类管理按钮 ==================== */
.manage-cat-btn {
    background: transparent;
    border: 1px dashed var(--glass-border);
    color: var(--text-dim);
    padding: 8px 16px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 15px;
    white-space: nowrap;
}

/* ==================== 导航网格布局（Style 0 默认） ==================== */
.nav-grid {
    display: grid;
    gap: 15px;
    margin: 0 auto;
    width: 100%;
    grid-template-columns: repeat(auto-fill, minmax(min(var(--card-w, 85px), 100%), 1fr));
}

/* ==================== 卡片样式（Style 0 默认） ==================== */
.card {
    background: var(--glass);
    border: none;
    border-radius: var(--radius);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: visible; /* 允许气泡溢出显示 */
    animation: fadeInUp 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) both;
    width: 100%;
    height: var(--card-h, 105px); /* 🚀 统一高度，解决因内容或新建卡片高度参差不齐的问题 */
    box-sizing: border-box;
}

body:not(.view-style-2) .card {
    width: 100% !important;
    max-width: var(--card-w, 105px) !important;
    height: var(--card-h, 105px) !important;
    margin: 0 auto;
}

/* 淡入上浮动画 */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Task 4.4: 新增网址虚线卡片 */
.add-new-card {
    cursor: pointer;
    min-height: var(--card-h, 105px); /* 🚀 对齐默认 105px 卡片高度 */
    height: var(--card-h, 105px); /* 🚀 对齐默认 105px 卡片高度 */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    border: 1px dashed var(--glass-border) !important;
    background: transparent !important;
    box-shadow: none !important;
}

body:not(.view-style-2) .add-new-card {
    width: 100% !important;
    max-width: var(--card-w, 105px) !important;
    height: var(--card-h, 105px) !important;
    min-height: var(--card-h, 105px) !important;
    margin: 0 auto;
}

.add-new-card:hover {
    border-color: var(--primary) !important;
    background: rgba(57, 157, 255, 0.1) !important;
    transform: translateY(-2px);
}

.add-new-card i {
    font-size: 24px;
    color: var(--primary);
    margin-bottom: 4px;
}

.add-new-card h3 {
    font-size: 12px !important;
    color: var(--text-dim) !important;
}

.add-new-card.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.card:hover {
    background: var(--glass-hover);
    transform: translateY(-2px);
    box-shadow: 0 0 15px rgba(57, 157, 255, 0.5), 0 0 30px rgba(57, 157, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.card.sortable-ghost {
    opacity: 0.4;
    background: var(--primary);
}

.card.hidden-item {
    opacity: 0.3;
    filter: grayscale(1);
}

.card a {
    text-decoration: none;
    color: inherit;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0;
    overflow: hidden;
    gap: 6px;
}

/* ==================== 全局气泡提示框 (Task 4.13) ==================== */
[data-tooltip]:not([data-tooltip=""])::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 12px); /* 还原为向上弹出（优化空间后避免遮挡） */
    left: 50%;
    transform: translateX(-50%) translateY(8px); /* 还原初始向上偏移 */
    background: rgba(20, 20, 20, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #fff;
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 11px;
    white-space: pre-wrap;
    z-index: 5000; /* 提升到侧边栏之上 */
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
    width: max-content;
    max-width: 220px;
    text-align: center;
    line-height: 1.6;
}

[data-tooltip]:not([data-tooltip=""])::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 4px); /* 还原为向上弹出 */
    left: 50%;
    transform: translateX(-50%) translateY(8px); /* 还原初始动效 */
    border: 5px solid transparent;
    border-top-color: rgba(20, 20, 20, 0.85); /* 还原小箭头朝下，指向卡片主体 */
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 5000;
    pointer-events: none;
}

[data-tooltip]:not([data-tooltip=""]):hover::after,
[data-tooltip]:not([data-tooltip=""]):hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* 兼容旧有的卡片特定逻辑 */
body.page-manage-active .card[data-tooltip]::after,
body.page-manage-active .card[data-tooltip]::before {
    display: none !important;
}

/* 移动端/触屏设备适配：禁用 hover 气泡 */
@media (hover: none) and (pointer: coarse) {
    [data-tooltip]::after,
    [data-tooltip]::before {
        display: none !important;
    }
    /* 触屏下禁用侧边栏 hover 展开，改由 JS 或 Pin 控制 */
    body.sidebar-folded .sidebar:hover {
        width: var(--sidebar-mini-width);
        box-shadow: none;
    }
}

/* ==================== 卡片图标与标题（Style 0） ==================== */
.icon-wrapper {
    width: var(--icon-size, 48px);
    height: var(--icon-size, 48px);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 4px auto 8px auto;
    overflow: hidden;
    transition: all 0.3s ease;
}

.card img {
    width: 24px;
    height: 24px;
    border-radius: 8px;
    object-fit: contain;
    transition: all 0.3s ease, opacity 0.3s ease;
    /* 初始透明，配合 loading="lazy" 减少闪烁感 */
    opacity: 1; 
}

/* 优化 Zen Mode 切换时主区域的位移动画 */
.main-content {
    transition: margin-left 0.6s cubic-bezier(0.165, 0.84, 0.44, 1), transform 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
    will-change: margin-left, transform;
}

.card .emoji-icon {
    font-size: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.card h3 {
    font-size: calc(14px * var(--card-font-scale, 1));
    font-weight: 500;
    text-align: center;
    width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    white-space: normal;
    color: #fff;
    line-height: 1.25;
    min-height: calc(2.5em * var(--card-font-scale, 1));
}

/* ==================== 管理操作按钮 ==================== */
.admin-actions {
    position: absolute;
    top: 5px;
    right: 5px;
    display: flex;
    gap: 3px;
    z-index: 20;
    opacity: 1;
}

.action-mini {
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 22px;
    height: 22px;
    border-radius: 5px;
    color: #fff;
    cursor: pointer;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==================== 管理操作区域 ==================== */
/* ==================== 管理操作区域 (Task 4.12 极简工具栏) ==================== */
.sidebar-admin-toolbar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 6px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

body.light-theme .sidebar-admin-toolbar {
    background: rgba(0, 0, 0, 0.04);
}

.toolbar-item {
    flex: 1;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 8px !important;
    cursor: pointer;
    position: relative; /* 为气泡提供定位基准 */
    overflow: visible !important; /* Task 4.14: 确保气泡不被裁剪 */
    transition: all 0.2s ease;
}

.toolbar-item .nav-icon {
    margin-right: 0 !important;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toolbar-item:hover {
    background: var(--glass-hover);
    color: var(--primary);
}

.toolbar-item.active {
    background: transparent !important;
    color: var(--primary) !important;
}

/* 侧边指示器 (Task 9.1) */
.toolbar-item.active::before {
    content: '';
    position: absolute;
    left: -2px;
    top: 20%;
    height: 60%;
    width: 3px;
    background: var(--primary);
    border-radius: 0 4px 4px 0;
    box-shadow: 0 0 10px var(--primary);
}

.toolbar-item .nav-label {
    font-size: 12px;
    font-weight: 500;
    margin-left: 6px;
    display: none; /* 默认隐藏，仅在特定模式下或hover展示？不，用户要求“仅显示页面管理四个字” */
}

body.admin-mode .toolbar-item.active .nav-label {
    display: block;
}

body.admin-mode .toolbar-item.active {
    grid-column: span 4;
}

/* 侧边栏内管理工具子菜单微调 */
.admin-tools-submenu {
    padding-left: 10px;
    margin-top: 2px;
    border-left: 2px dashed var(--glass-border);
    margin-left: 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-admin-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
