/* ==========================================================================
   MOBILE DESIGN SYSTEM - Reddit Clone
   ========================================================================== */

/* Mobile Bottom Navigation (Visible only on mobile) */
.mobile-bottom-nav {
    display: none;
    /* Hidden by default */
}

@media (max-width: 767px) {
    /* ====================
     Layout Adjustments
     ==================== */

    /* Hide Desktop Sidebar */
    .reddit-sidebar {
        display: none !important;
    }

    /* Full Width Main Content */
    .reddit-main {
        width: 100%;
        padding: 0;
        margin-bottom: 60px;
        /* Space for bottom nav */
        background-color: var(--bg-primary);
    }

    .reddit-container {
        display: block;
        padding: 0;
        max-width: 100%;
        margin: 0;
    }

    /* ====================
     Header Adjustments
     ==================== */
    .reddit-header {
        padding: 8px 12px;
        position: sticky;
        top: 0;
        z-index: var(--z-sticky);
        background-color: var(--bg-primary);
        border-bottom: 1px solid var(--border-color);
    }

    /* Compact Header for Mobile */
    .reddit-nav {
        grid-template-columns: auto 1fr auto;
        gap: 12px;
        display: grid;
        align-items: center;
    }

    .reddit-nav-right> :not(.theme-toggle-btn):not(.user-menu) {
        /* Hide desktop nav actions except theme toggle and user menu (if needed) */
        display: none;
    }

    .reddit-search {
        width: 100%;
        height: 36px;
        border-radius: 20px;
    }

    .reddit-search-input {
        border-radius: 20px;
        background-color: var(--bg-secondary);
        border: none;
        height: 100%;
    }

    /* ====================
     Bottom Navigation
     ==================== */
    .mobile-bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 56px;
        /* Standard tab bar height */
        background-color: var(--bg-primary);
        /* Match system dark/light */
        border-top: 1px solid var(--border-color);
        z-index: var(--z-fixed);
        padding-bottom: env(safe-area-inset-bottom);
        /* iOS Safe Area */
    }

    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        color: var(--text-secondary);
        height: 100%;
        gap: 4px;
        background: none;
        border: none;
        padding: 4px 0;
    }

    .mobile-nav-item.active {
        color: var(--text-primary);
    }

    .mobile-nav-item svg {
        width: 24px;
        height: 24px;
        stroke-width: 1.5px;
    }

    .mobile-nav-label {
        font-size: 10px;
        font-weight: 500;
    }

    .mobile-create-btn {
        color: var(--text-primary);
    }

    .mobile-create-btn .plus-icon {
        width: 28px;
        height: 28px;
        stroke-width: 2px;
    }

    /* ====================
     Reddit News Card Style
     ==================== */
    .reddit-post {
        padding: 12px 16px;
        border-radius: 0;
        /* Full width on mobile usually implies list style */
        margin-bottom: 0;
        /* Connected list */
        border-bottom: 1px solid var(--border-color);
        box-shadow: none;
        /* Remove card shadow for cleaner list view */

        /* Grid Layout */
        display: grid;
        grid-template-areas:
            "header header"
            "body body"
            "footer footer";
        gap: 8px;
    }

    .reddit-post:last-child {
        border-bottom: none;
    }

    .reddit-post-content {
        display: contents;
        /* Removes wrapper box so children participate in grid */
        padding: 0;
        /* Reset */
    }

    /* === Header Area === */
    .post-header {
        grid-area: header;
        font-size: 12px;
        color: var(--text-secondary);
        margin: 0;
        display: flex;
        align-items: center;
    }

    .post-subreddit {
        color: var(--text-primary);
        font-weight: 700;
        margin-right: 4px;
    }

    /* === Body Area === */
    .post-body {
        grid-area: body;
        display: flex;
        flex-direction: row;
        /* Title left, img right */
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        margin: 0;
    }

    .post-text {
        flex: 1;
    }

    .post-title {
        font-size: 16px;
        font-weight: 600;
        line-height: 1.4;
        margin: 0 0 4px 0;
        color: var(--text-primary);
    }

    /* Truncate excerpt or hide it */
    .post-excerpt {
        display: none;
    }

    .post-media {
        width: 90px;
        height: 65px;
        border-radius: 8px;
        flex-shrink: 0;
        order: 2;
        /* Ensure image is on the right */
        overflow: hidden;
        margin: 0;
    }

    .post-image {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    /* === Footer Area === */
    /* Re-targeted Vote Section */
    .reddit-vote {
        grid-area: footer;
        /* Place in footer row */
        display: flex !important;
        position: static;
        width: auto;
        background: none;
        border: none;
        padding: 0;
        margin-right: auto;
        /* Push to left */
        flex-direction: row;
        border-radius: 16px;
        border: 1px solid transparent;
        /* No border usually on modern Reddit mobile, just background */
        background-color: transparent;
        height: 32px;
        align-items: center;
        gap: 0;
    }

    /* Optional: Reddit style grey pill background for actions? 
     The screenshot shows black background with grey icons/text 
     and maybe subtle outlines or background pills. 
     Let's stick to simple first. */

    .reddit-vote .vote-btn {
        padding: 4px 8px;
        width: auto;
        height: 100%;
    }

    .reddit-vote .vote-count {
        padding: 0 2px;
        font-size: 12px;
        font-weight: 600;
    }

    /* Footer Actions */
    .post-footer {
        grid-area: footer;
        display: flex;
        align-items: center;
        /* The vote is already in the grid area 'footer' by CSS rule above?
         No, .reddit-vote is a sibling of .reddit-post-content.
         .post-footer is INSIDE .reddit-post-content.
         
         Since we used display: contents on .reddit-post-content,
         .post-footer children become grid items if we aren't careful.
         
         Actually .post-footer is a direct child of .reddit-post-content.
         So .post-footer IS the grid item.
         
         We want .reddit-vote AND .post-footer to share the 'footer' area?
         That would stack them.
         
         Correction: 
         We need the VOTE component and the ACTIONS component to appear side-by-side in the footer row.
         We can let them share the row by not assigning 'footer' area to both, 
         or by making them flex containers.
         
         But .reddit-vote structure is separate.
         Current HTML:
         <article class="reddit-post">
            <div class="reddit-vote">...</div>
            <div class="reddit-post-content">
                ...header...
                ...body...
                <div class="post-footer">...</div>
            </div>
         </article>
      */

        /* Solution: 
        Assign specific columns in the footer row.
     */
    }


    /* Reset grid areas to be more explicit about columns */
    .reddit-post {
        grid-template-columns: auto 1fr;
        /* Use simple footer layout where vote and actions share the footer row */
        grid-template-areas:
            "header header"
            "body body"
            "footer footer";
    }

    /* Wait, if both occupy footer, how do they align? */
    .reddit-vote {
        grid-row: 3;
        grid-column: 1;
        /* First bit of footer */
        justify-self: start;
        margin-right: 12px;

        /* Style as Pill */
        border: 1px solid var(--border-color);
        border-radius: 24px;
        padding: 0 4px;
    }

    .post-footer {
        grid-row: 3;
        grid-column: 2;
        /* Rest of footer */
        justify-self: start;
        display: flex;
        align-items: center;
        width: 100%;
        margin: 0;
    }

    .post-actions {
        display: flex;
        align-items: center;
        width: 100%;
        gap: 8px;
        /* Spacing between pills */
    }

    .post-action {
        border: 1px solid var(--border-color);
        border-radius: 24px;
        padding: 4px 12px;
        height: 32px;
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 12px;
        font-weight: 600;
    }

    /* Hide text labels in actions if screen strictly small? 
     Screenshot shows icons + text numbers for comments. */

}

/* Dark Mode Specific Tweaks for Mobile */
[data-theme="dark"] .mobile-bottom-nav {
    background-color: #000000;
    /* Pure black for bottom bar usually */
    border-top: 1px solid #1a1a1b;
}

[data-theme="dark"] .reddit-header {
    background-color: #000000;
    /* Match pure black background */
}

[data-theme="dark"] body {
    background-color: #000000;
    /* Pure black bg */
}

[data-theme="dark"] .reddit-post {
    background-color: #000000;
    border-bottom-color: #1a1a1b;
}

/* ====================
   Mobile Bottom Sheet
   ==================== */
.mobile-comment-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--bg-primary);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    z-index: 400; /* Below header (500) */
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    max-height: 80vh;
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-comment-sheet.active {
    transform: translateY(0);
}

.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.sheet-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
}

.sheet-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    padding: 0 8px;
    line-height: 1;
    cursor: pointer;
}

.sheet-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sheet-textarea {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 16px;
    /* Prevent zoom on focus */
    resize: none;
}

.sheet-actions {
    display: flex;
    justify-content: flex-end;
}

.mobile-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 400; /* Below header (500) */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.mobile-sheet-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Dark mode tweaks for sheet */
[data-theme="dark"] .mobile-comment-sheet {
    background-color: #1a1a1b;
    border-top: 1px solid #343536;
}

[data-theme="dark"] .sheet-textarea {
    background-color: #272729;
    border-color: #343536;
}