/*
 * Right sidebar — namespace #rsidebar
 *
 * Modernized v1.0 — extracted from style.css + dark-mode.css.
 *  - :where() để giảm specificity (cho phép override dễ + chuẩn modern CSS).
 *  - CSS custom properties cho theme (light/dark switch chỉ override --rs-*).
 *  - Specific transitions thay cho `transition: all` (giảm repaint).
 *  - content-visibility: auto skip render off-screen widgets.
 *
 * Frontend visual phải khớp pixel-for-pixel với code cũ.
 * Mobile hide do body.css (.b__side) xử lý — không duplicate ở đây.
 */

:where(#rsidebar) {
    /* Theme tokens — light defaults */
    --rs-title-color: #f0f9ef;
    --rs-title-font: "Oswald", sans-serif;
    --rs-item-font: "Roboto Condensed", sans-serif;
    --rs-item-color: #2c3e50;
    --rs-link-color: #1e272e;
    --rs-link-hover: #27ae60;
    --rs-red-color: #861023;
    --rs-border: #ddd;
    --rs-list-bg: #1a1f24;
    --rs-shadow-sm: 0 3px 8px rgba(0, 0, 0, .15);
    --rs-shadow-md: 0 4px 12px rgba(0, 0, 0, .25);
    --rs-any-text: #f0f4ff;
    --rs-any-link: #e6eeff;
    --rs-any-link-hover: #fffdda;

    /* Off-screen render skip — widgets dưới fold không paint cho tới khi scroll vào view */
    content-visibility: auto;
    contain-intrinsic-size: 0 800px;
}

/* ─── Widget container ─── */
:where(#rsidebar) .widget {
    margin-bottom: 20px;
}

/* ─── Widget title (h2) ─── */
:where(#rsidebar) h2 {
    margin: 0;
    padding: 14px 18px 10px;
    font-family: var(--rs-title-font);
    font-size: 20px;
    font-weight: 600;
    color: var(--rs-title-color);
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 2px 5px rgba(0, 0, 0, .45);
    background: url(./img/bg_sidebar_title.png) center/cover no-repeat;
    border-bottom: 2px solid rgba(255, 255, 255, .3);
    border-radius: 8px 8px 0 0;
    box-shadow: var(--rs-shadow-md);
}

/* ─── Widget body list (2-column grid) ─── */
:where(#rsidebar) .widget ul {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px 15px;
    margin: 0;
    padding: 15px;
    list-style: none;
    background: url(https://www.9minecraft.net/images/bg_sidebar.png) repeat;
    border: 1px solid var(--rs-border);
    border-radius: 0 0 8px 8px;
    box-shadow: var(--rs-shadow-sm);
}

:where(#rsidebar) li {
    margin: 0;
    padding: 0;
    list-style: none;
}

/* ─── Nested items (menu link rows) ─── */
:where(#rsidebar) li li {
    position: relative;
    padding-left: 22px;
    font-family: var(--rs-item-font);
    font-size: 16px;
    font-weight: 400;
    line-height: 1.6;
    color: var(--rs-item-color);
}

:where(#rsidebar) li li::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 0;
    width: 14px;
    height: 14px;
    background: url(./img/r-sidebar-diamond.png) center/contain no-repeat;
}

:where(#rsidebar) li li a {
    color: var(--rs-link-color);
    font-weight: 400;
    text-decoration: none;
    transition: color .25s ease, font-weight .25s ease;
}

:where(#rsidebar) li li a:hover {
    color: var(--rs-link-hover);
    font-weight: 500;
    text-decoration: underline;
}

/* Red accent items */
:where(#rsidebar) li li.mine-red a {
    color: var(--rs-red-color);
    font-weight: 600;
}

:where(#rsidebar) li li.mine-red a:hover {
    color: var(--rs-link-hover);
    font-weight: 600;
    text-decoration: underline;
}

/* ─── "Any Posts" widget (custom widget_ninemine_any_posts) ─── */
:where(#rsidebar) .widget_ninemine_any_posts {
    margin-top: 20px;
    margin-bottom: 20px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--rs-shadow-md);
}

:where(#rsidebar) .widget_ninemine_any_posts .widgettitle {
    padding: 14px 16px;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, .5);
    border-radius: 8px 8px 0 0;
}

:where(#rsidebar) .widget_ninemine_any_posts .ninemine-any-posts {
    display: block;
    margin: 0;
    padding: 12px;
    list-style: none;
    background: url(./img/bg_anypost.png) repeat;
    color: var(--rs-any-text);
}

:where(#rsidebar) .widget_ninemine_any_posts ul,
:where(#rsidebar) .widget_ninemine_any_posts li {
    margin: 0;
    padding: 0;
    list-style: none;
}

:where(#rsidebar) .widget_ninemine_any_posts li::before {
    content: none;
}

:where(#rsidebar) .widget_ninemine_any_posts .ninemine-any-post {
    display: flex;
    align-items: center;
    padding-bottom: 12px;
    margin-bottom: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

:where(#rsidebar) .widget_ninemine_any_posts .ninemine-any-post:last-child {
    padding-bottom: 0;
    margin-bottom: 0;
    border-bottom: none;
}

:where(#rsidebar) .widget_ninemine_any_posts .ninemine-any-post__thumb {
    flex: 0 0 120px;
    min-width: 120px;
    margin: 0 10px 0 8px;
    border-radius: 4px;
    overflow: hidden;
}

:where(#rsidebar) .widget_ninemine_any_posts .ninemine-any-post__title a {
    flex: 1;
    display: block;
    color: var(--rs-any-link);
    font-weight: 700;
    line-height: 1.4;
    text-decoration: none;
    transition: color .2s ease;
}

:where(#rsidebar) .widget_ninemine_any_posts .ninemine-any-post__title a:hover {
    color: var(--rs-any-link-hover);
    text-decoration: underline;
}

/* ────────────────────────────────────────────────────────
   DARK MODE — chỉ override theme tokens + ảnh nền sáng
   ──────────────────────────────────────────────────────── */
[data-theme="dark"] :where(#rsidebar) {
    --rs-item-color: #cbd5e1;
    --rs-link-color: #cbd5e1;
    --rs-link-hover: #fbbf24;
    --rs-red-color: #f87171;
    --rs-border: #2a3038;
    --rs-shadow-sm: 0 3px 8px rgba(0, 0, 0, .5);
    --rs-shadow-md: 0 4px 12px rgba(0, 0, 0, .5);
}

[data-theme="dark"] :where(#rsidebar) .widget {
    background: transparent;
}

/* Title: dirt block bg đã tối — chỉ darken nhẹ và ép màu chữ trắng */
[data-theme="dark"] :where(#rsidebar) h2,
[data-theme="dark"] :where(#rsidebar) .widgettitle {
    color: #f8fafc;
    filter: brightness(.92);
    border-bottom-color: rgba(255, 255, 255, .12);
}

/* List body: bỏ ảnh nền sáng → dark surface */
[data-theme="dark"] :where(#rsidebar) .widget ul {
    background-image: none;
    background-color: var(--rs-list-bg);
}

/* Any Posts widget — giữ gradient title, body chuyển dark */
[data-theme="dark"] :where(#rsidebar) .widget_ninemine_any_posts .widgettitle {
    color: #fff;
}

[data-theme="dark"] :where(#rsidebar) .widget_ninemine_any_posts .ninemine-any-posts {
    background-image: none;
    background-color: var(--rs-list-bg);
    color: var(--rs-item-color);
}

/* Red accent hover dark */
[data-theme="dark"] :where(#rsidebar) li li.mine-red a:hover {
    color: #fca5a5;
}
