/* CSS Custom Properties for theming */
:root {
    /* Light theme - more white */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #495057;
    --text-muted: #6c757d;
    --border-color: #dee2e6;
    --border-hover: #adb5bd;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.15);
    --accent-color: #007bff;
    --accent-hover: #0056b3;
    --success-color: #28a745;
    --error-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
}

[data-theme="dark"] {
    /* Dark theme - more black */
    --bg-primary: #000000;
    --bg-secondary: #111111;
    --bg-tertiary: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #e9ecef;
    --text-muted: #adb5bd;
    --border-color: #2d2d2d;
    --border-hover: #404040;
    --shadow: 0 2px 10px rgba(255, 255, 255, 0.1);
    --shadow-hover: 0 4px 20px rgba(255, 255, 255, 0.15);
    --accent-color: #007bff;
    --accent-hover: #0056b3;
    --success-color: #28a745;
    --error-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
}

/* Auto theme detection */
@media (prefers-color-scheme: dark) {
    [data-theme="auto"] {
        --bg-primary: #000000;
        --bg-secondary: #111111;
        --bg-tertiary: #1a1a1a;
        --text-primary: #ffffff;
        --text-secondary: #e9ecef;
        --text-muted: #adb5bd;
        --border-color: #2d2d2d;
        --border-hover: #404040;
        --shadow: 0 2px 10px rgba(255, 255, 255, 0.1);
        --shadow-hover: 0 4px 20px rgba(255, 255, 255, 0.15);
        --accent-color: #007bff;
        --accent-hover: #0056b3;
        --success-color: #28a745;
        --error-color: #dc3545;
        --warning-color: #ffc107;
        --info-color: #17a2b8;
    }
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header styles */
header {
    text-align: center;
    margin-bottom: 40px;
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: 15px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.header-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

header h1 {
    font-size: 2.5rem;
    margin: 0;
    color: var(--accent-color);
}

.article-stats {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-bottom: 20px;
}

.stats-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.stats-number {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--accent-color);
}

.stats-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.search-container {
    max-width: 400px;
}

.search-input {
    width: 100%;
    padding: 15px 20px;
    border: 2px solid var(--border-color);
    border-radius: 25px;
    font-size: 16px;
    outline: none;
    transition: all 0.3s ease;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.search-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

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

/* Import button */
.import-container {
    display: flex;
    align-items: center;
}

.import-btn {
    background: var(--accent-color);
    border: 2px solid var(--accent-color);
    border-radius: 25px;
    padding: 12px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    color: white;
    font-size: 14px;
    font-weight: 500;
}

.import-btn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.import-btn:active {
    transform: translateY(0);
}

.import-btn svg {
    transition: transform 0.3s ease;
}

.import-btn:hover svg {
    transform: translateY(-2px);
}

.export-btn {
    background: var(--success-color);
    border: 2px solid var(--success-color);
    border-radius: 25px;
    padding: 12px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    color: white;
    font-size: 14px;
    font-weight: 500;
}

.export-btn:hover {
    background: #218838;
    border-color: #218838;
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.export-btn:active {
    transform: translateY(0);
}

.export-btn svg {
    transition: transform 0.3s ease;
}

.export-btn:hover svg {
    transform: translateY(-2px);
}

/* Theme toggle button */
.theme-toggle {
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    color: var(--text-primary);
}

.theme-toggle:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: scale(1.05);
}

.theme-toggle:active {
    transform: scale(0.95);
}

/* Test math button */
.test-math-btn {
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    color: var(--text-primary);
    font-size: 20px;
}

.test-math-btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: scale(1.05);
}

.test-math-btn:active {
    transform: scale(0.95);
}

.theme-icon {
    width: 24px;
    height: 24px;
    transition: opacity 0.3s ease;
}

/* Show/hide icons based on theme */
[data-theme="light"] .moon-icon,
[data-theme="dark"] .sun-icon,
[data-theme="auto"] .sun-icon {
    opacity: 0;
    position: absolute;
}

[data-theme="light"] .sun-icon,
[data-theme="dark"] .moon-icon,
[data-theme="auto"] .moon-icon {
    opacity: 1;
}

/* Articles grid */
.articles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 25px;
    margin-bottom: 40px;
}

.article-card {
    background: var(--bg-secondary);
    border-radius: 15px;
    padding: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.article-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
}

.article-card h3 {
    font-size: 1.3rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.article-card p {
    color: var(--text-secondary);
    margin-bottom: 15px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

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

.article-date {
    background: var(--bg-tertiary);
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
}

/* Article date tooltip */
.article-language {
    background: var(--bg-tertiary);
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
    position: relative;
}

.article-language::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 1rem;
    white-space: nowrap;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1000;
    margin-bottom: 8px;
}

.article-language::before {
    content: "";
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--border-color);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    margin-bottom: 3px;
}

.article-language:hover::after,
.article-language:hover::before {
    opacity: 1;
    visibility: visible;
}

/* Imported article styles */
.article-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
}

.article-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.remove-article-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    opacity: 0.6;
    transition: all 0.3s ease;
    padding: 5px;
    border-radius: 5px;
}

.remove-article-btn:hover {
    opacity: 1;
    background: rgba(220, 53, 69, 0.1);
    transform: scale(1.1);
}

.imported-badge {
    font-size: 18px;
    opacity: 0.7;
    transition: opacity 0.3s ease;
}

.imported-article {
    border-color: var(--accent-color);
    background: linear-gradient(135deg, var(--bg-secondary) 0%, rgba(0, 123, 255, 0.05) 100%);
}

.imported-article:hover {
    border-color: var(--accent-hover);
    background: linear-gradient(135deg, var(--bg-secondary) 0%, rgba(0, 123, 255, 0.1) 100%);
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
}

.modal-content {
    position: relative;
    background-color: var(--bg-primary);
    margin: 2% auto;
    width: 90%;
    height: 90%;
    border-radius: 15px;
    box-shadow: var(--shadow-hover);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.3s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 30px;
    background: #545658;
    color: white;
    border-radius: 15px 15px 0 0;
}

.modal-header h2 {
    font-size: 1.5rem;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease;
}

.close-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.modal-body {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    background: var(--bg-primary);
    transition: background-color 0.3s ease;
}

/* Article content styles */
.article-content {
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.8;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

/* KaTeX mathematical expressions styling */
.article-content .katex {
    font-size: 1.1em;
    color: var(--text-primary) !important;
    font-family: 'KaTeX_Main', 'Times New Roman', serif;
}

.article-content .katex-display {
    margin: 1.5rem 0;
    text-align: center;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 1rem 0;
}

.article-content .katex-display .katex {
    font-size: 1.2em;
    display: block;
}

.article-content .katex-error {
    color: #e53e3e !important;
    background: rgba(229, 62, 62, 0.1);
    padding: 0.5rem;
    border-radius: 4px;
    border: 1px solid rgba(229, 62, 62, 0.3);
}

/* Ensure math expressions are readable in both themes */
[data-theme="dark"] .article-content .katex,
[data-theme="auto"] .article-content .katex {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .article-content .katex .mord,
[data-theme="auto"] .article-content .katex .mord {
    color: var(--text-primary) !important;
}

/* Debug styling for unrendered math */
.math-debug {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    padding: 0.5rem;
    border-radius: 4px;
    margin: 0.5rem 0;
    font-family: monospace;
}

[data-theme="dark"] .math-debug {
    background: #2d3748;
    border-color: #4a5568;
    color: #e2e8f0;
}

.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4,
.article-content h5,
.article-content h6 {
    margin: 2rem 0 1rem 0;
    color: var(--text-primary);
}

.article-content h1 {
    font-size: 2.5rem;
    border-bottom: 3px solid var(--accent-color);
    padding-bottom: 10px;
}

.article-content h2 {
    font-size: 2rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
}

.article-content h3 {
    font-size: 1.5rem;
    color: var(--text-secondary);
}

.article-content p {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

.article-content ul,
.article-content ol {
    margin: 1.5rem 0;
    padding-left: 2rem;
}

.article-content li {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.article-content blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 1.5rem;
    margin: 1.5rem 0;
    font-style: italic;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 1rem 1.5rem;
    border-radius: 0 8px 8px 0;
}

.article-content code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    color: var(--text-primary);
}

.article-content pre {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 1.5rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1.5rem 0;
}

.article-content pre code {
    background: none;
    color: inherit;
    padding: 0;
}

.article-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1.5rem 0;
    box-shadow: var(--shadow);
}

.article-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.article-content th,
.article-content td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.article-content th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-primary);
}

.article-content tr:hover {
    background: var(--bg-tertiary);
}

/* Loading spinner */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-primary);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .header-controls {
        flex-direction: column;
        gap: 15px;
    }
    
    .articles-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .modal-content {
        width: 95%;
        height: 95%;
        margin: 2.5% auto;
    }
    
    .modal-header {
        padding: 15px 20px;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .article-content h1 {
        font-size: 2rem;
    }
    
    .article-content h2 {
        font-size: 1.5rem;
    }
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-primary);
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 15px;
}

.empty-state p {
    font-size: 1.1rem;
    opacity: 0.8;
}

/* Search results count */
.search-results {
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-primary);
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Theme transition for all elements */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}
