/**
 * Nebula Theme - Sidebar & Widgets Stylesheet
 * Version: 3.0.0
 * 参考设计：腾讯云技术社区、安全客、先知社区
 * 原则：无硬编码，通过CSS变量控制
 */

/* ============================
   Sidebar Container
   ============================ */

.nebula-sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.nebula-sidebar__empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--nebula-text-muted, #94A3B8);
    font-size: 0.875rem;
}

.nebula-sidebar__empty p {
    margin-bottom: 12px;
}

.nebula-sidebar__empty a {
    color: var(--nebula-primary, #0EA5E9);
    text-decoration: none;
}

/* ============================
   Widget Card Base — 统一卡片
   ============================ */

.nebula-sidebar .widget,
.nebula-sidebar > div[id^="nebula"],
.nebula-sidebar > aside {
    background: var(--nebula-bg, #FFFFFF);
    border-radius: 8px;
    border: 1px solid var(--nebula-border, #E2E8F0);
    padding: 16px;
    transition: box-shadow 0.2s ease;
}

.nebula-sidebar .widget:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* ============================
   Widget Title — 统一标题
   ============================ */

.nebula-sidebar .widget-title,
.nebula-sidebar .widgettitle,
.nebula-sidebar h2.widgettitle {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--nebula-text, #1E293B);
    margin: 0 0 12px 0;
    padding: 0 0 10px 0;
    border-bottom: 1px solid var(--nebula-border, #E2E8F0);
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.4;
}

/* ============================
   Search Widget — 搜索框
   ============================ */

.nebula-sidebar .widget_search .search-form {
    display: flex;
    gap: 0;
}

.nebula-sidebar .widget_search .search-field {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--nebula-border, #E2E8F0);
    border-radius: 6px 0 0 6px;
    font-size: 0.8125rem;
    outline: none;
    transition: border-color 0.15s;
    background: var(--nebula-bg, #fff);
    color: var(--nebula-text, #1E293B);
}

.nebula-sidebar .widget_search .search-field:focus {
    border-color: var(--nebula-primary, #0EA5E9);
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.15);
}

.nebula-sidebar .widget_search .search-submit {
    padding: 8px 14px;
    background: var(--nebula-primary, #0EA5E9);
    color: #fff;
    border: none;
    border-radius: 0 6px 6px 0;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background 0.15s;
}

.nebula-sidebar .widget_search .search-submit:hover {
    background: var(--nebula-primary-hover, #0284C7);
}

/* ============================
   Recent Posts — 热门文章（安全客风格排行）
   ============================ */

.nebula-sidebar .widget_recent_entries ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nebula-sidebar .widget_recent_entries li {
    padding: 10px 0;
    border-bottom: 1px solid #F1F5F9;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.nebula-sidebar .widget_recent_entries li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.nebula-sidebar .widget_recent_entries li:first-child {
    padding-top: 0;
}

.nebula-sidebar .widget_recent_entries a {
    font-size: 0.8125rem;
    color: var(--nebula-text, #1E293B);
    text-decoration: none;
    line-height: 1.5;
    flex: 1;
    transition: color 0.15s;
}

.nebula-sidebar .widget_recent_entries a:hover {
    color: var(--nebula-primary, #0EA5E9);
}

.nebula-sidebar .widget_recent_entries .post-date {
    display: block;
    font-size: 0.75rem;
    color: var(--nebula-text-muted, #94A3B8);
    margin-top: 2px;
}

/* ============================
   Tag Cloud — 标签云（药丸标签）
   ============================ */

.nebula-sidebar .widget_tag_cloud .tagcloud {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.nebula-sidebar .widget_tag_cloud .tagcloud a {
    display: inline-block;
    padding: 4px 10px;
    background: #F1F5F9;
    color: var(--nebula-text-secondary, #64748b);
    font-size: 0.75rem !important;
    border-radius: 4px;
    text-decoration: none;
    transition: all 0.15s ease;
    line-height: 1.4;
}

.nebula-sidebar .widget_tag_cloud .tagcloud a:hover {
    background: var(--nebula-primary, #0EA5E9);
    color: #fff;
    transform: translateY(-1px);
}

/* ============================
   Categories — 分类列表（安全客风格）
   ============================ */

.nebula-sidebar .widget_categories ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nebula-sidebar .widget_categories li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #F1F5F9;
    font-size: 0.8125rem;
}

.nebula-sidebar .widget_categories li:last-child {
    border-bottom: none;
}

.nebula-sidebar .widget_categories a {
    color: var(--nebula-text, #1E293B);
    text-decoration: none;
    transition: color 0.15s;
}

.nebula-sidebar .widget_categories a:hover {
    color: var(--nebula-primary, #0EA5E9);
}

.nebula-sidebar .widget_categories .count {
    font-size: 0.6875rem;
    color: var(--nebula-text-muted, #94A3B8);
    background: #F1F5F9;
    padding: 1px 6px;
    border-radius: 10px;
}

/* ============================
   Custom Nebula Widgets
   ============================ */

/* --- 热门排行小工具 --- */
.nebula-ranking-widget {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nebula-ranking-widget li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid #F1F5F9;
}

.nebula-ranking-widget li:last-child {
    border-bottom: none;
}

.nebula-ranking-widget .rank-badge {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6875rem;
    font-weight: 700;
    color: #fff;
    background: var(--nebula-text-muted, #94A3B8);
    margin-top: 2px;
}

.nebula-ranking-widget li:nth-child(1) .rank-badge { background: #EF4444; }
.nebula-ranking-widget li:nth-child(2) .rank-badge { background: #F97316; }
.nebula-ranking-widget li:nth-child(3) .rank-badge { background: #EAB308; }

.nebula-ranking-widget .rank-title {
    font-size: 0.8125rem;
    color: var(--nebula-text, #1E293B);
    text-decoration: none;
    line-height: 1.5;
    flex: 1;
    transition: color 0.15s;
}

.nebula-ranking-widget .rank-title:hover {
    color: var(--nebula-primary, #0EA5E9);
}

.nebula-ranking-widget .rank-views {
    font-size: 0.6875rem;
    color: var(--nebula-text-muted, #94A3B8);
    flex-shrink: 0;
    margin-top: 2px;
}

/* --- 分类导航小工具 --- */
.nebula-category-nav-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.nebula-category-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 6px;
    background: #F8FAFC;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.15s ease;
    border: 1px solid transparent;
}

.nebula-category-nav-item:hover {
    border-color: var(--nebula-primary, #0EA5E9);
    background: #F0F9FF;
    transform: translateY(-1px);
}

.nebula-category-nav-item .cat-name {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--nebula-text, #1E293B);
    margin-bottom: 2px;
}

.nebula-category-nav-item .cat-count {
    font-size: 0.6875rem;
    color: var(--nebula-text-muted, #94A3B8);
}

/* --- TOC 文章目录小工具 --- */
.nebula-toc-widget-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 400px;
    overflow-y: auto;
}

.nebula-toc-widget-list::-webkit-scrollbar {
    width: 3px;
}

.nebula-toc-widget-list::-webkit-scrollbar-thumb {
    background: var(--nebula-border, #E2E8F0);
    border-radius: 3px;
}

.nebula-toc-widget-list li {
    margin: 0;
    padding: 0;
}

.nebula-toc-widget-list a {
    display: block;
    padding: 6px 8px;
    font-size: 0.8125rem;
    color: var(--nebula-text-secondary, #64748b);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.15s;
    line-height: 1.4;
    border-left: 2px solid transparent;
}

.nebula-toc-widget-list a:hover,
.nebula-toc-widget-list a.active {
    color: var(--nebula-primary, #0EA5E9);
    background: #F0F9FF;
    border-left-color: var(--nebula-primary, #0EA5E9);
}

.nebula-toc-widget-list .toc-h3 a {
    padding-left: 20px;
    font-size: 0.75rem;
}

/* --- 作者卡片小工具 --- */
.nebula-author-card {
    text-align: center;
    padding: 16px 8px;
}

.nebula-author-card .author-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    margin: 0 auto 10px;
    border: 2px solid var(--nebula-primary, #0EA5E9);
}

.nebula-author-card .author-name {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--nebula-text, #1E293B);
    margin-bottom: 4px;
}

.nebula-author-card .author-bio {
    font-size: 0.8125rem;
    color: var(--nebula-text-secondary, #64748b);
    line-height: 1.5;
}

/* --- CTA订阅小工具 --- */
.nebula-cta-widget {
    background: linear-gradient(135deg, #0EA5E9, #2563EB) !important;
    border: none !important;
    color: #fff;
    text-align: center;
    padding: 24px 16px !important;
    border-radius: 8px !important;
}

.nebula-cta-widget .cta-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.nebula-cta-widget .cta-desc {
    font-size: 0.8125rem;
    opacity: 0.9;
    margin-bottom: 16px;
    line-height: 1.5;
}

.nebula-cta-widget .cta-button {
    display: inline-block;
    padding: 8px 24px;
    background: #fff;
    color: #0EA5E9;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.15s;
}

.nebula-cta-widget .cta-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* --- 安全快讯小工具 --- */
.nebula-ticker-widget {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nebula-ticker-widget li {
    padding: 8px 0;
    border-bottom: 1px solid #F1F5F9;
}

.nebula-ticker-widget li:last-child {
    border-bottom: none;
}

.nebula-ticker-widget a {
    font-size: 0.8125rem;
    color: var(--nebula-text, #1E293B);
    text-decoration: none;
    line-height: 1.5;
    transition: color 0.15s;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.nebula-ticker-widget a:hover {
    color: var(--nebula-primary, #0EA5E9);
}

.nebula-ticker-widget .ticker-time {
    font-size: 0.6875rem;
    color: var(--nebula-text-muted, #94A3B8);
    margin-top: 2px;
}

/* ============================
   Article Page Sidebar Layout
   ============================ */

.nebula-article-sidebar {
    width: var(--nebula-sidebar-ratio, 30%);
    flex-shrink: 0;
    position: sticky;
    top: 80px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    scrollbar-width: thin;
}

.nebula-article-sidebar::-webkit-scrollbar {
    width: 3px;
}

.nebula-article-sidebar::-webkit-scrollbar-thumb {
    background: var(--nebula-border, #E2E8F0);
    border-radius: 3px;
}

/* ============================
   Home Page Sidebar
   ============================ */

.ds-home-sidebar {
    width: var(--nebula-sidebar-ratio, 30%);
    flex-shrink: 0;
}

/* ============================
   Dark Mode
   ============================ */

body.dark-mode .nebula-sidebar .widget,
body.dark-mode .nebula-sidebar > div[id^="nebula"] {
    background: #1E293B;
    border-color: #334155;
}

body.dark-mode .nebula-sidebar .widget-title,
body.dark-mode .nebula-sidebar .widgettitle {
    color: #F1F5F9;
    border-bottom-color: #334155;
}

body.dark-mode .nebula-sidebar .widget_search .search-field {
    background: #0F172A;
    border-color: #334155;
    color: #E2E8F0;
}

body.dark-mode .nebula-sidebar .widget_recent_entries a,
body.dark-mode .nebula-sidebar .widget_categories a {
    color: #E2E8F0;
}

body.dark-mode .nebula-sidebar .widget_recent_entries a:hover,
body.dark-mode .nebula-sidebar .widget_categories a:hover {
    color: var(--nebula-primary, #38BDF8);
}

body.dark-mode .nebula-sidebar .widget_recent_entries li,
body.dark-mode .nebula-sidebar .widget_categories li {
    border-bottom-color: #334155;
}

body.dark-mode .nebula-sidebar .widget_tag_cloud .tagcloud a {
    background: #334155;
    color: #94A3B8;
}

body.dark-mode .nebula-sidebar .widget_tag_cloud .tagcloud a:hover {
    background: var(--nebula-primary, #38BDF8);
    color: #0F172A;
}

body.dark-mode .nebula-sidebar .widget_categories .count {
    background: #334155;
}

body.dark-mode .nebula-ranking-widget .rank-title {
    color: #E2E8F0;
}

body.dark-mode .nebula-ranking-widget li {
    border-bottom-color: #334155;
}

body.dark-mode .nebula-category-nav-item {
    background: #334155;
}

body.dark-mode .nebula-category-nav-item:hover {
    border-color: var(--nebula-primary, #38BDF8);
    background: #1E3A5F;
}

body.dark-mode .nebula-category-nav-item .cat-name {
    color: #E2E8F0;
}

body.dark-mode .nebula-toc-widget-list a {
    color: #94A3B8;
}

body.dark-mode .nebula-toc-widget-list a:hover,
body.dark-mode .nebula-toc-widget-list a.active {
    color: var(--nebula-primary, #38BDF8);
    background: #1E3A5F;
}

body.dark-mode .nebula-author-card .author-name {
    color: #F1F5F9;
}

body.dark-mode .nebula-ticker-widget a {
    color: #E2E8F0;
}

body.dark-mode .nebula-ticker-widget li {
    border-bottom-color: #334155;
}

/* ============================
   Responsive
   ============================ */

@media (max-width: 1024px) {
    .nebula-article-sidebar {
        width: 100%;
        position: static;
        max-height: none;
    }
    .ds-home-sidebar {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .nebula-sidebar .widget {
        padding: 12px;
    }
    .nebula-category-nav-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
