/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS Variables for theming */
:root {
    /* Light mode colors */
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border-color: #e0e0e0;
    --accent-color: #007acc;
    --accent-hover: #005a99;
    --success-color: #28a745;
    --error-bg: #ffebee;
    --error-color: #c62828;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Dark mode colors (default) */
body {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #808080;
    --border-color: #404040;
    --accent-color: #4da6ff;
    --accent-hover: #66b3ff;
    --success-color: #4ade80;
    --error-bg: #451a1a;
    --error-color: #ff6b6b;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Light mode override */
body.light-mode {
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border-color: #e0e0e0;
    --accent-color: #007acc;
    --accent-hover: #005a99;
    --success-color: #28a745;
    --error-bg: #ffebee;
    --error-color: #c62828;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Header */
.header {
    padding: 2rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.title-section {
    text-align: center;
    flex: 1;
}

.site-title {
    font-size: 2.5rem;
    font-weight: 300;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.site-subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 400;
}

.header-controls {
    display: flex;
    align-items: center;
}

.dark-mode-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.dark-mode-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.light-mode-icon {
    display: none;
}

body.light-mode .light-mode-icon {
    display: block;
}

body.light-mode .dark-mode-icon {
    display: none;
}

/* Controls */
.controls {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
}

.view-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.toggle-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.toggle-btn.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.toggle-btn:hover:not(.active) {
    background: var(--bg-primary);
    border-color: var(--accent-color);
}

.search-container {
    position: relative;
    margin-bottom: 1rem;
}

#search-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

#search-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

#search-input::placeholder {
    color: var(--text-muted);
}

.clear-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted);
    display: none;
}

.clear-btn:hover {
    color: var(--text-primary);
}

.source-filters {
    margin-bottom: 1rem;
}

.filter-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 0.5rem 1rem;
    margin: 0.25rem;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.filter-btn:hover {
    border-color: var(--accent-color);
    background: var(--bg-primary);
}

.all-btn {
    background: var(--success-color);
    color: white;
    border-color: var(--success-color);
}

.uncheck-btn {
    background: var(--error-color);
    color: white;
    border-color: var(--error-color);
}

.uncheck-btn:hover {
    background: #ff5252;
    border-color: #ff5252;
}

.checkbox-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.source-checkbox {
    display: flex;
    align-items: center;
    margin: 0.25rem;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.source-checkbox input {
    margin-right: 0.5rem;
    accent-color: var(--accent-color);
}

.refresh-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.refresh-btn {
    padding: 0.5rem 1rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.refresh-btn:hover {
    background: var(--accent-hover);
}

.refresh-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

.last-updated {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Loading and Error States */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.error-messages {
    margin-bottom: 1rem;
}

.error-message {
    background: var(--error-bg);
    color: var(--error-color);
    padding: 0.75rem;
    border-radius: 4px;
    border-left: 4px solid var(--error-color);
    margin-bottom: 0.5rem;
}

.hidden {
    display: none !important;
}

/* News Feed */
.news-feed {
    background: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
}

.pagination-btn {
    padding: 0.5rem 1rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

.pagination-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

.page-info {
    font-weight: 500;
    color: var(--text-primary);
    min-width: 100px;
    text-align: center;
}

.pagination-size {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.pagination-size label {
    color: var(--text-secondary);
}

.pagination-size select {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.news-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s;
}

.news-item:hover {
    background-color: var(--bg-primary);
}

.news-item:last-child {
    border-bottom: none;
}

.news-item.filtered-out {
    display: none;
}

.news-source {
    display: inline-block;
    background: var(--accent-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.news-title {
    font-size: 1.1rem;
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

.news-title a {
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.2s;
}

.news-title a:hover {
    color: var(--accent-color);
    text-decoration: underline;
}

.news-meta {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.news-time {
    font-style: italic;
}

.news-description {
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

/* Group Headers for Grouped View */
.source-group {
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

.source-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.source-header {
    background: var(--bg-primary);
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.source-header .source-count {
    color: var(--text-secondary);
    font-weight: normal;
    font-size: 0.9rem;
}

/* Footer */
.footer {
    text-align: center;
    padding: 2rem 0;
    margin-top: 2rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.footer a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.2s;
}

.footer a:hover {
    text-decoration: underline;
    color: var(--accent-hover);
}

/* Modal Styles */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--bg-secondary);
    margin: 15% auto;
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    position: relative;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    color: var(--text-primary);
}

.close {
    color: var(--text-muted);
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    top: 1rem;
    right: 1rem;
    cursor: pointer;
    transition: color 0.2s;
}

.close:hover,
.close:focus {
    color: var(--text-primary);
    text-decoration: none;
}

.modal-content h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.modal-content ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.modal-content li {
    margin-bottom: 0.5rem;
    line-height: 1.4;
    color: var(--text-secondary);
}

.modal-content code {
    background: var(--bg-primary);
    color: var(--accent-color);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-size: 0.85rem;
    word-break: break-all;
    border: 1px solid var(--border-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 0 15px;
    }
    
    .header-content {
        flex-direction: column;
        text-align: center;
    }
    
    .title-section {
        order: 1;
    }
    
    .header-controls {
        order: 2;
        margin-top: 1rem;
    }
    
    .site-title {
        font-size: 2rem;
    }
    
    .controls {
        padding: 1rem;
    }
    
    .view-toggle {
        flex-direction: column;
    }
    
    .toggle-btn {
        margin-bottom: 0.5rem;
    }
    
    .checkbox-container {
        flex-direction: column;
    }
    
    .source-checkbox {
        margin: 0.125rem 0;
        padding: 0.5rem;
        background: var(--bg-primary);
        border-radius: 4px;
        border: 1px solid var(--border-color);
    }
    
    .refresh-container {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .news-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
    
    .modal-content {
        width: 95%;
        margin: 10% auto;
        padding: 1.5rem;
    }
    
    .pagination {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .pagination-size {
        flex-direction: column;
        text-align: center;
    }
    
    /* Better touch targets for mobile */
    .toggle-btn, .filter-btn, .pagination-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .dark-mode-toggle {
        width: 52px;
        height: 52px;
    }
}

@media (max-width: 480px) {
    .site-title {
        font-size: 1.5rem;
    }
    
    .news-item {
        padding: 0.75rem;
    }
    
    .news-title {
        font-size: 1rem;
    }
    
    .source-filters .filter-btn {
        display: block;
        width: 100%;
        margin: 0.25rem 0;
        text-align: left;
    }
    
    .controls {
        padding: 0.75rem;
    }
    
    .modal-content {
        padding: 1rem;
        margin: 5% auto;
    }
    
    /* Improve text readability on small screens */
    .news-description {
        font-size: 0.9rem;
    }
    
    .pagination {
        padding: 1rem;
    }
    
    .page-info {
        font-size: 0.9rem;
        min-width: auto;
    }
}

/* Print Styles */
@media print {
    .controls,
    .footer {
        display: none;
    }
    
    .news-item {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    .news-title a {
        color: #333 !important;
        text-decoration: none !important;
    }
    
    .news-title a:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}