/* Public Feed Styles - EMSource */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg: #f8fafc;
    --bg-card: #fff;
    --bg-header: #fff;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --radius: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-full: 9999px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
}

/* Dark Mode */
.dark {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-header: #1e293b;
    --border: #334155;
    --border-light: #334155;
    --gray-50: #1e293b;
    --gray-100: #334155;
    --gray-200: #475569;
    --gray-300: #64748b;
    --gray-400: #94a3b8;
    --gray-500: #94a3b8;
    --gray-600: #cbd5e1;
    --gray-700: #e2e8f0;
    --gray-800: #f1f5f9;
    --gray-900: #f8fafc;
}

/* High Contrast */
.high-contrast {
    --gray-800: #000;
    --gray-900: #000;
    --bg: #fff;
    --bg-card: #fff;
    --border: #000;
}
.high-contrast a { text-decoration: underline !important; }
.high-contrast .btn { border: 2px solid currentColor !important; }

/* Highlight Links */
.highlight-links a { background: #fef08a !important; color: #000 !important; padding: 0 2px; }
.highlight-links .site-logo,
.highlight-links .btn,
.highlight-links .cat-pill,
.highlight-links .article-title-link { background: transparent !important; color: inherit !important; }
.highlight-links .article-title-link { text-decoration: underline !important; color: var(--primary) !important; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--gray-800);
    font-size: 1rem;
    line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 960px; margin: 0 auto; padding: 0 1rem; }

/* Header */
.site-header {
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
}
.header-inner {
    display: flex; align-items: center; justify-content: space-between;
    height: 60px;
}
.site-logo {
    display: flex; align-items: center; gap: 0.625rem;
    font-size: 1.125rem; font-weight: 700; color: var(--gray-900);
    text-decoration: none;
}
.site-logo-img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    border-radius: 0.5rem;
}
.site-logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    justify-content: center;
}
.site-logo-text-main {
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.2;
}
.site-logo-text-sub {
    font-size: 0.65rem;
    font-weight: 400;
    color: var(--gray-500);
    line-height: 1;
    margin-top: 0.125rem;
    letter-spacing: 0.01em;
}
.site-logo:hover { text-decoration: none; }
.header-right { display: flex; align-items: center; gap: 0.5rem; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 0.375rem;
    padding: 0.5rem 1rem; border-radius: var(--radius);
    font-size: 0.875rem; font-weight: 500; font-family: inherit;
    border: 1px solid transparent; cursor: pointer;
    text-decoration: none; transition: all 0.15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: var(--bg-card); border-color: var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); }
.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); }

.dark .btn-outline {
    background: transparent;
    border-color: var(--gray-500);
    color: #ffffff;
}

.dark .btn-outline:hover {
    background: var(--gray-200);
    border-color: var(--gray-400);
    color: #ffffff;
}

.dark .btn-ghost {
    color: #ffffff;
}

.dark .btn-ghost:hover {
    background: var(--gray-200);
    color: #ffffff;
}
.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.75rem; }
.btn-lg { padding: 0.625rem 1.5rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { padding: 0.375rem; border-radius: var(--radius); background: none; border: none; cursor: pointer; color: var(--gray-400); transition: all 0.15s; }
.btn-icon:hover { color: var(--primary); background: var(--gray-100); }
.btn-icon.active { color: #eab308; }

/* Dark mode toggle icons */
#dark-mode-toggle .icon-sun { display: inline-block; }
#dark-mode-toggle .icon-moon { display: none; }
html.dark #dark-mode-toggle .icon-sun { display: none; }
html.dark #dark-mode-toggle .icon-moon { display: inline-block; }

/* New articles banner */
.new-banner {
    background: var(--primary); color: #fff; padding: 0.5rem 0; text-align: center;
}
.new-banner-btn {
    background: none; border: none; color: #fff; font-family: inherit;
    font-size: 0.875rem; font-weight: 500; cursor: pointer;
    display: inline-flex; align-items: center; gap: 0.5rem;
}
.new-banner-btn:hover { text-decoration: underline; }

/* Filter bar */
.site-main { padding: 1.5rem 0 3rem; }
.filter-bar { margin-bottom: 1.5rem; }

.filter-categories {
    display: flex; flex-wrap: wrap; gap: 0.375rem; margin-bottom: 0.75rem;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.filter-categories::-webkit-scrollbar { display: none; }

.cat-pill {
    display: inline-flex; align-items: center; gap: 0.375rem;
    padding: 0.375rem 0.875rem; border-radius: var(--radius-full);
    font-size: 0.8125rem; font-weight: 500; font-family: inherit;
    border: 1px solid var(--border); background: var(--bg-card); color: var(--gray-600);
    cursor: pointer; white-space: nowrap; transition: all 0.15s;
}
.cat-pill:hover { border-color: var(--gray-300); background: var(--gray-50); }
.cat-pill.active {
    background: var(--cat-color, var(--primary));
    color: #fff; border-color: transparent;
}
.cat-count {
    font-size: 0.6875rem; background: rgba(0,0,0,0.1);
    padding: 0 0.375rem; border-radius: var(--radius-full);
}
.cat-pill.active .cat-count { background: rgba(255,255,255,0.25); }

.filter-controls { display: flex; gap: 0.5rem; }
.filter-select {
    padding: 0.5rem 0.75rem; border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 0.875rem; font-family: inherit;
    background: var(--bg-card); color: var(--gray-700); min-width: 150px;
}
.filter-select:focus { outline: none; border-color: var(--primary); }

.search-wrapper { position: relative; flex: 1; }
.search-wrapper svg {
    position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%);
    color: var(--gray-400); pointer-events: none;
}
.search-input {
    width: 100%; padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 0.875rem; font-family: inherit; background: var(--bg-card); color: var(--gray-800);
}
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

/* Articles Feed */
.articles-feed { display: flex; flex-direction: column; gap: 0.75rem; }

.article-card {
    background: var(--bg-card); border-radius: var(--radius-lg);
    padding: 1.25rem; box-shadow: var(--shadow);
    transition: box-shadow 0.15s;
    border: 1px solid transparent;
}
.article-card:hover { box-shadow: var(--shadow-md); }
.article-card.is-read { opacity: 0.7; }

.dark .article-card {
    border-color: var(--border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.dark .article-card:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    border-color: var(--gray-300);
}

.article-meta {
    display: flex; align-items: center; gap: 0.5rem;
    margin-bottom: 0.5rem; flex-wrap: wrap;
}
.source-badge {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.125rem 0.5rem; border-radius: var(--radius-full);
    font-size: 0.6875rem; font-weight: 600; color: #fff; white-space: nowrap;
}
.oa-badge {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.125rem 0.5rem; border-radius: var(--radius-full);
    font-size: 0.6875rem; font-weight: 600; color: #fff; white-space: nowrap;
    background: #e67e22; text-decoration: none; transition: background 0.15s;
}
.oa-badge:hover { background: #d35400; }
.article-date { font-size: 0.75rem; color: var(--gray-400); }
.article-readtime { font-size: 0.75rem; color: var(--gray-400); font-style: italic; }
.article-authors { font-size: 0.75rem; color: var(--gray-500); margin-bottom: 0.25rem; line-height: 1.4; }

.article-title-link {
    display: block; font-size: 1.0625rem; font-weight: 600;
    color: var(--gray-900); line-height: 1.4; margin-bottom: 0.375rem;
    text-decoration: none;
}
.article-title-link:hover { color: var(--primary); text-decoration: none; }

.dark .article-title-link {
    color: #ffffff;
}

.dark .article-title-link:hover {
    color: var(--primary);
}

.article-excerpt {
    font-size: 0.875rem; color: var(--gray-500); line-height: 1.6;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; margin-bottom: 0.75rem;
}

.dark .article-excerpt {
    color: var(--gray-400);
}

.dark .article-authors {
    color: var(--gray-400);
}

/* AI Summary Section */
.article-summary-section {
    margin: 0.75rem 0;
}

.article-summary-generate,
.article-summary-header {
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-generate-summary,
.btn-summary-toggle {
    display: inline-flex; align-items: center; gap: 0.375rem;
    padding: 0.375rem 0.75rem; border-radius: var(--radius);
    font-size: 0.75rem; font-weight: 500; font-family: inherit;
    background: var(--gray-100); border: 1px solid var(--border);
    color: var(--gray-700); cursor: pointer; transition: all 0.15s;
}

.btn-generate-summary:hover {
    background: var(--gray-200); border-color: var(--gray-300);
}

.btn-summary-toggle {
    background: transparent; border: none; color: var(--primary);
    padding: 0.25rem 0.5rem;
    flex: 1;
}

.btn-summary-toggle:hover {
    background: var(--gray-50);
}

.article-summary-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-regenerate-summary {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.25rem 0.5rem; border-radius: var(--radius);
    background: transparent; border: 1px solid var(--border);
    color: var(--gray-600); cursor: pointer;
    transition: all 0.15s; font-size: 0.6875rem;
}

.btn-regenerate-summary:hover {
    background: var(--gray-100);
    border-color: var(--gray-300);
    color: var(--primary);
}

.btn-regenerate-summary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-delete-summary {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.25rem; border-radius: var(--radius);
    background: transparent; border: 1px solid var(--border);
    color: var(--gray-500); cursor: pointer;
    transition: all 0.15s; width: 24px; height: 24px;
}

.btn-delete-summary:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
}

.btn-delete-summary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-summary-toggle svg {
    transition: none;
    transform: none !important;
}

.article-summary-content {
    margin-top: 0.5rem; padding: 0.75rem; background: var(--gray-50);
    border-left: 3px solid var(--primary); border-radius: var(--radius);
}

.article-summary-text {
    font-size: 0.8125rem; color: var(--gray-700); line-height: 1.6;
    margin: 0;
}

.spinner-small {
    display: inline-block; width: 12px; height: 12px;
    border: 2px solid var(--gray-300); border-top-color: var(--primary);
    border-radius: 50%; animation: spin 0.6s linear infinite;
}

.dark .spinner-small {
    border-color: var(--gray-400);
    border-top-color: var(--primary);
}

.dark .article-summary-content {
    background: var(--gray-100);
    border-left-color: var(--primary);
}

.dark .article-summary-text {
    color: #e2e8f0;
}

.dark .btn-generate-summary {
    background: var(--gray-200);
    border-color: var(--gray-300);
    color: #ffffff;
}

.dark .btn-generate-summary:hover {
    background: var(--gray-300);
    border-color: var(--gray-400);
    color: #ffffff;
}

.dark .btn-summary-toggle {
    color: var(--primary);
}

.dark .btn-summary-toggle span {
    color: #ffffff;
}

.dark .btn-summary-toggle:hover {
    background: var(--gray-200);
}

.dark .btn-summary-toggle:hover span {
    color: #ffffff;
}

.dark .btn-regenerate-summary {
    background: var(--gray-200);
    border-color: var(--gray-300);
    color: #ffffff;
}

.dark .btn-regenerate-summary:hover {
    background: var(--gray-300);
    border-color: var(--primary);
    color: var(--primary);
}

.dark .btn-delete-summary {
    background: var(--gray-200);
    border-color: var(--gray-300);
    color: #cbd5e1;
}

.dark .btn-delete-summary:hover {
    background: #7f1d1d;
    border-color: #991b1b;
    color: #fca5a5;
}

.article-footer {
    display: flex; align-items: center; justify-content: space-between;
}
.article-categories { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.cat-tag {
    display: inline-block; padding: 0.0625rem 0.375rem; border-radius: var(--radius-full);
    font-size: 0.625rem; font-weight: 600; color: #fff;
}
.article-actions { display: flex; gap: 0.25rem; }

.dark .btn-icon:hover {
    background: var(--gray-200);
}

/* Load more */
.load-more-wrapper { text-align: center; margin-top: 1.5rem; }

/* Loading */
.loading-state { text-align: center; padding: 3rem; }
.spinner {
    width: 32px; height: 32px; border: 3px solid var(--gray-200);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 0.6s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal { display: none; position: fixed; inset: 0; z-index: 200; align-items: center; justify-content: center; }
.modal.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.modal-content {
    position: relative; background: var(--bg-card); border-radius: var(--radius-lg);
    width: 100%; max-width: 440px; padding: 2rem; box-shadow: var(--shadow-md);
}
.modal-close {
    position: absolute; top: 1rem; right: 1rem;
    background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--gray-400); line-height: 1;
}
.modal-content h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.375rem; }
.modal-desc { color: var(--gray-500); font-size: 0.875rem; margin-bottom: 1.25rem; }

.form-group { margin-bottom: 0.75rem; }
.form-input {
    width: 100%; padding: 0.625rem 0.75rem; border: 1px solid var(--gray-300);
    border-radius: var(--radius); font-size: 0.875rem; font-family: inherit;
    background: var(--bg-card); color: var(--gray-800);
}
.form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

.checkbox-label {
    display: flex; align-items: flex-start; gap: 0.5rem; cursor: pointer;
    font-size: 0.8125rem; color: var(--gray-600); line-height: 1.4;
}
.checkbox-label input[type="checkbox"] { margin-top: 0.125rem; flex-shrink: 0; }

.subscribe-msg {
    margin-top: 1rem; padding: 0.75rem; border-radius: var(--radius);
    font-size: 0.875rem; text-align: center;
}
.subscribe-msg.success { background: #f0fdf4; color: #166534; }
.subscribe-msg.error { background: #fef2f2; color: #991b1b; }

/* Footer */
.site-footer {
    text-align: center; padding: 2rem 0; border-top: 1px solid var(--border);
    color: var(--gray-400); font-size: 0.8125rem;
}
.site-footer a { color: var(--gray-500); }
.site-footer a:hover { color: var(--primary); text-decoration: underline; }
.footer-links {
    display: flex; justify-content: center; gap: 1.5rem; margin-top: 0.5rem;
}
.footer-links a { color: var(--gray-400); }
.footer-links a:hover { color: var(--primary); }
.footer-credit {
    margin-top: 0.75rem; color: var(--gray-400); font-size: 0.75rem;
}
.footer-credit a { color: var(--gray-500); font-weight: 500; }
.footer-credit a:hover { color: var(--primary); }

/* Empty state */
.empty-feed {
    text-align: center; padding: 4rem 2rem; color: var(--gray-400);
}
.empty-feed svg { margin-bottom: 1rem; }
.empty-feed h3 { font-size: 1.125rem; color: var(--gray-600); margin-bottom: 0.5rem; }

/* Back to Top */
.back-to-top {
    position: fixed; bottom: 2rem; right: 2rem;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--primary); color: #fff; border: none;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow-md);
    opacity: 0; transform: translateY(1rem);
    transition: opacity 0.2s, transform 0.2s;
    z-index: 90;
}
.back-to-top.visible { opacity: 1; transform: none; }
.back-to-top:hover { background: var(--primary-hover); }

/* Accessibility Widget */
.a11y-toggle {
    position: fixed; bottom: 5rem; right: 2rem;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--gray-700); color: #fff; border: none;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow-md); z-index: 90;
}
.a11y-toggle:hover { background: var(--gray-600); }

.a11y-panel {
    position: fixed; bottom: 10rem; right: 2rem;
    width: 240px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
    padding: 1rem; z-index: 91;
    display: none;
}
.a11y-panel.open { display: block; }
.a11y-panel h3 { font-size: 0.875rem; font-weight: 600; margin-bottom: 0.75rem; color: var(--gray-800); }
.a11y-group { margin-bottom: 0.75rem; }
.a11y-group:last-child { margin-bottom: 0; }
.a11y-group > span { display: block; font-size: 0.75rem; color: var(--gray-500); margin-bottom: 0.375rem; }
.a11y-buttons { display: flex; gap: 0.25rem; }

/* ── RTL Comprehensive ── */
[dir="rtl"] body { text-align: right; }
[dir="rtl"] .header-inner { flex-direction: row-reverse; }
[dir="rtl"] .header-right { flex-direction: row-reverse; }
[dir="rtl"] .site-logo { flex-direction: row-reverse; }
[dir="rtl"] .filter-controls { flex-direction: row-reverse; }
[dir="rtl"] .filter-categories { flex-direction: row-reverse; }
[dir="rtl"] .article-meta { flex-direction: row-reverse; }
[dir="rtl"] .article-footer { flex-direction: row-reverse; }
[dir="rtl"] .article-categories { flex-direction: row-reverse; }
[dir="rtl"] .article-actions { flex-direction: row-reverse; }
[dir="rtl"] .footer-links { flex-direction: row-reverse; }

[dir="rtl"] .search-wrapper svg { left: auto; right: 0.75rem; }
[dir="rtl"] .search-input { padding: 0.5rem 2.25rem 0.5rem 0.75rem; }
[dir="rtl"] .modal-close { right: auto; left: 1rem; }

[dir="rtl"] .back-to-top { right: auto; left: 2rem; }
[dir="rtl"] .a11y-toggle { right: auto; left: 2rem; }
[dir="rtl"] .a11y-panel { right: auto; left: 2rem; }

[dir="rtl"] .cat-pill { flex-direction: row-reverse; }
[dir="rtl"] .source-badge { flex-direction: row-reverse; }
[dir="rtl"] .btn { flex-direction: row-reverse; }
[dir="rtl"] .new-banner-btn { flex-direction: row-reverse; }
[dir="rtl"] .checkbox-label { flex-direction: row-reverse; }

/* Static page styles (privacy, terms, accessibility) */
.static-page { max-width: 720px; margin: 2rem auto; padding: 0 1rem; }
.static-page h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--gray-900); }
.static-page .page-meta { color: var(--gray-400); font-size: 0.875rem; margin-bottom: 2rem; }
.static-page h2 { font-size: 1.25rem; font-weight: 600; margin: 1.5rem 0 0.75rem; color: var(--gray-800); }
.static-page p { margin-bottom: 1rem; color: var(--gray-600); line-height: 1.7; }
.static-page ul { margin: 0 0 1rem 1.5rem; color: var(--gray-600); line-height: 1.7; }
[dir="rtl"] .static-page ul { margin: 0 1.5rem 1rem 0; }
.static-page a { color: var(--primary); }

/* Responsive */
@media (max-width: 640px) {
    .header-inner { height: 52px; }
    .site-logo span { display: none; }
    .filter-controls { flex-direction: column; }
    [dir="rtl"] .filter-controls { flex-direction: column; }
    .filter-select { min-width: 0; width: 100%; }
    .article-card { padding: 1rem; }
    .article-title-link { font-size: 0.9375rem; }
    .container { padding: 0 0.75rem; }
    .back-to-top, .a11y-toggle { right: 1rem; }
    [dir="rtl"] .back-to-top, [dir="rtl"] .a11y-toggle { right: auto; left: 1rem; }
    .a11y-panel { right: 1rem; left: auto; }
    [dir="rtl"] .a11y-panel { right: auto; left: 1rem; }
}
