@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .app-sidebar {
        display: none;
    }

    .app-main {
        margin-left: 0;
    }

    /* Header rail is .desktop-only; if shown, keep nav + hide brand-row actions. */
    .app-topbar .topbar-actions,
    .app-topbar .topbar-spacer {
        display: none;
    }

    .app-subnav.is-admin-mobile:not(.is-hidden) {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0 0.75rem;
        width: 100%;
    }

    .app-subnav.is-admin-mobile:not(.is-hidden)::-webkit-scrollbar {
        display: none;
    }

    .app-subnav.is-admin-mobile .subnav-link {
        flex-shrink: 0;
        white-space: nowrap;
    }

    .mobile-header {
        display: flex;
    }

    .bottom-nav {
        display: block;
    }

    .app-content {
        padding: 1rem;
    }

    .app-content.has-bottom-nav {
        padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 1rem);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .page-header-row {
        flex-direction: column;
    }

    .page-title {
        font-size: 1.25rem;
    }

    .toast {
        bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 0.5rem);
    }

    .profile-panel {
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        max-height: 85vh;
        overflow-y: auto;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        padding-bottom: calc(env(safe-area-inset-bottom) + 0.5rem);
    }
}

@media (min-width: 769px) {
    .toast {
        bottom: 1.5rem;
    }

    .mobile-only {
        display: none !important;
    }

    .profile-backdrop.show {
        display: none;
    }

    .profile-panel {
        top: calc(56px + 0.5rem);
        right: 1.5rem;
    }

    body:has(.preview-banner.show) .profile-panel {
        top: calc(56px + 2.5rem);
    }

    .profile-user {
        align-items: flex-start;
        text-align: left;
    }

    .profile-user-avatar {
        display: none;
    }

    .profile-member-meta {
        display: none;
    }
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }

    .search-pagination-item button,
    .search-pagination-item span {
        min-width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .search-pagination-item button,
    .search-pagination-item span {
        min-width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }

    .search-pagination-item.more-pages span {
        font-size: 0.65rem;
        max-width: 70px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}
