/**
 * Digest View Styles
 * A newspaper-style daily digest layout
 */

/* === Container === */
.digest-container {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: var(--spacing-lg) var(--inline-padding);
}

/* === Empty State === */
.digest-empty {
    text-align: center;
    padding: var(--spacing-4xl) var(--spacing-lg);
    color: var(--color-text-muted);
}

.digest-empty h2 {
    color: var(--color-text-secondary);
    font-size: var(--font-size-xl);
    margin-bottom: var(--spacing-sm);
}

.digest-empty p {
    margin-bottom: var(--spacing-md);
}

.digest-empty .hint {
    font-size: var(--font-size-sm);
    margin-bottom: var(--spacing-xl);
}

.digest-empty-actions {
    display: flex;
    gap: var(--spacing-md);
    justify-content: center;
    flex-wrap: wrap;
}

/* === Sections === */
.digest-section {
    margin-bottom: var(--spacing-3xl);
}

.digest-section-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    margin: 0 0 var(--spacing-lg);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--color-border);
}

/* === Entity Groups === */
.digest-entity-group {
    margin-bottom: var(--spacing-lg);
}

.digest-entity-group:last-child {
    margin-bottom: 0;
}

.entity-group-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-xs);
    border-bottom: 1px dotted var(--color-border);
}

.entity-group-header-compact {
    margin-bottom: var(--spacing-sm);
    padding-bottom: 0;
    border-bottom: none;
}

.entity-group-header-inline {
    margin-bottom: var(--spacing-xs);
    padding-bottom: 0;
    border-bottom: none;
}

.entity-group-name {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    text-decoration: none;
}

.entity-group-name:hover {
    color: var(--color-text-primary);
}

.entity-group-count {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* === Importance Tiers (subtle visual weight) === */
/* High importance: slightly more prominent */
.importance-high .lead-headline,
.importance-high .featured-headline,
.importance-high .headline-link {
    font-weight: var(--font-weight-semibold);
}

/* Medium importance: default styling (no changes needed) */

/* Low importance: slightly reduced prominence */
.importance-low .lead-headline,
.importance-low .featured-headline,
.importance-low .headline-link {
    color: var(--color-text-secondary);
}

.importance-low .lead-summary,
.importance-low .featured-summary {
    color: var(--color-text-light);
}

/* === Lead Stories (Tier 1) === */
.digest-lead-section {
    margin-bottom: var(--spacing-3xl);
}

.digest-lead-card {
    display: flex;
    gap: var(--spacing-md);
    padding: var(--spacing-lg) 0;
    border-bottom: 1px solid var(--color-border);
}

.digest-lead-card:last-child {
    border-bottom: none;
}

.lead-rank {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    background: var(--color-primary);
    color: var(--color-bg-body);
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-sm);
    border-radius: 50%;
    flex-shrink: 0;
}

.lead-content {
    flex: 1;
    min-width: 0;
}

/* Lead card thumbnail */
.lead-thumbnail {
    width: 200px;
    height: 134px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    background: var(--color-bg-light);
}

/* Hide broken images gracefully */
.lead-thumbnail:not([src]),
.lead-thumbnail[src=""],
.lead-thumbnail[src="None"] {
    display: none;
}

.lead-headline {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
    margin: 0 0 var(--spacing-sm);
}

.lead-headline a {
    color: var(--color-text-primary);
    text-decoration: none;
}

.lead-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-bottom: var(--spacing-md);
    flex-wrap: wrap;
}

.lead-sources a {
    color: var(--color-text-muted);
    text-decoration: none;
}

/* Entity name in meta line */
.meta-entity {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
}

.meta-entity a {
    color: var(--color-text-muted);
    text-decoration: none;
}

.meta-entity a:hover {
    color: var(--color-primary);
}

.lead-summary {
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
    color: var(--color-text-secondary);
    margin: 0;
    white-space: pre-wrap;
}

/* Primary source domain in meta line */
.lead-source {
    font-size: var(--font-size-sm);
}

.lead-source a {
    color: var(--color-text-muted);
    text-decoration: none;
}

.lead-source a:hover {
    color: var(--color-primary);
}


/* === Featured Stories (Tier 2) === */
.digest-featured-grid {
    column-count: 1;
}

@media (min-width: 900px) {
    .digest-featured-grid {
        column-count: 2;
        column-gap: var(--spacing-lg);
    }

    .digest-featured-card {
        break-inside: avoid;
    }
}

.featured-group {
    margin-bottom: var(--spacing-lg);
}

.featured-group:last-child {
    margin-bottom: 0;
}

.digest-featured-card {
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--color-border);
}

.digest-featured-card:last-child {
    border-bottom: none;
}

.featured-headline {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-tight);
    margin: 0 0 var(--spacing-xs);
}

.featured-headline a {
    color: var(--color-text-primary);
    text-decoration: none;
}

.featured-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-bottom: var(--spacing-sm);
}

.featured-source {
    color: var(--color-text-muted);
    text-decoration: none;
}

.featured-summary {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    color: var(--color-text-muted);
    margin: 0;
    white-space: pre-wrap;
}

/* Primary source domain in meta line */
.featured-source {
    font-size: var(--font-size-xs);
}

.featured-source a {
    color: var(--color-text-muted);
    text-decoration: none;
}

.featured-source a:hover {
    color: var(--color-primary);
}

/* === "More:" sources line (shared between lead/featured) === */
.story-more-sources {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-top: var(--spacing-xs);
}

.story-more-sources a {
    color: var(--color-text-secondary);
    text-decoration: none;
}

.story-more-sources a:hover {
    color: var(--color-primary);
}

/* === Headlines (Tier 3) === */
.digest-headlines {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.headline-group {
    margin-bottom: 0;
}

.headline-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.headline-row {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) 0;
    border-bottom: 1px dotted var(--color-border);
}

.headline-row:last-child {
    border-bottom: none;
}

.headline-link {
    flex: 1;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    text-decoration: none;
    line-height: var(--line-height-tight);
}

.headline-sources {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    white-space: nowrap;
}

.headline-time {
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
    white-space: nowrap;
}

.headline-summary {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    color: var(--color-text-secondary);
    margin: var(--spacing-sm) 0 0 0;
    width: 100%;
}

/* === Section Actions === */
.section-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-sm);
}

.btn-section-read {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    cursor: pointer;
    padding: var(--spacing-xs) 0;
    transition: color var(--transition-fast);
}

.btn-section-read:hover {
    color: var(--color-primary);
}

/* === Footer === */
.digest-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-md);
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--color-border);
    flex-wrap: wrap;
}

.digest-more-link {
    color: var(--color-primary);
    text-decoration: none;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
}

.digest-mark-read {
    font-size: var(--font-size-sm);
}

/* === Hover States === */
@media (hover: hover) {
    .lead-headline a:hover,
    .featured-headline a:hover,
    .headline-link:hover {
        color: var(--color-primary);
    }

    .lead-sources a:hover,
    .featured-source:hover {
        color: var(--color-primary);
    }

    .digest-more-link:hover {
        text-decoration: underline;
    }
}

/* === Expandable Cards === */
.digest-card {
    cursor: pointer;
}

/* Keyboard selection highlight */
.digest-card.selected {
    background: var(--color-bg-light);
}

.headline-row.selected {
    background: var(--color-bg-light);
    border-radius: var(--radius-sm);
}

.digest-card.expanded {
    background: var(--color-bg-light);
}

.digest-lead-card.expanded {
    flex-wrap: wrap;
}

.headline-row.expanded {
    background: var(--color-bg-light);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    margin: var(--spacing-xs) 0;
    border-bottom: none;
    flex-wrap: wrap;
}

/* Preview summary stays visible when expanded - we update its content with full text */

/* Story details inline - flows directly after the preview summary */
.digest-card .story-details-inline {
    width: 100%;
}

.digest-card .details-divider {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: var(--spacing-md) 0;
}

.digest-card .source-links-inline {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-bottom: var(--spacing-md);
}

.digest-card .source-links-inline a {
    color: var(--color-text-secondary);
    text-decoration: none;
}

.digest-card .source-links-inline a:hover {
    color: var(--color-primary);
}

/* Action buttons in expanded digest cards */
.digest-expanded-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-xs);
    list-style: none;
    margin: var(--spacing-md) 0 0;
    padding: 0;
}

.digest-expanded-actions li {
    display: inline-flex;
}

.digest-expanded-actions button,
.digest-expanded-actions a {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-fast);
}

.digest-expanded-actions button:hover,
.digest-expanded-actions a:hover {
    border-color: var(--color-text-muted);
    color: var(--color-text-secondary);
}

.digest-expanded-actions .bookmark-action.is-bookmarked button {
    color: var(--color-star);
    border-color: var(--color-star);
}

.digest-expanded-actions .feedback-actions {
    display: flex;
    gap: var(--spacing-xs);
}

.digest-expanded-actions .feedback-actions button {
    padding: var(--spacing-xs);
}

.digest-expanded-actions .action-label {
    display: none;
}

@media (min-width: 620px) {
    .digest-expanded-actions .action-label {
        display: inline;
    }
}

/* Inline analysis button */
.digest-card .btn-inline-analyze {
    padding: var(--spacing-xs) var(--spacing-sm);
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    cursor: pointer;
    margin-top: var(--spacing-sm);
}

.digest-card .btn-inline-analyze:hover {
    border-color: var(--color-text-muted);
    color: var(--color-text-secondary);
}

.digest-card .details-loading,
.digest-card .details-error {
    padding: var(--spacing-md);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

/* Related stories in expanded cards */
.digest-card .related-stories-inline {
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-sm);
    border-top: 1px solid var(--color-border);
}

.digest-card .related-header {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--spacing-xs);
}

.digest-card .related-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.digest-card .related-item {
    display: flex;
    align-items: baseline;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs) 0;
}

.digest-card .related-link {
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: var(--font-size-sm);
}

.digest-card .related-link:hover {
    color: var(--color-primary);
}

.digest-card .related-meta {
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
    white-space: nowrap;
}

/* === Mobile Adjustments === */
@media (max-width: 619px) {
    .digest-lead-card {
        flex-direction: column;
        align-items: flex-start;
    }

    .lead-rank {
        width: 1.5rem;
        height: 1.5rem;
        font-size: var(--font-size-xs);
        margin-bottom: var(--spacing-xs);
    }

    .lead-headline {
        font-size: var(--font-size-md);
    }

    /* Hide thumbnails on mobile for cleaner layout */
    .lead-thumbnail {
        display: none;
    }

    .headline-actions {
        opacity: 1;
    }

    .digest-footer {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .digest-mark-read {
        width: 100%;
    }
}

/* ========== Source Items (TechMeme-style) ========== */

.source-items {
    list-style: none;
    margin: var(--spacing-sm) 0 var(--spacing-sm) var(--spacing-md);
    padding: 0;
    border-left: 2px solid var(--color-border);
    padding-left: var(--spacing-md);
}

.source-items .also-label {
    color: var(--color-text-light);
    font-size: var(--font-size-xs);
    font-style: italic;
    margin-bottom: var(--spacing-xs);
}

.source-items li {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    margin-bottom: var(--spacing-xs);
    color: var(--color-text-secondary);
}

.source-items li:last-child {
    margin-bottom: 0;
}

.source-items .source-name {
    color: var(--color-text-muted);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    white-space: nowrap;
}

.source-items .source-name:has(+ .source-title)::after {
    content: ": ";
}

.source-items .source-name:hover {
    color: var(--color-primary);
}

.source-items .source-title {
    color: var(--color-text-secondary);
}

.source-items .more-sources {
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
    font-style: italic;
}

.source-items .discussion-link {
    font-style: italic;
}

/* Compact source items for featured tier */
.source-items-compact {
    margin: var(--spacing-xs) 0 var(--spacing-xs) var(--spacing-sm);
    padding-left: var(--spacing-sm);
    border-left-width: 1px;
}

.source-items-compact li {
    font-size: var(--font-size-xs);
    margin-bottom: 2px;
}

/* ========== Cross-Entity Badges ========== */

.entity-badges {
    display: inline-flex;
    gap: var(--spacing-xs);
    margin-left: var(--spacing-sm);
    vertical-align: middle;
    flex-wrap: wrap;
}

.entity-badge {
    display: inline-block;
    padding: 1px var(--spacing-xs);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-normal);
    border-radius: var(--radius-sm);
    text-decoration: none;
    background: var(--color-bg-light);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    white-space: nowrap;
}

.entity-badge:hover {
    border-color: var(--color-text-muted);
    color: var(--color-text-secondary);
}

.entity-badge-more {
    font-style: italic;
    color: var(--color-text-light);
    background: none;
    border: none;
    padding: 1px 0;
}

/* Compact badges for featured tier */
.entity-badges-compact {
    margin-left: var(--spacing-xs);
}

.entity-badges-compact .entity-badge {
    font-size: 10px;
    padding: 0 var(--spacing-xs);
}

/* Inline badges for headlines tier */
.entity-badges-inline {
    margin-left: var(--spacing-xs);
    flex-shrink: 0;
}

.entity-badges-inline .entity-badge {
    font-size: 10px;
    padding: 0 4px;
}

/* ========== Related Stories Inline ========== */

.story-related-inline {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-top: var(--spacing-sm);
    padding-top: var(--spacing-sm);
    border-top: 1px dotted var(--color-border);
}

.story-related-inline .related-label {
    font-weight: var(--font-weight-medium);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-right: var(--spacing-xs);
}

.story-related-inline .related-story-link {
    color: var(--color-text-secondary);
    text-decoration: none;
}

.story-related-inline .related-story-link:hover {
    color: var(--color-primary);
}

.story-related-inline .related-age {
    color: var(--color-text-light);
    margin-left: var(--spacing-xs);
    font-size: 10px;
}

.story-related-inline .related-sep {
    margin: 0 var(--spacing-xs);
    color: var(--color-text-light);
}

/* ========== Source Count in Meta ========== */

.lead-source-count,
.featured-source-count {
    color: var(--color-text-light);
}

.lead-source-count::before,
.featured-source-count::before {
    content: "·";
    margin-right: var(--spacing-xs);
}

/* ========== Mobile Adjustments for New Features ========== */

@media (max-width: 619px) {
    /* Hide source items on small screens to reduce clutter */
    .source-items,
    .source-attribution {
        display: none;
    }

    /* Show compact badges */
    .entity-badges {
        margin-left: 0;
        margin-top: var(--spacing-xs);
        display: flex;
    }

    /* Hide related stories on very small screens */
    .story-related-inline {
        display: none;
    }
}

/* ==========================================================================
   Lead Source Attribution (Techmeme-style)
   ========================================================================== */

.source-attribution {
    margin-top: var(--spacing-sm);
}

.source-attribution .lead-source {
    margin-bottom: var(--spacing-xs);
}

.source-attribution .lead-source .source-name {
    font-weight: var(--font-weight-medium);
}

.source-attribution .lead-source .source-name.lead {
    font-weight: var(--font-weight-semibold);
}

.source-attribution .lead-source .source-title {
    color: var(--color-text-secondary);
    margin-left: var(--spacing-xs);
}

.source-attribution .also-sources {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.source-attribution .also-sources .also-label {
    color: var(--color-text-muted);
    margin-right: var(--spacing-xs);
}

.source-attribution .also-sources .source-name {
    color: var(--color-text-secondary);
}

.source-attribution .also-sources .source-name:hover {
    color: var(--color-primary);
}

/* Inline consensus/conflicts in expanded digest cards */
.consensus-inline,
.conflicts-inline {
    font-size: var(--font-size-sm);
    margin: var(--spacing-sm) 0;
    color: var(--color-text-secondary);
    line-height: 1.4;
}

.consensus-label,
.conflicts-label {
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
}

.conflicts-inline {
    color: var(--color-warning-text, #ffcc80);
}

.conflicts-label {
    color: var(--color-warning, #f57c00);
}

/* Lead source in expanded details */
.lead-label {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.also-label {
    color: var(--color-text-muted);
}
