/**
 * Forum Responsive Styles
 * Mobile-first approach with breakpoints for tablet and desktop
 */

/* ============================================
   BASE MOBILE STYLES (< 640px)
   Most styles use clamp() so minimal overrides needed
   ============================================ */

/* ============================================
   COMPACT MOBILE (max-width: 640px)
   ============================================ */

@media (max-width: 640px) {
    /* Forum page header */
    .forum-header,
    .category-header {
        text-align: left;
    }

    /* Search bar: compact inline layout */
    .forum-search-bar {
        margin-bottom: 1rem;
    }

    .search-form-wrapper {
        flex-direction: column;
    }

    .search-input-group {
        width: 100%;
    }

    .search-filter-group {
        width: 100%;
    }

    .search-filter-group .filter-select {
        max-width: none;
    }

    .search-input-wrapper input {
        min-height: 44px;
    }

    .search-submit {
        width: 100%;
        min-height: 44px;
    }

    .search-submit-text {
        display: inline;
    }

    /* Forum filters: stack on mobile */
    .forum-filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        justify-content: space-between;
        width: 100%;
    }

    .filter-label {
        display: block;
    }

    .filter-select {
        flex: 1;
        min-height: 44px;
    }

    .forum-filters .btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    /* Category groups: horizontal scroll */
    .forum-category-group {
        margin-bottom: 1.5rem;
    }

    .forum-category-grid {
        display: flex;
        gap: 0.5rem;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        padding: 0.25rem 0;
        flex-wrap: nowrap;
        margin: 0 -1rem;
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .forum-category-grid::-webkit-scrollbar {
        display: none;
    }

    .forum-category-card {
        flex-shrink: 0;
        min-width: 200px;
        max-width: 280px;
    }

    /* Topics table compact */
    .forum-topics-table-wrapper {
        margin: 0 -1rem;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .forum-topics-table th,
    .forum-topics-table td {
        padding: 0.75rem 1rem;
    }

    /* Hide less important columns on mobile */
    .forum-topics-table .col-category,
    .forum-topics-table .col-replies {
        display: none;
    }

    /* Topic card stack layout */
    .topic-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    /* Topic stats horizontal on mobile */
    .topic-stats {
        flex-direction: row;
        width: 100%;
        min-width: auto;
        justify-content: flex-start;
        gap: 0.5rem;
    }

    .topic-stats .stat-group {
        flex-direction: row;
        gap: 0.5rem;
    }

    .topic-stats .label {
        text-transform: none;
        letter-spacing: normal;
    }

    /* Topic header compact */
    .topic-header {
        padding: 1.25rem;
    }

    /* Topic actions stack + full width */
    .topic-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .topic-action-btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    /* Replies header stack */
    .replies-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .replies-sort {
        width: 100%;
        justify-content: space-between;
    }

    .sort-select,
    .replies-sort select {
        flex: 1;
        max-width: 200px;
        min-height: 44px;
    }

    /* Reply item stack layout */
    .reply-item {
        flex-direction: column;
        gap: 0.75rem;
    }

    .reply-item--nested {
        margin-left: 1rem;
        border-left: 2px solid var(--border);
        padding-left: 1rem;
    }

    /* Vote buttons horizontal on mobile */
    .vote-buttons {
        flex-direction: row;
        order: 2;
        margin-top: 0.75rem;
        gap: 0.5rem;
        width: 100%;
    }

    .vote-button {
        width: 44px;
        height: 44px;
    }

    .vote-score {
        min-width: 48px;
        text-align: center;
    }

    /* Reply actions touch friendly */
    .reply-actions {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .reply-actions button,
    .reply-actions a {
        min-height: 44px;
        padding: 0.5rem;
    }

    /* Reply form full width */
    .reply-form {
        padding: 1rem;
    }

    .reply-form textarea {
        min-height: 150px;
    }

    .reply-form-actions {
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .reply-form-actions .btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    /* Reply login prompt */
    .reply-login-prompt {
        padding: 2rem 1rem;
    }

    .reply-login-prompt .btn {
        width: 100%;
        min-height: 48px;
    }

    /* Replies empty */
    .replies-empty {
        padding: 2.5rem 1rem;
    }

    /* Pagination touch friendly */
    .forum-pagination {
        flex-wrap: wrap;
        gap: 0.375rem;
    }

    .pagination-button {
        min-width: 44px;
        height: 44px;
    }

    /* Modal bottom sheet on mobile */
    .forum-modal {
        align-items: flex-end;
        padding: 0;
    }

    .forum-modal__content {
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        border-bottom: none;
        padding: 1.25rem;
    }

    .forum-modal__actions {
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .forum-modal__actions .btn {
        width: 100%;
        min-height: 44px;
    }

    /* New topic form */
    .forum-new-topic {
        padding: 1rem 0 3rem;
    }

    .topic-form {
        padding: 1.25rem;
    }

    .form-input,
    .form-select,
    .form-textarea {
        min-height: 44px;
    }

    .form-textarea {
        min-height: 180px;
    }

    .form-actions {
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .form-actions .btn {
        width: 100%;
        min-height: 48px;
        justify-content: center;
    }

    .form-guidelines {
        padding: 0.75rem;
    }

    /* Forum stats wrap */
    .forum-stats {
        flex-wrap: wrap;
        gap: 1rem;
        padding: 1.25rem;
        justify-content: space-around;
    }

    .stat-item {
        flex: 1;
        min-width: 80px;
    }

    /* Breadcrumbs horizontal scroll */
    .breadcrumbs-list {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .breadcrumbs-list::-webkit-scrollbar {
        display: none;
    }

    .forum-breadcrumbs {
        position: relative;
    }

    .forum-breadcrumbs::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 40px;
        background: linear-gradient(to right, transparent, var(--bg-primary));
        pointer-events: none;
    }
}

/* ============================================
   TABLET (576px+)
   ============================================ */

@media (min-width: 576px) {
    /* Category grid */
    .forum-category-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        overflow-x: visible;
        flex-wrap: wrap;
        margin: 0;
        padding-left: 0;
        padding-right: 0;
    }

    /* Topic card row layout */
    .topic-card {
        flex-direction: row;
        align-items: center;
    }

    /* Topic stats column */
    .topic-stats {
        flex-direction: column;
        width: auto;
        min-width: 72px;
    }

    .topic-stats .stat-group {
        flex-direction: column;
        gap: 0.25rem;
    }

    .topic-stats .label {
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }

    /* Vote buttons column */
    .vote-buttons {
        flex-direction: column;
        order: 0;
        margin-top: 0;
        width: auto;
    }

    /* Nested replies more indent */
    .reply-item--nested {
        margin-left: 2rem;
        border-left: none;
        padding-left: 0;
        position: relative;
    }

    .reply-item--nested::before {
        content: '';
        position: absolute;
        left: -1rem;
        top: 0;
        bottom: 0;
        width: 2px;
        background: var(--border);
    }

    /* Modal normal */
    .forum-modal {
        align-items: center;
        padding: 1rem;
    }

    .forum-modal__content {
        max-width: 480px;
        border-radius: 12px;
        border-bottom: 1px solid var(--border);
    }

    .forum-modal__actions {
        flex-direction: row;
    }

    .forum-modal__actions .btn {
        width: auto;
    }

    /* Topic actions row */
    .topic-actions {
        flex-direction: row;
    }

    .topic-action-btn {
        width: auto;
    }

    /* Reply form actions row */
    .reply-form-actions {
        flex-direction: row;
    }

    .reply-form-actions .btn {
        width: auto;
    }
}

/* ============================================
   DESKTOP (992px+)
   ============================================ */

@media (min-width: 992px) {
    /* Category grid 3 columns */
    .forum-category-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Forum actions row */
    .forum-actions {
        flex-direction: row;
        align-items: center;
    }

    .forum-search {
        max-width: 400px;
    }

    /* Search bar horizontal */
    .search-form-wrapper {
        flex-direction: row;
    }

    .search-filter-group {
        min-width: 200px;
        width: auto;
    }

    .search-submit {
        width: auto;
    }

    /* Reply item row */
    .reply-item {
        flex-direction: row;
    }

    .reply-item--nested {
        margin-left: 3rem;
    }

    /* Replies header row */
    .replies-header {
        flex-direction: row;
        align-items: center;
        gap: 0;
    }

    .replies-sort {
        width: auto;
        justify-content: flex-end;
    }

    .sort-select,
    .replies-sort select {
        flex: 0;
        max-width: none;
    }

    /* Forum filters row */
    .forum-filters {
        flex-direction: row;
        align-items: center;
    }

    .filter-group {
        justify-content: flex-start;
        width: auto;
    }
}

/* ============================================
   TOUCH DEVICE ADJUSTMENTS
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    /* Ensure minimum 44x44px touch targets */
    .vote-button,
    .reply-actions button,
    .reply-actions a,
    .topic-action-btn,
    .pagination-button,
    .filter-select,
    .sort-select {
        min-width: 44px;
        min-height: 44px;
    }

    /* Larger tap areas for small interactive elements */
    .breadcrumb-item a {
        padding: 0.5rem;
        margin: -0.5rem;
    }

    .reply-actions button,
    .reply-actions a {
        padding: 0.75rem;
    }
}

/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .forum-category-card,
    .topic-card,
    .reply-item,
    .vote-button,
    .topic-action-btn,
    .pagination-button,
    .forum-modal__content,
    .btn,
    .forum-new-topic-btn {
        transition: none;
    }

    .forum-modal__content {
        animation: none;
    }

    .forum-loading__spinner,
    .spinner,
    .skeleton {
        animation: none;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .forum-actions,
    .forum-filters,
    .forum-new-topic-btn,
    .topic-actions,
    .reply-actions,
    .reply-form,
    .vote-buttons,
    .forum-pagination,
    .forum-modal {
        display: none !important;
    }

    .forum-index,
    .forum-topic,
    .forum-category,
    .forum-new-topic {
        padding: 0;
        background: none;
    }

    .topic-card,
    .reply-item,
    .forum-category-card,
    .topic-header {
        box-shadow: none;
        border: 1px solid #ddd;
        break-inside: avoid;
    }
}
