/* AIAStock 响应式布局样式 */

/* 注销：移除复杂的header响应式代码 - 新的header结构自适应所有设备 */
/* 
@media (max-width: 768px) {
    .header-left {
        flex: 0 0 45px !important;
    }
    .logo {
        width: 36px !important;
        height: 36px !important;
        font-size: 20px !important;
    }
    .center-controls.collapsed {
        left: 5px;
    }
    .header-center.collapsed .input-news-ticker {
        left: 60px;
        right: 10px;
    }
}

@media (max-width: 480px) {
    .center-controls.collapsed .ai-analysis-btn {
        padding: 8px 12px;
        min-width: 40px;
        font-size: 12px;
    }
    .header-center.collapsed .input-news-ticker {
        left: 50px;
        right: 5px;
        height: 40px;
    }
}
*/

/* 主内容区域基础样式 */
.main-content {
    flex: 1;
    /* padding: 20px; */ /* COMMENTED OUT: Conflicts with mobile_spacing_unified.css system */
    overflow-x: hidden; overflow-y: auto; /* 🚨 HARD RULE: 가로 스크롤 절대 금지 */
    background: #0f172a;
}

.content-wrapper {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* 动态面板容器 */
.dynamic-panels-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    min-height: 300px;
}

.dynamic-panel {
    transition: all 0.3s ease;
}

/* 静态面板容器 */
.static-panel-container {
    width: 100%;
    min-height: 380px;
    height: auto; /* 改为auto，让内容决定高度 */
    min-height: 600px; /* 为多面板提供更多空间 */
}

/* 确保面板在静态区域内正确显示 */
#static-panels-area {
    width: 100%;
    min-height: 400px;
    height: auto; /* 让内容决定高度 */
    display: block; /* 改为block，让子元素决定布局方式 */
    position: relative;
    z-index: 1;
}

/* 单面板模式下的居中显示 */
#static-panels-area:not(.multi-panel-mode) {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 多面板模式下确保容器可以显示grid布局 */
#static-panels-area.multi-panel-mode {
    display: block !important;
    align-items: unset !important;
    justify-content: unset !important;
}

/* 全屏模式 */
.panel-fullscreen {
    position: fixed !important;
    top: 64px !important;
    left: 64px !important;
    right: 0 !important;
    bottom: 0 !important;
    width: auto !important;
    height: auto !important;
    z-index: 999;
    margin: 0 !important;
    background: rgba(15, 23, 42, 0.98);
}

.panel-fullscreen .panel-body {
    height: calc(100% - 50px) !important;
}

/* PC端布局 (>1200px) */
@media (min-width: 1200px) {
    .content-wrapper {
        flex-direction: row;
        align-items: flex-start;
    }

    .dynamic-panels-container {
        display: grid !important;  /* 桌面端强制显示赛马面板 */
        flex: 0 0 45%;
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .static-panel-container {
        flex: 1;
        margin-left: 20px;
    }

    .dynamic-panel {
        height: 380px;
    }
}

/* 平板布局 (768px - 1199px) */
@media (min-width: 768px) and (max-width: 1199px) {
    .main-content {
        /* padding: 15px; */ /* COMMENTED OUT: Conflicts with mobile_spacing_unified.css system */
    }

    /* 注销：平板端header代码移至统一结构 */
    /* .header-center { flex: 1 !important; min-width: 0 !important; overflow: hidden !important; } */
    /* #simpleNews { font-size: 13px !important; } */
        overflow: hidden !important;
    }

    .dynamic-panels-container {
        display: grid !important;  /* 平板端强制显示赛马面板 */
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .dynamic-panel {
        height: 300px;
    }

    .panel-template {
        width: 100% !important;
        max-width: 600px;
        margin: 0 auto;
    }
}

/* 手机布局 (<768px) */
@media (max-width: 767px) {
    /* 🔧 修复：保持sidebar在左侧，不改变main-container的flex-direction */
    .main-container {
        flex-direction: row; /* 保持水平布局，sidebar始终在左侧 */
    }

    /* Header新闻滚动响应式修复 */
    .header-center {
        flex: 1 !important;
        min-width: 0 !important; /* 防止内容溢出 */
        overflow: hidden !important;
    }

    #simpleNews {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        overflow: hidden !important;
        font-size: 12px !important; /* 移动端字体稍小 */
    }

    /* 修复新闻滚动动画在移动端的显示 */
    #simpleNews > div {
        max-width: none !important;
        white-space: nowrap !important;
    }

    /* 显示header右侧的Sidebar切换按钮 */
    .mobile-sidebar-toggle {
        display: flex !important;
    }

    /* 显示手机模式下拉导航菜单 */
    .mobile-nav-dropdown {
        display: block !important;
    }

    /* 🔧 修复：移除错误的sidebar位置调整 - 保持原有布局 */

    /* 手机模式下的遮罩层 */
    .mobile-sidebar-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease-in-out;
    }

    .mobile-sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    .content-wrapper {
        gap: 15px;
    }

    /* 移动端隐藏动态面板 - 只在真正的小屏幕上隐藏 */
    .dynamic-panels-container {
        display: none !important;
    }

    /* 显示动态面板时 */
    .dynamic-panels-container.mobile-show {
        display: grid !important;
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .dynamic-panel {
        height: 280px;
    }

    .panel-template {
        width: 100% !important;
        height: auto !important;
        min-height: 300px;
    }

    .panel-body {
        height: 250px !important;
    }

    .panel-fullscreen {
        left: 0 !important;
        bottom: 60px !important;
        top: 64px !important;
    }

    /* 新闻滚动条移动端优化 */
    .news-ticker-container {
        font-size: 14px;
    }

    /* Header移动端优化 */
    .header {
        padding: 0 15px;
    }

    .center-controls {
        flex: 1;
    }

    .input-group {
        display: flex;
        gap: 8px;
        width: 100%;
    }

    .stock-input {
        flex: 1;
        min-width: 0;
    }
}

/* 超小屏幕 (<480px) */
@media (max-width: 480px) {
    .header {
        padding: 0 10px;
    }

    /* 超小屏幕下的新闻滚动优化 */
    #simpleNews {
        font-size: 11px !important; /* 更小的字体 */
        line-height: 36px !important; /* 调整行高适应更小的header */
    }

    .header-center {
        min-width: 0 !important;
        overflow: hidden !important;
    }

    .logo svg {
        width: 36px;
        height: 36px;
    }

    .stock-input {
        width: 120px;
        font-size: 14px;
        padding: 6px 10px;
    }

    .ai-analysis-btn {
        padding: 6px 12px;
        font-size: 14px;
    }

    .panel-header h3 {
        font-size: 16px;
    }

    .data-table {
        font-size: 12px;
    }

    .data-table th,
    .data-table td {
        padding: 6px;
    }

    .nav-item {
        width: 40px;
        height: 40px;
        margin: 4px;
    }

    .nav-icon svg {
        width: 20px;
        height: 20px;
    }
}

/* 横屏模式优化 */
@media (orientation: landscape) and (max-height: 600px) {
    .header {
        height: 50px !important;
    }

    .dynamic-panel {
        height: calc(100vh - 120px);
    }

    .panel-body {
        height: calc(100% - 36px) !important;
    }

    .sidebar {
        height: 50px;
    }

    .nav-item {
        width: 40px;
        height: 40px;
    }
}

/* 原移动端显示切换按钮已移除，改用header右侧的sidebar切换按钮 */

/* 平板端优化导航提示 */
@media (min-width: 768px) and (max-width: 1199px) {
    .nav-item {
        position: relative;
    }

    .nav-item::after {
        content: attr(data-tooltip);
        position: absolute;
        left: 100%;
        top: 50%;
        transform: translateY(-50%);
        margin-left: 10px;
        background: rgba(0, 0, 0, 0.8);
        color: white;
        padding: 4px 8px;
        border-radius: 4px;
        font-size: 12px;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }

    .nav-item:hover::after {
        opacity: 1;
    }
}

/* 确保图表在各种屏幕上正确显示 */
.chart-container {
    width: 100% !important;
    height: 100% !important;
    min-height: 200px;
}

/* 响应式字体大小 */
@media (max-width: 1199px) {
    html {
        font-size: 15px;
    }
}

@media (max-width: 767px) {
    html {
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 13px;
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .nav-item {
        -webkit-tap-highlight-color: transparent;
    }

    .panel-action,
    .ai-analysis-btn,
    button {
        min-height: 44px;
        min-width: 44px;
    }
}

/* 多选面板样式 */
.nav-item.active {
    background: #6366f1;
    color: white;
    position: relative;
}

/* 多选时的面板尺寸调整 */
.multi-panel-mode .panel-template {
    width: 100% !important;
    min-width: 320px;
    max-width: 417.33px;
    height: 340px !important;
}

.multi-panel-mode .panel-header {
    height: 36px !important;
}

.multi-panel-mode .panel-body {
    height: calc(100% - 36px) !important;
}

/* 多选提示 */
.multi-select-hint {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(99, 102, 241, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.multi-select-hint.show {
    opacity: 1;
}

/* 多面板容器基础样式 - 与style.css中的grid布局保持一致 */
.multi-panel-container {
    width: 100%;
    height: 100%;
    /* display属性由style.css中的grid样式决定，这里不重复定义 */
    gap: 15px;
    padding: 10px;
    box-sizing: border-box;
}

.panel-wrapper {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 2个面板布局 */
.panel-count-2.desktop-layout {
    flex-direction: row;
}

.panel-count-2.mobile-layout {
    flex-direction: column;
    overflow-y: auto;
}

/* 3个面板布局 */
.panel-count-3.desktop-layout {
    flex-direction: row;
}

.panel-count-3.tablet-layout {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
}

/* 강제 전체 너비 제거 */

.panel-count-3.mobile-layout {
    flex-direction: column;
    overflow-y: auto;
}

/* 4个面板网格布局 */
.panel-count-4.grid-layout {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

/* 5개 패널 - 자연스러운 플로우 (강제 레이아웃 제거) */

.panel-count-5.mobile-layout {
    flex-direction: column;
    overflow-y: auto;
}

/* 6个面板布局 */
.panel-count-6.grid-layout {
    display: grid;
}

.panel-count-6.desktop-grid {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

.panel-count-6.tablet-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(3, 1fr);
}

.panel-count-6.mobile-layout {
    flex-direction: column;
    overflow-y: auto;
}

/* 🚨 HARD RULE: 多面板模式必须保持Panel统一尺寸 417.33px × 380px */
.multi-panel-mode .panel-template {
    width: 417.33px !important;
    height: 380px !important;
    max-width: 417.33px !important;
    min-width: 417.33px !important;
    max-height: 380px !important;
    min-height: 380px !important;
}

/* 🚨 HARD RULE: 手机端不得修改Panel内部尺寸 - 只能调整容器 */
@media (max-width: 767px) {
    .multi-panel-container {
        gap: 15px;
        padding: 5px;
        /* 只修改容器间距，不修改Panel */
    }
    
    /* 🚨 禁止修改Panel尺寸 - Panel必须保持417.33px × 380px */
    .mobile-layout .panel-template {
        width: 417.33px !important;
        height: 380px !important;
        /* 禁止任何尺寸修改 */
    }
    
    .mobile-layout .panel-header {
        height: 30px !important; /* 保持标准高度 */
    }
    
    .mobile-layout .panel-body {
        height: calc(380px - 30px) !important; /* 固定计算，不响应 */
        /* 字体大小可调整，但不修改容器 */
        font-size: 12px;
    }
}

/* 平板端多面板样式 */
@media (min-width: 768px) and (max-width: 1199px) {
    .multi-panel-container {
        gap: 15px;
    }
    
    .tablet-layout .panel-template,
    .grid-layout .panel-template {
        height: 320px !important;
    }
    
    .tablet-layout .panel-header,
    .grid-layout .panel-header {
        height: 36px !important;
    }
    
    .tablet-layout .panel-body,
    .grid-layout .panel-body {
        height: calc(100% - 36px) !important;
    }
}

/* 桌面端多面板样式 */
@media (min-width: 1200px) {
    /* 2个面板 */
    .panel-count-2 .panel-template {
        max-width: 600px;
        height: 380px !important;
    }
    
    /* 3个面板 */
    .panel-count-3 .panel-template {
        max-width: 420px;
        height: 360px !important;
    }
    
    /* 4个面板 */
    .panel-count-4 .panel-template {
        height: 340px !important;
    }
    
    /* 5个面板 */
    .panel-count-5 .panel-template {
        height: 320px !important;
    }
    
    /* 6个面板 */
    .panel-count-6 .panel-template {
        height: 300px !important;
    }
    
    /* 调整标题和内容高度 */
    .panel-count-4 .panel-header,
    .panel-count-5 .panel-header,
    .panel-count-6 .panel-header {
        height: 36px !important;
        font-size: 14px;
    }
    
    .panel-count-4 .panel-body,
    .panel-count-5 .panel-body,
    .panel-count-6 .panel-body {
        height: calc(100% - 36px) !important;
    }
}

/* 确保图表在多面板模式下正确显示 */
.multi-panel-mode .chart-container {
    width: 100% !important;
    height: 100% !important;
}

/* 滚动条优化 */
.mobile-layout::-webkit-scrollbar {
    width: 4px;
}

.mobile-layout::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

/* 面板内容缩放 */
.panel-count-5 .data-table,
.panel-count-6 .data-table {
    font-size: 11px;
}

.panel-count-5 .data-table th,
.panel-count-5 .data-table td,
.panel-count-6 .data-table th,
.panel-count-6 .data-table td {
    padding: 4px;
}

/* 打印样式 */
@media print {
    .sidebar,
    .header {
        display: none !important;
    }

    .main-content {
        padding: 0;
    }

    .panel-template {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}