/* ═══════════════════════════════════════════════════════════════════════════
   Topics List Component — Premium Redesign
   ═══════════════════════════════════════════════════════════════════════════ */

.topics-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    padding: 1.5rem 0;
    width: 100%;
}

/* Ensure the parent #discoverGrid doesn't constrain the topics grid when in topics view */
#discoverGrid.is-topics-view {
    display: block !important;
}

/* ── Individual Topic Card (Grid Style) ─────────────────────────────────── */
.topic-list-item {
    background: var(--bg-card, #ffffff);
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    border: 1px solid var(--border-light, #f1f1f1);
    border-radius: 12px;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    min-height: 0;
}

.topic-list-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-color: var(--accent-primary, #059669);
}

/* ── Main Row Layout (Simplified for Grid) ────────────────────────────── */
.topic-main {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 12px;
    flex: 1;
    min-height: 0;
}

.topic-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Fills space between title and footer (preview + sources) */
.topic-card-body-fill {
    flex: 1 1 auto;
    min-height: 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 4px;
}

.topic-text-pair {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-light, #f1f1f1);
}

.topic-text-pair:last-child {
    border-bottom: none;
}

.topic-text-pair .topic-text-item {
    margin-bottom: 0.35rem;
}

.topic-text-source-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #0d6e4f;
    text-decoration: none;
}

.topic-text-source-link:hover {
    text-decoration: underline;
}

.topic-card-preview {
    margin: 0;
    flex: 1 1 auto;
    min-height: 0;
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-secondary, #64748b);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
    line-clamp: 5;
    overflow: hidden;
}

.topic-sources-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.topic-source-icon {
    text-decoration: none;
    flex-shrink: 0;
}

.topic-source-icon__circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    background: hsl(var(--source-hue, 200), 48%, 92%);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.topic-source-icon:hover .topic-source-icon__circle {
    transform: scale(1.06);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.topic-source-icon__letter {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 800;
    line-height: 1;
    color: hsl(var(--source-hue, 200), 42%, 32%);
    pointer-events: none;
}

.topic-source-icon__favicon {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 2;
    border-radius: 50%;
    background: #fff;
}

.topic-sources-more {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
}

.topic-details-urls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
}

.topic-modal .topic-source-icon__circle {
    width: 44px;
    height: 44px;
}

/* ── Top Meta Row (category + date + counts) ─────────────────────────── */
.topic-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.topic-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent-primary, #059669);
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(5, 150, 105, 0.1);
}

.topic-timestamp {
    font-size: 11px;
    color: var(--text-tertiary, #94a3b8);
    font-weight: 400;
}

.topic-counts {
    display: flex;
    gap: 8px;
}

.count-badge {
    font-size: 10px;
    color: var(--text-tertiary, #94a3b8);
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 3px;
}

.topic-top .meta-sep {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--text-tertiary, #94a3b8);
    opacity: 0.5;
}

/* ── Title (Fully Visible) ────────────────────────────────────────────── */
.topic-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary, #1e293b);
    margin: 0 0 8px 0;
    line-height: 1.4;
    /* Full visibility: removed line-clamp */
    display: block;
    overflow: visible;
}

/* ── Bottom Stats ────────────────────────────────── */
.topic-stats {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 12px;
    border-top: 1px solid var(--border-light, #f1f1f1);
}

.sentiment-pill {
    font-size: 10px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    text-transform: capitalize;
}

.sentiment-pill.positive { background: #ecfdf5; color: #059669; }
.sentiment-pill.negative { background: #fef2f2; color: #dc2626; }
.sentiment-pill.neutral  { background: #f8fafc; color: #64748b; }

.impact-bar {
    display: flex;
    gap: 3px;
}

.impact-dot {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: #e2e8f0;
}

.impact-dot.filled { background: #f59e0b; }
.impact-dot.filled-high { background: #ef4444; }

/* ── Hide legacy expand icon in grid ── */
.topic-expand-icon {
    display: none;
}

/* ── Modal Overlay ── */
.topic-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.topic-modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ── Modal ── */
.topic-modal {
    background: white;
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    border-radius: 16px;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.topic-modal-overlay.active .topic-modal {
    transform: translateY(0);
}

.modal-header {
    position: sticky;
    top: 0;
    background: white;
    padding: 24px 32px;
    border-bottom: 1px solid #f1f1f1;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 2;
}

.modal-header-content {
    flex: 1;
}

.modal-meta {
    margin-bottom: 8px;
}

.modal-topic-title {
    font-size: 24px;
    font-weight: 800;
    line-height: 1.3;
    color: #0f172a;
    margin: 4px 0 16px 0;
}

.modal-stats {
    display: flex;
}

.modal-stats .topic-stats {
    width: 100%;
    justify-content: flex-start;
    gap: 16px;
    border-top: none;
    padding-top: 0;
}

.modal-close-btn {
    background: #f1f5f9;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #64748b;
    margin-left: 16px;
}

.modal-body {
    padding: 32px;
}

.topic-details-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #94a3b8;
    margin: 24px 0 12px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.topic-details-label:first-child {
    margin-top: 0;
}

.topic-details {
    display: none;
}

.topic-modal .topic-details {
    display: block;
}

.topic-text-item {
    font-size: 14px;
    line-height: 1.6;
    color: #334155;
    padding: 16px;
    background: #f8fafc;
    border-radius: 12px;
    margin-bottom: 12px;
    border-left: 4px solid #e2e8f0;
}


/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .topics-grid-container {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .topic-modal {
        max-height: 95vh;
    }
    .modal-header, .modal-body {
        padding: 20px;
    }
}
