/* News page — card-stack feed with infinite scroll.
   Reuses agi's design tokens (--color-text, --color-border, --color-bg-elev,
   --color-primary) so dark/light mode follows the rest of the app. Layout is
   intentionally narrower than the knowledge grid because a long-form list
   reads better in a single column.
*/

.news-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem 0 4rem;
}

.news-list {
    display: flex;
    flex-direction: column;
    gap: .85rem;
}

.news-card {
    display: block;
    padding: 1rem 1.15rem;
    background: var(--color-bg-elev, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s ease, box-shadow .15s ease, transform .05s ease;
}

.news-card:hover {
    border-color: var(--color-primary, #2563eb);
    box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.04);
}

.news-card:active {
    transform: translateY(1px);
}

.news-card-head {
    display: flex;
    align-items: baseline;
    gap: .65rem;
    margin-bottom: .4rem;
    font-size: .8rem;
    color: var(--color-text-muted);
}

.news-card-source {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--color-text-secondary);
}

.news-card-symbols {
    display: inline-flex;
    flex-wrap: wrap;
    gap: .25rem;
}

.news-card-symbol {
    padding: 1px 6px;
    background: var(--color-bg-subtle, #f3f4f6);
    border-radius: 4px;
    font-size: .7rem;
    color: var(--color-text-secondary);
}

/* 클릭 시 /stock 상세로 이동하는 심볼 칩 — 클릭 가능 어포던스. */
.news-card-symbol--link {
    cursor: pointer;
    transition: background .1s ease, color .1s ease;
}
.news-card-symbol--link:hover {
    background: var(--color-primary, #2563eb);
    color: #fff;
}

.news-card-date {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

.news-card-title {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--color-text);
    margin: 0 0 .35rem;
}

.news-card-preview {
    margin: 0;
    color: var(--color-text-secondary);
    font-size: .9rem;
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.news-loading,
.news-sentinel {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: .875rem;
}

.news-sentinel { min-height: 1px; }

.news-empty {
    margin-top: 3rem;
    text-align: center;
    color: var(--color-text-muted);
}

@media (max-width: 640px) {
    .news-page { padding: 1rem 0 3rem; }
    .news-card { padding: .85rem .8rem; }
    .news-card-title { font-size: .98rem; }
    .news-card-preview { -webkit-line-clamp: 2; font-size: .85rem; }
}

/* ─── /news feed section title ─────────────────────────────────────────────
   Divider heading between the AI digest (top) and the article feed (below).
   Hidden until the feed has content (news.js unhides). */
.news-feed-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 2rem 0 1rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--color-border, #e5e7eb);
}

/* ─── Home (chat) landing — slim news PREVIEW card ──────────────────────────
   A subordinate teaser linking to /news. The full digest lives on /news; the
   home screen keeps only this one-line card so its identity reads as "chat",
   not "news dashboard". Hidden until home_news.js confirms a digest exists. */
.home-news-preview {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin: 1.75rem auto 0;
    /* 채팅 입력창(.chat-input-inner)·최근 주식 위젯과 동일한 폭 기준:
       width:100% + max-width:800px. width:100% 가 없으면 column-flex 부모에서
       auto 좌우 마진이 stretch 를 막아 모바일에서 콘텐츠 폭으로 줄어든다. */
    width: 100%;
    max-width: 800px;
    padding: .7rem .9rem;
    background: var(--color-bg-elev, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: border-color .12s ease, background .12s ease;
}

.home-news-preview:hover {
    border-color: var(--color-primary, #2563eb);
    background: var(--color-bg-subtle, #f8fafc);
}

.home-news-preview-ico {
    font-size: 1.1rem;
    line-height: 1;
    flex: 0 0 auto;
}

.home-news-preview-body {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    min-width: 0;
    flex: 1 1 auto;
}

.home-news-preview-head {
    display: flex;
    align-items: baseline;
    gap: .5rem;
}

.home-news-preview-title {
    font-size: .85rem;
    font-weight: 600;
    color: var(--color-text);
}

.home-news-preview-time {
    font-size: .7rem;
    color: var(--color-text-muted);
    opacity: .7;
    font-variant-numeric: tabular-nums;
}

.home-news-preview-teaser {
    font-size: .82rem;
    color: var(--color-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.home-news-preview-link {
    flex: 0 0 auto;
    font-size: .8rem;
    font-weight: 500;
    color: var(--color-primary, #2563eb);
    white-space: nowrap;
}

/* ─── Home (chat) landing — recent KNOWLEDGE preview card ───────────────────
   Shares the full .home-news-preview chassis (the element carries both classes),
   so only the pair-spacing differs: the knowledge card leads the group, and the
   news card directly below hugs it so the two read as one coherent pair. */
.home-knowledge-preview + .home-news-preview {
    margin-top: .6rem;
}

/* ─── /news AI digest block ─────────────────────────────────────────────────
   The categorized summary at the TOP of the /news page (overview-first), above
   the article feed. Single-column cards; each summary line expands to its cited
   source articles. */
.news-digest {
    margin: 0 0 1rem;
}

.news-digest-head {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    margin-bottom: .75rem;
    padding: 0 .25rem;
}

.news-digest-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}

.news-digest-time {
    font-size: .72rem;
    color: var(--color-text-muted);
    opacity: .7;
    font-variant-numeric: tabular-nums;
}

/* Single-column stack — multi-column makes scanning hard (the eye has to
   z-pattern across categories), and expand panels would shove neighboring
   columns down inconsistently. One column = a clear top-to-bottom reading
   path that matches the article feed below. */
.news-digest-grid {
    display: flex;
    flex-direction: column;
    gap: .65rem;
}

.news-digest-card {
    padding: .85rem 1rem;
    background: var(--color-bg-elev, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 10px;
}

.news-digest-cat {
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--color-primary, #2563eb);
    margin-bottom: .4rem;
}

.news-digest-items {
    margin: 0;
    /* li 가 display:flex 라 불릿 마커가 안 보임 → 좌측 들여쓰기 불필요(낭비 여백 제거). */
    padding-left: 0;
    font-size: .88rem;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

.news-digest-items li { margin-bottom: .25rem; }
.news-digest-items li:last-child { margin-bottom: 0; }

/* Previous bucket's digest — demoted below the latest: hair-line divider +
   slightly muted so the eye lands on the current summary first. */
.news-digest-prev {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--color-border, #e5e7eb);
    opacity: .82;
}

.news-digest-head--prev { margin-bottom: .6rem; }

.news-digest-title--prev {
    font-size: .9rem;
    color: var(--color-text-secondary, var(--color-text-muted));
}

/* Inline item layout — text + count badge inline. The badge is absolutely
   positioned top-right so multi-line text never pushes it onto its own line;
   padding-right reserves a fixed gutter for it. */
.news-digest-item {
    display: flex;
    align-items: baseline;
    gap: .35rem;
    flex-wrap: wrap;
    padding: 1px 4px;
    padding-right: 1.9rem;
    margin-left: -4px;
    border-radius: 6px;
    transition: background .1s ease;
    position: relative;
}

.news-digest-item--expandable {
    cursor: pointer;
}

.news-digest-item--expandable:hover {
    background: var(--color-bg-subtle, #f3f4f6);
}

.news-digest-item--expandable:focus-visible {
    outline: 2px solid var(--color-primary, #2563eb);
    outline-offset: 1px;
}

.news-digest-item-text { flex: 1 1 auto; min-width: 0; }

/* Count badge — plain "+N" shown only for 2+ related; muted color + small
   font keep it secondary. tabular-nums so widths align. */
.news-digest-badge {
    position: absolute;
    top: .35em;
    right: .35rem;
    font-size: .72em;
    font-weight: 600;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: transparent;
    transition: color .12s ease;
    user-select: none;
}

.news-digest-badge--count {
    color: var(--color-text-muted, #94a3b8);
}

.news-digest-item--expandable:hover .news-digest-badge--count {
    color: var(--color-primary, #2563eb);
}

.news-digest-item--expandable[aria-expanded="true"] .news-digest-badge--count {
    color: var(--color-primary, #2563eb);
}

.news-digest-related {
    flex-basis: 100%;
    margin: .35rem 0 0;
    padding: .45rem .55rem;
    background: var(--color-bg-subtle, #f8fafc);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    list-style: none;
}

.news-digest-related li { margin-bottom: .25rem; }
.news-digest-related li:last-child { margin-bottom: 0; }

.news-digest-related-link {
    display: flex;
    flex-direction: column;
    gap: 1px;
    text-decoration: none;
    color: inherit;
    padding: 3px 4px;
    border-radius: 5px;
}

.news-digest-related-link:hover {
    background: var(--color-bg-elev, #fff);
}

.news-digest-related-title {
    font-size: .8rem;
    font-weight: 500;
    color: var(--color-text);
    line-height: 1.35;
}

.news-digest-related-meta {
    font-size: .7rem;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

.news-digest-related-empty {
    color: var(--color-text-muted);
    font-size: .75rem;
    font-style: italic;
}

@media (max-width: 640px) {
    .home-news-preview { margin-top: 1.25rem; }
    .home-news-preview-teaser { display: none; }
    .news-digest-card { padding: .75rem .85rem; }
}
