/* 股票分析页面样式 - 修复版本，匹配现有HTML结构 */

/* 导入主界面字体和变量 */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap');

/* 全局box-sizing设置，防止元素超出容器 */
*, *::before, *::after {
    box-sizing: border-box;
}

/* 继承主界面CSS变量 */
:root {
    --bg-color: #f7f8fa;
    --chat-container-bg: #ffffff;
    --ai-message-bg: #f0f4f8;
    --user-message-bg: #e1eefe;
    --primary-text-color: #333;
    --secondary-text-color: #666;
    --accent-color: #4a80ff;
    --border-color: #e0e0e0;
    --shadow-color: rgba(0, 0, 0, 0.05);
    --font-family: 'Noto Sans SC', sans-serif;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --chat-container-bg: #2d2d2d;
    --ai-message-bg: #3a3a3a;
    --user-message-bg: #4a80ff;
    --primary-text-color: #ffffff;
    --secondary-text-color: #cccccc;
    --accent-color: #5a90ff;
    --border-color: #404040;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --success-color: #34d399;
    --error-color: #f87171;
    --warning-color: #fbbf24;
}

/* 页面主体 - 采用与主界面相同的布局逻辑 */
body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    color: var(--primary-text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    padding: 20px;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    overflow-y: auto; /* 允许页面垂直滚动 */
    overflow-x: hidden; /* 禁止水平滚动 */
}

/* 小屏幕优化 */
@media (max-width: 1600px) {
    body {
        padding: 10px;
    }
}

/* 主容器 - 匹配HTML中的analysis-container */
.analysis-container {
    width: 90%;
    max-width: 1400px;
    background-color: var(--chat-container-bg);
    border-radius: 16px;
    box-shadow: 0 8px 24px var(--shadow-color);
    overflow-x: hidden !important; /* 禁止水平滚动 */
    overflow-y: visible; /* 允许垂直滚动 */
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    z-index: 1;
    isolation: isolate; /* 创建新的层叠上下文，防止子元素溢出 */
}

/* 页面头部 - 匹配analysis-header */
.analysis-header {
    padding: 24px 32px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--chat-container-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

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

.header-left h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-text-color);
}

.back-btn {
    background: none;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 14px;
    color: var(--secondary-text-color);
    transition: all 0.2s;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    touch-action: manipulation;
}

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

.theme-toggle-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s;
    min-height: 40px;
    touch-action: manipulation;
}

.theme-toggle-btn:hover {
    background-color: var(--ai-message-bg);
}

/* 搜索栏 - 匹配search-section */
.search-section {
    padding: 20px 32px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--ai-message-bg);
}

.search-box {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

#symbol-input {
    flex: 1;
    min-width: 200px;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--chat-container-bg);
    color: var(--primary-text-color);
    font-size: 16px;
    transition: all 0.2s;
}

#symbol-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(74, 128, 255, 0.1);
}

#search-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
    min-height: 44px;
    touch-action: manipulation;
}

#search-btn:hover {
    background-color: #3a6dd9;
}

/* 快捷股票标签 - 匹配quick-symbols */
.quick-symbols {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.quick-symbols .label {
    font-size: 14px;
    color: var(--secondary-text-color);
    font-weight: 500;
}

.symbol-tag {
    background-color: var(--chat-container-bg);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 16px;
    cursor: pointer;
    font-size: 12px;
    color: var(--secondary-text-color);
    transition: all 0.2s;
    touch-action: manipulation;
}

.symbol-tag:hover {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

/* 主内容区域 - 匹配content-wrapper */
.content-wrapper {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    padding: 24px;
    min-height: 600px;
    overflow: visible; /* 允许滚动 */
    position: relative;
}

/* 大屏幕优化 */
@media (min-width: 1400px) {
    .content-wrapper {
        grid-template-columns: 3fr 1fr;
    }
}

/* 左侧图表区域 - 匹配charts-section */
.charts-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-width: 0; /* 防止flex item溢出 */
    max-width: 100%;
    overflow: visible; /* 允许滚动 */
    position: relative;
}

/* 图表卡片 - 匹配chart-card */
.chart-card {
    background-color: var(--chat-container-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden !important;
    transition: all 0.2s;
    position: relative;
    contain: layout style paint;
    resize: vertical; /* 允许手动调整高度 */
    max-height: 800px; /* 限制最大高度 */
    min-height: 300px; /* 限制最小高度 */
}

.chart-card:hover {
    box-shadow: 0 4px 12px var(--shadow-color);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--ai-message-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.card-header h2, .card-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-text-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-tip {
    font-size: 14px;
    cursor: help;
    opacity: 0.7;
}

.symbol-input-small {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--chat-container-bg);
    color: var(--primary-text-color);
    font-size: 14px;
    width: 100px;
}

.fullscreen-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

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

/* 图表容器 - 匹配chart-container */
.chart-container {
    padding: 20px;
    min-height: 300px;
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow: hidden !important; /* 图表内部必须隐藏溢出 */
}

.chart-large {
    min-height: 500px;
}

/* 确保图表响应式 */
.chart-container > div {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
}

/* TradingView组件容器 - 强制约束尺寸，避免溢出 */
.tradingview-widget-container {
    width: 100% !important;
    height: 100% !important;
    min-height: 300px;
    max-width: 100% !important;
    overflow: hidden !important;
    border-radius: 8px;
    background-color: var(--chat-container-bg);
    position: relative !important;
}

.tradingview-widget-container__widget {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    position: relative !important;
}

.tradingview-widget-container iframe {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    border: none !important;
    border-radius: 8px;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
}

/* TradingView内部元素强制约束 */
.tradingview-widget-container *,
.tradingview-widget-container *::before,
.tradingview-widget-container *::after {
    max-width: 100% !important;
}

/* 阻止TradingView元素逃逸到容器外 */
.chart-card,
.data-card {
    transform: translateZ(0); /* 创建新的渲染层 */
    will-change: transform;
}

/* 特别约束各个TradingView组件 */
#stock-heatmap,
#market-overview,
#economic-calendar,
#advanced-chart {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
    position: relative !important;
}

#stock-heatmap *,
#market-overview *,
#economic-calendar *,
#advanced-chart * {
    max-width: 100% !important;
}

/* 阻止TradingView在body下创建额外元素和弹出层 */
body > div:not(.analysis-container):not(.fullscreen-container),
body > iframe {
    display: none !important;
}

/* 允许analysis-container内的所有元素 */
.analysis-container,
.analysis-container * {
    z-index: auto;
}

/* 全屏容器层级最高 */
.fullscreen-container {
    z-index: 9999 !important;
}

/* 右侧数据区域 - 匹配data-section */
.data-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-width: 0; /* 防止flex item溢出 */
}

.data-card {
    background-color: var(--chat-container-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.2s;
    resize: vertical; /* 允许手动调整高度 */
    max-height: 800px; /* 限制最大高度 */
    min-height: 300px; /* 限制最小高度 */
}

.data-card:hover {
    box-shadow: 0 4px 12px var(--shadow-color);
}

/* 标签页 - 匹配data-tabs-container */
.data-tabs-container {
    display: flex;
    flex-direction: column;
    height: 600px;
}

.tabs-nav {
    display: flex;
    background-color: var(--ai-message-bg);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    background: none;
    border: none;
    padding: 12px 16px;
    cursor: pointer;
    color: var(--secondary-text-color);
    font-size: 13px;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    white-space: nowrap;
    touch-action: manipulation;
    flex: 1;
    text-align: center;
}

.tab-btn:hover {
    color: var(--accent-color);
    background-color: rgba(74, 128, 255, 0.05);
}

.tab-btn.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
    font-weight: 600;
    background-color: var(--chat-container-bg);
}

/* 标签页内容 - 匹配tabs-content */
.tabs-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.tab-pane {
    display: none;
    flex: 1;
    overflow: hidden;
    flex-direction: column;
}

.tab-pane.active {
    display: flex;
}

.tab-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--ai-message-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.tab-header h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-text-color);
}

.refresh-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    min-height: 32px;
    touch-action: manipulation;
}

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

.tab-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.placeholder-text {
    text-align: center;
    color: var(--secondary-text-color);
    font-style: italic;
}

/* 高级功能区域 */
.advanced-section {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.advanced-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-text-color);
}

/* 列表容器 */
.news-list,
.insider-list,
.ipo-list {
    max-height: 400px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* 列表项样式 */
.news-item,
.insider-item,
.ipo-item {
    padding: 12px;
    margin-bottom: 8px;
    background-color: var(--chat-container-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s;
}

.news-item:hover,
.insider-item:hover,
.ipo-item:hover {
    box-shadow: 0 2px 8px var(--shadow-color);
    transform: translateY(-1px);
}

.news-item:last-child,
.insider-item:last-child,
.ipo-item:last-child {
    margin-bottom: 0;
}

/* 新闻项详细样式 */
.news-item {
    display: flex;
    gap: 12px;
}

.news-image {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

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

.news-title {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
}

.news-title a {
    color: var(--primary-text-color);
    text-decoration: none;
}

.news-title a:hover {
    color: var(--accent-color);
}

.news-summary {
    margin: 0 0 8px 0;
    font-size: 12px;
    color: var(--secondary-text-color);
    line-height: 1.4;
}

.news-meta {
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: var(--secondary-text-color);
}

/* 内幕交易样式 */
.insider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.insider-detail {
    margin: 4px 0;
    font-size: 12px;
    color: var(--secondary-text-color);
}

/* IPO项样式 */
.ipo-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.ipo-detail {
    margin: 4px 0;
    font-size: 12px;
    color: var(--secondary-text-color);
}

/* 徽章样式 */
.badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.badge.buy {
    background-color: var(--success-color);
    color: white;
}

.badge.sell {
    background-color: var(--error-color);
    color: white;
}

/* 通用文本样式 */
.loading-text {
    text-align: center;
    color: var(--secondary-text-color);
    padding: 2rem;
}

.error-text {
    text-align: center;
    color: var(--error-color);
    padding: 2rem;
}

/* 实时报价数据网格 */
.quote-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.quote-item {
    padding: 12px;
    background-color: var(--ai-message-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.quote-item .label {
    font-size: 12px;
    color: var(--secondary-text-color);
    margin-bottom: 4px;
}

.quote-item .value {
    font-size: 18px;
    font-weight: 600;
    color: var(--primary-text-color);
}

.quote-item .value.positive {
    color: var(--success-color);
}

.quote-item .value.negative {
    color: var(--error-color);
}

/* 公司信息网格 */
.company-info-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 12px;
    background-color: var(--ai-message-bg);
    border-radius: 6px;
}

.info-row .label {
    font-size: 13px;
    color: var(--secondary-text-color);
}

.info-row .value {
    font-size: 13px;
    font-weight: 500;
    color: var(--primary-text-color);
    text-align: right;
}

/* 公司Logo */
.company-logo {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin: 0 auto 16px;
    display: block;
    border-radius: 8px;
    background-color: var(--ai-message-bg);
    padding: 8px;
}

/* 公司详情 */
.company-info {
    text-align: center;
}

.company-info h4 {
    margin: 0 0 12px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-text-color);
}

.company-detail {
    margin: 8px 0;
    font-size: 13px;
    color: var(--secondary-text-color);
}

.company-link {
    display: inline-block;
    margin-top: 12px;
    padding: 8px 16px;
    background-color: var(--accent-color);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 13px;
    transition: all 0.2s;
}

.company-link:hover {
    background-color: #3a6dd9;
}

/* 目标价网格 */
.target-price-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.target-item {
    padding: 12px;
    background-color: var(--ai-message-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.target-item .label {
    font-size: 12px;
    color: var(--secondary-text-color);
    margin-bottom: 4px;
    display: block;
}

.target-item .value {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-text-color);
}

.target-item .value.price {
    color: var(--accent-color);
}

/* 全屏模态框 */
.fullscreen-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: none;
}

.fullscreen-container.active {
    display: flex;
    flex-direction: column;
}

.fullscreen-header {
    padding: 20px;
    background-color: var(--chat-container-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.fullscreen-header h3 {
    margin: 0;
    color: var(--primary-text-color);
}

.fullscreen-close-btn {
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.fullscreen-close-btn:hover {
    opacity: 0.8;
}

.fullscreen-content {
    flex: 1;
    padding: 20px;
    overflow: auto;
}

/* 响应式设计 - 与主界面保持一致 */
@media (max-width: 1400px) {
    .content-wrapper {
        grid-template-columns: 2fr 1fr;
    }
}

@media (max-width: 1200px) {
    .content-wrapper {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .data-section {
        order: -1;
    }

    .data-tabs-container {
        height: 400px;
    }
}

@media (min-width: 769px) and (max-width: 1200px) {
    .analysis-container {
        width: 95%;
    }
    
    .content-wrapper {
        padding: 20px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 0;
        align-items: stretch;
    }

    .analysis-container {
        width: 100%;
        border-radius: 0;
        max-width: none;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
    }

    .analysis-header {
        padding: 12px 16px;
        flex-shrink: 0;
    }

    .header-left h1 {
        font-size: 16px;
    }

    .search-section {
        padding: 12px 16px;
        flex-shrink: 0;
    }

    .search-box {
        gap: 8px;
    }

    #symbol-input {
        font-size: 16px; /* 防止iOS自动缩放 */
        padding: 10px;
    }

    .content-wrapper {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 12px;
        overflow: visible;
    }

    .charts-section {
        gap: 12px;
        overflow: visible;
    }

    .chart-card {
        border-radius: 8px;
        resize: vertical; /* 移动端也支持调整高度 */
        min-height: 250px; /* 移动端最小高度 */
        max-height: 600px; /* 移动端最大高度 */
    }

    .data-card {
        resize: vertical; /* 移动端也支持调整高度 */
        min-height: 250px; /* 移动端最小高度 */
        max-height: 600px; /* 移动端最大高度 */
    }

    .card-header {
        padding: 10px 12px;
    }

    .card-header h2, .card-header h3 {
        font-size: 13px;
    }

    .chart-container {
        padding: 12px;
        min-height: 200px;
        height: auto;
    }

    .chart-large {
        min-height: 250px;
        height: auto;
    }

    .tradingview-widget-container {
        min-height: 200px !important;
        max-height: 250px !important;
        height: auto !important;
    }

    /* 为TradingView iframe设置合理的高度 */
    .tradingview-widget-container__widget {
        min-height: 200px !important;
        max-height: 250px !important;
        height: auto !important;
    }

    .tradingview-widget-container__widget iframe {
        min-height: 200px !important;
        max-height: 250px !important;
        height: auto !important;
    }

    .data-section {
        gap: 12px;
    }

    .data-tabs-container {
        min-height: 250px;
        max-height: 300px;
    }

    .tabs-nav {
        -webkit-overflow-scrolling: touch;
    }

    .tab-btn {
        padding: 8px 10px;
        font-size: 11px;
    }

    .tab-header {
        padding: 10px 12px;
    }

    .tab-header h3, .tab-header h4 {
        font-size: 13px;
    }

    .tab-body {
        padding: 12px;
        max-height: 220px;
        overflow-y: auto;
    }

    .quick-symbols {
        gap: 6px;
    }

    .symbol-tag {
        font-size: 11px;
        padding: 4px 8px;
    }
    
    /* 移动端列表和网格 */
    .quote-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .quote-item {
        padding: 8px 10px;
    }
    
    .quote-item .value {
        font-size: 14px;
    }
    
    .news-list,
    .insider-list,
    .ipo-list {
        max-height: 200px;
        overflow-y: auto;
    }

    .news-item,
    .insider-item,
    .ipo-item {
        padding: 10px 0;
    }
    
    .company-info-grid {
        gap: 8px;
    }
    
    .info-row {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .company-logo {
        width: 50px;
        height: 50px;
    }
    
    .advanced-section {
        margin-bottom: 16px;
        padding-bottom: 12px;
    }

    /* 经济日历卡片优化 */
    #economic-calendar .card-header {
        padding: 10px 12px;
    }

    #economic-calendar .tradingview-widget-container {
        min-height: 200px !important;
        max-height: 250px !important;
    }
}