/* ============================================================
   Track My Stocks — Mobile App UI
   ALL rules are scoped to max-width: 768px.
   Desktop layout is completely unaffected.

   DARK FIXED:  .mob-header, .mob-cat-tabs, .mob-bottom-nav
   THEME-AWARE: everything else (cards, background, text, inputs)
                follows the existing site light/dark CSS variables
   ============================================================ */

/* ── Utility: hide/show helpers ───────────────────────────── */
.mobile-only { display: none !important; }

@media (max-width: 768px) {
    .mobile-only { display: flex !important; }
    /* <nav> elements also use flex */
    nav.mobile-only { display: flex !important; }
    .desktop-only { display: none !important; }
}

/* ════════════════════════════════════════════════════════════
   MOBILE LAYOUT — everything below only fires on ≤768px
   ════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

    /* ── Body: only add bottom padding for fixed nav bar ──── */
    body {
        padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)) !important;
        margin-bottom: 0 !important;
        overflow-x: hidden !important;
    }

    /* ── Hide desktop chrome elements (footer removed from list) ── */
    .market-ticker-bar,
    .site-header,
    .main-nav,
    .sub-nav,
    .mobile-menu-toggle,
    .mobile-overlay,
    .breaking-bar,
    #backToTop,
    .featured-section,
    .top-news-section,
    .rss-home-section,
    .ad-placeholder,
    .ad-container-wrapper,
    .pagination {
        display: none !important;
    }

    /* Reset desktop padding on main */
    main {
        padding: 0 !important;
        margin: 0 !important;
    }

    .page-wrap {
        max-width: 100% !important;
        padding: 8px 12px 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    /* Fix container horizontal overflow */
    .container {
        padding-left: 12px !important;
        padding-right: 12px !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ══════════════════════════════════════════════════════
       ALWAYS DARK: Mobile Header — fixed dark regardless of theme
       ══════════════════════════════════════════════════════ */
    .mob-header {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        background: #0d0d0d !important;
        padding: 0 16px !important;
        height: 52px !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 1001 !important;
        border-bottom: 1px solid #1e1e1e !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .mob-logo {
        font-family: 'Inter', sans-serif !important;
        font-size: 18px !important;
        font-weight: 800 !important;
        color: #ffffff !important;
        text-decoration: none !important;
        letter-spacing: -0.4px !important;
        line-height: 1 !important;
    }

    .mob-header-right {
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
    }

    .mob-header-avatar {
        width: 30px !important;
        height: 30px !important;
        border-radius: 50% !important;
        background: #2a2a2a !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        color: #aaaaaa !important;
        font-size: 14px !important;
        text-decoration: none !important;
        border: 1px solid #333 !important;
        flex-shrink: 0 !important;
    }

    /* ══════════════════════════════════════════════════════
       ALWAYS DARK: Category tabs bar — fixed dark
       ══════════════════════════════════════════════════════ */
    .mob-cat-tabs {
        display: flex !important;
        background: #0d0d0d !important;
        border-bottom: 1px solid #1e1e1e !important;
        position: sticky !important;
        top: 52px !important;
        z-index: 999 !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .mob-cat-inner {
        display: flex !important;
        align-items: center !important;
        overflow-x: auto !important;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
        padding: 0 12px !important;
        width: 100% !important;
    }

    .mob-cat-inner::-webkit-scrollbar {
        display: none !important;
    }

    /* Tabs are always white-on-dark since the bar is dark */
    .mob-cat-tab {
        display: inline-flex !important;
        align-items: center !important;
        white-space: nowrap !important;
        padding: 10px 14px !important;
        font-family: 'Inter', sans-serif !important;
        font-size: 14px !important;
        font-weight: 500 !important;
        color: #888888 !important;
        text-decoration: none !important;
        border-bottom: 2px solid transparent !important;
        transition: color 0.2s ease, border-color 0.2s ease !important;
        flex-shrink: 0 !important;
    }

    .mob-cat-tab:hover {
        color: #ffffff !important;
    }

    .mob-cat-tab.mob-active {
        color: #ffffff !important;
        font-weight: 700 !important;
        border-bottom-color: #ffffff !important;
    }

    /* ══════════════════════════════════════════════════════
       THEME-AWARE: News cards — use existing CSS variables
       so they respect the user's light/dark mode toggle.
       Only layout overrides are applied here.
       ══════════════════════════════════════════════════════ */

    /* News feed list */
    .news-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 16px !important;
        padding: 16px 0 !important;
        width: 100% !important;
    }

    /* Card — rounded on mobile, uses theme bg color */
    .news-card {
        border-radius: 16px !important;
        overflow: hidden !important;
        width: 100% !important;
        display: block !important;
        margin: 0 !important;
        /* background / border come from existing theme variables — NOT overridden */
    }

    /* Card image — full-width with 16:9 ratio */
    .card-image-wrap {
        width: 100% !important;
        aspect-ratio: 16 / 9 !important;
        overflow: hidden !important;
        border-radius: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        position: relative !important;
        background: var(--bg-light, #f5f5f5) !important;
    }

    .card-image {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        display: block !important;
        border-radius: 0 !important;
    }

    /* Fallback placeholder — theme-aware */
    .card-img-placeholder {
        width: 100% !important;
        height: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-direction: column !important;
        gap: 8px !important;
        color: var(--ink-faint) !important;
    }

    .card-img-placeholder i {
        font-size: 32px !important;
    }

    /* Clickable image link wrapper */
    .card-link-wrapper {
        display: block !important;
        text-decoration: none !important;
    }

    /* Action bar layout */
    .card-action-bar {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 10px 14px 6px !important;
        /* background follows theme via existing styles */
    }

    /* Card body padding */
    .card-body {
        padding: 6px 14px 16px !important;
        border-top: none !important;
    }

    /* Title — larger on mobile, inherits theme color */
    .card-title {
        font-family: 'Inter', sans-serif !important;
        font-size: 16px !important;
        font-weight: 700 !important;
        line-height: 1.4 !important;
        margin-bottom: 8px !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 3 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        /* color follows theme — NOT overridden */
    }

    .card-title a {
        text-decoration: none !important;
    }

    /* Excerpt — inherits theme color */
    .card-excerpt {
        font-family: 'Inter', sans-serif !important;
        font-size: 13.5px !important;
        line-height: 1.6 !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 4 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        margin: 0 !important;
        /* color follows theme — NOT overridden */
    }

    /* Flatten the card toggle wrapper height on mobile */
    .card-toggle-wrapper {
        height: auto !important;
        overflow: visible !important;
        position: relative !important;
    }

    .card-excerpt-container {
        position: static !important;
        opacity: 1 !important;
        transform: none !important;
    }

    /* Comments panel on card — initially hidden */
    .card-comments {
        position: static !important;
        opacity: 0 !important;
        transform: none !important;
        pointer-events: none !important;
        height: 0 !important;
        overflow: hidden !important;
        display: none !important;
    }

    .card-toggle-wrapper.show-comments .card-comments {
        display: flex !important;
        opacity: 1 !important;
        height: auto !important;
        pointer-events: auto !important;
    }

    .card-toggle-wrapper.show-comments .card-excerpt-container {
        display: none !important;
    }

    /* Prevent any horizontal overflow */
    .page-wrap,
    .news-grid,
    .news-card,
    .card-body,
    .card-image-wrap {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ══════════════════════════════════════════════════════
       ALWAYS DARK: Bottom Navigation Bar — fixed dark
       ══════════════════════════════════════════════════════ */
    .mob-bottom-nav {
        display: flex !important;
        align-items: center !important;
        justify-content: space-around !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: calc(60px + env(safe-area-inset-bottom, 0px)) !important;
        min-height: 60px !important;
        background: #0d0d0d !important;
        border-top: 1px solid #1e1e1e !important;
        border-bottom: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        margin-bottom: 0 !important;
        z-index: 9999 !important;
        padding: 0 8px env(safe-area-inset-bottom, 0px) 8px !important;
        box-sizing: border-box !important;
        outline: none !important;
    }

    .mob-nav-item {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 3px !important;
        color: #666666 !important;
        text-decoration: none !important;
        font-family: 'Inter', sans-serif !important;
        font-size: 10px !important;
        font-weight: 500 !important;
        flex: 1 !important;
        height: 60px !important;
        max-height: 60px !important;
        transition: color 0.2s ease !important;
        min-width: 0 !important;
        padding: 4px 2px !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    .mob-nav-item svg {
        display: block !important;
        flex-shrink: 0 !important;
    }

    .mob-nav-item img {
        width: 22px !important;
        height: 22px !important;
        object-fit: contain !important;
        display: block !important;
        /* Inactive: gray tint */
        filter: brightness(0) saturate(100%) invert(40%) !important;
        transition: filter 0.2s ease !important;
    }

    .mob-nav-item span {
        font-size: 10px !important;
        font-weight: 500 !important;
        white-space: nowrap !important;
        color: inherit !important;
        display: block !important;
        line-height: 1 !important;
    }

    /* Active nav item — white */
    .mob-nav-item.active {
        color: #ffffff !important;
        font-weight: 700 !important;
    }

    .mob-nav-item.active svg {
        color: #ffffff !important;
    }

    .mob-nav-item.active img {
        /* Active: full white */
        filter: brightness(0) saturate(100%) invert(100%) !important;
    }

    .mob-nav-item.active span {
        color: #ffffff !important;
        font-weight: 700 !important;
    }

    /* ── Stock & Sector Mobile Theme Overrides ─────────────── */
    .stock-page {
        background: var(--bg, #fafaf8) !important;
        color: var(--ink, #0f172a) !important;
        padding: 20px 0 !important;
    }
    .stock-header-card {
        background: var(--bg-card, #ffffff) !important;
        border: 1px solid var(--border, #e2e8f0) !important;
        color: var(--ink, #0f172a) !important;
    }
    .stock-name-info h1 {
        color: var(--ink, #0f172a) !important;
    }
    .search-news-list {
        background: var(--bg-card, transparent) !important;
    }
    .search-news-item {
        border-bottom: 1px solid var(--border-light, #e8e8e4) !important;
    }
    .sni-title {
        color: var(--ink, #0f172a) !important;
    }
    .sni-time {
        color: var(--ink-light, #64748b) !important;
    }
    .empty-news-box {
        background: var(--bg-card, #ffffff) !important;
        border: 1px solid var(--border, #e2e8f0) !important;
        color: var(--ink-light, #64748b) !important;
    }
}
