/* ========================================
   资源页外壳与收藏面板
   ======================================== */

body.resources-page {
    --resources-subject-tabs-height: 44px;
    box-sizing: border-box;
    padding-top: calc(var(--site-nav-height, 54px) + 1px);
}

.resources-subject-toolbar {
    position: relative;
    z-index: 850;
    display: flex;
    align-items: stretch;
    gap: 10px;
    width: 100%;
    height: var(--resources-subject-tabs-height);
    margin-top: 0;
    padding: 0 12px;
    box-sizing: border-box;
    background: var(--page-bg, #f5f7fa);
    flex-shrink: 0;
}

.resources-subject-tabs {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    width: auto;
    flex: 1 1 auto;
    min-width: 0;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    background: transparent;
    box-shadow: inset 0 -2px #e5e7eb;
}

.resources-subject-tabs::-webkit-scrollbar {
    display: none;
}

.resources-subject-tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-width: max-content;
    height: 100%;
    padding: 0 1rem;
    box-sizing: border-box;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    background: transparent;
    color: #6b7280;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.resources-subject-tab:hover {
    border-bottom-color: transparent;
    background: rgba(59, 130, 246, 0.05);
    color: #3b82f6;
    text-decoration: none;
}

.resources-subject-tab.active,
.resources-subject-tab[aria-current="page"] {
    border-bottom-color: #3b82f6;
    background: transparent;
    color: #3b82f6;
    font-weight: 600;
}

.resources-subject-tab:focus-visible {
    z-index: 1;
    outline: 3px solid rgba(59, 130, 246, 0.25);
    outline-offset: -3px;
}

.resources-subject-tab i {
    width: 1rem;
    flex: 0 0 auto;
    font-size: 1rem;
    text-align: center;
}

.resources-subject-tab[hidden] {
    display: none !important;
}

.resources-subject-tools,
.resources-subject-status,
.resources-subject-actions {
    display: flex;
    align-items: center;
    min-width: 0;
}

.resources-subject-tools {
    flex: 0 0 auto;
    gap: 6px;
    white-space: nowrap;
}

.resources-subject-status,
.resources-subject-actions {
    gap: 6px;
}

.resources-toolbar-search {
    width: clamp(170px, 16vw, 230px);
    flex: 0 0 auto;
}

.resources-toolbar-search .search-input-wrapper i {
    left: 11px;
    font-size: 0.8rem;
}

.resources-toolbar-search .search-input {
    height: 32px;
    padding: 0 10px 0 32px;
    box-sizing: border-box;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.8rem;
}

.resources-remaining-display {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 32px;
    padding: 0 9px;
    box-sizing: border-box;
    border: 1px solid #dbe3ef;
    border-radius: 8px;
    background: #ffffff;
    color: #64748b;
    font-size: 0.72rem;
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
    white-space: nowrap;
}

.resources-remaining-display[hidden] {
    display: none !important;
}

.resources-remaining-display i {
    font-size: 0.68rem;
    opacity: 0.75;
}

.resources-remaining-display strong {
    margin: 0 1px;
    color: #2563eb;
}

.resources-remaining-display.is-low {
    border-color: #fde68a;
    background: #fffbeb;
    color: #92400e;
}

.resources-remaining-display.is-low strong {
    color: #d97706;
}

.resources-remaining-display.is-empty {
    border-color: #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

.resources-remaining-display.is-empty strong {
    color: #dc2626;
}

.course-layout {
    display: flex;
    margin-top: calc(var(--site-nav-height, 54px) + 1px);
    height: calc(100vh - var(--site-nav-height, 54px) - 1px);
    height: calc(100dvh - var(--site-nav-height, 54px) - 1px);
    max-height: calc(100vh - var(--site-nav-height, 54px) - 1px);
    max-height: calc(100dvh - var(--site-nav-height, 54px) - 1px);
    overflow: hidden;
}

body.resources-page .course-layout {
    margin-top: 0;
    height: calc(100vh - var(--site-nav-height, 54px) - var(--resources-subject-tabs-height) - 1px);
    height: calc(100dvh - var(--site-nav-height, 54px) - var(--resources-subject-tabs-height) - 1px);
    max-height: calc(100vh - var(--site-nav-height, 54px) - var(--resources-subject-tabs-height) - 1px);
    max-height: calc(100dvh - var(--site-nav-height, 54px) - var(--resources-subject-tabs-height) - 1px);
}

/* 课件页面固定在可视区域内，内容由内部面板滚动。 */
body.course-page {
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}

body.course-page .navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}

/* 左侧栏 */
.sidebar {
    width: 300px;
    min-width: 300px;
    background: var(--bg-white);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-header {
    padding: 0 12px;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 0.5px solid #333;
    border-radius: 4px;
    margin: 8px 12px 0 12px;
    background: white;
    flex-shrink: 0;
}

/* 浏览模式切换栏中的收藏按钮 */
.favorites-header-btn {
    margin-left: 0;
    padding: 0.6rem 0.5rem;
    font-size: 0.85rem;
    border-radius: 8px;
    background: transparent;
    border: none;
    border-bottom: none;
    color: #64748b;
    cursor: pointer;
    white-space: nowrap;
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-weight: 500;
    transition: color 0.25s cubic-bezier(0.4, 0, 0.2, 1),
        background-color 0.25s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 0;
}

.favorites-header-btn:hover {
    color: #f59e0b;
    background: rgba(255, 255, 255, 0.5);
}

.favorites-header-btn.active {
    color: #d97706;
    background: #ffffff;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.1);
}

.sidebar-header h2 {
    font-size: 1rem;
    margin: 0;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input-wrapper i {
    position: absolute;
    left: 14px;
    color: #94a3b8;
}

.search-input {
    width: 100%;
    padding: 0.55rem 1rem 0.55rem 2.5rem;
    border: 0.5px solid #333;
    background: white;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #334155;
    outline: none;
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input:focus {
    background: #ffffff;
    border-color: #bfdbfe;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.search-input::placeholder {
    color: #64748b;
}

/* 收藏功能 */

/* 浏览模式切换区中的收藏按钮 */
.favorites-mode-btn {
    position: relative;
}

.favorites-mode-btn i {
    color: #f59e0b;
}

.favorites-mode-btn.active {
    color: #f59e0b;
    border-bottom-color: #f59e0b;
    font-weight: 600;
    background: transparent;
}

.favorites-mode-btn.active i {
    color: #f59e0b;
}

.fav-count-badge {
    position: static;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 600;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 2px;
}

.fav-count-badge:empty,
.fav-count-badge[data-count="0"] {
    display: none;
}

/* 与目录区域同级的收藏面板 */
.favorites-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: white;
    min-height: 0;
    /* 允许 Flex 子元素收缩。 */
    max-height: calc(100vh - 280px);
    /* 限制最大高度，确保列表可以内部滚动。 */
}

.favorites-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: white;
    flex-shrink: 0;
}

.favorites-panel-title {
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.favorites-panel-title i {
    color: white;
}

.favorites-panel-header .favorites-count {
    background: rgba(255, 255, 255, 0.25);
    color: white;
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 10px;
}

.favorites-panel .favorites-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem;
    min-height: 0;
    /* 允许 Flex 子元素收缩并启用内部滚动。 */
    -webkit-overflow-scrolling: touch;
    /* 保持旧版 iOS 的惯性滚动。 */
}

/* 旧版收藏区域兼容样式 */
.favorites-section {
    background: white;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.favorites-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.favorites-header:hover {
    background: var(--bg-light);
}

.favorites-count {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-gray);
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
}

.favorites-toggle {
    color: var(--text-light);
    font-size: 0.75rem;
    transition: transform 0.2s;
}

.favorites-toggle.expanded {
    transform: rotate(180deg);
}

.favorites-list {
    max-height: none;
    overflow-y: auto;
}

.favorites-empty {
    padding: 1.5rem 1rem;
    text-align: center;
    color: #64748b;
}

.favorites-empty i {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    display: block;
}

.favorites-empty p {
    font-size: 0.85rem;
    margin: 0;
}

.favorites-login-tip {
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
}

.favorites-login-tip i {
    font-size: 1.25rem;
    color: var(--text-light);
    margin-bottom: 0.5rem;
    display: block;
}

.favorites-login-tip p {
    font-size: 0.8rem;
    margin: 0 0 0.75rem;
}

.favorites-login-btn {
    display: inline-block;
    padding: 0.4rem 1rem;
    background: var(--primary-color);
    color: white;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.2s;
}

.favorites-login-btn:hover {
    background: var(--primary-dark);
}

.favorite-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--bg-gray);
    transition: background 0.2s;
}

.favorite-item:hover {
    background: var(--primary-bg);
}

.favorite-item:last-child {
    border-bottom: none;
}

.favorite-item-info {
    flex: 1;
    min-width: 0;
}

.favorite-item-title {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.favorite-item-path {
    display: block;
    font-size: 0.7rem;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.15rem;
}

.favorite-item-remove {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: #64748b;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.favorite-item:hover .favorite-item-remove,
.favorite-item:focus-within .favorite-item-remove,
.favorite-item-remove:focus-visible {
    opacity: 1;
}

.favorite-item-remove:hover {
    background: #fee2e2;
    color: #dc2626;
}

/* 收藏按钮 */
.favorite-btn {
    transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.favorite-btn.favorited {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%) !important;
    color: white !important;
}

.favorite-btn.favorited:hover {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%) !important;
}

/* 基于缩略图卡片的收藏卡片 */
.thumbnail-card.favorites-card {
    position: relative;
}

.favorites-card-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease, color 0.2s ease,
        transform 0.2s ease, box-shadow 0.2s ease;
    color: #b45309;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 10;
}

.thumbnail-card.favorites-card:hover .favorites-card-remove,
.thumbnail-card.favorites-card:focus-within .favorites-card-remove,
.favorites-card-remove:focus-visible {
    opacity: 1;
}

.favorites-card-remove:hover {
    background: #fef3c7;
    color: #dc2626;
    transform: scale(1.1);
}

.favorites-card-remove i {
    font-size: 0.9rem;
}

/* 收藏为空时的占位内容 */
.favorites-thumbnail-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: #64748b;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f8fafc;
}

/* 网格只包含空状态时，为绝对定位内容提供参照。 */
.thumbnail-grid:has(.favorites-thumbnail-empty) {
    position: relative;
    min-height: 400px;
}

/* 不支持 :has() 的浏览器由脚本添加兼容类。 */
.thumbnail-grid--favorites-empty {
    position: relative;
    min-height: 400px;
}

.favorites-thumbnail-empty i {
    font-size: 4rem;
    color: #cbd5e1;
    margin-bottom: 20px;
}

.favorites-thumbnail-empty h3 {
    font-size: 1.25rem;
    color: #475569;
    margin: 0 0 8px;
    font-weight: 600;
}

.favorites-thumbnail-empty p {
    font-size: 0.9rem;
    color: #475569;
    margin: 0;
}

.favorites-login-btn-large {
    display: inline-block;
    margin-top: 20px;
    padding: 12px 32px;
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: white;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.favorites-login-btn-large:hover {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(245, 158, 11, 0.4);
}

.favorites-header-btn:focus-visible,
.favorite-item-remove:focus-visible,
.favorite-btn:focus-visible,
.favorites-card-remove:focus-visible,
.favorites-login-btn-large:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.35);
    outline-offset: 2px;
}

@media (hover: none) {
    .favorite-item-remove,
    .favorites-card-remove {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    .resources-subject-tab,
    .resources-remaining-display,
    .favorites-header-btn,
    .search-input,
    .favorites-header,
    .favorites-toggle,
    .favorites-login-btn,
    .favorite-item,
    .favorite-item-remove,
    .favorite-btn,
    .favorites-card-remove,
    .favorites-login-btn-large {
        transition: none;
    }

    .favorites-card-remove:hover,
    .favorites-login-btn-large:hover {
        transform: none;
    }
}

/* 手机端空状态 */
@media (max-width: 768px) {
    .favorites-thumbnail-empty {
        padding: 40px 20px;
        min-height: 200px;
    }

    .favorites-thumbnail-empty i {
        font-size: 3rem;
    }
}

.catalog-nav {
    padding: 0.75rem;
    padding-bottom: 120px;
    /* 为浮动的“关闭目录”按钮预留底部空间。 */
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
}
