/* ═══════════════════════════════════════
   FEED RESEARCH SHELL (LAYOUT & GRIDS)
═══════════════════════════════════════ */

/* ── Base Tab Container ── */
#feed-company_intel,
#feed-research {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    gap: 16px;
    box-sizing: border-box;

    /* Chart height tokens — adjusted per breakpoint below */
    --chart-h-lg: 340px;
    --chart-h-md: 240px;
    --chart-h-sm: 180px;
}

#feed-company_intel.active,
#feed-research.active {
    display: flex;
}

/* ── Company Intel: split-pane override ── */
#feed-company_intel {
    flex-direction: row;
    height: calc(100vh - 100px);
    min-height: 600px;
    overflow: hidden;
    gap: 0;
}

/* ── Left pane (1 part) ── */
.research-popular-pane {
    flex: 1 1 0;          /* 1:2 ratio — 1 part */
    min-width: 220px;
    max-width: 420px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg-surface);
    overflow: hidden;
}

.research-popular-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 10px;
    border-bottom: 1px solid var(--border);
}

.research-popular-list {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* ── Right pane (2 parts) ── */
.research-main-pane {
    flex: 2 1 0;          /* 1:2 ratio — 2 parts */
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0 0 0 16px;
    overflow-y: auto;
    overflow-x: hidden;
    gap: 16px;
}

/* ── Responsive: 1100px — stack vertically, strip becomes horizontal scroll ── */
@media (max-width: 1100px) {
    #feed-company_intel {
        flex-direction: column;
        height: auto;
        min-height: auto;
        overflow-y: auto;
        overflow-x: hidden;
        padding-bottom: 80px;
    }
    .research-popular-pane {
        flex: none;
        min-width: unset;
        max-width: unset;
        width: 100%;
        height: 160px;
        min-height: 160px;
        max-height: 160px;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow: hidden;
    }
    .research-popular-list {
        display: block;
        overflow: hidden;         /* carousel clips here — no scrollbar */
        height: calc(100% - 42px); /* subtract header height */
    }
    .research-main-pane {
        flex: none;
        min-height: unset;
        height: auto;
        padding-left: 0;
        overflow-y: visible;
    }
}

/* ── Responsive: 768px — mobile (strip stays, just shorter) ── */
@media (max-width: 768px) {
    #feed-company_intel {
        overflow-x: hidden;
        overflow-y: visible;
    }
    .research-popular-pane {
        height: 150px;
        min-height: 150px;
        max-height: 150px;
    }
    .research-main-pane {
        overflow-y: visible;
    }
}

/* ── Responsive: 480px — small mobile ── */
@media (max-width: 480px) {
    .research-popular-pane {
        height: 140px;
        min-height: 140px;
        max-height: 140px;
    }
}

/* ── Main Content Area ── */
/* No flex: 1 / min-height: 0 — children must grow to natural height
   so overflow-y: auto on the feed container actually triggers scroll */
#research-content-area {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.research-content {
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* ── Empty State Fix ── */
#research-content-area.empty-state {
    justify-content: center;
    align-items: center;
}

.empty-state-msg {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 400px;
    text-align: center;
    gap: 16px;
}

.research-dashboard {
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: 100%;
}

/* ── Top Header Widget ── */
.research-header-metrics {
    display: flex;
    align-items: center;
    gap: 24px;
    margin-top: 12px;
    margin-left: 48px;
    flex-wrap: wrap;
}

/* ── 3-Column Split Layout for Desktop ── */
.research-financials-split {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr; /* 50% Sankey | 25% Sub-bars | 25% Peers */
    gap: 16px;
    width: 100%;
    margin-bottom: 24px;
    align-items: stretch;
}

/* ── Chart Layout Base ── */
.research-sankey-card,
.research-peer-card {
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: var(--chart-h-lg);
    width: 100%;
    min-width: 0;
}

.research-charts-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    min-width: 0;
}

/* Revenue / Earnings / FCF individual chart cards — hard 280px box so ECharts always has a real height */
.research-chart-card {
    display: flex;
    flex-direction: column;
    position: relative;
    height: var(--chart-h-md);
    min-height: var(--chart-h-md);
    max-height: var(--chart-h-md);
    min-width: 0;
    overflow: hidden;
    isolation: isolate;
    flex-shrink: 0;
}

/* ── Bulletproof Canvas Wrappers ── */
.chart-canvas-wrapper {
    flex: 1 1 auto;
    position: relative;
    width: 100%;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.chart-canvas-wrapper > div,
.chart-canvas-wrapper canvas,
.chart-canvas-wrapper svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    max-width: 100%;
    display: block;
}

/* ── AI Analysis Masonry Grid Layout ── */
#ai-grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    width: 100%;
    margin-bottom: 24px;
    align-items: stretch;
}

.ai-card {
    display: flex;
    flex-direction: column;
}

/* ── Health & Valuation Grid Layout ── */
.healthflag-columns-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.healthflag-col {
    display: flex;
    flex-direction: column;
}


/* ════════════════════════════════════════
   RESPONSIVE LAYOUTS (RESEARCH)
════════════════════════════════════════ */

/* ── 1440px: Laptops ── */
@media (max-width: 1440px) {
    .research-financials-split { gap: 14px; }
    #ai-grid-container { gap: 14px; }
}

/* ── 1280px: Standard Laptops ── */
@media (max-width: 1280px) {
    .research-financials-split {
        grid-template-columns: 1.5fr 1fr 1fr;
    }
}

/* ── 1100px: Tablets / iPads ── */
@media (max-width: 1100px) {
    #ai-grid-container {
        grid-template-columns: repeat(2, 1fr);
    }

    .research-financials-split {
        grid-template-columns: 1fr 1fr;
    }
    .research-peer-card {
        grid-column: 1 / -1;
        min-height: 300px;
    }

    .tear-metric { width: auto; }
}

/* ── 768px: Mobile ── */
@media (max-width: 768px) {
    #feed-company_intel,
    #feed-research {
        --chart-h-lg: 280px;
        --chart-h-md: 200px;
        --chart-h-sm: 160px;
        /* padding-bottom: 80px; */
    }

    .research-financials-split {
        grid-template-columns: 1fr;
    }

    .research-sankey-card {
        min-height: var(--chart-h-lg);
    }

    .research-chart-card {
        height: var(--chart-h-md);
        min-height: var(--chart-h-md);
        max-height: var(--chart-h-md);
    }

    .research-peer-card {
        grid-column: 1 / -1;
        min-height: var(--chart-h-lg);
    }

    #ai-grid-container {
        grid-template-columns: 1fr;
    }

    .analyst-consensus-widget,
    .pt-widget {
        width: 100%;
    }
}

/* ── 480px: Small Mobile ── */
@media (max-width: 480px) {
    #feed-company_intel,
    #feed-research {
        --chart-h-lg: 240px;
        --chart-h-md: 180px;
        --chart-h-sm: 150px;
        padding-bottom: 80px;
    }

    .research-chart-card {
        height: var(--chart-h-sm);
        min-height: var(--chart-h-sm);
        max-height: var(--chart-h-sm);
    }

    .research-tear-sheet {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    #research-ticker-display { font-size: 18px; }
    .research-timestamp      { font-size: 10px; }
}
