/* ============================================
   AI Journalist -- Styles
   Dark theme default, light theme via prefers-color-scheme
   ============================================ */

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-modal: #1a1a2e;
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --border: #27273a;
    --shadow: rgba(0, 0, 0, 0.4);
    --tag-bg: #27273a;
    --tag-text: #c4b5fd;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

/* Light theme */
@media (prefers-color-scheme: light) {
    :root {
        --bg-primary: #f8f9fa;
        --bg-secondary: #ffffff;
        --bg-card: #ffffff;
        --bg-modal: #ffffff;
        --text-primary: #18181b;
        --text-secondary: #52525b;
        --text-muted: #a1a1aa;
        --accent: #4f46e5;
        --accent-hover: #6366f1;
        --border: #e4e4e7;
        --shadow: rgba(0, 0, 0, 0.1);
        --tag-bg: #f1f5f9;
        --tag-text: #4f46e5;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

/* ===== HEADER ===== */
header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 1.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.header-stats {
    background: var(--accent);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
}

/* ===== CONTROLS ===== */
.controls {
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.search-box {
    margin-bottom: 1rem;
}

.search-box input {
    width: 100%;
    padding: 0.875rem 1.25rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color var(--transition);
}

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

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

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

.filter-btn {
    padding: 0.5rem 1rem;
    background: var(--tag-bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all var(--transition);
}

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

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

/* ===== ARTICLES GRID ===== */
.articles-grid {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem 2rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

/* ===== ARTICLE CARD ===== */
.article-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.article-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--shadow);
    border-color: var(--accent);
}

.card-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.card-emoji {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.card-category {
    background: var(--tag-bg);
    color: var(--tag-text);
    padding: 0.25rem 0.625rem;
    border-radius: 12px;
    font-size: 0.75rem;
    text-transform: lowercase;
}

.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.card-tag {
    background: var(--tag-bg);
    color: var(--text-muted);
    padding: 0.125rem 0.5rem;
    border-radius: 8px;
    font-size: 0.6875rem;
}

.card-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== LOADING ===== */
.loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
}

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

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== END MESSAGE ===== */
.end-message {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
}

/* ===== MODAL ===== */
dialog {
    border: none;
    background: transparent;
    max-width: 90vw;
    width: 700px;
    max-height: 90vh;
    padding: 0;
    margin: auto;
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.7);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

@media (prefers-color-scheme: light) {
    dialog::backdrop {
        background: rgba(0, 0, 0, 0.4);
    }
}

.modal-content {
    background: var(--bg-modal);
    border-radius: var(--radius);
    padding: 2rem;
    position: relative;
    max-height: 85vh;
    overflow-y: auto;
    border: 1px solid var(--border);
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--tag-bg);
    border: none;
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
    z-index: 10;
}

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

.modal-header {
    margin-bottom: 1.5rem;
    padding-right: 3rem;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    line-height: 1.4;
}

.modal-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.modal-body {
    line-height: 1.8;
}

.modal-body h2 {
    font-size: 1.25rem;
    margin: 1.5rem 0 0.75rem;
    color: var(--text-primary);
}

.modal-body p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.modal-body ul, .modal-body ol {
    margin: 0.5rem 0 1rem 1.5rem;
    color: var(--text-secondary);
}

.modal-body li {
    margin-bottom: 0.375rem;
}

.modal-body a {
    color: var(--accent);
    text-decoration: none;
}

.modal-body a:hover {
    text-decoration: underline;
}

.modal-sources {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.modal-sources h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.modal-sources ul {
    list-style: none;
    margin-left: 0;
}

.modal-sources li {
    padding: 0.375rem 0;
}

.modal-sources a {
    color: var(--text-muted);
    font-size: 0.875rem;
    word-break: break-all;
}

.modal-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.modal-actions a {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--accent);
    color: white;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background var(--transition);
}

.modal-actions a:hover {
    background: var(--accent-hover);
}

.modal-actions a.secondary {
    background: var(--tag-bg);
    color: var(--text-primary);
}

.modal-actions a.secondary:hover {
    background: var(--border);
}

/* ===== FOOTER ===== */
footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    border-top: 1px solid var(--border);
}

footer a {
    color: var(--accent);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        text-align: center;
    }

    .articles-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        padding: 1.5rem;
    }

    dialog {
        max-width: 95vw;
    }
}

/* ===== NO RESULTS ===== */
.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
}

.no-results p {
    font-size: 1.125rem;
}

/* ===== BLOCKQUOTE ===== */
.modal-body blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--text-secondary);
    font-style: italic;
}

/* ===== CODE ===== */
.modal-body code {
    background: var(--tag-bg);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-size: 0.875rem;
}

.modal-body pre {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 1rem 0;
}

.modal-body pre code {
    background: none;
    padding: 0;
}

/* ===== FIGURE ===== */
.modal-body figure {
    margin: 1.5rem 0;
    text-align: center;
}

.modal-body figure img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
}

.modal-body figcaption {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}
