.home-week {
    --week-accent: var(--violet-dark);
    display: none;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    scroll-margin-top: calc(var(--header-height) + 16px);
}
.week-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 16px 18px;
    border: 1px solid var(--line-new);
    border-radius: 16px;
    background: var(--panel);
    overflow-wrap: anywhere;
}
.week-theme { background: linear-gradient(120deg, var(--violet-soft), var(--panel) 95%); }
.week-card .section-kicker { display: flex; align-items: center; gap: 8px; color: var(--week-accent); }
.week-card .section-kicker svg { width: 18px; height: 18px; }
.week-card h2 { margin: 10px 0 8px; font-size: 22px; line-height: 1.16; }
.week-card h2 a { color: var(--ink); text-decoration: none; }
.week-card p { max-width: 60ch; margin: 0; color: var(--text); font-size: 15px; line-height: 1.55; }
.week-footer { margin-top: auto; padding-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; }
.week-card small { color: var(--muted-new); font-size: 13px; }
.week-link { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; color: var(--week-accent); font-size: 14px; font-weight: 700; text-decoration: none; }
#week-calendar-title, .week-dates a { color: var(--week-accent); }
.week-dates { list-style: none; padding: 0; margin: 0; }
.week-dates li + li { border-top: 1px solid var(--line-new); }
.week-dates a { text-decoration: none; display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 2px 10px; padding: 8px 0; font-size: 15px; }
.week-card a:hover, .week-card a:focus-visible { text-decoration: underline; text-underline-offset: 3px; }
body.theme-dark .home-week { --week-accent: #c5b5ff; }
.home-week .week-ad {
    min-height: 64px;
    margin: 0;
    padding: 8px 14px;
    gap: 2px;
    border: 1px dashed var(--line-new);
    background: var(--paper);
    overflow-wrap: anywhere;
}
.week-ad .ad-kicker { font-size: 10px; color: var(--muted-new); }
.week-ad strong { font: inherit; font-size: 14px; font-weight: 700; }
.week-ad span { font-size: 12px; color: var(--muted-new); }

/* Keep the rail in the document flow. Its full-height parent bounds the sticky card. */
#main-content :is(.page-layout, .home-feed-layout):has(> .home-week) {
    display: grid;
    max-width: var(--page-max-width);
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
}
#main-content :is(.page-layout, .home-feed-layout) > .home-week {
    display: none;
    flex-direction: column;
    min-width: 0;
    align-self: stretch;
}
#main-content .page-layout > .content-column { min-width: 0; }
.sidebar-tail { display: grid; gap: 10px; }
@media (min-width: 1100px) {
    #main-content :is(.page-layout, .home-feed-layout) > .home-week { display: flex; }
    #main-content :is(.page-layout, .home-feed-layout):has(> .home-week) {
        grid-template-columns: minmax(0, 1fr) clamp(240px, 20vw, 292px);
    }
    .home-week > .sidebar-tail {
        position: sticky;
        top: calc(var(--header-height) + 14px);
    }
}
@media print {
    #main-content :is(.page-layout, .home-feed-layout) > .home-week { display: none; }
    #main-content :is(.page-layout, .home-feed-layout):has(> .home-week) { display: block; }
}

#main-content .page-layout:has(.sidebar-body-row) {
    display: block;
    max-width: var(--page-max-width);
}
.sidebar-body-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; min-width: 0; }
.sidebar-body-content { min-width: 0; }
.sidebar-body-grid { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; }
.sidebar-body-row > .home-week { display: none; flex-direction: column; min-width: 0; }
@media screen and (min-width: 1100px) {
    .sidebar-body-row { grid-template-columns: minmax(0, 1fr) clamp(240px, 20vw, 292px); }
    .sidebar-body-row > .home-week { display: flex; }
}
@media print {
    .sidebar-body-row { display: block; }
    .sidebar-body-row > .home-week { display: none; }
}
/* Count cards get their own row when the catalogue has a narrow reading area. */
@media screen and (min-width: 761px) and (max-width: 1250px) {
    .category-directory-hero.portal-section-hero {
        grid-template-columns: auto minmax(0, 1fr);
    }
    .category-directory-hero .category-directory-stats {
        grid-column: 1 / -1;
        flex-wrap: wrap;
    }
}

@media screen and (min-width: 1100px) {
    .page-layout:has(.home-week) .authors-directory-modern { grid-template-columns: minmax(0, 1fr); }
    .page-layout:has(.home-week) :is(.authors-tools, .search-controls) {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 172px), 1fr));
    }
    .page-layout:has(.home-week) :is(.authors-tools, .search-controls) > * {
        grid-column: auto;
        min-width: 0;
    }
    .page-layout:has(.home-week) .authors-list {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    }
}

.search-hero + .sidebar-body-row,
.category-directory-hero + .sidebar-body-row { margin-block-start: 18px; }
.sidebar-body-content > :first-child { margin-block-start: 0; }

/* Profile card + "Моя библиотека" at the top of the right rail (moved from the left menu). */
.rail-profile {
    display: grid;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--line-new);
    border-radius: 16px;
    background: var(--panel);
}
.rail-profile-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.rail-profile-avatar {
    flex: none; width: 46px; height: 46px; border-radius: 50%; overflow: hidden;
    display: grid; place-items: center;
    background: var(--violet-soft); color: var(--week-accent); font-weight: 700; font-size: 18px; text-decoration: none;
}
.rail-profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.rail-profile-identity { display: grid; min-width: 0; flex: 1; color: var(--ink); text-decoration: none; }
.rail-profile-identity strong { font-size: 15px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-profile-identity small { color: var(--muted-new); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-profile-guest .rail-profile-identity small { white-space: normal; line-height: 1.35; }
.rail-profile-icon {
    flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
    color: var(--muted-new); border: 1px solid var(--line-new); transition: color .15s, background .15s;
}
.rail-profile-icon svg { width: 18px; height: 18px; }
.rail-profile-icon:is(:hover, :focus-visible, .is-active) { color: var(--week-accent); background: var(--violet-soft); }
.rail-profile-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 0; }
.rail-profile-stats a {
    display: flex; flex-direction: column-reverse; align-items: center; padding: 8px 4px;
    border-radius: 10px; background: var(--paper, var(--violet-soft)); text-decoration: none;
}
.rail-profile-stats a:hover { background: var(--violet-soft); }
.rail-profile-stats dd { margin: 0; color: var(--ink); font-weight: 700; font-size: 16px; line-height: 1.2; }
.rail-profile-stats dt { color: var(--muted-new); font-size: 12px; }
.rail-profile-write {
    display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px;
    border-radius: 10px; background: var(--week-accent); color: #fff; font-weight: 700; font-size: 14px; text-decoration: none;
}
body.theme-dark .rail-profile-write { color: #1b1530; }
.rail-profile-write svg { width: 16px; height: 16px; }
.rail-profile-write:hover { filter: brightness(1.08); }
.rail-profile-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rail-profile-actions .button { justify-content: center; text-align: center; }
.rail-library { display: grid; gap: 2px; margin: 0 -8px; padding-top: 10px; border-top: 1px solid var(--line-new); }
.rail-library p {
    margin: 2px 10px 6px; color: var(--muted-new); font-size: 11px; font-weight: 700;
    letter-spacing: .1em; text-transform: uppercase;
}
.rail-library a {
    display: flex; align-items: center; gap: 12px; min-height: 38px; padding: 0 10px;
    border-radius: 10px; color: var(--ink); font-size: 14px; font-weight: 600; text-decoration: none;
}
.rail-library a svg { width: 18px; height: 18px; color: var(--muted-new); flex: none; }
.rail-library a span { flex: 1; min-width: 0; }
.rail-library a:is(:hover, :focus-visible) { background: var(--violet-soft); }
.rail-library a.is-active { background: var(--violet-soft); color: var(--week-accent); }
.rail-library a.is-active svg { color: var(--week-accent); }
.rail-library b {
    min-width: 22px; padding: 1px 7px; border-radius: 999px; text-align: center;
    background: var(--week-accent); color: #fff; font-size: 12px; line-height: 18px;
}
body.theme-dark .rail-library b { color: #1b1530; }
.rail-library b.is-quiet { background: transparent; color: var(--muted-new); font-weight: 600; }
.rail-library b[hidden] { display: none; }
.rail-profile-logout { margin: 0; padding-top: 8px; border-top: 1px solid var(--line-new); }
.rail-profile-logout button {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 0 2px;
    border: 0; border-radius: 8px; background: transparent; color: var(--muted-new);
    font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.rail-profile-logout button:is(:hover, :focus-visible) { background: var(--violet-soft); color: var(--week-accent); }
.rail-profile-logout svg { width: 18px; height: 18px; flex: none; }
