body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    margin: 10px;
    background-color: #f4f4f8;
    color: #333;
}
h1 { 
    text-align: center; 
    color: #444; 
    margin-bottom: 10px; 
    font-size: 1.8rem;
}
.controls {
    text-align: center;
    margin-bottom: 20px;
}
.archive-button {
    padding: 8px 15px;
    font-size: 0.9em;
    cursor: pointer;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #eee;
}
.archive-button.active {
    background-color: #d4edda; /* Light green */
    border-color: #c3e6cb;
    font-weight: bold;
}
.archive-settings-button {
    padding: 8px 15px;
    font-size: 0.9em;
    cursor: pointer;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #eee;
    margin-left: 10px;
}
/* Modal styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}
.modal.show {
    display: flex;
}
.modal-content {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}
.close-button {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    cursor: pointer;
    color: #555;
}
.website-checkboxes {
    margin: 15px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.website-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
}
.save-button {
    padding: 8px 15px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}
.modal-actions {
    margin-top: 15px;
    display: flex;
    justify-content: flex-end;
}
.topic {
    border: 1px solid #dcdcdc;
    margin-bottom: 20px;
    border-radius: 10px;
    background-color: #fff;
    box-shadow: 0 4px 8px rgba(0,0,0,0.08);
    overflow: hidden; /* Contain children */
}
.topic-header {
    padding: 12px 15px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.topic-header h2 {
    margin: 0;
    font-size: 1.3em;
    color: #333;
    font-weight: 600;
}
.topic-summary {
    margin: 0;
    padding: 10px 15px;
    font-size: 0.95em;
    color: #444;
    background-color: #f8f9fa;
    border-top: 1px solid #eee;
    border-bottom: 1px solid #eee;
    line-height: 1.4;
}
.topic-info-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
.topic-info {
    font-size: 0.8em;
    color: #666;
    font-weight: normal;
    white-space: nowrap; /* Prevent wrapping */
}
.topic-similarity {
    font-size: 0.8em;
    color: #555;
    font-weight: bold;
    background-color: #e9ecef;
    padding: 2px 6px;
    border-radius: 4px;
}
.articles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); /* Slightly smaller for mobile */
    gap: 15px;
    padding: 15px;
    display: none; 
}
.topic.open .articles-grid {
    display: grid;
}
.article {
    border: 1px solid #eee;
    border-radius: 6px;
    padding: 15px;
    background-color: #f9f9f9; /* Default background */
    min-height: 110px; /* Slightly reduced minimum height */
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* Pushes source to bottom */
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease-in-out;
}
.article:hover {
     transform: translateY(-3px);
     box-shadow: 0 3px 6px rgba(0,0,0,0.1);
}

/* Image container */
.article-image {
    width: 100%;
    margin-bottom: 10px;
    border-radius: 4px;
    overflow: hidden;
}

.article-image img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

.article-content {
    position: relative; /* Ensure content is above pseudo-element */
    z-index: 1;
    background-color: rgba(255, 255, 255, 0.7); /* Slight white overlay for readability */
    padding: 5px;
    border-radius: 3px;
    display: inline-block; /* Shrink wrap content */
    max-width: 100%;
}
.article-content p { margin: 0; }
.article a {
    text-decoration: none;
    color: #0056b3;
    font-weight: bold;
    font-size: 1em;
    display: block; /* Ensure link takes width */
    margin-bottom: 5px;
}
.article a:hover { text-decoration: underline; color: #003d80; }
.source {
    font-size: 0.8em;
    color: #666;
    font-style: italic;
    display: block;
    margin-top: auto; /* Pushes to bottom in flex */
    position: relative; /* Ensure it's above pseudo-element */
    z-index: 1;
    background-color: rgba(255, 255, 255, 0.7);
    padding: 2px 4px;
    border-radius: 3px;
    align-self: flex-start; /* Align left */
}

.header-info {
    text-align: center;
    margin: 0 auto 20px;
    max-width: 800px;
    padding: 0 15px;
    color: #555;
    font-size: 0.95em;
}

.footer {
    margin-top: 40px;
    padding: 20px;
    text-align: center;
    border-top: 1px solid #ddd;
    color: #666;
    font-size: 0.85em;
    background-color: #f8f9fa;
}

/* Media queries for better mobile experience */
@media (max-width: 768px) {
    body {
        margin: 8px;
    }
    h1 {
        font-size: 1.5rem;
    }
    .topic-header {
        padding: 10px;
    }
    .topic-header h2 {
        font-size: 1.1em;
        width: 100%;
    }
    .topic-info-container {
        width: 100%;
        justify-content: flex-start;
    }
    .articles-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        padding: 10px;
        gap: 10px;
    }
    .article {
        min-height: 100px;
        padding: 12px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.3rem;
    }
    .articles-grid {
        grid-template-columns: 1fr;
    }
    .article {
        min-height: 80px;
    }
}
