/**
 * TrollKhach - Responsive Styles
 * Tham chiếu: UI-DESIGN-SYSTEM.md Section 5
 */

/* ============================================================
   Tablet: 640px - 1024px
   ============================================================ */
@media (max-width: 1024px) {
    .sidebar-right { display: none; }
    .desktop-only { display: none; }

    .site-layout { padding: var(--space-4); gap: var(--space-4); }

    .sidebar-left {
        width: 64px;
        overflow: hidden;
        flex-shrink: 0;
    }

    .sidebar-left .nav-label,
    .sidebar-left .filter-label,
    .sidebar-left .sidebar-title,
    .sidebar-left .sidebar-section { display: none; }

    .sidebar-left .sidebar-nav { margin-bottom: 0; }

    .nav-item a { justify-content: center; padding: var(--space-3); }
    .nav-item a .icon { width: 22px; height: 22px; }

    .site-content { max-width: 540px; }
}

/* ============================================================
   Mobile: < 768px
   ============================================================ */
@media (max-width: 767px) {
    /* Layout */
    .site-layout {
        flex-direction: column;
        padding: 0;
        gap: 0;
    }

    .sidebar-left,
    .sidebar-right { display: none; }

    .site-content { max-width: 100%; }

    .single-thread-view {
        gap: var(--space-2);
    }

    .single-thread-topbar {
        top: 0;
        padding: var(--space-2) var(--space-3) 0;
    }

    .single-thread-comments {
        border-radius: 0;
        border-left: none;
        border-right: none;
        padding: var(--space-3);
    }

    .single-comments-list-wrap,
    .single-comments-footer {
        padding: var(--space-2);
    }

    .single-comments-input-row textarea {
        padding-right: 64px;
    }

    .single-comments-submit-btn {
        right: 6px;
        top: 6px;
        transform: none;
        height: 26px;
        min-height: 26px;
        font-size: 12px;
        padding: 0 10px;
    }

    .single-comment-item.depth-1 {
        margin-left: 18px;
    }

    .single-comment-action {
        height: 24px;
        min-height: 24px;
        font-size: 11px;
    }

    .single-thread-comments .comment-modal-body {
        overflow: visible !important;
        max-height: none !important;
    }

    .comment-meta-row {
        align-items: flex-start;
        gap: var(--space-1-5);
    }

    .comment-actions {
        gap: 6px;
    }

    .comment-action-btn,
    .cmt-react-btn {
        font-size: 11px;
        min-height: 24px;
        height: 24px;
    }

    .single-comments-panel .single-comment-actions .comment-action-btn,
    .single-comments-panel .single-comment-actions .cmt-react-btn {
        min-height: 24px;
        height: 24px;
        line-height: 1;
        padding: 0 8px;
    }

    /* Header */
    .site-header { height: 52px; }
    .header-inner { padding: 0 var(--space-3); }

    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        cursor: pointer;
        padding: var(--space-2);
        color: var(--color-neutral-600);
        border-radius: var(--radius-full);
    }

    .menu-toggle:hover { background: var(--color-neutral-50); }

    .main-navigation .primary-menu {
        display: none;
        position: absolute;
        top: 52px;
        left: 0;
        right: 0;
        background: var(--color-neutral-0);
        border-bottom: 1px solid var(--color-neutral-100);
        flex-direction: column;
        padding: var(--space-2);
        box-shadow: var(--shadow-sm);
    }

    .main-navigation.toggled .primary-menu { display: flex; }

    .btn-compose .btn-text { display: none; }
    .btn-compose { padding: 0; width: 40px; justify-content: center; }

    /* Feed readability on mobile */
    .feed-tab-bar .tab-btn {
        font-size: 0.8125rem;
        padding: var(--space-2-5) var(--space-3);
    }

    /* Make tabs fill width evenly whether 3 or 4 tabs */
    .feed-tab-bar .tab-btn {
        flex: 1;
        justify-content: center;
        text-align: center;
        min-width: 0;
    }

    .composer-row {
        gap: var(--space-2);
    }

    .composer-actions {
        flex-wrap: nowrap;
        gap: var(--space-1);
        overflow-x: visible;
    }

    .composer-actions .composer-chip,
    .composer-actions .composer-submit {
        flex: 1;
        min-width: 0;
        justify-content: center;
        white-space: nowrap;
    }

    .composer-actions .composer-chip {
        padding: 5px 8px;
        font-size: 0.75rem;
    }

    .composer-actions .composer-chip {
        font-size: 0;
        width: 42px;
        height: 32px;
        flex: 0 0 42px;
        padding: 0;
        gap: 0;
    }

    .composer-actions .composer-chip svg {
        display: block;
        width: 17px;
        height: 17px;
    }

    .composer-actions .composer-submit {
        margin-left: auto;
        padding-left: 8px;
        padding-right: 8px;
        font-size: 0.75rem;
        gap: 0;
        white-space: nowrap;
        flex: 0 0 auto;
    }

    .composer-actions .composer-submit svg {
        display: none;
    }

    .composer-avatar {
        width: 32px;
        height: 32px;
        border-radius: var(--radius-full);
        overflow: hidden;
    }

    .composer-trigger-inner {
        padding: var(--space-2) var(--space-3);
        gap: var(--space-2);
    }
    .composer-trigger-avatar { width: 28px; height: 28px; }
    .composer-trigger-input {
        font-size: 0.75rem;
        padding: 6px 10px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .composer-dialog {
        width: 100%;
        max-width: 100%;
        max-height: calc(100vh - 12px);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    }
    .composer-header { padding: 10px 14px; }
    .composer-header h3 { font-size: 14px; }
    .composer-body { padding: 10px 14px; gap: 8px; }
    .composer-textarea { font-size: 14px; min-height: 80px; }
    .composer-title-input { font-size: 14px; }
    .composer-author-row { gap: 6px; margin-bottom: 4px; }
    .composer-author-row .composer-avatar { width: 28px; height: 28px; }
    .composer-author-info strong { font-size: 13px; }

    .composer-meta-row {
        padding: 6px 2px;
    }
    .composer-meta-row-label { font-size: 12px; }
    .composer-tags-input { height: 32px; font-size: 0.8rem; }
    .composer-fields-grid { grid-template-columns: 1fr; gap: 6px; }
    .composer-meta-pickers { grid-template-columns: 1fr; }
    .composer-char-count { font-size: 11px; }
    .composer-footer { padding: 10px 14px; gap: 6px; }
    .composer-submit-btn { font-size: 13px; padding: 6px 16px; }

    .composer-picker-sheet-body {
        padding: 10px;
    }

    .composer-field-full {
        grid-column: auto;
    }

    .composer-meta-note {
        margin-top: 0;
        font-size: 11px;
    }

    .composer-url-actions {
        justify-content: stretch;
    }

    .composer-url-actions .btn {
        flex: 1;
    }

    .composer-link-chip span {
        max-width: 180px;
    }

    .composer-input {
        min-height: 40px;
        font-size: 0.875rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }


    .composer-title-input {
        min-height: auto;
        padding: 2px 0 4px;
        font-size: 0.95rem;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        border: 0;
    }

    .post-card-header {
        gap: var(--space-2);
    }

    .post-card-header .post-card-avatar {
        width: 40px;
        height: 40px;
    }

    .post-author-sub {
        gap: var(--space-1-5);
    }

    .post-author-name {
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.9375rem;
    }

    .post-time {
        font-size: 0.75rem;
    }

    .post-card-body {
        font-size: 0.875rem;
        line-height: 1.5;
    }

    .post-card-actions {
        gap: 0;
    }

    .post-action-btn {
        padding: var(--space-1-5) var(--space-2);
        font-size: 0.8125rem;
    }

    .post-action-btn .action-count {
        min-width: 0;
    }

    /* Post Cards */
    .post-card {
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: 1px solid var(--color-neutral-100);
        border-bottom: 1px solid var(--color-neutral-100);
        margin-bottom: 1px;
    }

    /* Modals - full screen mobile */
    .modal {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    /* Footer */
    .footer-inner { flex-direction: column; text-align: center; }
    .footer-menu { justify-content: center; }
    .footer-social { justify-content: center; }

    /* Pagination */
    .nav-links { flex-wrap: wrap; }

    /* Bottom Mobile Nav */
    .bottom-mobile-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--color-neutral-0);
        border-top: 1px solid var(--color-neutral-200);
        padding: var(--space-1-5) 0 env(safe-area-inset-bottom, 0);
        z-index: var(--z-30);
        justify-content: space-around;
        -webkit-backdrop-filter: blur(8px);
        backdrop-filter: blur(8px);
    }

    @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
        .bottom-mobile-nav {
            background: rgba(255, 255, 255, 0.98);
        }

        [data-theme="dark"] .bottom-mobile-nav {
            background: rgba(17, 17, 17, 0.98);
        }
    }

    .bottom-mobile-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: var(--space-1) var(--space-3);
        color: var(--color-neutral-500);
        font-size: 0.625rem;
        font-weight: var(--font-medium);
        transition: color var(--transition-fast);
        text-decoration: none;
    }

    .bottom-mobile-nav a.active { color: var(--dub-accent-blue); }
    .bottom-mobile-nav a .icon { width: 22px; height: 22px; }

    /* Hide command bar & popup on mobile (use bottom nav instead) */
    .cmd-bar,
    .cmd-bar:not([hidden]),
    #cmd-bar,
    #cmd-bar:not([hidden]) { display: none !important; }

    /* Compose FAB */
    .fab-compose {
        position: fixed;
        bottom: calc(64px + env(safe-area-inset-bottom, 0));
        right: var(--space-4);
        width: 52px;
        height: 52px;
        border-radius: var(--radius-full);
        background: #000000;
        color: var(--color-neutral-0);
        border: none;
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
        cursor: pointer;
        z-index: var(--z-20);
        display: flex;
        align-items: center;
        justify-content: center;
        transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    }

    .fab-compose:active { transform: scale(0.92); }

    /* Toast mobile */
    .toast-container {
        right: var(--space-4);
        left: var(--space-4);
    }

    .toast { max-width: 100%; }

    /* Feed bottom padding for nav */
    .site-content { padding-bottom: 70px; }
}

/* ============================================================
   Mobile S: < 375px
   ============================================================ */
@media (max-width: 374px) {
    .post-card { padding: var(--space-3); }
    .post-action-btn { padding: var(--space-2) var(--space-2-5); font-size: var(--text-xs); }

    .post-card-body {
        font-size: 0.8125rem;
        line-height: 1.45;
    }

    .post-author-name {
        font-size: 0.875rem;
    }

    .post-time {
        font-size: 0.75rem;
    }

    .badge {
        font-size: 0.6875rem;
        padding: 1px 8px;
    }

    .feed-tab-bar .tab-btn {
        padding: var(--space-2-5) var(--space-2);
        font-size: 0.75rem;
        gap: var(--space-1);
    }

    .composer-actions {
        gap: var(--space-1-5);
    }

    .composer-chip {
        width: 40px;
        height: 32px;
        flex: 0 0 40px;
        padding: 0;
        font-size: 0;
    }

    .composer-input {
        min-height: 40px;
        font-size: 0.8125rem;
    }

    .composer-meta-row-label {
        font-size: 0.8125rem;
    }

    .composer-title-input {
        min-height: auto;
        padding: 2px 0 4px;
        font-size: 0.875rem;
        border: 0;
    }

    .bottom-mobile-nav a {
        padding: var(--space-1) var(--space-1-5);
        font-size: 0.5625rem;
        line-height: 1.1;
    }

    .bottom-mobile-nav a .icon {
        width: 20px;
        height: 20px;
    }

    .fab-compose {
        width: 48px;
        height: 48px;
        bottom: calc(60px + env(safe-area-inset-bottom, 0));
    }
}

@media (max-width: 340px) {
    .bottom-mobile-nav a {
        font-size: 0;
        padding: var(--space-1);
    }

    .bottom-mobile-nav a .icon {
        width: 22px;
        height: 22px;
    }
}

/* ============================================================
   Desktop fine-tuning
   ============================================================ */
@media (min-width: 1025px) {
    .mobile-only { display: none; }
    .bottom-mobile-nav { display: none; }
    .fab-compose { display: none; }

    .main-feed { max-width: var(--feed-max-width); width: 100%; margin: 0 auto; }
}

/* Mobile drawer */
.mobile-drawer-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 99998;
    background: rgba(0,0,0,0.5);
}
.mobile-drawer-overlay:not([hidden]) { display: block; }
.mobile-drawer {
    display: none;
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 99999;
    width: min(320px, 80vw); background: var(--color-neutral-0);
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
    animation: drawerIn 0.15s ease-out;
}
.mobile-drawer:not([hidden]) { display: flex; }
@keyframes drawerIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.mobile-drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; border-bottom: 1px solid var(--color-neutral-100);
}
.mobile-drawer-title { font-size: 16px; font-weight: 600; }
.mobile-drawer-close {
    width: 28px; height: 28px; border: none; border-radius: 50%;
    background: transparent; color: var(--color-neutral-400);
    font-size: 22px; cursor: pointer; display: flex;
    align-items: center; justify-content: center;
}
.mobile-drawer-close:hover { background: var(--color-neutral-100); }
.mobile-drawer-body { flex: 1; overflow-y: auto; padding: 8px 0; }
.mobile-drawer-body .sidebar-left {
    display: block !important; width: auto; padding: 0; border: none;
}
.mobile-drawer-body .sidebar-left .sidebar-section,
.mobile-drawer-body .sidebar-left .nav-label,
.mobile-drawer-body .sidebar-left .filter-label,
.mobile-drawer-body .sidebar-left .sidebar-title {
    display: block !important;
}
.mobile-drawer-body .sidebar-sticky { padding: 0; }
.mobile-drawer-body .sidebar-brand { display: none; }
.mobile-drawer-body .sidebar-nav { border-bottom: 1px solid var(--color-neutral-100); padding-bottom: 4px; margin-bottom: 4px; }
.mobile-drawer-body .nav-item a {
    padding: 10px 16px; font-size: 14px; justify-content: flex-start; gap: 10px;
    border: none; border-radius: 0; margin: 0;
}
.mobile-drawer-body .nav-item.active a,
.mobile-drawer-body .nav-item.current-menu-item a {
    background: var(--color-neutral-100);
    border: none;
}
.mobile-drawer-body .nav-item a .icon { width: 20px; height: 20px; }
.mobile-drawer-body .nav-label {
    padding: 8px 16px 4px; font-size: 10px; text-transform: uppercase;
    letter-spacing: 0.5px; color: var(--color-neutral-400);
}
.mobile-drawer-body .sidebar-section { padding: 0 16px; margin: 12px 0; border: none; }
.mobile-drawer-body .sidebar-section + .sidebar-section { padding-top: 12px; border-top: 1px solid var(--color-neutral-100); }
.mobile-drawer-body .sidebar-title { font-size: 12px; margin: 0 0 6px; padding: 0; }
.mobile-drawer-body .filter-item a { padding: 6px 0; font-size: 13px; gap: 8px; }
.mobile-drawer-body .filter-dot { width: 8px; height: 8px; }
.mobile-drawer-body .flair-hash { font-size: 13px; }
.mobile-drawer-body .filter-toggle { font-size: 12px; }
.mobile-menu-btn {
    background: none; border: none; color: var(--color-neutral-600);
    cursor: pointer; padding: 8px; display: flex; align-items: center;
}

@media (min-width: 1025px) and (max-width: 1279px) {
    .site-content { max-width: 540px; }
}

@media (min-width: 1280px) {
    .site-content { max-width: var(--feed-max-width); }
}

/* ============================================================
   Missing pages - Mobile responsive
   ============================================================ */
@media (max-width: 767px) {
    /* 404 page */
    .error-404 {
        min-height: 50vh;
    }
    .error-code {
        font-size: clamp(3rem, 15vw, 5rem);
    }
    .error-title {
        font-size: var(--text-lg);
    }
    .error-actions .btn {
        max-width: 100%;
    }
    .search-form-inline {
        max-width: 100%;
    }

    /* Search results */
    .search-title {
        font-size: var(--text-lg);
    }
    .search-form {
        flex-direction: column;
    }
    .search-form .search-field {
        width: 100%;
    }
    .search-submit {
        width: 100%;
    }
    .search-result-item {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    /* Archive */
    .archive-title {
        font-size: var(--text-lg);
    }

    /* Single post */
    .single-post-full .post-actions {
        overflow-x: auto;
        gap: 2px;
    }
    .single-post-full .btn-action {
        padding: 6px 10px;
        font-size: 12px;
        white-space: nowrap;
    }
    .related-grid {
        grid-template-columns: 1fr;
        gap: var(--space-2);
    }
    .post-card-compact {
        border-radius: var(--radius-md);
    }

    /* Admin page */
    .site-content-admin {
        padding: var(--space-3);
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-2);
    }
    .stat-card {
        padding: var(--space-3);
    }
    .stat-card .stat-value {
        font-size: var(--text-xl);
    }
    .admin-nav .tab-btn {
        padding: 6px 12px;
        font-size: var(--text-xs);
    }
    .seed-banner {
        flex-direction: column;
        text-align: center;
    }
}

@media (max-width: 374px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .admin-nav {
        flex-direction: column;
        align-items: stretch;
    }
    .admin-nav .tab-btn {
        text-align: center;
    }
}

/* Print */
@media print {
    .sidebar-left,
    .sidebar-right,
    .bottom-mobile-nav,
    .fab-compose,
    .site-header,
    .post-card-actions,
    .post-actions,
    .social-actions-bar,
    .comments-area,
    .related-posts,
    .composer-trigger,
    .composer-modal,
    .toast-container,
    .report-modal,
    .admin-nav,
    .notifications-center,
    .btn,
    .btn-social,
    .btn-action { display: none !important; }

    body { background: white; color: black; }
    .site-layout { display: block; }
    .site-content { max-width: 100%; }
    .post-card { border: none; box-shadow: none; break-inside: avoid; }
    .post-card-body { -webkit-line-clamp: unset; overflow: visible; }
}

/* ============================================================
   Responsive Images
   ============================================================ */
@media (max-width: 600px) {
    .post-card-media img { max-height: 300px; }
    .profile-cover { height: 100px; }
    .profile-avatar { margin-top: -35px; }
    .profile-avatar img { width: 70px; height: 70px; }
    .profile-media-grid { grid-template-columns: 1fr; }
    .profile-media-control-row { grid-template-columns: 1fr; }
}

/* ============================================================
   Print Styles
   ============================================================ */
@media print {
    .sidebar-left, .sidebar-right, .site-header, .site-footer,
    .post-card-actions, .bottom-mobile-nav, .fab-compose,
    .comments-area { display: none !important; }

    .site-content { max-width: 100%; }
    .post-card { border: none; box-shadow: none; break-inside: avoid; }
}

/* ============================================================
   Mag page — Mobile
   ============================================================ */
@media (max-width: 767px) {
    .mag-layout {
        padding: var(--space-3);
    }

    .mag-breadcrumb {
        margin-bottom: var(--space-3);
        font-size: 12px;
    }

    .mag-filter-bar {
        flex-wrap: nowrap;
        gap: var(--space-2);
        margin-bottom: var(--space-4);
    }

    .mag-filter-cats {
        gap: var(--space-1);
    }

    .mag-filter-cat {
        font-size: 11px;
        padding: 4px 10px;
    }

    /* Featured: stack dọc */
    .mag-featured {
        grid-template-columns: 1fr;
        gap: var(--space-3);
        margin-bottom: var(--space-4);
    }

    .mag-featured-main-img {
        aspect-ratio: 16 / 12;
    }

    .mag-featured-main-title {
        font-size: 17px;
    }

    .mag-featured-main-excerpt {
        font-size: 13px;
    }

    .mag-featured-side {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--space-2);
    }

    .mag-featured-side-item {
        flex-direction: column;
    }

    .mag-featured-side-img {
        max-width: 100%;
        width: 100%;
        aspect-ratio: 16 / 10;
        height: auto;
    }

    .mag-featured-side-body {
        padding: var(--space-2);
    }

    .mag-featured-side-title {
        font-size: 13px;
        -webkit-line-clamp: 2;
    }

    .mag-featured-side-excerpt {
        display: none;
    }

    .mag-featured-side-date {
        font-size: 10px;
    }

    /* List: 2 cột trên mobile */
    .mag-list {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
    }

    .mag-card-image {
        aspect-ratio: 16 / 11;
    }

    .mag-card-body {
        padding: var(--space-2) var(--space-3);
    }

    .mag-card-title {
        font-size: 14px;
    }

    .mag-card-title a {
        -webkit-line-clamp: 2;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .mag-card-excerpt {
        font-size: 12px;
        -webkit-line-clamp: 2;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .mag-card-meta {
        font-size: 11px;
        margin-bottom: var(--space-1);
    }

    .mag-card-date {
        font-size: 11px;
    }

    .mag-placeholder-label {
        font-size: 20px;
    }
}

/* Mobile nhỏ: < 480px — 1 cột */
@media (max-width: 480px) {
    .mag-featured-side {
        grid-template-columns: 1fr;
    }

    .mag-list {
        grid-template-columns: 1fr;
    }
}
