/* ==========================================================================
    4. АДАПТИВНЫЕ СТИЛИ (медиа-запросы для мобильных устройств)
    ========================================================================== */

@media (max-width: 992px) {
    .contacts-grid,
    .all-news-grid,
    .resources-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 900px) {
    /* --- ШАПКА --- */
    .site-header .container {
        flex-wrap: wrap;
        row-gap: 15px;
    }
    .site-header .logo {
        flex-grow: 1;
    }
    .site-header .main-nav {
        order: 3;
        width: 100%;
        max-height: 0;
        overflow: hidden;
        visibility: hidden;
        opacity: 0;
        transition: max-height 0.4s ease-out, opacity 0.3s ease-out, visibility 0.4s;
    }
    .site-header nav.is-open {
        visibility: visible;
        opacity: 1;
        max-height: 500px;
    }
    .site-header .mobile-nav-toggle {
        order: 4;
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: var(--bg-cards);
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        padding: 10px 15px;
        border-radius: 6px;
        width: 100%;
        font-size: 1.1em;
        cursor: pointer;
    }
    .site-header .mobile-nav-toggle .fa-chevron-down {
        transition: transform 0.3s;
    }
    .site-header .mobile-nav-toggle[aria-expanded="true"] .fa-chevron-down {
        transform: rotate(180deg);
    }
    .site-header nav ul {
        flex-direction: column;
        align-items: center;
        width: 100%;
    }
    .site-header nav ul li {
        margin-left: 0;
        margin-bottom: 10px;
        width: 100%;
        text-align: center;
    }
    .site-header nav ul li a {
        background: var(--bg-cards);
        padding: 10px;
    }
    .site-header nav ul li.active a {
        background-color: var(--accent-blue);
        color: #fff;
    }
    html.light-theme .site-header nav ul li.active a {
        color: #fff;
    }
    .header-search-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 100%;
        padding: 0;
        background: rgba(0,0,0,0.001); /* прозрачный, но кликабельный фон для работы JS */
        display: flex;
        justify-content: center;
        align-items: flex-start;
        padding-top: 60px; /* чуть ниже шапки */
    }
    .header-search-form {
        width: 90%;
        max-width: 400px;
        border-radius: 12px;
        background: var(--bg-header);
        box-shadow:
            0 4px 12px rgba(0, 0, 0, 0.12),
            0 8px 24px rgba(0, 0, 0, 0.08),
            0 0 20px color-mix(in srgb, var(--accent-blue) 20%, transparent);
        transition: box-shadow 0.3s ease;
    }
    .header-search-form:hover {
        box-shadow:
            0 6px 14px rgba(0, 0, 0, 0.15),
            0 12px 28px rgba(0, 0, 0, 0.1),
            0 0 25px color-mix(in srgb, var(--accent-blue) 35%, transparent);
    }

    /* --- ОБЩИЕ ЛЭЙАУТЫ И СЕТКИ --- */
    .contacts-grid, .news-grid, .all-news-grid, .resources-grid {
        grid-template-columns: 1fr;
    }
    .video-courses-grid {
        grid-template-columns: 1fr;
    }
    .news-card-long {
        grid-column: span 1;
    }
    .contact-card {
        flex-direction: column;
    }
    .shichko-bio-section {
        flex-direction: column;
        text-align: center;
    }

    /* --- ФОРМЫ И ПОИСК --- */
    .search-page-form {
        flex-direction: column;
        align-items: stretch;
    }
    .search-results-list .news-item {
        flex-direction: column;
    }
    .app-buttons-container {
        grid-template-columns: 1fr;
    }

    /* --- СТРАНИЦА НОВОСТИ И КОНТЕНТ (ИСПРАВЛЕНО) --- */
    .latest-news-full, .single-news {
        padding: 20px;
    }
    .latest-news-full h1, .single-news h1 {
        font-size: 1.8em;
    }
    .latest-news-image-wrapper img, 
    .single-news-image-wrapper img, 
    .rendered-content .image-gallery.single-image img {
        width: 100%;
        height: auto;
        object-fit: contain;
    }

    /* --- ФОРУМ: ОБЩЕЕ --- */
    .forum-user-panel {
        flex-direction: column;
        align-items: flex-start;
    }
    .user-stats {
        width: 100%;
        margin-top: 15px;
        justify-content: center;
    }

    /* --- ФОРУМ: ПОСТЫ (ИСПРАВЛЕНО) --- */
    .forum-post {
        flex-direction: row;
        background: var(--bg-cards);
        border: 1px solid var(--border-color);
        border-radius: 10px;
        margin-bottom: 15px;
        padding: 10px;
        box-shadow: 0 2px 6px rgba(0,0,0,0.05);
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    .forum-post:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    }
    .post-user-info {
        width: 80px;
        flex-shrink: 0;
        border-right: 1px solid var(--border-color);
        padding: 10px 5px;
        font-size: 0.8em;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    .user-avatar {
        width: 55px;
        height: 55px;
        border-radius: 50%;
        border: 2px solid var(--border-color);
    }
    .post-user-info strong {
        font-size: 0.9em;
        font-weight: bold;
        display: block;
        word-break: break-word; /* Добавлено для переноса длинных ников */
        line-height: 1.2;
    }
    .user-role {
        display: inline-block;
        padding: 2px 5px;
        font-size: 0.7em;
        border-radius: 6px;
        background: var(--bg-main);
        margin-top: 3px;
        max-width: 100%;
        word-break: break-word; /* Добавлено для переноса длинных ролей */
        box-sizing: border-box;
    }
    .user-details-toggle {
        display: none;
    }
    .post-user-info .user-details {
        display: block;
        font-size: 0.8em; /* Уменьшен шрифт для деталей */
        width: 100%;
    }
    .post-user-info .user-details p {
        margin: 6px 0;
        color: var(--text-secondary);
        word-wrap: break-word; /* Добавлено для переноса длинного города */
    }
    .post-content {
        width: calc(100% - 80px);
        padding-left: 10px;
        word-break: break-word;
    }
    .post-meta {
        font-size: 0.85em;
        color: var(--text-secondary);
        padding: 5px 0;
    }
    .post-actions {
        padding-top: 5px;
        gap: 8px;
    }
    .btn-action {
        width: 40px;
        height: 40px;
        border-radius: 8px;
        background-color: var(--bg-main);
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .btn-action:hover {
        background-color: var(--accent-blue);
        color: #fff;
    }
    .reply-form-container {
        padding: 20px 15px;
    }

    /* --- ФОРУМ: СПИСОК ТЕМ (МОБИЛЬНЫЙ ВИД) --- */
    .forum-section {
        background: var(--bg-cards);
        border-radius: 10px;
        padding: 14px;
        margin-bottom: 16px;
        border: 1px solid var(--border-color);
        box-shadow: 0 2px 6px rgba(0,0,0,0.04);
    }
    .section-header {
        padding: 0;
        margin-bottom: 10px;
        border: none;
    }
    .section-header h2 {
        font-size: 1.2em;
        font-weight: 600;
        margin-bottom: 4px;
    }
    .section-header p {
        font-size: 0.85em;
        color: var(--text-secondary);
        margin: 0;
    }
    .mobile-only-label {
        display: block;
        font-size: 1.2em;
        font-weight: bold;
        margin-bottom: 15px;
        color: var(--text-secondary);
    }
    .topics-table {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
        border: none;
        background: transparent;
    }
    .topics-table thead {
        display: none;
    }
    .topics-table, .topics-table tbody, .topics-table tr, .topics-table td {
        display: block;
        width: 100%;
        box-sizing: border-box;
    }
    .topics-table tr {
        display: flex;
        flex-direction: column;
        background: var(--bg-main);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 12px;
        transition: background-color 0.15s ease, transform 0.15s ease;
    }
    .topics-table tr:active {
        background-color: color-mix(in srgb, var(--accent-blue) 5%, var(--bg-main));
        transform: scale(0.99);
    }
    .topics-table td {
        padding: 0;
        border-bottom: none;
    }
    .topics-table td::before {
        display: none;
    }
    .topics-table .col-title {
        font-size: 1em;
        font-weight: 500;
        margin-bottom: 4px;
    }
    .topics-table .subsection-description {
        font-size: 0.8em;
        color: var(--text-secondary);
    }
    .topics-table .col-status,
    .topics-table .col-topics, .topics-table .col-posts,
    .topics-table .col-replies, .topics-table .col-author,
    .topics-table .col-lastpost, .topics-table .col-actions {
        display: none;
    }
    .mobile-stats-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 5px;
        text-align: center;
        margin-top: 15px;
        padding-top: 15px;
        border-top: 1px solid var(--border-color);
    }
    .stat-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 5px;
    }
    .stat-label {
        font-size: 0.7em;
        color: var(--text-secondary);
        margin-bottom: 5px;
        text-transform: uppercase;
    }
    .stat-value {
        font-size: 0.8em;
        font-weight: bold;
        color: var(--text-primary);
        line-height: 1.3;
    }
    .stat-value a {
        font-weight: 500;
        display: flex;
        flex-direction: column;
    }
    .stat-value a span, .stat-value a time {
        font-size: 0.9em;
        font-weight: normal;
        color: var(--text-secondary);
    }
    .topic-card-body {
        display: block;
        margin-top: 15px;
        padding-top: 15px;
        border-top: 1px solid var(--border-color);
    }
    .topic-card-meta {
        display: flex;
        justify-content: space-between;
        font-size: 0.8em;
        color: var(--text-secondary);
        margin-bottom: 15px;
    }
    .topic-card-lastpost {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 0.85em;
        color: var(--text-secondary);
    }
    .topic-card-lastpost a {
        color: var(--text-primary);
    }
    .topic-card-lastpost a:hover {
        color: var(--accent-blue);
    }
    .topic-card-lastpost .post-date {
        font-size: 0.9em;
        color: var(--text-secondary);
    }
    .mobile-sort-options {
        display: flex;
        gap: 8px;
        margin-bottom: 20px;
        background: var(--bg-cards);
        padding: 12px;
        border-radius: 8px;
        border: 1px solid var(--border-color);
        align-items: center;
    }
    .mobile-sort-options span {
        color: var(--text-secondary);
        font-weight: 500;
        margin-right: auto;
    }
    .mobile-sort-options a {
        padding: 8px 12px;
        border-radius: 8px;
        text-decoration: none;
        color: var(--text-primary);
        background: var(--bg-main);
        border: 1px solid var(--border-color);
        white-space: nowrap;
    }
    .mobile-sort-options a.active {
        background: var(--accent-blue);
        color: #fff;
        border-color: var(--accent-blue);
        font-weight: bold;
    }
    .mobile-title-header {
        display: flex;
        align-items: center;
        gap: 10px;
    }
    .topic-icon-container.mobile-only {
        display: block;
        font-size: 1.2em;
        flex-shrink: 0;
    }
    .topic-card-actions.mobile-only {
        display: flex;
        justify-content: flex-end;
        gap: 10px;
        margin-top: 15px;
        padding-top: 10px;
        border-top: 1px solid var(--border-color);
    }
    .topic-card-actions .btn-action {
        width: 36px;
        height: 36px;
        background-color: var(--bg-main);
    }

    /* --- ПРОЧЕЕ --- */
    .my-posts-list .post-item-meta .post-date {
        float: none;
        display: block;
        margin-top: 5px;
    }
    .image-gallery.multi-image,
    .image-gallery.multi-image img {
        width: 150px;
        height: 150px;
        object-fit: cover;
    }
    .method-hero {
        padding: 2.5rem 20px;
    }
    .method-hero h1 {
        font-size: 2.2em;
    }
    .method-hero .subtitle {
        font-size: 1.1em;
    }
    .method-main-content {
        padding: 1.5rem 15px;
    }
    .content-section {
        padding: 20px;
    }
    .poll-container {
        padding: 20px;
    }

    /* --- Адаптация баннера Cookie --- */
    .cookie-consent-content {
        flex-direction: column;
        text-align: center;
        gap: 15px;
        padding: 15px;
    }
    .cookie-consent-content p {
        font-size: 0.8em;
        margin-bottom: 0;
    }
    .cookie-consent-buttons {
        justify-content: center;
        width: 100%;
    }
    
    /* --- Анимация появления нового сообщения --- */
    .forum-post.new-message {
        animation: fadeInUp 0.3s ease both;
    }
    @keyframes fadeInUp {
        from {
            opacity: 0;
            transform: translateY(10px);
        }
        to   {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* --- Прилипшая навигация --- */
    .smart-nav {
        position: sticky;
        top: 0;
        z-index: 50;
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        background-color: color-mix(in srgb, var(--bg-cards) 85%, transparent);
        box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    }

    /* --- Плавающая кнопка Новая тема --- */
    .fab-new-topic {
        position: fixed;
        right: 16px;
        bottom: 16px;
        z-index: 60;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 14px 18px;
        border-radius: 999px;
        background: var(--accent-blue);
        color: #fff !important;
        text-decoration: none;
        font-weight: 600;
        box-shadow: 0 6px 18px rgba(0,0,0,0.15);
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }
    .fab-new-topic:active {
        transform: translateY(1px) scale(0.98);
    }
    .fab-new-topic i {
        font-size: 1.1em;
    }

    /* --- Пагинация --- */
    .pagination {
        justify-content: center;
        gap: 8px;
    }
    .pagination a, .pagination span {
        padding: 10px 14px;
        border-radius: 10px;
        font-weight: 600;
        background: var(--bg-cards);
    }
    .pagination .current-page {
        background: var(--accent-blue);
        color: #fff;
    }

    /* --- Фильтры --- */
    .mobile-sort-options {
        gap: 8px;
        padding: 12px;
        border-radius: 8px;
    }
    .mobile-sort-options a {
        padding: 8px 12px;
        border-radius: 8px;
        background: var(--bg-main);
    }

    /* --- Анимация появления карточек --- */
    .topics-table tr {
        animation: topicFadeIn 0.25s ease both;
    }
    @keyframes topicFadeIn {
        from { opacity: 0; transform: translateY(6px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    /* --- Исправление вылезания длинного города под аватаром --- */
    .post-user-info .user-details p {
        word-wrap: break-word; /* Добавлено */
    }
}
