/* AI 聊天通用样式 - 供 index.php 和 view.php 共用 */

.main-content {
    height: 100%;
}

.chat-card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 480px;
    overflow: hidden;
}

.chat-header {
    padding: 18px 24px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 10px 10px 0 0;
}

.chat-header h2 {
    font-size: 17px;
    color: #333;
    margin: 0;
    font-weight: 600;
}

.chat-header .meta {
    font-size: 12px;
    color: #888;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: #f8f9fa;
}

.message {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #fff;
    flex-shrink: 0;
    margin: 0 12px;
}

img.message-avatar {
    object-fit: cover;
    padding: 0;
}

.message.user .message-avatar {
    background: #1c499e;
    order: 2;
    margin-right: 0;
}

.message.assistant .message-avatar {
    background: #fff;
    margin-left: 0;
    padding: 0;
    overflow: hidden;
    border: 2px solid #1c499e;
}

.message-body {
    display: flex;
    flex-direction: column;
    max-width: 70%;
}

.message.user .message-body {
    align-items: flex-end;
}

.message.assistant .message-body {
    align-items: flex-start;
}

.message-content {
    position: relative;
    padding: 12px 16px;
    padding-right: 40px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}

.copy-btn {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: #bbb;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.2s;
    font-size: 12px;
}

.copy-btn::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: #333;
    color: #fff;
    font-size: 11px;
    font-weight: normal;
    line-height: 1;
    white-space: nowrap;
    border-radius: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 10;
}

.copy-btn::before {
    content: "";
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: #333;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 10;
}

.copy-btn:hover::after,
.copy-btn:hover::before {
    opacity: 1;
}

.message-content:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #1c499e;
}

.copy-btn.copied {
    color: #27ae60;
    opacity: 1;
}

.copy-btn.copied::after {
    content: attr(data-tip-done);
    background: #27ae60;
}

.copy-btn.copied::before {
    border-top-color: #27ae60;
}

.message.user .message-content {
    background: #f0f0f0;
    color: #333;
    border: 1px solid #e8e8e8;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: #fff;
    color: #333;
    border: 1px solid #e8e8e8;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: #aaa;
    margin-top: 6px;
}

.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid #f0f0f0;
    background: #fff;
    border-radius: 0 0 10px 10px;
}

.chat-input-wrap {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-input-wrap textarea {
    flex: 1;
    min-height: 46px;
    max-height: 200px;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.6;
    resize: none;
    overflow-y: hidden;
    font-family: inherit;
}

.chat-input-wrap textarea:focus {
    outline: none;
    border-color: #1c499e;
}

.chat-input-wrap textarea::-webkit-scrollbar {
    width: 6px;
}

.chat-input-wrap textarea::-webkit-scrollbar-thumb {
    background: #c0c4cc;
    border-radius: 3px;
}

.chat-input-wrap button {
    padding: 12px 24px;
    background: #1c499e;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.chat-input-wrap button:hover {
    opacity: 0.9;
}

.chat-input-wrap button:disabled {
    background: #a0aec0;
    cursor: not-allowed;
}

.send-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.char-counter {
    font-size: 12px;
    color: #999;
    line-height: 1;
    white-space: nowrap;
    user-select: none;
}

.char-counter.exceeded {
    color: #e74c3c;
    font-weight: 500;
}

.chat-toolbar {
    display: flex;
    gap: 6px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #f5f5f5;
    overflow-x: auto;
    flex-wrap: nowrap;
}

.chat-toolbar::-webkit-scrollbar {
    height: 4px;
}

.chat-toolbar::-webkit-scrollbar-thumb {
    background: #e0e0e0;
    border-radius: 2px;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    background: #f5f7fa;
    color: #666;
    border: 1px solid transparent;
    border-radius: 16px;
    font-size: 13px;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    cursor: pointer;
}

.toolbar-btn:hover {
    background: #eaf0fb;
    color: #1c499e;
    border-color: #d0daee;
}

.toolbar-role-select {
    padding: 5px 12px;
    background: #f5f7fa;
    color: #666;
    border: 1px solid transparent;
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.2s;
}

.toolbar-role-select:hover {
    background: #eaf0fb;
    color: #1c499e;
    border-color: #d0daee;
}

.toolbar-role-select:focus {
    outline: none;
    border-color: #1c499e;
}

.empty-tip {
    text-align: center;
    color: #aaa;
    padding: 60px 20px;
    font-size: 14px;
}

/* 角色选择器 */
.chat-role-selector {
    padding: 12px 24px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-role-selector select {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    color: #333;
    background: #fff;
    cursor: pointer;
}

.chat-role-selector select:focus {
    outline: none;
    border-color: #1c499e;
}

.chat-role-selector .role-hint {
    font-size: 12px;
    color: #888;
}

/* ===== Markdown 渲染样式 ===== */
.md-text {
    white-space: normal;
    word-wrap: break-word;
}

.md-text p {
    margin: 0 0 10px;
    line-height: 1.7;
}

.md-text p:last-child {
    margin-bottom: 0;
}

.md-text h1, .md-text h2, .md-text h3,
.md-text h4, .md-text h5, .md-text h6 {
    margin: 16px 0 10px;
    font-weight: 600;
    line-height: 1.4;
    color: #222;
}

.md-text h1 { font-size: 1.4em; }
.md-text h2 { font-size: 1.3em; }
.md-text h3 { font-size: 1.2em; }
.md-text h4 { font-size: 1.1em; }
.md-text h5 { font-size: 1em; }
.md-text h6 { font-size: 0.95em; }

.md-text h1:first-child, .md-text h2:first-child,
.md-text h3:first-child, .md-text h4:first-child,
.md-text h5:first-child, .md-text h6:first-child {
    margin-top: 0;
}

.md-text ul, .md-text ol {
    margin: 8px 0;
    padding-left: 24px;
}

.md-text ul { list-style: disc; }
.md-text ol { list-style: decimal; }

.md-text li {
    margin: 3px 0;
    line-height: 1.6;
}

.md-text li > ul, .md-text li > ol {
    margin: 3px 0;
}

.md-text strong {
    font-weight: 600;
    color: #222;
}

.md-text em {
    font-style: italic;
}

.md-text del {
    text-decoration: line-through;
    color: #999;
}

.md-text a {
    color: #1c499e;
    text-decoration: none;
    border-bottom: 1px solid rgba(28, 73, 158, 0.3);
    transition: border-color 0.2s;
}

.md-text a:hover {
    border-bottom-color: #1c499e;
}

.md-text blockquote {
    margin: 10px 0;
    padding: 8px 14px;
    border-left: 3px solid #1c499e;
    background: rgba(28, 73, 158, 0.05);
    color: #555;
    border-radius: 0 6px 6px 0;
}

.md-text blockquote p {
    margin: 0;
}

.md-text hr {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 16px 0;
}

/* 行内代码 */
.md-text code {
    padding: 1px 6px;
    margin: 0 2px;
    background: rgba(0, 0, 0, 0.06);
    color: #d6336c;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

/* 代码块 */
.md-text pre {
    margin: 12px 0;
    padding: 14px 16px;
    background: #2d2d2d;
    color: #e6e6e6;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.88em;
    line-height: 1.5;
}

.md-text pre code {
    padding: 0;
    margin: 0;
    background: transparent;
    color: inherit;
    border-radius: 0;
    font-size: inherit;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    white-space: pre;
}

/* 表格 */
.md-text .table-wrapper {
    overflow-x: auto;
    margin: 12px 0;
}

.md-text table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92em;
    margin: 12px 0;
}

.md-text th {
    background: #f0f2f5;
    font-weight: 600;
    text-align: left;
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    color: #333;
}

.md-text td {
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
}

.md-text tr:nth-child(even) td {
    background: #fafbfc;
}

.md-text img {
    max-width: 100%;
    border-radius: 6px;
    margin: 8px 0;
}

/* 任务列表 */
.md-text .task-list-item {
    list-style: none;
    margin-left: -20px;
}

.md-text input[type="checkbox"] {
    margin-right: 6px;
}

/* AI 生成的 HTML 内容样式 */
.message-content .md-text {
    display: block;
}

.message.assistant .message-content {
    white-space: normal;
}

.message.assistant .message-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 8px 0;
}

.message.assistant .message-content a {
    color: #1c499e;
    text-decoration: none;
    word-break: break-all;
}

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

.message.assistant .message-content div[style*="box-shadow"],
.message.assistant .message-content div[style*="border-radius"] {
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.message.assistant .message-content table {
    max-width: 100%;
    overflow-x: auto;
}

.message.assistant .message-content h1,
.message.assistant .message-content h2,
.message.assistant .message-content h3,
.message.assistant .message-content h4,
.message.assistant .message-content h5,
.message.assistant .message-content h6 {
    margin: 12px 0 8px;
    line-height: 1.4;
}

.message.assistant .message-content p {
    margin: 8px 0;
    line-height: 1.7;
}

.message.assistant .message-content ul,
.message.assistant .message-content ol {
    padding-left: 20px;
    margin: 8px 0;
}

.message.assistant .message-content ul { list-style: disc; }
.message.assistant .message-content ol { list-style: decimal; }

.message.assistant .message-content hr {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 12px 0;
}

.message.assistant .message-content code {
    background: rgba(0,0,0,0.06);
    color: #d6336c;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

.message.assistant .message-content pre {
    background: #2d2d2d;
    color: #e6e6e6;
    padding: 14px 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

.message.assistant .message-content pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    font-size: inherit;
}

.message.assistant .message-content blockquote {
    margin: 10px 0;
    padding: 8px 14px;
    border-left: 3px solid #1c499e;
    background: rgba(28,73,158,0.05);
    color: #555;
    border-radius: 0 6px 6px 0;
}

.message.assistant .message-content del {
    text-decoration: line-through;
    color: #999;
}

/* FAQ 消息徽章 */
.faq-badge { display: inline-block; font-size: 10px; font-weight: 600; color: #1c499e; background: #e8f0fe; padding: 1px 6px; border-radius: 3px; margin-right: 6px; vertical-align: middle; letter-spacing: 0.5px; }

/* ===== 动态在线状态图标 ===== */
.status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    background: #27ae60;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
    position: relative;
    flex-shrink: 0;
}

.status-dot::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: rgba(39, 174, 96, 0.3);
    animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    50% {
        transform: scale(1.6);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

.chat-header .title-wrap {
    display: flex;
    align-items: center;
}

/* ===== 加载动画（思考中） ===== */
.breath-dots {
    display: flex;
    gap: 10px;
    align-items: center;
    height: 20px;
}
.breath-dots span {
    width: 10px;
    height: 10px;
    background: #1c499e;
    border-radius: 50%;
    animation: breath 1.2s ease infinite;
}
.breath-dots span:nth-child(1) { animation-delay: 0s; }
.breath-dots span:nth-child(2) { animation-delay: 0.2s; }
.breath-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes breath {
    0%, 100% { transform: scale(0.6); opacity: 0.4; }
    50% { transform: scale(1.2); opacity: 1; }
}

/* ===== FAQ 常见问答面板 ===== */
.faq-panel {
    background: #fff;
    border-top: 1px solid #f0f0f0;
    border-bottom: 1px solid #f0f0f0;
    padding: 12px 24px;
    max-height: 200px;
    overflow-y: auto;
    animation: faqSlideDown 0.2s ease-out;
}

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

.faq-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.faq-panel-title {
    font-size: 13px;
    color: #1c499e;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.faq-panel-title::before {
    content: '💡';
    font-size: 14px;
}

.faq-panel-close {
    background: none;
    border: none;
    color: #999;
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.2s;
}

.faq-panel-close:hover {
    color: #666;
}

.faq-panel-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.faq-item {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    background: #f5f7fa;
    border: 1px solid #e8e8e8;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
    color: #333;
    max-width: 100%;
    box-sizing: border-box;
}

.faq-item:hover {
    background: #eaf0fb;
    border-color: #1c499e;
    color: #1c499e;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(28, 73, 158, 0.15);
}

.faq-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 280px;
}

/* ========================================================
   FAQ 卡片组件库（供 AI 生成的 HTML 复用，禁止内联 style）
   配色：主色 #1c499e / 成功 #2e7d32 / 警告 #ed6c02 / 危险 #c62828
   ======================================================== */

/* 卡片容器 */
.message-content .faq-card {
    border-radius: 10px;
    padding: 14px 16px;
    margin: 10px 0;
    box-sizing: border-box;
}

/* 卡片标题（左侧蓝色色条） */
.message-content .faq-card-title {
    font-size: 20px;
    font-weight: 600;
    color: #1c499e;
    margin: 0 0 20px;
    padding-left: 10px;
    border-left: 4px solid #1c499e;
    line-height: 1.4;
}

/* 卡片副标题 */
.message-content .faq-card-subtitle {
    font-size: 13px;
    color: #888;
    margin: -6px 0 10px;
    padding-left: 14px;
}

/* 小标签（药丸形）+ 语义变体 */
.message-content .faq-tag {
    display: inline-block;
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 12px;
    background: #e8f0fe;
    color: #1c499e;
    margin: 0 4px 4px 0;
    line-height: 1.6;
}
.message-content .faq-tag-success { background: #e8f5e9; color: #2e7d32; padding: 2px 10px; border-radius: 4px;}
.message-content .faq-tag-warn    { background: #fff4e5; color: #ed6c02; padding: 2px 10px; border-radius: 4px;}
.message-content .faq-tag-danger  { background: #fdecea; color: #c62828; padding: 2px 10px; border-radius: 4px;}
.message-content .faq-tag-neutral { background: #f0f2f5; color: #666; padding: 2px 10px; border-radius: 4px;}

/* 提示框基类 */
.message-content .faq-note,
.message-content .faq-tip,
.message-content .faq-warn,
.message-content .faq-danger {
    margin: 8px 0;
    padding: 8px 12px;
    border-radius: 6px;
    color: #444;
    font-size: 13px;
    line-height: 1.6;
}
/* 信息提示（蓝） */
.message-content .faq-note   { background: #e8f0fe; border-left: 3px solid #1c499e; }
.message-content .faq-note-title { font-weight: 600; color: #1c499e; margin-bottom: 4px; }
/* 成功提示（绿） */
.message-content .faq-tip    { background: #e8f5e9; border-left: 3px solid #2e7d32; }
.message-content .faq-tip-title  { font-weight: 600; color: #2e7d32; margin-bottom: 4px; }
/* 警告提示（橙） */
.message-content .faq-warn   { background: #fff4e5; border-left: 3px solid #ed6c02; }
.message-content .faq-warn-title { font-weight: 600; color: #ed6c02; margin-bottom: 4px; }
/* 危险提示（红） */
.message-content .faq-danger { background: #fdecea; border-left: 3px solid #c62828; }
.message-content .faq-danger-title { font-weight: 600; color: #c62828; margin-bottom: 4px; }

/* 步骤列表（自动编号圆圈） */
.message-content .faq-steps {
    margin: 10px 0;
    padding: 0;
    list-style: none;
    counter-reset: faq-step;
}
.message-content .faq-steps li {
    position: relative;
    padding: 5px 0 5px 34px;
    margin: 0;
    line-height: 1.6;
    counter-increment: faq-step;
}
.message-content .faq-steps li::before {
    content: counter(faq-step);
    position: absolute;
    left: 0;
    top: 6px;
    width: 24px;
    height: 24px;
    background: #1c499e;
    color: #fff;
    border-radius: 50%;
    text-align: center;
    line-height: 24px;
    font-size: 12px;
    font-weight: 600;
}

/* 键值对属性列表 */
.message-content .faq-kv {
    margin: 10px 0;
    padding: 0;
    list-style: none;
}
.message-content .faq-kv li {
    padding: 5px 0;
    border-bottom: 1px dashed #eee;
    line-height: 1.6;
}
.message-content .faq-kv li:last-child { border-bottom: none; }
.message-content .faq-kv-key {
    display: inline-block;
    font-weight: 600;
    color: #555;
    min-width: 90px;
    margin-right: 8px;
}

/* 高亮文字 + 语义变体 */
.message-content .faq-highlight         { color: #1c499e; font-weight: 600; }
.message-content .faq-highlight-success { color: #2e7d32; font-weight: 600; }
.message-content .faq-highlight-warn    { color: #ed6c02; font-weight: 600; }
.message-content .faq-highlight-danger  { color: #c62828; font-weight: 600; }

/* 脚注 */
.message-content .faq-footer {
    font-size: 12px;
    color: #94a3b8;
    text-align: right;
    margin-top: 6px;
    padding-top: 4px;
    border-top: 1px solid #e2e8f0;
}