/* 中建香港 Thomas - 明亮渐变主题（蓝绿安全风） */
:root {
    --wa-bg-deep: #eef8f5;
    --wa-bg-primary: #ffffff;
    --wa-bg-secondary: rgba(255, 255, 255, 0.64);
    --wa-bg-tertiary: rgba(255, 255, 255, 0.78);
    --wa-bg-hover: rgba(255, 255, 255, 0.92);

    --wa-msg-user: #1c74d9;
    --wa-msg-user-light: #2f8ef0;
    --wa-msg-ai: rgba(255, 255, 255, 0.9);
    --wa-msg-ai-light: #ffffff;

    --wa-text-primary: #1d2b2f;
    --wa-text-secondary: #5d6f75;
    --wa-text-muted: #84959d;

    --wa-accent: #16a66e;
    --wa-accent-light: #2bc38a;
    --wa-link: #227db6;
    --wa-safety-orange: #ff9f43;
    --wa-voice-red: #f15c6d;

    --wa-border: rgba(173, 205, 212, 0.62);
    --wa-online: #16a66e;
    --wa-offline: #f15c6d;

    --wa-shadow: 0 10px 26px rgba(61, 117, 126, 0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    font-family: 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background:
        radial-gradient(1200px 520px at -8% -8%, rgba(178, 238, 223, 0.56), transparent 65%),
        radial-gradient(1000px 520px at 100% 100%, rgba(183, 224, 242, 0.46), transparent 68%),
        linear-gradient(132deg, #edf8f4 0%, #e9f8f6 50%, #e2f2fa 100%);
    color: var(--wa-text-primary);
    overflow: hidden;
}

/* 状态栏 */
.status-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 64px;
    background: var(--wa-bg-secondary);
    border-bottom: 1px solid var(--wa-border);
    box-shadow: 0 6px 14px rgba(62, 128, 140, 0.08);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
}

.status-left { display: flex; align-items: center; gap: 10px; flex: 1; }

.status-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background-color: var(--wa-text-muted);
    transition: all 0.3s ease;
}
.status-dot.online {
    background-color: var(--wa-online);
    box-shadow: 0 0 8px var(--wa-online);
}
.status-dot.offline {
    background-color: var(--wa-offline);
}

.status-text {
    font-size: 14px;
    color: var(--wa-text-secondary);
    font-weight: 500;
}

.status-title {
    font-size: 16px;
    font-weight: 600;
    color: #1f2c32;
    flex: 1;
    text-align: center;
}

.status-right {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.mode-switch {
    display: inline-flex;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid var(--wa-border);
    border-radius: 999px;
    padding: 2px;
    gap: 2px;
}

.mode-btn {
    border: none;
    background: transparent;
    color: var(--wa-text-secondary);
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn.active {
    background: var(--wa-accent);
    color: white;
}

/* 聊天容器 */
.chat-container {
    position: fixed;
    top: 64px; left: 0; right: 0; bottom: 132px;
    background:
        radial-gradient(circle at 20% 18%, rgba(186, 238, 226, 0.42), transparent 44%),
        radial-gradient(circle at 82% 78%, rgba(190, 227, 244, 0.40), transparent 46%),
        linear-gradient(125deg, #edf9f4 0%, #e8f8f7 52%, #e2f3fb 100%);
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar { width: 8px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb {
    background: var(--wa-border);
    border-radius: 4px;
}

/* 欢迎消息 */
.welcome-message {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100%;
    padding: 40px 20px;
}

.welcome-content {
    text-align: center;
    color: var(--wa-text-secondary);
    max-width: 400px;
    animation: fadeIn 0.5s ease;
}

.welcome-content i {
    font-size: 48px;
    color: var(--wa-accent);
    margin-bottom: 20px;
}

.welcome-content h3 {
    color: var(--wa-text-primary);
    font-size: 20px;
    margin-bottom: 12px;
}

.welcome-content p {
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 8px;
}

.welcome-hint {
    font-size: 13px;
    color: var(--wa-text-muted);
    margin-top: 20px;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(173, 205, 212, 0.55);
    border-radius: 8px;
    display: inline-block;
}

/* 消息样式 */
.message {
    display: flex;
    margin-bottom: 12px;
    animation: slideIn 0.3s ease;
    width: fit-content;
    max-width: 85%;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    margin-left: auto;
    justify-content: flex-end;
}

.message.ai {
    margin-right: auto;
    justify-content: flex-start;
}

.message-content {
    display: inline-block;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 14.2px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    box-shadow: var(--wa-shadow);
    max-width: 100%;
    min-height: 0;
    position: relative;
}

.message.user .message-content {
    background: #d9fdd3;
    color: #1f2d1f;
    border-bottom-right-radius: 16px;
    width: fit-content;
    max-width: min(70vw, 420px);
    padding: 8px 12px 18px 12px;
}

/* 用户气泡动态宽度（更接近 WhatsApp） */
.message.user.compact .message-content {
    max-width: min(42vw, 170px);
    padding: 6px 10px 18px 10px;
}

.message.user.medium .message-content {
    max-width: min(56vw, 280px);
    padding: 7px 11px 18px 11px;
}

.message.user.long .message-content {
    max-width: min(72vw, 480px);
}

.message.ai .message-content {
    background: #ffffff;
    color: #111111;
    border-bottom-left-radius: 16px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.text-content {
    white-space: normal;
    line-height: 1.6;
    color: #1f2937;
}

.ai-text-block {
    margin-bottom: 10px;
}

.ai-md-h2, .ai-md-h3 {
    margin: 10px 0 8px;
    color: #111827;
    font-weight: 700;
    line-height: 1.35;
}

.ai-md-h2 {
    font-size: 20px;
}

.ai-md-h3 {
    font-size: 17px;
}

.ai-md-p {
    margin: 6px 0;
    line-height: 1.65;
}

.ai-md-list {
    margin: 6px 0 10px 20px;
    padding: 0;
}

.ai-md-list li {
    margin: 4px 0;
}

.ai-md-hr {
    border: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.12);
    margin: 10px 0;
}

.ai-table-wrap {
    margin: 0;
    overflow-x: auto;
}

.ai-table-card {
    margin: 12px 0;
    border: 1px solid rgba(0, 0, 0, 0.16);
    border-radius: 14px;
    overflow: hidden;
    background: #ffffff;
}

.ai-table-card-title {
    padding: 10px 14px;
    font-size: 20px;
    font-weight: 700;
    color: #111827;
    border-bottom: 1px solid rgba(0, 0, 0, 0.12);
    background: #f9fafb;
}

.ai-markdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 16px;
    background: #fff;
}

.ai-markdown-table th,
.ai-markdown-table td {
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 14px 12px;
    text-align: left;
    vertical-align: top;
    word-break: break-word;
}

.ai-markdown-table thead th {
    background: #f3f4f6;
    font-weight: 600;
    font-size: 18px;
}

.message-time {
    font-size: 11px;
    color: var(--wa-text-muted);
    margin-top: 4px;
    text-align: right;
}

.message.user .message-time {
    position: absolute;
    right: 8px;
    bottom: 3px;
    margin-top: 0;
    color: #5f7f5f;
}

.message.ai .message-time {
    color: #7a7a7a;
}

/* 输入区域 */
.input-area {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: linear-gradient(180deg, rgba(237, 248, 244, 0) 0%, rgba(237, 248, 244, 0.86) 38%, rgba(233, 245, 246, 0.95) 100%);
    border-top: none;
    padding: 8px 16px 14px;
    z-index: 1000;
}

/* 图片预览区域（新增） */
.image-preview {
    display: none;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.78);
    border-radius: 12px;
    border: 1px solid var(--wa-accent);
}

.image-preview img {
    height: 60px;
    width: auto;
    border-radius: 8px;
    object-fit: cover;
    border: 2px solid var(--wa-accent);
}

.remove-image {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: var(--wa-offline);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}
.remove-image:hover { transform: scale(1.1); }

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: rgba(255, 255, 255, 0.84);
    border-radius: 28px;
    padding: 9px 13px;
    border: 1px solid rgba(173, 205, 212, 0.72);
    box-shadow: 0 12px 30px rgba(58, 114, 124, 0.15);
    transition: all 0.2s;
    max-width: 980px;
    margin: 0 auto;
}

.input-wrapper:focus-within {
    border-color: rgba(20, 169, 111, 0.45);
    box-shadow: 0 12px 30px rgba(58, 114, 124, 0.2);
}

/* 按钮样式（语音+图片+发送） */
.voice-btn, .image-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--wa-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.voice-btn:hover, .image-btn:hover {
    background: #eef4fc;
    color: var(--wa-accent);
}

.voice-btn.recording {
    color: var(--wa-voice-red);
    animation: pulse-red 1.5s infinite;
}

.image-btn.has-image {
    color: var(--wa-safety-orange);
    background: rgba(255, 159, 67, 0.16);
}

body.app-mode-general .image-btn,
body.app-mode-general .image-preview {
    display: none !important;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(241, 92, 109, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(241, 92, 109, 0); }
    100% { box-shadow: 0 0 0 0 rgba(241, 92, 109, 0); }
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--wa-text-primary);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    min-height: 24px;
    padding: 6px 4px;
    font-family: inherit;
}

textarea:focus { outline: none; }
textarea::placeholder { color: var(--wa-text-muted); }

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #16a66e 0%, #28bf87 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover { filter: brightness(1.03); transform: scale(1.05); }
.send-btn.stop { background: var(--wa-offline); }

.input-hint {
    text-align: center;
    font-size: 11px;
    color: var(--wa-text-muted);
    margin-top: 6px;
    opacity: 0.7;
}

/* 流式输出样式 */
.thinking {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.thinking span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--wa-text-muted);
    animation: bounce 1.4s infinite ease-in-out;
}

.thinking span:nth-child(1) { animation-delay: -0.32s; }
.thinking span:nth-child(2) { animation-delay: -0.16s; }
.thinking span:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 16px;
    background-color: var(--wa-accent-light);
    margin-left: 2px;
    animation: blink 1s infinite;
    vertical-align: middle;
}

@keyframes blink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }

/* 来源信息 */
.sources-info {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--wa-border);
    font-size: 12px;
    color: var(--wa-text-secondary);
}

.source-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-bottom: 6px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.62);
    border-radius: 6px;
}

.source-item.clickable {
    width: 100%;
    border: 1px solid transparent;
    color: var(--wa-text-secondary);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.source-item.clickable:hover {
    border-color: var(--wa-accent);
    color: var(--wa-text-primary);
    background: rgba(0, 168, 132, 0.08);
}

.source-item.clickable span {
    text-align: left;
    word-break: break-word;
}

.source-item i { color: var(--wa-accent); font-size: 10px; margin-top: 3px; }

.regulation-version-notice {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(22, 166, 110, 0.35);
    background: rgba(233, 250, 243, 0.92);
    color: #176045;
    font-size: 12px;
    line-height: 1.45;
}

.regulation-version-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    margin-bottom: 4px;
}

.regulation-version-meta {
    margin-top: 4px;
    color: inherit;
    opacity: 0.82;
}

.source-version-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 5px;
    border-radius: 999px;
    background: rgba(22, 166, 110, 0.12);
    color: #176045;
    font-style: normal;
    font-size: 11px;
}

.sources-files-title {
    margin-top: 10px;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--wa-text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.source-item.file-source {
    border: 1px dashed var(--wa-border);
    background: rgba(255, 255, 255, 0.58);
}

.sources-collapse {
    margin-top: 8px;
    border: 1px solid var(--wa-border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.55);
    overflow: hidden;
}

.sources-collapse summary {
    list-style: none;
    cursor: pointer;
    padding: 8px 10px;
    font-weight: 600;
    color: var(--wa-text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
}

.sources-collapse summary::-webkit-details-marker {
    display: none;
}

.sources-collapse[open] summary {
    border-bottom: 1px solid var(--wa-border);
    background: rgba(22, 166, 110, 0.06);
}

.sources-collapse-body {
    padding: 8px;
}

/* 来源上下文弹窗 */
.source-context-modal {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.source-context-card {
    width: min(760px, 100%);
    max-height: 80vh;
    background: #ffffff;
    border: 1px solid var(--wa-border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.35);
}

.source-context-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--wa-border);
    background: var(--wa-bg-tertiary);
}

.source-context-close {
    border: none;
    background: transparent;
    color: var(--wa-text-secondary);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

.source-context-body {
    margin: 0;
    padding: 14px;
    background: #ffffff;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: var(--wa-text-primary);
    max-height: calc(80vh - 48px);
    overflow: auto;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
}

/* 消息中的图片样式（新增） */
.message-image {
    max-width: 200px;
    max-height: 150px;
    border-radius: 12px;
    margin-top: 8px;
    cursor: pointer;
    border: 2px solid var(--wa-border);
    display: block;
    transition: transform 0.2s;
}

.message-image:hover {
    transform: scale(1.02);
    border-color: var(--wa-accent);
}

/* AI消息中的图片网格（新增） */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--wa-border);
}

.image-grid img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--wa-border);
    cursor: pointer;
    transition: all 0.2s;
}

.image-grid img:hover {
    border-color: var(--wa-accent);
    transform: scale(1.02);
}

/* 语音录制弹窗 */
.voice-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.voice-modal-content {
    background: var(--wa-bg-secondary);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.voice-wave {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    height: 60px;
    margin-bottom: 20px;
}

.voice-wave span {
    width: 6px;
    background: var(--wa-voice-red);
    border-radius: 3px;
    animation: wave 1s ease-in-out infinite;
}

.voice-wave span:nth-child(1) { height: 20%; animation-delay: 0s; }
.voice-wave span:nth-child(2) { height: 40%; animation-delay: 0.1s; }
.voice-wave span:nth-child(3) { height: 60%; animation-delay: 0.2s; }
.voice-wave span:nth-child(4) { height: 40%; animation-delay: 0.3s; }
.voice-wave span:nth-child(5) { height: 20%; animation-delay: 0.4s; }

@keyframes wave {
    0%, 100% { transform: scaleY(0.5); opacity: 0.5; }
    50% { transform: scaleY(1); opacity: 1; }
}

.voice-timer {
    color: var(--wa-text-secondary);
    font-size: 24px;
    font-family: monospace;
    margin-bottom: 30px;
}

.voice-stop-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    border: 3px solid var(--wa-voice-red);
    background: transparent;
    color: var(--wa-voice-red);
    cursor: pointer;
    font-size: 24px;
}

.voice-stop-btn:hover {
    background: var(--wa-voice-red);
    color: white;
}

/* 响应式 */
@media (max-width: 768px) {
    .chat-container { padding: 12px; bottom: 120px; }
    .message { max-width: 90%; }
    .image-grid { grid-template-columns: repeat(2, 1fr); }
}