/**
 * 伊伊爱人工智能客服 - 主样式文件
 * 包含完整的浏览器兼容性支持
 */

/* 基础重置和全局样式 */
* {
    margin: 0;
    padding: 0;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    /* 渐变背景 - 添加前缀和降级 */
    background: #667eea; /* 降级方案 */
    background: -webkit-linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background: -moz-linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background: -o-linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    /* Flexbox兼容性 */
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -moz-box-orient: vertical;
    -moz-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
}

/* 头部样式 */
.header {
    background: rgba(255, 255, 255, 0.1);
    /* Backdrop-filter兼容性 - 添加前缀和降级 */
    background: rgba(255, 255, 255, 0.15); /* 降级方案：稍微增加不透明度 */
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    padding: 1rem 0;
    text-align: center;
    color: white;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

/* 容器布局 */
.container {
    max-width: 96vw;
    margin: 0 auto;
    padding: 2rem;
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -moz-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    gap: 2rem;
    /* IE降级方案 - 使用margin替代gap */
}

/* IE降级：为子元素添加margin */
.container > * {
    margin-right: 2rem;
}

.container > *:last-child {
    margin-right: 0;
}

/* 聊天面板 */
.chat-panel {
    width: 100%;
    -webkit-box-flex: 2;
    -webkit-flex: 2;
    -moz-box-flex: 2;
    -ms-flex: 2;
    flex: 2;
    background: white;
    /* Border-radius兼容性 */
    -webkit-border-radius: 12px;
    -moz-border-radius: 12px;
    border-radius: 12px;
    /* Box-shadow兼容性 */
    -webkit-box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    -moz-box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -moz-box-orient: vertical;
    -moz-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    /* Calc兼容性 */
    height: -webkit-calc(100vh - 142px);
    height: -moz-calc(100vh - 142px);
    height: calc(100vh - 142px);
    width: (100vw - 64px);
}

/* 信息面板 */
.info-panel {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -moz-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    background: white;
    -webkit-border-radius: 12px;
    -moz-border-radius: 12px;
    border-radius: 12px;
    -webkit-box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    -moz-box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    height: fit-content;
}

/* 聊天头部 */
.chat-header {
    padding: 1.5rem;
    border-bottom: 1px solid #eee;
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -moz-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    gap: 1rem;
}

/* IE降级：为chat-header子元素添加margin */
.chat-header > * {
    margin-right: 1rem;
}

.chat-header > *:last-child {
    margin-right: 0;
}

/* 状态指示器 */
.status-dot {
    width: 12px;
    height: 12px;
    background: #4CAF50;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border-radius: 50%;
    -webkit-animation: pulse 2s infinite;
    -moz-animation: pulse 2s infinite;
    -o-animation: pulse 2s infinite;
    animation: pulse 2s infinite;
}

/* 动画兼容性 - 添加前缀 */
@-webkit-keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

@-moz-keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

@-o-keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* 聊天消息区域 */
.chat-messages {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -moz-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -moz-box-orient: vertical;
    -moz-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    gap: 1rem;
}

/* IE降级：为chat-messages子元素添加margin */
.chat-messages > * {
    margin-bottom: 1rem;
}

.chat-messages > *:last-child {
    margin-bottom: 0;
}

/* 消息样式 */
.message {
    max-width: 80%;
    padding: 0.75rem 1rem;
    -webkit-border-radius: 18px;
    -moz-border-radius: 18px;
    border-radius: 18px;
    word-wrap: break-word;
}

.message.user {
    -webkit-align-self: flex-end;
    -ms-flex-item-align: end;
    align-self: flex-end;
    background: #007AFF;
    color: white;
}

.message.bot {
    -webkit-align-self: flex-start;
    -ms-flex-item-align: start;
    align-self: flex-start;
    background: #f0f0f0;
    color: #333;
}

.message.result {
    align-self: flex-start;
    background: #e8f5e8;
    color: #2d5a2d;
    max-width: 100%;
    font-family: monospace;
    white-space: pre-wrap;
}

.message.expression {
    align-self: flex-start;
    background: #f0f8ff;
    color: #1e3a8a;
    max-width: 100%;
    font-family: 'Courier New', monospace;
    white-space: pre-wrap;
    border-left: 4px solid #3b82f6;
    font-size: 14px;
}

/* Markdown渲染样式 */
.markdown-content {
    line-height: 1;
}

.markdown-content h1, .markdown-content h2, .markdown-content h3 {
    margin: 0.5em 0;
    color: #333;
}

.markdown-content h1 { font-size: 1.5em; }
.markdown-content h2 { font-size: 1.3em; }
.markdown-content h3 { font-size: 1.1em; }

.markdown-content p {
    margin: 0.5em 0;
}

.markdown-content code {
    background: #f4f4f4;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.markdown-content pre {
    background: #f8f8f8;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 1em;
    overflow-x: auto;
    margin: 0.5em 0;
}

.markdown-content pre code {
    background: none;
    padding: 0;
}

.markdown-content blockquote {
    border-left: 4px solid #ddd;
    margin: 0.5em 0;
    padding-left: 1em;
    color: #666;
}

.markdown-content ul, .markdown-content ol {
    margin: 0em 0 0em 1.5em;
}

.markdown-content li {
    margin: 0.2em 0;
}

/* 表格样式 */
.markdown-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0; /* 移除margin，因为容器已经有了 */
    min-width: 300px; /* 确保表格有最小宽度 */
    border: none; /* 移除表格外边框，使用容器边框 */
}

/* 表格容器，支持水平滚动 */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* iOS平滑滚动 */
    margin: 0.5em 0;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
}

/* 表格容器滚动条样式 */
.table-container::-webkit-scrollbar {
    height: 6px;
}

.table-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.table-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.markdown-content th, .markdown-content td {
    border: 1px solid #ddd;
    padding: 8px 12px;
    text-align: left;
}

.markdown-content th {
    background-color: #f2f2f2;
    font-weight: bold;
}

.markdown-content tr:nth-child(even) {
    background-color: #f9f9f9;
}

.markdown-content a {
    color: #007AFF;
    text-decoration: none;
}

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

.markdown-content strong {
    font-weight: bold;
}

.markdown-content em {
    font-style: italic;
}

/* 输入区域 */
.chat-input {
    padding: 1.5rem;
    border-top: 1px solid #eee;
    display: flex;
    gap: 1rem;
}

.input-group {
    flex: 1;
    display: flex;
    gap: 0.5rem;
}

/* 输入框样式 */
input[type="text"] {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -moz-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid #ddd;
    -webkit-border-radius: 25px;
    -moz-border-radius: 25px;
    border-radius: 25px;
    outline: none;
    font-size: 16px;
}

input[type="text"]:focus {
    border-color: #007AFF;
}

/* 按钮样式 */
button {
    padding: 0.75rem 1.5rem;
    background: #007AFF;
    color: white;
    border: none;
    -webkit-border-radius: 25px;
    -moz-border-radius: 25px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 16px;
    -webkit-transition: background 0.3s;
    -moz-transition: background 0.3s;
    -o-transition: background 0.3s;
    transition: background 0.3s;
}

button:hover {
    background: #0056CC;
}

button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* 信息区域样式 */
.info-section {
    margin-bottom: 2rem;
}

.info-section h3 {
    color: #333;
    margin-bottom: 1rem;
    font-size: 18px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid #eee;
}

/* 加载动画 */
.loading {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #ddd;
    border-top: 2px solid #007AFF;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border-radius: 50%;
    -webkit-animation: spin 1s linear infinite;
    -moz-animation: spin 1s linear infinite;
    -o-animation: spin 1s linear infinite;
    animation: spin 1s linear infinite;
}

@-webkit-keyframes spin {
    0% { -webkit-transform: rotate(0deg); }
    100% { -webkit-transform: rotate(360deg); }
}

@-moz-keyframes spin {
    0% { -moz-transform: rotate(0deg); }
    100% { -moz-transform: rotate(360deg); }
}

@-o-keyframes spin {
    0% { -o-transform: rotate(0deg); }
    100% { -o-transform: rotate(360deg); }
}

@keyframes spin {
    0% { 
        -webkit-transform: rotate(0deg);
        -moz-transform: rotate(0deg);
        -o-transform: rotate(0deg);
        transform: rotate(0deg); 
    }
    100% { 
        -webkit-transform: rotate(360deg);
        -moz-transform: rotate(360deg);
        -o-transform: rotate(360deg);
        transform: rotate(360deg); 
    }
}

/* 示例查询样式 */
.example-queries {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.example-query {
    padding: 0.5rem 1rem;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.example-query:hover {
    background: #e9ecef;
    border-color: #007AFF;
}

/* Loading动画样式 */
.loading-dots {
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

.loading-text {
    margin-right: 0.5rem;
}

.loading-dots .dot {
    -webkit-animation: loading-bounce 1.4s infinite ease-in-out;
    -moz-animation: loading-bounce 1.4s infinite ease-in-out;
    -o-animation: loading-bounce 1.4s infinite ease-in-out;
    animation: loading-bounce 1.4s infinite ease-in-out;
    font-weight: bold;
    font-size: 1.2em;
}

.loading-dots .dot:nth-child(2) {
    -webkit-animation-delay: 0.2s;
    -moz-animation-delay: 0.2s;
    -o-animation-delay: 0.2s;
    animation-delay: 0.2s;
}

.loading-dots .dot:nth-child(3) {
    -webkit-animation-delay: 0.4s;
    -moz-animation-delay: 0.4s;
    -o-animation-delay: 0.4s;
    animation-delay: 0.4s;
}

.loading-dots .dot:nth-child(4) {
    -webkit-animation-delay: 0.6s;
    -moz-animation-delay: 0.6s;
    -o-animation-delay: 0.6s;
    animation-delay: 0.6s;
}

@-webkit-keyframes loading-bounce {
    0%, 80%, 100% {
        opacity: 0.3;
        -webkit-transform: scale(1);
    }
    40% {
        opacity: 1;
        -webkit-transform: scale(1.2);
    }
}

@-moz-keyframes loading-bounce {
    0%, 80%, 100% {
        opacity: 0.3;
        -moz-transform: scale(1);
    }
    40% {
        opacity: 1;
        -moz-transform: scale(1.2);
    }
}

@-o-keyframes loading-bounce {
    0%, 80%, 100% {
        opacity: 0.3;
        -o-transform: scale(1);
    }
    40% {
        opacity: 1;
        -o-transform: scale(1.2);
    }
}

@keyframes loading-bounce {
    0%, 80%, 100% {
        opacity: 0.3;
        -webkit-transform: scale(1);
        -moz-transform: scale(1);
        -o-transform: scale(1);
        transform: scale(1);
    }
    40% {
        opacity: 1;
        -webkit-transform: scale(1.2);
        -moz-transform: scale(1.2);
        -o-transform: scale(1.2);
        transform: scale(1.2);
    }
}

/* 打字机效果样式 */
.typing-cursor {
    color: #007AFF;
    -webkit-animation: cursor-blink 1s infinite;
    -moz-animation: cursor-blink 1s infinite;
    -o-animation: cursor-blink 1s infinite;
    animation: cursor-blink 1s infinite;
    font-weight: normal;
}

@-webkit-keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

@-moz-keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

@-o-keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

@keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Loading消息特殊样式 */
.loading-message {
    background: #f8f9fa !important;
    border: 1px dashed #dee2e6;
    -webkit-animation: loading-pulse 2s infinite ease-in-out;
    -moz-animation: loading-pulse 2s infinite ease-in-out;
    -o-animation: loading-pulse 2s infinite ease-in-out;
    animation: loading-pulse 2s infinite ease-in-out;
}

@-webkit-keyframes loading-pulse {
    0%, 100% { background-color: #f8f9fa; }
    50% { background-color: #e9ecef; }
}

@-moz-keyframes loading-pulse {
    0%, 100% { background-color: #f8f9fa; }
    50% { background-color: #e9ecef; }
}

@-o-keyframes loading-pulse {
    0%, 100% { background-color: #f8f9fa; }
    50% { background-color: #e9ecef; }
}

@keyframes loading-pulse {
    0%, 100% { background-color: #f8f9fa; }
    50% { background-color: #e9ecef; }
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        -webkit-box-orient: vertical;
        -webkit-box-direction: normal;
        -webkit-flex-direction: column;
        -moz-box-orient: vertical;
        -moz-box-direction: normal;
        -ms-flex-direction: column;
        flex-direction: column;
        padding: 1rem;
    }
    
    .chat-panel {
        height: -webkit-calc(100vh - 142px);
        height: -moz-calc(100vh - 142px);
        height: calc(100vh - 142px);
    }
    
    /* 移动端表格优化 */
    .markdown-content table {
        font-size: 14px; /* 稍微减小字体 */
        min-width: 400px; /* 增加最小宽度确保可读性 */
    }
    
    .markdown-content th, .markdown-content td {
        padding: 6px 8px; /* 减小内边距以节省空间 */
        white-space: nowrap; /* 防止文字换行 */
    }
    
    .table-container {
        max-width: 500px;
    }
    
    /* 表格滚动提示 */
    .table-container::after {
        content: "← 左右滑动查看更多 →";
        display: block;
        text-align: center;
        font-size: 12px;
        color: #999;
        margin-top: 5px;
        font-style: italic;
    }
}

/* IE兼容性检测和降级方案 */
.no-flexbox .container {
    display: block;
}

.no-flexbox .chat-panel {
    width: 65%;
    float: left;
    margin-right: 2%;
}

.no-flexbox .info-panel {
    width: 33%;
    float: right;
}

.no-flexbox .chat-messages {
    display: block;
}

.no-flexbox .message.user {
    float: right;
    clear: both;
}

.no-flexbox .message.bot {
    float: left;
    clear: both;
}

.no-flexbox .chat-input {
    display: block;
}

.no-flexbox .input-group {
    display: block;
}

.no-flexbox input[type="text"] {
    width: 70%;
    display: inline-block;
    vertical-align: top;
}

.no-flexbox button {
    width: 25%;
    display: inline-block;
    vertical-align: top;
    margin-left: 2%;
}

/* 清除浮动 */
.no-flexbox .container:after,
.no-flexbox .chat-messages:after,
.no-flexbox .chat-input:after {
    content: "";
    display: table;
    clear: both;
}
