/* ========================================
   CSS 变量 - 主题系统
   ======================================== */

:root {
    /* 深色模式（默认） */
    --bg-primary: #1a1a2e;
    --bg-sidebar: #16213e;
    --bg-card: #1e2a45;
    --bg-header: #16213e;
    --bg-footer: #16213e;
    --bg-input: #0f1729;
    --bg-code: #111827;
    --bg-code-inline: #2a2a4a;

    --text-primary: #e0e0e0;
    --text-secondary: #8a8a9a;
    --text-muted: #6a6a7a;

    --accent: #e94560;
    --accent-hover: #f05672;

    --border-color: #2a2a4a;
    --border-light: #252545;

    --shadow-card: none;
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.15);

    --blockquote-bg: rgba(233, 69, 96, 0.06);
    --table-head-bg: #16213e;

    --overlay-bg: rgba(0, 0, 0, 0.5);
}

/* 浅色模式 */
html.light {
    --bg-primary: #f4f5f7;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --bg-header: #ffffff;
    --bg-footer: #ffffff;
    --bg-input: #f0f1f3;
    --bg-code: #f0f0f0;
    --bg-code-inline: #e8e8ec;

    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;

    --accent: #d81e5b;
    --accent-hover: #c41850;

    --border-color: #e0e0e0;
    --border-light: #ebebed;

    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.12);

    --blockquote-bg: rgba(216, 30, 91, 0.04);
    --table-head-bg: #f7f7f9;

    --overlay-bg: rgba(0, 0, 0, 0.35);
}

/* ========================================
   全局样式
   ======================================== */

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

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

a:hover {
    text-decoration: underline;
}

/* ========================================
   顶部栏
   ======================================== */

.header {
    height: 60px;
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

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

/* 菜单按钮（移动端） */
.menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    padding: 6px;
    border-radius: 6px;
    transition: background-color 0.2s;
    margin-right: 4px;
}

.menu-btn:hover {
    background-color: var(--border-light);
}

/* 主题切换按钮 */
.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    cursor: pointer;
    color: var(--text-primary);
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
}

.theme-toggle:hover {
    border-color: var(--accent);
    background-color: var(--border-light);
}

/* 图标显示/隐藏：深色模式显示月亮，浅色模式显示太阳 */
html.dark .icon-sun { display: none; }
html.dark .icon-moon { display: block; }
html.light .icon-sun { display: block; }
html.light .icon-moon { display: none; }

/* ========================================
   容器布局
   ======================================== */

.container {
    display: flex;
    flex: 1;
    min-height: calc(100vh - 60px - 48px);
}

/* ========================================
   左侧侧边栏
   ======================================== */

.sidebar {
    width: 260px;
    min-width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    padding: 24px 20px;
    overflow-y: auto;
    flex-shrink: 0;
    position: sticky;
    top: 60px;
    height: calc(100vh - 60px);
}

.search-box {
    margin-bottom: 28px;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    color: var(--text-primary);
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.12);
}

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

/* 搜索下拉框 */
.search-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-hover);
    max-height: 260px;
    overflow-y: auto;
    z-index: 50;
}

.search-dropdown.active {
    display: block;
}

.search-dropdown-item {
    padding: 9px 14px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    border-bottom: 1px solid var(--border-light);
}

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

.search-dropdown-item:hover,
.search-dropdown-item.highlighted {
    background-color: rgba(233, 69, 96, 0.06);
    color: var(--accent);
}

.search-dropdown .dropdown-empty {
    padding: 14px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.recent-updates,
.stats {
    margin-bottom: 28px;
}

.recent-updates h3,
.stats h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.recent-updates ul {
    list-style: none;
}

.recent-updates li {
    padding: 7px 24px 7px 14px;
    position: relative;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    transition: color 0.2s;
    line-height: 1.5;
}

/* 删除按钮（悬停显示） */
.recent-updates li .delete-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    transition: color 0.15s, background-color 0.15s;
    padding: 0;
    text-align: center;
}

.recent-updates li .delete-btn:hover {
    color: var(--accent);
    background-color: rgba(216, 30, 91, 0.1);
}

.recent-updates li:hover .delete-btn {
    display: block;
}

/* 小圆点装饰 */
.recent-updates li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 13px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: var(--text-muted);
    transition: background-color 0.2s;
}

.recent-updates li:hover {
    color: var(--accent);
}

.recent-updates li:hover::before {
    background-color: var(--accent);
}

/* 当前选中的公司高亮 */
.recent-updates li.active {
    color: var(--accent);
    font-weight: 600;
}

.recent-updates li.active::before {
    background-color: var(--accent);
}

.stats p {
    font-size: 14px;
    color: var(--text-secondary);
}

#totalCount {
    color: var(--accent);
    font-weight: 700;
    font-size: 16px;
}

/* 添加新公司按钮 */
.add-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    margin-top: 12px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background-color: var(--accent);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.add-btn:active {
    transform: scale(0.97);
}

/* 刷新新闻按钮（次要按钮） */
.refresh-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    margin-top: 10px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.refresh-btn:active {
    transform: scale(0.97);
}

.refresh-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ========================================
   AI 生成模态框
   ======================================== */

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--overlay-bg);
    z-index: 500;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 90%;
    max-width: 560px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    position: relative;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close-btn:hover {
    color: var(--text-primary);
    background-color: var(--border-light);
}

.modal-body {
    padding: 22px;
}

.modal-body label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.modal-body input {
    width: 100%;
    padding: 11px 14px;
    font-size: 15px;
    color: var(--text-primary);
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.modal-body input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.12);
}

.modal-body textarea {
    width: 100%;
    min-height: 200px;
    padding: 11px 14px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    outline: none;
    resize: vertical;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
    font-family: inherit;
}

.modal-body textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.12);
}

.modal-hint {
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.modal-footer {
    padding: 16px 22px 22px;
}

.generate-submit-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 11px;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    background-color: var(--accent);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.generate-submit-btn:hover {
    background-color: var(--accent-hover);
}

.generate-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.generating-status {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-card);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 10;
}

.generating-status p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* 加载旋转动画 */
.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========================================
   右侧主内容区
   ======================================== */

.main-content {
    flex: 1;
    padding: 32px 40px;
    overflow-y: auto;
}

.loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 15px;
}

.card-container {
    width: 100%;
}

/* ========================================
   公司卡片
   ======================================== */

.company-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 24px;
    margin-bottom: 16px;
    cursor: pointer;
    box-shadow: var(--shadow-card);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.company-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
    border-color: var(--border-light);
}

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

.card-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.card-date {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    margin-left: 16px;
}

.card-summary {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.65;
}

/* 展开的完整内容区域 */
.card-content {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    display: none;
    animation: fadeIn 0.25s ease;
}

.card-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ========================================
   Markdown 渲染内容（双主题适配）
   ======================================== */

.card-content h1,
.card-content h2,
.card-content h3,
.card-content h4,
.card-content h5,
.card-content h6 {
    color: var(--text-primary);
    margin-top: 24px;
    margin-bottom: 12px;
    font-weight: 650;
    letter-spacing: -0.3px;
    line-height: 1.4;
}

.card-content h1 { font-size: 22px; }
.card-content h2 { font-size: 19px; }
.card-content h3 { font-size: 17px; }
.card-content h4 { font-size: 15px; }

.card-content p {
    margin-bottom: 14px;
    color: var(--text-secondary);
    line-height: 1.75;
}

.card-content strong {
    color: var(--text-primary);
    font-weight: 600;
}

.card-content blockquote {
    border-left: 3px solid var(--accent);
    padding: 12px 18px;
    margin: 18px 0;
    color: var(--text-secondary);
    background-color: var(--blockquote-bg);
    border-radius: 0 6px 6px 0;
    font-style: italic;
}

.card-content ul,
.card-content ol {
    margin: 14px 0;
    padding-left: 24px;
}

.card-content li {
    margin-bottom: 7px;
    color: var(--text-secondary);
    line-height: 1.65;
}

.card-content li::marker {
    color: var(--accent);
}

.card-content code {
    background-color: var(--bg-code-inline);
    color: var(--accent);
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 13px;
    font-family: "SF Mono", "Cascadia Code", "Consolas", monospace;
}

.card-content pre {
    background-color: var(--bg-code);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 18px 20px;
    overflow-x: auto;
    margin: 18px 0;
}

.card-content pre code {
    background-color: transparent;
    padding: 0;
    color: var(--text-primary);
    font-size: 13.5px;
    line-height: 1.6;
}

.card-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 24px 0;
}

.card-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 18px 0;
    border-radius: 6px;
    overflow: hidden;
}

.card-content th,
.card-content td {
    border: 1px solid var(--border-color);
    padding: 11px 14px;
    text-align: left;
    font-size: 14px;
}

.card-content th {
    background-color: var(--table-head-bg);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 13px;
}

.card-content td {
    color: var(--text-secondary);
}

.card-content a {
    color: var(--accent);
}

.card-content a:hover {
    text-decoration: underline;
}

/* 图片响应式 */
.card-content img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 12px 0;
}

/* ========================================
   财务数据汇总表
   ======================================== */

.financial-table-wrapper {
    overflow-x: auto;
}

.financial-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.financial-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.financial-table th,
.financial-table td {
    border: 1px solid var(--border-color);
    padding: 11px 12px;
    text-align: center;
    white-space: nowrap;
}

.financial-table th {
    background-color: var(--table-head-bg);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 13px;
}

.financial-table tbody tr {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.financial-table tbody tr:hover {
    background-color: rgba(233, 69, 96, 0.06);
}

.financial-table tbody tr.active {
    background-color: rgba(233, 69, 96, 0.10);
}

/* 公司名称列 */
.financial-table .col-company {
    color: var(--accent);
    font-weight: 600;
    min-width: 160px;
}

/* 数值列 */
.financial-table .num-positive {
    color: #ef4444;
}
.financial-table .num-negative {
    color: #22c55e;
}

/* 展开详情区域 */
.table-detail {
    display: none;
    animation: fadeIn 0.25s ease;
}

.table-detail.active {
    display: block;
}

/* 无匹配提示 */
.no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 15px;
}

/* ========================================
   底部栏
   ======================================== */

.footer {
    background-color: var(--bg-footer);
    border-top: 1px solid var(--border-color);
    padding: 16px 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    flex-shrink: 0;
}

/* ========================================
   移动端侧边栏遮罩 + 抽屉
   ======================================== */

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--overlay-bg);
    z-index: 200;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ========================================
   响应式布局 (<=768px)
   ======================================== */

@media screen and (max-width: 768px) {
    .menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar {
        position: fixed;
        top: 60px;
        left: -280px;
        bottom: 0;
        z-index: 201;
        width: 270px;
        min-width: 270px;
        border-right: none;
        box-shadow: none;
        transition: left 0.3s ease;
        height: auto;
        padding: 24px 18px;
        overflow-y: auto;
    }

    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
    }

    .main-content {
        padding: 20px 16px;
    }

    .card-container {
        max-width: 100%;
    }

    .company-card {
        padding: 18px 16px;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .card-date {
        margin-left: 0;
        margin-top: 4px;
    }

    .header {
        padding: 0 16px;
    }

    .main-content {
        padding: 20px 16px;
    }
}

/* ========================================
   财经新闻样式
   ======================================== */

/* 新闻列表容器 */
.news-feed {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-card);
}

.news-feed h3 {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 16px 0;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

/* 单条新闻 */
.news-item {
    padding: 14px 0;
    border-bottom: 1px solid var(--border-light);
    transition: background-color 0.15s ease;
}

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

.news-item:hover {
    background-color: rgba(233, 69, 96, 0.04);
    border-radius: 6px;
    padding-left: 8px;
    padding-right: 8px;
}

/* 新闻标题链接 */
.news-title {
    display: block;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    margin-bottom: 6px;
    text-decoration: none;
    transition: color 0.2s ease;
}

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

/* 新闻元信息（时间、来源、情绪） */
.news-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.news-time {
    color: var(--text-muted);
}

.news-source {
    color: var(--text-secondary);
}

/* 情绪标签 */
.news-sentiment {
    display: inline-block; /* 确保标签独占一部分空间 */
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-left: 4px;
}

/* 深色模式 - 利好：红色 */
.sentiment-positive {
    background-color: rgba(239, 68, 68, 0.15); /* 红色背景 */
    color: #ef4444; /* 红色文字 */
}

/* 深色模式 - 利空：绿色 */
.sentiment-negative {
    background-color: rgba(34, 197, 94, 0.15); /* 绿色背景 */
    color: #22c55e; /* 绿色文字 */
}

/* 深色模式 - 中性：灰色 */
.sentiment-neutral {
    background-color: rgba(156, 163, 175, 0.15);
    color: #9ca3af;
}

/* 浅色模式适配 */
html.light .sentiment-positive {
    background-color: rgba(220, 38, 38, 0.12);
    color: #dc2626; /* 浅色模式下稍深的红色 */
}

html.light .sentiment-negative {
    background-color: rgba(22, 163, 74, 0.12);
    color: #16a34a; /* 浅色模式下稍深的绿色 */
}

html.light .sentiment-neutral {
    background-color: rgba(156, 163, 175, 0.12);
    color: #6b7280;
}

/* 移动端适配 */
@media screen and (max-width: 768px) {
    .news-feed {
        padding: 16px;
        margin-bottom: 20px;
    }

    .news-feed h3 {
        font-size: 15px;
        margin-bottom: 12px;
        padding-bottom: 10px;
    }

    .news-item {
        padding: 12px 0;
    }

    .news-title {
        font-size: 13px;
        line-height: 1.6;
        margin-bottom: 8px;
    }

    .news-meta {
        font-size: 11px;
        gap: 6px;
    }

    .news-sentiment {
        padding: 2px 6px;
        font-size: 10px;
    }
}
