/*
  Page Layout System v2
  Controls: body[data-layout="1col|2col"]
  Structure:
    .page-layout-wrapper (flex container)
      .main-with-sidebar (main content, flex:1)
      .page-sidebar (sidebar, 280px)
*/

/* ===== Main Layout Wrapper (flex) ===== */
.page-layout-wrapper {
    display: flex;
    gap: 28px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 16px;
    align-items: flex-start;
}

/* 1-column: hide sidebar, content full width */
body[data-layout="1col"] .page-sidebar {
    display: none !important;
}

body[data-layout="1col"] .main-with-sidebar {
    max-width: 900px;
    margin: 0 auto;
    flex: none;
}

body[data-layout="1col"] .page-layout-wrapper {
    display: block;
    max-width: 1200px;
    padding: 20px 16px;
}

body[data-layout="1col"] .home-v2 {
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

/* Article detail specific */
body[data-layout="1col"] .article-detail-layout {
    max-width: 900px;
    margin: 0 auto;
}

body:not([data-layout="1col"]) .article-detail-layout {
    max-width: 100%;
}

/* Filter card / grid pages (article list, encyclopedia, library, album) */
body:not([data-layout="1col"]) .main-with-sidebar > .filter-card,
body:not([data-layout="1col"]) .main-with-sidebar > .article-grid,
body:not([data-layout="1col"]) .main-with-sidebar > .encyclopedia-list,
body:not([data-layout="1col"]) .main-with-sidebar > .library-grid,
body:not([data-layout="1col"]) .main-with-sidebar > .waterfall-full {
    max-width: 100%;
}

/* Footer adjustment when sidebar exists */
body:not([data-layout="1col"]) .footer--with-sidebar {
    /* footer already handles this via JS */
}

/* Sidebar inner styling */
.page-sidebar .sidebar-inner {
    position: sticky;
    top: 80px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    scrollbar-width: none;
}
.page-sidebar .sidebar-inner::-webkit-scrollbar {
    display: none;
}

/* Sidebar widget base */
.sidebar-widget {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #eee);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 16px;
}
.sidebar-widget:last-child {
    margin-bottom: 0;
}
.widget-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-primary, #333);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--color-primary, #913500);
}
.widget-title svg {
    color: var(--color-primary, #913500);
    flex-shrink: 0;
}

/* Widget list styles */
.widget-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.widget-list-text li {
    padding: 4px 0;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}
.widget-list-text li:last-child { border-bottom: none; }
.wlt-rank {
    font-size: 11px;
    color: #999;
    margin-right: 6px;
}
.wlt-title {
    font-size: 13px;
    color: var(--color-text-secondary, #666);
    text-decoration: none;
    transition: color 0.2s;
}
.wlt-title:hover {
    color: var(--color-primary, #913500);
}

/* Widget article list (with cover) */
.widget-list-article li {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}
.widget-list-article li:last-child { border-bottom: none; }
.wla-cover {
    width: 60px;
    height: 44px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
}
.wla-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.wla-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.wla-title {
    font-size: 13px;
    color: var(--color-text-primary, #333);
    text-decoration: none;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.wla-title:hover { color: var(--color-primary, #913500); }
.wla-views {
    font-size: 11px;
    color: #999;
    display: flex;
    align-items: center;
    gap: 3px;
}

/* Widget book list */
.widget-list-book li {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}
.widget-list-book li:last-child { border-bottom: none; }
.wlb-cover {
    width: 40px;
    height: 56px;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
}
.wlb-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.wlb-cover-placeholder {
    width: 40px;
    height: 56px;
    background: linear-gradient(135deg, #f0e8dc, #e0d4c4);
    border-radius: 4px;
    flex-shrink: 0;
}
.wlb-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.wlb-title {
    font-size: 13px;
    color: var(--color-text-primary, #333);
    text-decoration: none;
    line-height: 1.4;
}
.wlb-author {
    font-size: 11px;
    color: #999;
}

/* Widget tags cloud */
.widget-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.widget-tag {
    display: inline-block;
    padding: 3px 10px;
    background: #f5f5f5;
    border-radius: 14px;
    font-size: 12px;
    color: #666;
    text-decoration: none;
    transition: all 0.2s;
}
.widget-tag:hover {
    background: var(--color-primary, #913500);
    color: #fff;
}

/* Responsive */
@media (max-width: 1024px) {
    .layout-container {
        display: block !important;
        padding: 12px;
    }

    .page-sidebar {
        display: none !important; /* on tablet, use mobile overlay instead */
    }

    .main-with-sidebar {
        width: 100% !important;
    }

    /* Show mobile toggle button instead */
    .sidebar-toggle-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
}

@media (max-width: 768px) {
    body[data-layout="1col"] .main-with-sidebar,
    body[data-layout="1col"] .layout-container,
    body[data-layout="1col"] .home-v2,
    body[data-layout="1col"] .article-detail-layout {
        max-width: 100%;
        padding: 0 8px;
    }

    .article-related-content {
        grid-template-columns: 1fr;
    }

    .filter-card {
        padding: 12px;
    }
}
