/* style3 даёт .mid-articles { display:grid } и перебивает нативный [hidden]. */
#mid-articles[hidden],
#mid-articles-topics[hidden],
#mid:has(#mid-articles-sort input[value="newest"]:checked) #mid-articles-topics,
#mid:has(#mid-articles-sort input[value="topics"]:checked) #mid-articles {
    display: none !important;
}

/* ===== ПЕРЕКЛЮЧАТЕЛЬ СОРТИРОВКИ СТАТЕЙ ===== */
#mid-articles-sort {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px;
    margin: 0 0 28px;
    background: #eef7f0;
    border: 1px solid #e0ede4;
    border-radius: 14px;
}

/* Прячем сам radio, кликаем по label */
#mid-articles-sort input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0; height: 0;
    pointer-events: none;
}

/* Label = кнопка-сегмент */
#mid-articles-sort label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 22px;
    font-size: 15px;
    font-weight: 700;
    color: #6a8574;
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    transition: all 0.22s ease;
    white-space: nowrap;
}

/* Иконки перед текстом */
/* По темам — дерево */
#mid-articles-sort label:nth-of-type(1)::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  vertical-align: -3px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%233d9540' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 5v14'/%3E%3Cpath d='M7 8h8'/%3E%3Cpath d='M7 12h10'/%3E%3Cpath d='M7 16h6'/%3E%3Ccircle cx='7' cy='8' r='1.4'/%3E%3Ccircle cx='7' cy='12' r='1.4'/%3E%3Ccircle cx='7' cy='16' r='1.4'/%3E%3C/svg%3E");
}

/* По новизне — искра/звёздочка */
#mid-articles-sort label:nth-of-type(2)::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  vertical-align: -3px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%233d9540' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3c.4 3.6 1.4 4.6 5 5-3.6.4-4.6 1.4-5 5-.4-3.6-1.4-4.6-5-5 3.6-.4 4.6-1.4 5-5z'/%3E%3Cpath d='M18.5 13.5c.2 1.6.6 2 2.2 2.2-1.6.2-2 .6-2.2 2.2-.2-1.6-.6-2-2.2-2.2 1.6-.2 2-.6 2.2-2.2z'/%3E%3C/svg%3E");
}

/* Hover на невыбранном */
#mid-articles-sort label:hover {
    color: #3d9540;
    background: rgba(255,255,255,0.6);
}

/* АКТИВНЫЙ сегмент — label, содержащий :checked radio */
#mid-articles-sort label:has(input:checked) {
    background: #ffffff;
    color: #3d9540;
    box-shadow: 0 3px 10px rgba(92,184,92,0.18);
}

/* ===== Fallback для старых браузеров без :has() ===== */
/* Если :has не поддерживается — подсветку активного даём через JS-класс .is-active */
#mid-articles-sort label.is-active {
    background: #ffffff;
    color: #3d9540;
    box-shadow: 0 3px 10px rgba(92,184,92,0.18);
}

@media (max-width: 480px) {
    #mid-articles-sort { width: 100%; }
    #mid-articles-sort label { flex: 1; justify-content: center; padding: 11px 12px; }
}

/* Темы + новизна: компактные карточки как на главной */
.mid-articles-topic { margin: 0 0 28px; }
.mid-articles-topic__title {
    margin: 0 0 14px;
    padding: 0 4px;
    color: #191C1F;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.35;
}

#mid-articles.mid-articles--compact,
#mid-articles-topics .mid-articles--compact {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    max-width: 1100px;
    margin: 0;
    padding: 0;
}

#mid .article-card--compact {
    display: flex;
    align-items: stretch;
    gap: 0;
    text-decoration: none;
    background: #fff;
    border: 1px solid #e4efe8;
    border-radius: 16px;
    overflow: hidden;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}
#mid .article-card--compact:hover {
    transform: translateY(-4px);
    box-shadow: 0 16px 36px rgba(92, 184, 92, 0.16);
    border-color: #5cb85c;
}
#mid .article-card--compact > div:first-child {
    flex: 0 0 160px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}
#mid .article-card--compact > div:last-child {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    padding: 18px 20px;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
    color: #1f2f24;
}
#mid .article-card--compact:hover > div:last-child {
    color: #46a046;
}

.article-card__free {
    display: inline-block;
    flex: 0 0 auto;
    width: auto;
    max-width: max-content;
    margin: 0 0 8px;
    padding: 3px 8px;
    border-radius: 999px;
    background: #eef7f0;
    color: #3d9540;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .02em;
    line-height: 1.3;
    text-transform: uppercase;
}
.article-card > div:last-child > span:not(.article-card__free) {
    display: block;
    width: 100%;
}
.article-card__date {
    display: block;
    margin-top: 6px;
    color: #7a8a80;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.3;
}
#mid .article-card--compact:hover .article-card__date {
    color: #7a8a80;
}
.article-card:has(.article-card__free) > div:last-child {
    padding-top: 10px;
}
#mid .article-card--compact:has(.article-card__free) > div:last-child {
    padding-top: 8px;
}

/* ===== АДАПТИВ ===== */
@media (max-width: 900px) {
    #mid-articles.mid-articles--compact,
    #mid-articles-topics .mid-articles--compact { grid-template-columns: 1fr; }
    #mid > h1 { font-size: 30px; }
}
@media (max-width: 560px) {
    #mid > .mid-text { font-size: 16px; }
    #mid .article-card--compact > div:first-child { flex: 0 0 110px; }
    #mid .article-card--compact > div:last-child { font-size: 15px; padding: 14px 16px; }
}
