:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: rgba(37, 99, 235, 0.12);
    --text-main: #111827;
    --text-secondary: #4b5563;
    --text-light: #9ca3af;
    --bg-body: #f6f7f9;
    --bg-card: #ffffff;
    --bg-soft: #f9fafb;
    --border-color: rgba(17, 24, 39, 0.12);
    --shadow: 0 1px 2px rgba(17, 24, 39, 0.06);
    --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.05);
    --shadow-md: 0 10px 20px rgba(17, 24, 39, 0.08);
    --shadow-lg: 0 18px 40px rgba(17, 24, 39, 0.12);
    --radius: 12px;
    --sent-pos-bg: rgba(16, 185, 129, 0.14);
    --sent-pos-text: #059669;
    --sent-neg-bg: rgba(239, 68, 68, 0.14);
    --sent-neg-text: #dc2626;
    --sent-neu-bg: rgba(100, 116, 139, 0.12);
    --sent-neu-text: var(--text-secondary);
    --tag-category-bg: rgba(59, 130, 246, 0.14);
    --tag-category-text: #0369a1;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --primary-color: #60a5fa;
    --primary-hover: #3b82f6;
    --primary-light: rgba(96, 165, 250, 0.18);
    --text-main: #e5e7eb;
    --text-secondary: #a3b0c2;
    --text-light: #6b7280;
    --bg-body: #0b1220;
    --bg-card: #0f172a;
    --bg-soft: #111c33;
    --border-color: rgba(148, 163, 184, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 10px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 18px 40px rgba(0, 0, 0, 0.5);
    --sent-pos-bg: rgba(34, 197, 94, 0.14);
    --sent-pos-text: #34d399;
    --sent-neg-bg: rgba(239, 68, 68, 0.14);
    --sent-neg-text: #fca5a5;
    --sent-neu-bg: rgba(148, 163, 184, 0.12);
    --sent-neu-text: #cbd5e1;
    --tag-category-bg: rgba(96, 165, 250, 0.14);
    --tag-category-text: #93c5fd;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    background: var(--bg-body);
    color: var(--text-main);
    line-height: 1.55;
    padding-bottom: 56px;
}

a { color: inherit; }

.app-container,
.container { max-width: 1160px; margin: 0 auto; padding: 0 16px; }

button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; border: 1px solid transparent; background: transparent; }

:focus-visible { outline: 2px solid var(--primary-light); outline-offset: 2px; }

.app-header {
    background: var(--bg-card);
    background: color-mix(in srgb, var(--bg-card) 92%, transparent);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 50;
    padding: 10px 0;
    backdrop-filter: blur(10px);
}
.header-content { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 750; font-size: 1.1rem; color: var(--text-main); text-decoration: none; letter-spacing: 0.1px; }
.logo-icon { color: var(--primary-color); }

.header-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.nav-links { display: flex; gap: 14px; align-items: center; min-width: 0; }
.nav-link { color: var(--text-secondary); text-decoration: none; font-weight: 650; font-size: 0.92rem; }
.nav-link:hover { color: var(--primary-color); }
.nav-link.active { color: var(--primary-color); }

.theme-toggle {
    width: 34px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    height: auto;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 650;
    cursor: pointer;
    border-radius: 999px;
}
.theme-toggle:hover { color: var(--primary-color); background: transparent; }

.github-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    color: var(--text-secondary);
    border-radius: 999px;
    transition: color 0.2s;
}
.github-link:hover {
    color: var(--primary-color);
}

.config-warning { margin-top: 12px; margin-bottom: 12px; padding: 12px 14px; border-radius: var(--radius); border: 1px solid rgba(245, 158, 11, 0.35); background: rgba(245, 158, 11, 0.12); }
.config-warning-title { font-weight: 800; color: #92400e; }
.config-warning-desc { margin-top: 4px; color: #92400e; font-size: 0.9rem; line-height: 1.4; }

@media (max-width: 640px) {
    .header-content { flex-wrap: wrap; align-items: flex-start; }
    .header-actions { width: 100%; justify-content: space-between; }
    .nav-links {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        gap: 12px;
        scrollbar-width: none;
    }
    .nav-links::-webkit-scrollbar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

.hidden { display: none !important; }
.md-hidden { display: block; }
.md-show { display: none; }

@media (min-width: 768px) {
    .md-hidden { display: none; }
    .md-show { display: flex; }
}

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

body.page-topics .page-wrap { margin-top: 18px; }
body.page-topics .page-title { font-size: 1.35rem; font-weight: 850; margin: 6px 0 16px; letter-spacing: 0.2px; }
body.page-topics .hint { color: var(--text-secondary); font-size: 0.92rem; margin-bottom: 12px; }
body.page-topics .topic-list { display: flex; flex-direction: column; gap: 12px; }
body.page-topics .topic-card { background: var(--bg-card); border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--border-color); box-shadow: var(--shadow); cursor: pointer; }
body.page-topics .topic-card:hover { border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); }
body.page-topics .topic-name { font-weight: 850; font-size: 1.05rem; margin-bottom: 8px; line-height: 1.35; }
body.page-topics .topic-summary { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 12px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
body.page-topics .meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 8px; }
body.page-topics .tag { display: inline-flex; align-items: center; gap: 6px; padding: 2px 0; border-radius: 0; background: transparent; border: none; color: var(--text-light); }
body.page-topics .empty { background: var(--bg-card); border-radius: var(--radius); padding: 18px; border: 1px dashed var(--border-color); color: var(--text-secondary); }
body.page-topics .loading { color: var(--text-secondary); font-size: 0.9rem; }

body.page-topics .back-row { margin: 6px 0 10px; }
body.page-topics .back-link { color: var(--primary-color); text-decoration: none; font-weight: 750; }
body.page-topics .back-link:hover { text-decoration: underline; }
body.page-topics .topic-header { background: var(--bg-card); border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--border-color); box-shadow: var(--shadow); }
body.page-topics .topic-name { font-size: 1.25rem; font-weight: 900; line-height: 1.35; }
body.page-topics .tag-heat { background: rgba(239, 68, 68, 0.12); color: #dc2626; border-color: rgba(239, 68, 68, 0.25); font-weight: 800; }
body.page-topics.page-topic-detail .topic-summary { margin-top: 12px; }
body.page-topics.page-topic-detail #newsCard { margin-top: 12px; }
body.page-topics.page-topic-detail .text,
body.page-topics.page-topic-detail .tl-content,
body.page-topics.page-topic-detail .news-summary { word-break: break-word; }
@media (max-width: 640px) {
    body.page-topics.page-topic-detail .topic-header { padding: 14px 14px; }
    body.page-topics.page-topic-detail .grid { gap: 10px; }
    body.page-topics.page-topic-detail .card { padding: 12px 14px; }
    body.page-topics.page-topic-detail .card-title { font-size: 0.98rem; }
}
body.page-topics .grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 12px; }
/* body.page-topics .grid { grid-template-columns: 1.1fr 0.9fr; } */
body.page-topics .card { background: var(--bg-card); border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--border-color); box-shadow: var(--shadow); }
body.page-topics .card-title { font-size: 1rem; font-weight: 900; margin-bottom: 10px; }
body.page-topics .card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
body.page-topics .card-head .card-title { margin-bottom: 0; }
body.page-topics .btn-mini { font-size: 0.85rem; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--border-color); background: var(--bg-soft); color: var(--text-secondary); font-weight: 750; }
body.page-topics .btn-mini:hover { color: var(--text-main); border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); }
body.page-topics .btn-mini:disabled { opacity: 0.6; cursor: not-allowed; }
body.page-topics .text { white-space: pre-wrap; color: var(--text-secondary); font-size: 0.92rem; line-height: 1.7; }
body.page-topics .timeline { display: flex; flex-direction: column; gap: 10px; }
body.page-topics .tl-item { border-left: 3px solid color-mix(in srgb, var(--primary-color) 35%, transparent); padding-left: 12px; }
body.page-topics .tl-time { font-size: 0.78rem; color: var(--text-light); margin-bottom: 4px; }
body.page-topics .tl-content { font-size: 0.92rem; color: var(--text-secondary); line-height: 1.6; }
body.page-topics .tl-source { margin-top: 6px; font-size: 0.8rem; }
body.page-topics .tl-source a { color: var(--primary-color); text-decoration: none; }
body.page-topics .tl-source a:hover { text-decoration: underline; }
body.page-topics .news-list { display: flex; flex-direction: column; gap: 10px; }
body.page-topics .news-card { border: 1px solid var(--border-color); border-radius: 10px; padding: 12px; background: var(--bg-card); }
body.page-topics .news-title { font-weight: 900; color: var(--text-main); text-decoration: none; line-height: 1.35; }
body.page-topics .news-title:hover { color: var(--primary-color); }
body.page-topics .news-meta { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 10px; font-size: 0.78rem; color: var(--text-secondary); }
body.page-topics .news-summary { margin-top: 8px; background: var(--bg-soft); border: 1px solid var(--border-color); padding: 10px; border-radius: 8px; color: var(--text-secondary); font-size: 0.88rem; line-height: 1.6; white-space: pre-wrap; }
body.page-topics .err { color: #b91c1c; font-size: 0.9rem; }

body.page-admin .admin-wrap { padding: 24px 0 60px; }
body.page-admin .admin-card { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
body.page-admin .admin-title { font-size: 1.1rem; font-weight: 750; margin-bottom: 12px; }
body.page-admin .admin-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
body.page-admin .admin-input { width: 320px; max-width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--border-color); border-radius: 10px; outline: none; background: var(--bg-card); color: var(--text-main); }
body.page-admin .admin-input:focus { border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); box-shadow: 0 0 0 3px var(--primary-light); }
body.page-admin .admin-btn { height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border-color); background: var(--bg-card); color: var(--text-main); }
body.page-admin .admin-btn.primary { background: var(--primary-color); color: #fff; border-color: var(--primary-color); }
body.page-admin .admin-btn.danger { background: #ef4444; color: #fff; border-color: #ef4444; }
body.page-admin .admin-hint { color: var(--text-secondary); font-size: 0.9rem; margin-top: 8px; line-height: 1.5; }
body.page-admin .admin-textarea { width: 100%; min-height: 260px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 0.9rem; border: 1px solid var(--border-color); border-radius: 12px; padding: 12px; outline: none; background: var(--bg-card); color: var(--text-main); }
body.page-admin .CodeMirror { width: 100%; min-height: 260px; border: 1px solid var(--border-color); border-radius: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 0.9rem; }
body.page-admin .CodeMirror-scroll { min-height: 260px; }
body.page-admin .CodeMirror-gutters { background: var(--bg-card); border-right: 1px solid var(--border-color); border-top-left-radius: 12px; border-bottom-left-radius: 12px; }
body.page-admin .cm-s-default .cm-comment { color: var(--text-light); }
body.page-admin .admin-tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--border-color); margin-top: 16px; }
body.page-admin .admin-tab { border: 1px solid transparent; border-bottom: none; background: transparent; padding: 10px 14px; cursor: pointer; border-top-left-radius: 12px; border-top-right-radius: 12px; color: var(--text-secondary); font-weight: 750; }
body.page-admin .admin-tab.active { background: var(--bg-card); border-color: var(--border-color); color: var(--text-main); }
body.page-admin .admin-panels { margin-top: 12px; }
body.page-admin .admin-panel { display: none; }
body.page-admin .admin-panel.active { display: block; }
body.page-admin .admin-log-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
body.page-admin .admin-log { width: 100%; height: 600px; border: 1px solid var(--border-color); border-radius: 12px; padding: 12px; margin: 0; background: #0b1220; color: #e5e7eb; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 0.85rem; white-space: pre-wrap; }
body.page-admin .admin-status { margin-top: 10px; font-size: 0.9rem; color: var(--text-secondary); }
body.page-admin .admin-status.error { color: #dc2626; }
body.page-admin .admin-status.ok { color: #16a34a; }
body.page-admin .admin-split { display: grid; grid-template-columns: 1fr; gap: 16px; margin-top: 16px; }
@media (min-width: 1024px) { body.page-admin .admin-split { grid-template-columns: 1fr; } }

body.page-index .desktop-toolbar { display: none; flex-direction: row; gap: 12px; margin-top: 24px; align-items: center; }
body.page-index .toolbar-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
body.page-index .filter-group { display: flex; align-items: center; gap: 8px; background: var(--bg-card); padding: 4px; border-radius: 10px; border: 1px solid var(--border-color); }
body.page-index .search-box { position: relative; flex: 1; }
body.page-index .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-light); }
body.page-index .search-input-desktop { padding-left: 40px; }

body.page-index .btn-icon { padding: 8px; border-radius: 10px; color: var(--text-secondary); transition: background 0.2s; }
body.page-index .btn-icon:hover { background-color: var(--bg-soft); }
body.page-index .btn-primary { background-color: var(--primary-color); color: #fff; padding: 10px 20px; border-radius: 10px; font-weight: 700; width: 100%; box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2); }
body.page-index .btn-primary:active { opacity: 0.92; }
body.page-index .btn-filter { padding: 6px 12px; border: 1px solid var(--border-color); border-radius: 10px; font-size: 0.875rem; color: var(--text-secondary); background: var(--bg-card); transition: all 0.2s; }
body.page-index .btn-filter.active { background-color: var(--primary-color); color: #fff; border-color: var(--primary-color); }
body.page-index .input-text { width: 100%; height: 44px; padding: 0 16px; border: 1px solid var(--border-color); border-radius: 12px; font-size: 1rem; outline: none; transition: border 0.2s; background: var(--bg-card); color: var(--text-main); }
body.page-index .input-text:focus { border-color: var(--primary-color); box-shadow: 0 0 0 3px var(--primary-light); }
body.page-index .input-date { padding: 4px 8px; border: 1px solid var(--border-color); border-radius: 8px; font-size: 0.875rem; color: var(--text-secondary); background: var(--bg-card); }
body.page-index .select-filter { padding: 6px 32px 6px 12px; border: 1px solid var(--border-color); border-radius: 10px; font-size: 0.875rem; color: var(--text-secondary); background-color: var(--bg-card); appearance: none; background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234b5563' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"); background-repeat: no-repeat; background-position: right 8px center; background-size: 16px; cursor: pointer; }
html[data-theme="dark"] body.page-index .select-filter { background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a3b0c2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"); }
body.page-index .select-filter:focus { outline: none; color: var(--primary-color); }

body.page-index .mobile-menu-overlay { position: fixed; top: 0; right: 0; bottom: 0; left: 0; inset: 0; background: rgba(0,0,0,0.5); z-index: 60; display: none; align-items: flex-end; }
body.page-index .mobile-menu-overlay.show { display: flex; }
body.page-index .mobile-menu-content { background: var(--bg-card); width: 100%; border-radius: 20px 20px 0 0; padding: 20px; animation: slideUp 0.25s ease-out; max-height: 85vh; overflow-y: auto; border: 1px solid var(--border-color); border-bottom: none; }

body.page-index .menu-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
body.page-index .menu-section { margin-bottom: 20px; }

body.page-index .mobile-top-bar { background: var(--bg-card); padding: 12px; display: flex; gap: 12px; align-items: center; flex-wrap: nowrap; margin-bottom: 16px; margin-top: 0; border-radius: var(--radius); border: 1px solid var(--border-color); box-shadow: var(--shadow); }

/* Category Tabs */
.category-tabs-container {
    display: flex;
    overflow-x: auto;
    gap: 24px;
    padding: 0 4px;
    margin-top: 12px;
    margin-bottom: 12px;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none;  /* IE 10+ */
    white-space: nowrap;
    /* border-bottom: 1px solid var(--border-color); */
}
.category-tabs-container::-webkit-scrollbar { 
    display: none;  /* Chrome Safari */
}

.category-tab-item {
    padding: 12px 4px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-bottom: -1px;
}

.category-tab-item:hover {
    color: var(--primary-color);
}

.category-tab-item.active {
    background: transparent;
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: 700;
    box-shadow: none;
}
body.page-index .mobile-search-group { flex: 1; min-width: 0; display: flex; align-items: center; background: var(--bg-soft); border-radius: 12px; padding: 0 4px 0 12px; border: 1px solid var(--border-color); height: 40px; }
body.page-index .mobile-search-group input { border: none; background: transparent; width: 100%; min-width: 0; padding: 0; height: 100%; outline: none; font-size: 0.95rem; color: var(--text-main); }
body.page-index .btn-icon-search { border: none; background: transparent; font-size: 0.9rem; font-weight: 650; cursor: pointer; padding: 0 12px; color: var(--primary-color); white-space: nowrap; flex-shrink: 0; height: 100%; }
body.page-index .btn-more-filter { border: 1px solid var(--border-color); background: var(--bg-card); border-radius: 12px; padding: 0 16px; height: 44px; display: flex; align-items: center; justify-content: center; font-size: 0.9rem; font-weight: 650; color: var(--text-secondary); cursor: pointer; white-space: nowrap; flex-shrink: 0; }
body.page-index .menu-label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 700; margin-bottom: 8px; }
body.page-index .grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
body.page-index .flex-row { display: flex; gap: 8px; }
body.page-index .flex-1 { flex: 1; }

/* Shared News List Styles (Index & Report) */
.news-list { display: flex; flex-direction: column; gap: 16px; margin-top: 24px; }

.news-card { 
    background: var(--bg-card); 
    border-radius: var(--radius); 
    padding: 16px; 
    border: 1px solid var(--border-color); 
    box-shadow: var(--shadow); 
    transition: box-shadow 0.2s, border-color 0.2s;
}

.news-card:hover {
    box-shadow: var(--shadow-md);
    border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color));
}

body.page-report .news-card {
    border: none;
}

.card-body { display: flex; gap: 16px; align-items: flex-start; }

.rank { font-size: 1.5rem; font-weight: 800; color: color-mix(in srgb, var(--text-light) 35%, transparent); min-width: 32px; text-align: center; line-height: 1; }

.content { flex: 1; min-width: 0; }

.news-head { display: block; margin-bottom: 8px; }

/* .news-head .tag-category { margin-top: 2px; } */

.news-head .news-title { margin-bottom: 0; line-height: 1.5; }

/* CodeMirror Dark Mode Support */
html[data-theme="dark"] .CodeMirror {
    background: var(--bg-card);
    color: var(--text-main);
}
html[data-theme="dark"] .CodeMirror-gutters {
    background: var(--bg-card);
    border-right-color: var(--border-color);
}
html[data-theme="dark"] .CodeMirror-cursor {
    border-left-color: var(--text-main);
}
html[data-theme="dark"] .CodeMirror-linenumber {
    color: var(--text-secondary);
}
html[data-theme="dark"] .CodeMirror-selected {
    background: rgba(255, 255, 255, 0.1);
}
html[data-theme="dark"] .CodeMirror-line::selection, 
html[data-theme="dark"] .CodeMirror-line > span::selection, 
html[data-theme="dark"] .CodeMirror-line > span > span::selection { 
    background: rgba(255, 255, 255, 0.1); 
}

/* Report Page & Mobile Optimization */
.chart-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.chart-title {
    font-weight: 800;
    font-size: 1.05rem;
}

.chart-container {
    flex: 1;
    min-height: 350px;
    width: 100%;
}

.large-chart {
    height: 550px;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0;
    text-decoration: none;
}

.btn-link:hover {
    text-decoration: underline;
}

.summary-placeholder {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 10px;
    background: var(--bg-soft);
    border-radius: 8px;
}

.summary-content {
    line-height: 1.6;
    color: var(--text-secondary);
}

.summary-content.collapsed {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.summary-box {
    margin-top: 8px;
}

.btn-regen {
    font-size: 0.8rem;
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-card);
    cursor: pointer;
    margin-left: 8px;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    background: var(--bg-card);
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.metric-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-main);
}

.filter-section {
    background: var(--bg-card);
    padding: 20px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.search-bar-wrapper {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 16px;
}

.input-group {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 12px;
    color: var(--text-light);
    pointer-events: none;
}

.input-text-search {
    width: 100%;
    padding: 10px 10px 10px 36px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 1rem;
    background: var(--bg-soft);
    color: var(--text-main);
    outline: none;
    transition: all 0.2s;
}

.input-text-search:focus {
    background: var(--bg-card);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.btn-search {
    background: var(--primary-color);
    color: white;
    padding: 10px 24px;
    border-radius: 10px;
    font-weight: 600;
    white-space: nowrap;
    transition: opacity 0.2s;
    border: none;
    cursor: pointer;
}

.btn-search:hover {
    opacity: 0.9;
}

.chart-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.chart-row.full-width {
    width: 100%;
}

.chart-row.full-width .chart-card {
    width: 100%;
}

.chart-row.two-cols .chart-card {
    flex: 1;
    min-width: 0;
}

.news-card {
    margin-bottom: 12px;
}

.news-header-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}

.category-tag {
    background: #e0f2fe;
    color: #0369a1;
    flex-shrink: 0;
    font-size: 0.75rem;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 22px;
    border-radius: 4px;
    margin-top: 2px;
}

.meta-row {
    display: flex;
    gap: 10px;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    flex-wrap: wrap;
}

/* Mobile Overrides */
@media (max-width: 768px) {
    .container {
        padding: 0 12px;
    }

    .filter-section {
        padding: 16px;
    }

    .search-bar-wrapper {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .btn-search {
        width: 100%;
    }

    .metrics-grid {
        grid-template-columns: 1fr 1fr; /* 2 columns for metrics */
        gap: 12px;
    }
    
    .metric-card {
        padding: 12px;
    }

    .metric-value {
        font-size: 1.4rem;
    }

    .metric-label {
        font-size: 0.8rem;
    }

    .chart-row {
        display: flex; /* Changed from grid to flex column for better control */
        flex-direction: column;
        gap: 20px;
    }
    
    .chart-row.two-cols {
        display: flex;
        flex-direction: column;
    }

    .chart-row.two-cols .chart-card {
        width: 100%;
        margin-bottom: 0;
        flex: none;
    }
    
    .large-chart {
        height: 400px; /* Adjust height for mobile */
    }
    
    .chart-container {
        min-height: 300px;
    }

    .report-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 16px;
    }
    
    .report-title-group {
        width: 100%;
    }
    
    #infoTitle {
        font-size: 1.5rem;
        line-height: 1.3;
    }

    .report-actions {
        width: 100%;
        display: flex;
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 8px;
    }
}

/* News List Components (Shared) */
.news-title { font-size: 1.08rem; font-weight: 800; color: var(--text-main); margin-bottom: 8px; text-decoration: none; display: block; line-height: 1.4; cursor: pointer; }
.news-title:hover { color: var(--primary-color); }
.meta-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; font-size: 0.78rem; color: var(--text-secondary); margin-bottom: 12px; justify-content: space-between; }
.meta-left { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.meta-right { display: flex; gap: 12px; align-items: center; margin-left: auto; }
.meta-row .time-str { white-space: nowrap; }
.tag { padding: 2px 8px; border-radius: 999px; background: var(--bg-soft); border: 1px solid var(--border-color); }
.tag-heat { background: rgba(239, 68, 68, 0.12); color: #dc2626; border-color: rgba(239, 68, 68, 0.25); font-weight: 650; }
.tag-source { background: var(--bg-soft); }
.tag-category { background: var(--tag-category-bg); border-color: rgba(148, 163, 184, 0.18); color: var(--tag-category-text); font-weight: 750; border-radius: 999px; padding: 2px 8px; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; flex-shrink: 0; border: 1px solid rgba(148, 163, 184, 0.18); }
.sentiment-pill { font-weight: 750; }
.sentiment-pill.sent-pos { background: var(--sent-pos-bg); border-color: rgba(34, 197, 94, 0.25); color: var(--sent-pos-text); }
.sentiment-pill.sent-neg { background: var(--sent-neg-bg); border-color: rgba(239, 68, 68, 0.25); color: var(--sent-neg-text); }
.sentiment-pill.sent-neu { background: var(--sent-neu-bg); border-color: rgba(148, 163, 184, 0.22); color: var(--sent-neu-text); }
.segmented { background: var(--bg-soft); padding: 4px; border-radius: 10px; border: 1px solid var(--border-color); }
.btn-link { color: var(--primary-color); cursor: pointer; background: none; border: none; padding: 0; font-size: inherit; }
.btn-link:hover { text-decoration: underline; }
.summary-box { background: var(--bg-soft); padding: 12px; border-radius: 12px; font-size: 0.9rem; color: var(--text-secondary); line-height: 1.7; margin-top: 8px; overflow-wrap: break-word; position: relative; border: 1px solid var(--border-color); }
.summary-box img { max-width: 100%; height: auto; display: block; margin: 10px auto; border-radius: 10px; }
.summary-box figure { margin: 0; width: 100%; }
.summary-box figcaption { font-size: 0.75rem; color: var(--text-light); text-align: center; margin-top: 4px; }
.summary-content.collapsed { max-height: 12em; overflow: hidden; position: relative; mask-image: linear-gradient(to bottom, black 60%, transparent 100%); -webkit-mask-image: linear-gradient(to bottom, black 60%, transparent 100%); }
.summary-placeholder { color: var(--text-light); font-style: italic; display: flex; justify-content: space-between; align-items: center; }
.btn-regen { margin-left: 8px; color: var(--primary-color); cursor: pointer; border: none; background: none; font-size: 0.8rem; }
.btn-regen:disabled { color: var(--text-light); cursor: not-allowed; opacity: 0.6; }
.btn-regen:hover:not(:disabled) { text-decoration: underline; }

.related-dropdown { position: relative; display: inline-block; white-space: nowrap; }
.related-content { display: none; position: absolute; right: 0; top: 100%; background: var(--bg-card); border: 1px solid var(--border-color); box-shadow: var(--shadow-md); border-radius: 12px; padding: 8px; width: 280px; z-index: 10; margin-top: 6px; }
.related-content.show { display: block; }
.related-item { display: flex; justify-content: space-between; align-items: center; font-size: 0.875rem; color: var(--text-secondary); padding: 6px 0; border-bottom: 1px dashed var(--border-color); }
.related-item:last-child { border-bottom: none; }
.related-box { margin-top: 12px; border-top: 1px solid var(--border-color); padding-top: 8px; display: none; }
.related-box.show { display: block; }
.related-link { color: var(--primary-color); text-decoration: none; font-size: 0.78rem; }

.loading-state { text-align: center; padding: 32px 0; color: var(--text-light); font-size: 0.9rem; }
.md-hidden { display: block; }
.md-show { display: none; }

@media (min-width: 768px) {
    body.page-index .mobile-top-bar { display: none; }
    .md-hidden { display: none; }
    .md-show { display: flex; }
    body.page-index .desktop-toolbar { display: flex; }
    .rank { display: block; }
}
@media (max-width: 767px) { .rank { display: none; } }

@media (max-width: 768px) {
/* News Card Mobile Optimization */
    .news-card {
        padding: 16px; /* More internal padding */
    }

    .news-card .card-body {
        flex-direction: column; /* Stack rank and content */
        align-items: flex-start;
        gap: 8px;
    }
    
    .news-card .rank {
        display: none;
    }
    
    .news-card .content {
        width: 100%;
    }

    .news-card .content > div:first-child {
        flex-wrap: wrap;
    }
    
    .news-card .news-title {
        font-size: 1.05rem; /* Larger title for readability */
        line-height: 1.5;
        margin-bottom: 6px;
    }
    
    .news-header-row {
        flex-wrap: wrap; /* Allow tags to wrap */
        gap: 6px;
    }

    .meta-row {
        flex-wrap: wrap;
        gap: 8px;
        font-size: 0.8rem;
        margin-top: 8px;
        justify-content: flex-start; /* Ensure left alignment on mobile */
    }
    
    .meta-right {
        margin-left: 0; /* Remove auto margin to prevent right alignment on mobile */
        width: 100%; /* Ensure it takes full width if needed or let it flow naturally */
        justify-content: space-between; /* Align content to the left */
        display: flex;
    }

    .tag {
        margin-bottom: 2px;
    }
    
    .news-card .summary-box {
        font-size: 0.95rem; /* Larger summary text */
        line-height: 1.6;
        padding: 12px;
    }
    
    .history-sidebar {
        display: none; /* Hide sidebar on mobile by default to save space */
    }
}

/* CodeMirror Dark Mode Syntax Highlighting */
html[data-theme="dark"] .cm-s-default .cm-keyword { color: #c084fc; }
html[data-theme="dark"] .cm-s-default .cm-atom { color: #60a5fa; }
html[data-theme="dark"] .cm-s-default .cm-number { color: #4ade80; }
html[data-theme="dark"] .cm-s-default .cm-def { color: #93c5fd; }
html[data-theme="dark"] .cm-s-default .cm-variable { color: #e2e8f0; }
html[data-theme="dark"] .cm-s-default .cm-variable-2 { color: #cbd5e1; }
html[data-theme="dark"] .cm-s-default .cm-variable-3 { color: #94a3b8; }
html[data-theme="dark"] .cm-s-default .cm-property { color: #60a5fa; }
html[data-theme="dark"] .cm-s-default .cm-operator { color: #e2e8f0; }
html[data-theme="dark"] .cm-s-default .cm-comment { color: #6b7280; }
html[data-theme="dark"] .cm-s-default .cm-string { color: #fcd34d; }
html[data-theme="dark"] .cm-s-default .cm-string-2 { color: #fbbf24; }
html[data-theme="dark"] .cm-s-default .cm-meta { color: #94a3b8; }
html[data-theme="dark"] .cm-s-default .cm-builtin { color: #22d3ee; }
html[data-theme="dark"] .cm-s-default .cm-tag { color: #f87171; }
html[data-theme="dark"] .cm-s-default .cm-attribute { color: #a78bfa; }
html[data-theme="dark"] .cm-s-default .cm-header { color: #f3f4f6; }
html[data-theme="dark"] .cm-s-default .cm-hr { color: #4b5563; }
html[data-theme="dark"] .cm-s-default .cm-link { color: #60a5fa; }
html[data-theme="dark"] .cm-s-default .cm-error { color: #ef4444; background: rgba(239, 68, 68, 0.1); }


body.page-index .chat-widget-btn { position: fixed; bottom: 20px; right: 20px; width: 56px; height: 56px; border-radius: 999px; background: var(--primary-color); color: #fff; box-shadow: 0 10px 22px rgba(37, 99, 235, 0.35); display: flex; align-items: center; justify-content: center; font-size: 1.5rem; z-index: 100; }
body.page-index .chat-window { position: fixed; bottom: 90px; right: 20px; width: 350px; height: 500px; background: var(--bg-card); border-radius: 16px; box-shadow: var(--shadow-lg); display: none; flex-direction: column; z-index: 100; border: 1px solid var(--border-color); overflow: hidden; }
body.page-index .chat-window.show { display: flex; }
body.page-index .chat-header { padding: 12px 16px; background: var(--primary-color); color: #fff; font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
body.page-index .chat-header-controls { display: flex; gap: 8px; align-items: center; }
body.page-index .chat-switch { font-size: 0.75rem; background: rgba(255,255,255,0.2); padding: 2px 8px; border-radius: 999px; cursor: pointer; user-select: none; }
body.page-index .chat-switch.active { background: #fff; color: var(--primary-color); font-weight: 800; }
body.page-index .chat-messages { flex: 1; padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; background: var(--bg-soft); }
body.page-index .message { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: 0.9rem; line-height: 1.5; word-wrap: break-word; }
body.page-index .message.user { align-self: flex-end; background: var(--primary-color); color: #fff; border-bottom-right-radius: 4px; }
body.page-index .message.ai { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--border-color); border-bottom-left-radius: 4px; }
body.page-index .message.ai ol, body.page-index .message.ai ul { padding-left: 20px; margin: 4px 0; }
body.page-index .message.ai p { margin: 4px 0; }
body.page-index .chat-input-area { padding: 12px; border-top: 1px solid var(--border-color); background: var(--bg-card); display: flex; gap: 8px; flex-direction: column; }
body.page-index .chat-quick-questions { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
body.page-index .chat-chip { white-space: nowrap; font-size: 0.78rem; color: var(--primary-color); background: var(--primary-light); padding: 4px 10px; border-radius: 999px; cursor: pointer; border: 1px solid color-mix(in srgb, var(--primary-color) 22%, transparent); }
body.page-index .chat-input-row { display: flex; gap: 8px; width: 100%; }
body.page-index .chat-input { flex: 1; padding: 8px 12px; border: 1px solid var(--border-color); border-radius: 999px; outline: none; font-size: 0.9rem; background: var(--bg-card); color: var(--text-main); }
body.page-index .chat-input:focus { border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); box-shadow: 0 0 0 3px var(--primary-light); }
body.page-index .chat-send { color: var(--primary-color); font-weight: 750; font-size: 0.9rem; }
body.page-index .chat-send:disabled { color: var(--text-light); cursor: not-allowed; }

@media (max-width: 480px) {
    body.page-index .chat-window { width: 100%; height: 100%; bottom: 0; right: 0; border-radius: 0; }
    body.page-index .chat-widget-btn { bottom: 80px; }
    body.page-index .meta-right { width: 100%; margin-left: 0; justify-content: space-between; margin-top: 4px; }
}

body.page-index .ms-container { position: relative; display: inline-block; min-width: 140px; max-width: 200px; }
body.page-index .ms-container.full-width { width: 100%; max-width: none; min-width: 0; }
body.page-index .ms-trigger { padding: 0 28px 0 16px; border: 1px solid var(--border-color); border-radius: 12px; font-size: 1rem; color: var(--text-secondary); background: var(--bg-card); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; user-select: none; height: 44px; display: flex; align-items: center; }
body.page-index .ms-trigger:after { content: ""; position: absolute; right: 10px; top: 50%; margin-top: -2px; border: 4px solid transparent; border-top-color: color-mix(in srgb, var(--text-secondary) 75%, transparent); }
body.page-index .ms-dropdown { display: none; position: absolute; top: 100%; left: 0; z-index: 50; background: var(--bg-card); border: 1px solid var(--border-color); box-shadow: var(--shadow-md); border-radius: 12px; padding: 8px; margin-top: 6px; min-width: 220px; max-height: 300px; overflow-y: auto; }
body.page-index .ms-dropdown.show { display: block; }
body.page-index .ms-option { display: flex; align-items: center; padding: 6px 8px; cursor: pointer; border-radius: 10px; font-size: 0.9rem; color: var(--text-secondary); }
body.page-index .ms-option:hover { background: var(--bg-soft); }
body.page-index .ms-option input { margin-right: 8px; cursor: pointer; }
body.page-index .ms-search { padding: 4px 4px 8px 4px; border-bottom: 1px solid var(--border-color); margin-bottom: 4px; }
body.page-index .ms-search input { width: 100%; padding: 8px; border: 1px solid var(--border-color); border-radius: 10px; font-size: 0.9rem; outline: none; background: var(--bg-card); color: var(--text-main); }
body.page-index .ms-search input:focus { border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); box-shadow: 0 0 0 3px var(--primary-light); }
body.page-index .mobile-check-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; padding: 6px; border: 1px solid var(--border-color); border-radius: 12px; background: var(--bg-soft); }
body.page-index .mobile-check-item { display: flex; align-items: center; padding: 8px; background: var(--bg-card); border-radius: 10px; border: 1px solid transparent; cursor: pointer; }
body.page-index .mobile-check-item.checked { border-color: var(--primary-color); background: var(--primary-light); color: var(--primary-color); }
body.page-index .mobile-check-item input { margin-right: 10px; transform: scale(1.2); }

body.page-report .filter-section { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 16px; padding: 22px; margin-bottom: 28px; box-shadow: var(--shadow-sm); margin-top: 24px; }
body.page-report .search-bar-wrapper { display: flex; gap: 12px; align-items: center; width: 100%; }
body.page-report .input-group { flex: 1; position: relative; display: flex; align-items: center; height: 48px; }
body.page-report .input-icon { position: absolute; left: 16px; color: var(--text-light); font-size: 1.2rem; z-index: 1; }
body.page-report .input-text-search { width: 100%; height: 100%; border: 1px solid var(--border-color); outline: none; padding: 0 16px 0 48px; font-size: 1rem; border-radius: 14px; transition: border 0.2s, box-shadow 0.2s; color: var(--text-main); background: var(--bg-soft); }
body.page-report .input-text-search:focus { border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); background: var(--bg-card); box-shadow: 0 0 0 3px var(--primary-light); }
body.page-report .btn-search { background: var(--primary-color); color: #fff; border: none; padding: 0 18px; border-radius: 14px; cursor: pointer; height: 48px; font-size: 0.95rem; font-weight: 750; transition: filter 0.2s; white-space: nowrap; display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 18px color-mix(in srgb, var(--primary-color) 25%, transparent); }
body.page-report .btn-search:hover { filter: brightness(0.98); }
body.page-report .recent-reports { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; align-items: center; }
body.page-report .recent-label { font-size: 0.9rem; color: var(--text-secondary); margin-right: 4px; }
body.page-report .recent-tag { font-size: 0.85rem; color: var(--primary-color); background: var(--primary-light); padding: 6px 14px; border-radius: 999px; cursor: pointer; border: 1px solid color-mix(in srgb, var(--primary-color) 18%, transparent); transition: filter 0.2s; font-weight: 650; }
body.page-report .recent-tag:hover { filter: brightness(0.98); }

body.page-report .report-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 24px; padding: 0 8px; }
body.page-report .report-title-group h1 { font-size: 1.55rem; font-weight: 850; color: var(--text-main); line-height: 1.2; }
body.page-report .report-meta { color: var(--text-secondary); font-size: 0.95rem; margin-top: 6px; }
body.page-report .report-actions button { background: var(--bg-card); border: 1px solid var(--border-color); color: var(--text-secondary); padding: 8px 14px; border-radius: 12px; cursor: pointer; transition: border 0.2s, color 0.2s; font-size: 0.9rem; font-weight: 650; display: flex; align-items: center; gap: 6px; }
body.page-report .report-actions button:hover { border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); color: var(--primary-color); background: var(--primary-light); }

body.page-report .metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }
body.page-report .metric-card { background: var(--bg-card); padding: 20px; border-radius: 16px; box-shadow: var(--shadow-sm); text-align: left; border: 1px solid var(--border-color); transition: border 0.2s, box-shadow 0.2s; position: relative; overflow: hidden; }
body.page-report .metric-card:hover { box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); }
body.page-report .metric-label { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 8px; font-weight: 650; }
body.page-report .metric-value { font-size: 1.7rem; font-weight: 800; color: var(--text-main); letter-spacing: -0.4px; }
body.page-report .metric-sub { font-size: 0.78rem; color: var(--text-light); margin-top: 4px; }

body.page-report .analysis-card { background: var(--bg-card); border: 1px solid color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); padding: 28px; border-radius: 16px; box-shadow: var(--shadow-md); margin-bottom: 28px; position: relative; }
body.page-report .analysis-card::after { content: "ANALYSIS"; position: absolute; top: 14px; right: 18px; font-size: 2.6rem; font-weight: 900; color: color-mix(in srgb, var(--primary-color) 10%, transparent); pointer-events: none; }
body.page-report .chart-header.ai-header { border-bottom: 1px solid var(--border-color); padding-bottom: 16px; margin-bottom: 18px; }
body.page-report .analysis-content { font-size: 1rem; color: var(--text-secondary); line-height: 1.85; }
body.page-report .analysis-content h1, body.page-report .analysis-content h2 { color: var(--text-main); font-weight: 750; margin-top: 1.5em; margin-bottom: 0.5em; }
body.page-report .analysis-content strong { color: var(--primary-color); font-weight: 700; }
body.page-report .analysis-content ul, body.page-report .analysis-content ol { padding-left: 1.6em; margin: 0.6em 0; color: var(--text-secondary); }
body.page-report .analysis-content li { margin: 0.25em 0; }

body.page-report .chart-row { display: grid; gap: 20px; margin-bottom: 20px; }
body.page-report .chart-row.full-width { grid-template-columns: 1fr; }
body.page-report .chart-row.two-cols { grid-template-columns: 1fr 1fr; }
@media (max-width: 1024px) { body.page-report .chart-row.two-cols { grid-template-columns: 1fr; } }
body.page-report .chart-card { background: var(--bg-card); padding: 20px; border-radius: 16px; box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); height: 420px; display: flex; flex-direction: column; transition: box-shadow 0.2s, border 0.2s; }
body.page-report .chart-card:hover { box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); }
body.page-report .chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 10px; }
body.page-report .chart-title { font-size: 1.05rem; font-weight: 700; color: var(--text-main); display: flex; align-items: center; gap: 8px; }
body.page-report .chart-filter { font-size: 0.9rem; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--border-color); color: var(--text-secondary); cursor: pointer; background: var(--bg-card); outline: none; }
body.page-report .chart-filter:hover { border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); color: var(--primary-color); }
body.page-report .chart-container { flex: 1; width: 100%; height: 100%; min-height: 0; }

body.page-report .word-cloud-container { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 10px; 
    padding: 10px; 
    align-content: center; 
    align-items: center; 
    justify-content: center;
    /* Allow scrolling if content overflows */
    max-height: 400px;
    overflow-y: auto;
}

.chart-card.auto-height {
    height: auto;
    min-height: 420px;
}
body.page-report .cloud-tag { padding: 6px 14px; border-radius: 999px; color: #fff; cursor: default; white-space: nowrap; line-height: 1.2; font-weight: 650; box-shadow: var(--shadow-sm); }

body.page-report .table-card { background: var(--bg-card); padding: 0; border-radius: 16px; box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); overflow: hidden; }
body.page-report .table-header-wrapper { padding: 20px 20px 14px 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }

body.page-report .pagination { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 24px; padding-bottom: 24px; }
body.page-report .page-btn { background: var(--bg-card); border: 1px solid var(--border-color); color: var(--text-secondary); padding: 6px 12px; border-radius: 12px; cursor: pointer; font-size: 0.9rem; transition: border 0.2s, background 0.2s, color 0.2s; min-width: 32px; display: flex; justify-content: center; align-items: center; }
body.page-report .page-btn:hover:not(:disabled) { border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); color: var(--primary-color); background: var(--primary-light); }
body.page-report .page-btn.active { background: var(--primary-color); color: #fff; border-color: var(--primary-color); }
body.page-report .page-btn:disabled { opacity: 0.5; cursor: not-allowed; }

body.page-report .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: 1000; display: none; justify-content: center; align-items: center; opacity: 0; transition: opacity 0.25s; }
body.page-report .modal-overlay.show { display: flex; opacity: 1; }
body.page-report .modal-content { background: var(--bg-card); border-radius: 20px; box-shadow: var(--shadow-lg); width: 92%; max-width: 550px; transform: translateY(12px); transition: transform 0.25s; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border-color); }
body.page-report .modal-overlay.show .modal-content { transform: translateY(0); }
body.page-report .modal-header { padding: 18px 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: var(--bg-soft); }
body.page-report .modal-title { font-size: 1.05rem; font-weight: 750; color: var(--text-main); }
body.page-report .modal-close { cursor: pointer; font-size: 1.5rem; color: var(--text-secondary); }
body.page-report .modal-close:hover { color: var(--text-main); }
body.page-report .modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
body.page-report .modal-footer { padding: 14px 20px; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 12px; background: var(--bg-soft); }
body.page-report .form-group { display: flex; flex-direction: column; gap: 8px; }
body.page-report .form-label { font-size: 0.9rem; font-weight: 700; color: var(--text-main); }
body.page-report .form-control { padding: 10px 14px; border: 1px solid var(--border-color); border-radius: 12px; font-size: 0.95rem; width: 100%; outline: none; transition: border 0.2s, box-shadow 0.2s; background: var(--bg-card); color: var(--text-main); }
body.page-report .form-control:focus { border-color: color-mix(in srgb, var(--border-color) 60%, var(--primary-color)); box-shadow: 0 0 0 3px var(--primary-light); }
body.page-report .btn-cancel { background: var(--bg-card); border: 1px solid var(--border-color); color: var(--text-secondary); padding: 10px 18px; border-radius: 12px; cursor: pointer; font-weight: 750; }
body.page-report .btn-cancel:hover { background: var(--bg-soft); }
body.page-report .btn-confirm { background: var(--primary-color); border: none; color: #fff; padding: 10px 20px; border-radius: 12px; cursor: pointer; font-weight: 750; box-shadow: var(--shadow-sm); }
body.page-report .btn-confirm:hover { background: var(--primary-hover); }

body.page-report .custom-select { width: 100%; position: relative; }
body.page-report .select-trigger { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 12px; padding: 10px 14px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-size: 0.95rem; color: var(--text-main); }
body.page-report .select-trigger:hover { border-color: color-mix(in srgb, var(--border-color) 60%, var(--text-light)); }
body.page-report .select-options { position: absolute; top: 100%; left: 0; right: 0; background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 14px; box-shadow: var(--shadow-lg); margin-top: 8px; max-height: 250px; overflow-y: auto; display: none; z-index: 1005; padding: 6px; }
body.page-report .select-options.show { display: block; animation: fadeIn 0.2s; }
body.page-report .select-options label { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; font-size: 0.9rem; border-radius: 12px; color: var(--text-secondary); }
body.page-report .select-options label:hover { background: var(--primary-light); color: var(--primary-color); }

body.page-report .loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: color-mix(in srgb, var(--bg-body) 92%, transparent); display: none; flex-direction: column; justify-content: center; align-items: center; z-index: 2000; font-size: 1.05rem; color: var(--text-secondary); font-weight: 650; gap: 18px; backdrop-filter: blur(6px); }
body.page-report .spinner { width: 44px; height: 44px; border: 4px solid var(--primary-light); border-top: 4px solid var(--primary-color); border-radius: 50%; animation: spin 0.8s cubic-bezier(0.68, -0.55, 0.27, 1.55) infinite; }

body.page-report .history-sidebar { position: fixed; right: -320px; top: 0; width: 300px; height: 100vh; background: var(--bg-card); border-left: 1px solid var(--border-color); box-shadow: var(--shadow-lg); z-index: 100; display: flex; flex-direction: column; transition: right 0.28s cubic-bezier(0.4, 0, 0.2, 1); }
body.page-report .history-sidebar.show { right: 0; }
body.page-report .history-header { padding: 18px; border-bottom: 1px solid var(--border-color); font-weight: 800; font-size: 1.05rem; background: var(--bg-soft); display: flex; justify-content: space-between; align-items: center; }
body.page-report .history-list { overflow-y: auto; padding: 16px; flex: 1; }
body.page-report .history-group-title { font-size: 0.75rem; font-weight: 800; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.05em; margin: 16px 0 8px 0; padding-left: 4px; }
body.page-report .history-item { padding: 10px 14px; border-radius: 12px; cursor: pointer; font-size: 0.9rem; color: var(--text-main); transition: background 0.2s, border 0.2s, color 0.2s; display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; border: 1px solid transparent; }
body.page-report .history-item:hover { background: var(--primary-light); border-color: color-mix(in srgb, var(--primary-color) 18%, transparent); color: var(--primary-color); }
body.page-report .report-tag { font-size: 0.7rem; padding: 2px 8px; border-radius: 10px; font-weight: 750; }
body.page-report .tag-daily { background: rgba(59, 130, 246, 0.18); color: color-mix(in srgb, var(--primary-color) 75%, #1e40af); }
body.page-report .tag-weekly { background: rgba(16, 185, 129, 0.16); color: #065f46; }
body.page-report .tag-monthly { background: rgba(236, 72, 153, 0.14); color: #9d174d; }

body.page-report .history-quick-access { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
body.page-report .history-qa-item { font-size: 0.85rem; color: var(--text-secondary); background: var(--bg-soft); padding: 6px 12px; border-radius: 12px; cursor: pointer; border: 1px solid transparent; transition: background 0.2s, border 0.2s, color 0.2s; }
body.page-report .history-qa-item.qa-daily { background: rgba(59, 130, 246, 0.12); color: #1d4ed8; border-color: rgba(59, 130, 246, 0.2); }
body.page-report .history-qa-item.qa-weekly { background: rgba(16, 185, 129, 0.12); color: #047857; border-color: rgba(16, 185, 129, 0.2); }
body.page-report .history-qa-item.qa-monthly { background: rgba(236, 72, 153, 0.12); color: #be185d; border-color: rgba(236, 72, 153, 0.2); }
body.page-report .history-qa-item:hover { background: color-mix(in srgb, var(--bg-soft) 70%, var(--primary-light)); color: var(--primary-color); border-color: color-mix(in srgb, var(--primary-color) 18%, transparent); }
body.page-report .history-qa-more { font-size: 0.85rem; color: var(--primary-color); cursor: pointer; padding: 4px 8px; font-weight: 650; }

/* Desktop Drawer */
.desktop-drawer-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    justify-content: flex-end;
    opacity: 0;
    transition: opacity 0.3s;
}
.desktop-drawer-overlay.show {
    display: flex;
    opacity: 1;
}
.desktop-drawer-content {
    width: 360px;
    height: 100%;
    background: var(--bg-card);
    box-shadow: -4px 0 16px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.desktop-drawer-overlay.show .desktop-drawer-content {
    transform: translateX(0);
}
.drawer-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.drawer-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}
.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}
.drawer-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-soft);
}
.filter-section-drawer {
    margin-bottom: 24px;
}
.filter-section-drawer label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.ms-container.full-width {
    width: 100%;
    max-width: none;
}
.ms-container.full-width .ms-trigger {
    width: 100%;
}
body.page-report .history-qa-more:hover { text-decoration: underline; }

@media (max-width: 768px) {
    body.page-report .history-quick-access { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; width: 100%; }
    body.page-report .history-quick-access::-webkit-scrollbar { display: none; }
    body.page-report .history-qa-item { white-space: nowrap; flex-shrink: 0; }
    body.page-report .search-bar-wrapper { flex-direction: row; width: 100%; }
    body.page-report .btn-search { width: auto; padding: 0 14px; font-size: 0.9rem; flex-shrink: 0; }
    body.page-report .input-text-search { padding: 0 12px 0 36px; font-size: 0.9rem; }
    body.page-report .input-icon { left: 10px; font-size: 1rem; }
    body.page-report .metrics-grid { grid-template-columns: repeat(2, 1fr); }
    body.page-report .report-header { flex-direction: column; align-items: flex-start; gap: 16px; }
}

/* --- Task 1: Theme Toggle Icons --- */
.theme-toggle {
    width: 34px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
}

/* --- Task 2: Homepage Tags --- */
body.page-index .tag-category {
    font-size: 0.75rem;
    /* height: 20px;
    margin-top: 2px; */
}

/* --- Task 3: Topic Page Enhancements --- */

/* Timeline Styling */
body.page-topics .timeline {
    position: relative;
    padding-left: 10px;
    margin-top: 10px;
}

body.page-topics .tl-item {
    border-left: 2px solid var(--border-color);
    padding-left: 24px;
    padding-bottom: 24px;
    position: relative;
}

body.page-topics .tl-item:last-child {
    border-left-color: transparent;
}

body.page-topics .tl-item::before {
    content: "";
    position: absolute;
    left: -4px;
    top: 4px;
 width: 10px;
 height: 10px;
 border-radius: 50%;
 background: var(--bg-card);
 border: 2px solid var(--primary-color);
 z-index: 1;
}

body.page-topics .tl-time {
 font-weight: 700;
 color: var(--primary-color);
 margin-bottom: 4px;
}

/* Overview Text Visibility */
body.page-topics.page-topic-detail .topic-summary {
 -webkit-line-clamp: unset !important;
 display: block !important;
 overflow: visible !important;
 max-height: none !important;
}

/* News Source Grouping */
.source-group {
 padding: 0 !important;
 overflow: hidden;
}

.source-header {
 padding: 14px 16px;
 display: flex;
 justify-content: space-between;
 align-items: center;
 cursor: pointer;
 background: var(--bg-card);
 transition: background 0.2s;
}

.source-header:hover {
 background: var(--bg-soft);
}

.source-title-row {
 display: flex;
 align-items: center;
 gap: 10px;
}

.source-name {
 font-weight: 750;
 color: var(--text-main);
}

.source-count-badge {
 background: var(--primary-light);
 color: var(--primary-color);
 font-size: 0.75rem;
 padding: 2px 8px;
 border-radius: 999px;
 font-weight: 700;
}

.toggle-icon {
 font-size: 0.8rem;
 color: var(--text-light);
 transition: transform 0.2s;
}

.source-list {
 border-top: 1px solid var(--border-color);
 background: var(--bg-soft);
 padding: 8px 16px;
}

.source-item-row {
 display: flex;
 justify-content: space-between;
 align-items: center;
 padding: 8px 0;
 border-bottom: 1px dashed var(--border-color);
 gap: 12px;
}

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

.source-link {
 color: var(--text-secondary);
 text-decoration: none;
 font-size: 0.9rem;
 flex: 1;
 white-space: nowrap;
 overflow: hidden;
 text-overflow: ellipsis;
}

.source-link:hover {
 color: var(--primary-color);
 text-decoration: underline;
}

.source-time {
 font-size: 0.75rem;
 color: var(--text-light);
 white-space: nowrap;
}

/* --- Task 4: Mobile Responsive Overhaul --- */
@media (max-width: 768px) {
 .app-container, .container {
 padding: 0 12px;
 }
 .header-content {
 padding: 0 4px;
 }
 .card, .news-card {
 padding: 12px;
 }
 body {
 font-size: 15px;
 }
 h1 { font-size: 1.5rem; }
 h2 { font-size: 1.25rem; }
 body.page-topics .grid {
 gap: 16px;
 }
 .source-link {
 font-size: 0.85rem;
 }
 .mobile-menu-content {
 border-radius: 16px 16px 0 0;
 }
}

/* Desktop Filter Drawer */
.desktop-drawer-overlay {
    position: fixed; top: 0; right: 0; bottom: 0; left: 0;
    background: rgba(0,0,0,0.5); z-index: 100;
    display: none; justify-content: flex-end;
    opacity: 0; transition: opacity 0.3s;
}
.desktop-drawer-overlay.show { display: flex; opacity: 1; }

.desktop-drawer-content {
    width: 320px; background: var(--bg-card); height: 100%;
    box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    display: flex; flex-direction: column;
    transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.desktop-drawer-overlay.show .desktop-drawer-content { transform: translateX(0); }

.drawer-header { padding: 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.drawer-header h3 { margin: 0; font-size: 1.1rem; }

.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }

.drawer-footer { padding: 20px; border-top: 1px solid var(--border-color); }

.filter-section-drawer { margin-bottom: 24px; }
.filter-section-drawer label { display: block; margin-bottom: 8px; font-weight: 700; color: var(--text-secondary); font-size: 0.9rem; }

.ms-container.full-width { width: 100%; max-width: none; }
.ms-container.full-width .ms-trigger { width: 100%; }

/* Markdown Body Styles */
.markdown-body {
    color: var(--text-secondary);
    font-size: 0.92rem;
    line-height: 1.7;
    word-wrap: break-word;
}
.markdown-body p { margin-bottom: 1em; margin-top: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { color: var(--text-main); margin-top: 1.5em; margin-bottom: 0.5em; font-weight: 600; line-height: 1.3; }
.markdown-body h1 { font-size: 1.5em; border-bottom: 1px solid var(--border-color); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.3em; }
.markdown-body h3 { font-size: 1.1em; }
.markdown-body ul, .markdown-body ol { padding-left: 1.5em; margin-bottom: 1em; margin-top: 0; }
.markdown-body li { margin-bottom: 0.25em; }
.markdown-body a { color: var(--primary-color); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body strong { color: var(--text-main); font-weight: 600; }
.markdown-body blockquote { border-left: 4px solid var(--border-color); padding-left: 1em; color: var(--text-light); margin: 1em 0; }
.markdown-body code { background: var(--bg-soft); padding: 0.2em 0.4em; border-radius: 4px; font-family: monospace; font-size: 0.9em; }
.markdown-body pre { background: var(--bg-soft); padding: 1em; border-radius: 8px; overflow-x: auto; margin: 1em 0; }
.markdown-body pre code { background: none; padding: 0; }
.markdown-body img { max-width: 100%; border-radius: 8px; }
.markdown-body hr { height: 1px; background-color: var(--border-color); border: none; margin: 1.5em 0; }
