/* ===== TG风格在线客服 - 前端样式 ===== */
:root {
    --bg-primary: #0e1621;
    --bg-secondary: #17212b;
    --bg-chat: #0e1621;
    --bg-input: #242f3d;
    --bg-msg-visitor: #2b5c3a;
    --bg-msg-admin: #182533;
    --bg-msg-system: rgba(0,0,0,0.3);
    --text-primary: #f5f5f5;
    --text-secondary: #8b9bab;
    --text-time: #6d7f8f;
    --accent: #5eb5f7;
    --accent-hover: #4aa3e8;
    --green: #4dcd5e;
    --red: #e55454;
    --border: #1c2836;
    --shadow: rgba(0,0,0,0.3);
}

/* 白天主题 */
body.light {
    --bg-primary: #e8ecef;
    --bg-secondary: #ffffff;
    --bg-chat: #e8ecef;
    --bg-input: #f0f2f5;
    --bg-msg-visitor: #d0ebb6;
    --bg-msg-admin: #ffffff;
    --bg-msg-system: rgba(0,0,0,0.06);
    --text-primary: #1a1a1a;
    --text-secondary: #707579;
    --text-time: #9e9e9e;
    --accent: #3390ec;
    --accent-hover: #2b7fd4;
    --green: #4dcd5e;
    --red: #e55454;
    --border: #dce1e6;
    --shadow: rgba(0,0,0,0.1);
}

body.light .chat-messages {
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23000000' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

body.light .visitor .message-bubble {
    color: #1a1a1a;
}

body.light .admin .message-bubble {
    color: #1a1a1a;
    border: 1px solid var(--border);
}

body.light .admin-avatar {
    background: linear-gradient(135deg, #3390ec, #2b7fd4);
}

body.light .date-separator span {
    background: rgba(0,0,0,0.08);
    color: #707579;
}

body.light #messageInput {
    border: 1px solid var(--border);
}

body.light #messageInput:focus {
    background: #fff;
    border-color: var(--accent);
}

body.light .emoji-panel {
    background: #fff;
    border-color: var(--border);
}
body.light .emoji-tab:hover { background: rgba(0,0,0,0.04); }
body.light .sticker-item:hover { background: rgba(0,0,0,0.05); }

body.light .rating-modal {
    background: #fff;
}

body.light #ratingComment {
    background: #f0f2f5;
    border-color: var(--border);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

#chat-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 600px;
    margin: 0 auto;
    background: var(--bg-chat);
    position: relative;
}

/* 头部 */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 10;
    min-height: 56px;
}

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

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.admin-avatar {
    background: linear-gradient(135deg, #5eb5f7, #3a8fd4);
    color: white;
}

.admin-avatar svg {
    width: 26px;
    height: 26px;
}

.header-info {
    display: flex;
    flex-direction: column;
}

.header-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: background 0.3s;
}

.status-dot.online {
    background: var(--green);
    box-shadow: 0 0 6px rgba(77, 205, 94, 0.5);
}

.status-dot.offline {
    background: var(--red);
}

.header-actions {
    display: flex;
    gap: 8px;
}

.header-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.header-btn:hover {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
}

.header-btn svg {
    width: 20px;
    height: 20px;
}

/* 消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
    background: var(--bg-chat);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.015'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
}

.loading-spinner {
    display: flex;
    justify-content: center;
    padding: 20px;
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 日期分隔 */
.date-separator {
    text-align: center;
    padding: 8px 0;
}

.date-separator span {
    background: rgba(0,0,0,0.35);
    color: var(--text-secondary);
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 12px;
    backdrop-filter: blur(4px);
}

/* 消息气泡 */
.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: msgIn 0.25s ease-out;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-wrapper.visitor {
    align-self: flex-end;
}

.message-wrapper.admin {
    align-self: flex-start;
}

.message-wrapper.system {
    align-self: center;
    max-width: 90%;
}

.message-bubble {
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
    position: relative;
}

.visitor .message-bubble {
    background: var(--bg-msg-visitor);
    border-top-right-radius: 4px;
    color: var(--text-primary);
}

.admin .message-bubble {
    background: var(--bg-msg-admin);
    border-top-left-radius: 4px;
    color: var(--text-primary);
}

.system .message-bubble {
    background: var(--bg-msg-system);
    color: var(--text-secondary);
    font-size: 13px;
    text-align: center;
    border-radius: 8px;
    padding: 6px 16px;
    backdrop-filter: blur(4px);
}

.message-bubble.recalled {
    opacity: 0.5;
    font-style: italic;
}

.message-time {
    font-size: 11px;
    color: var(--text-time);
    margin-top: 2px;
    padding: 0 4px;
}

.visitor .message-time {
    text-align: right;
}

.admin .message-time {
    text-align: left;
}

/* 图片消息 */
.message-bubble img.chat-image {
    max-width: 260px;
    max-height: 300px;
    border-radius: 8px;
    cursor: pointer;
    display: block;
    transition: opacity 0.2s;
}

.message-bubble img.chat-image:hover {
    opacity: 0.9;
}

/* 文件消息 */
.file-message {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: rgba(0,0,0,0.15);
    border-radius: 8px;
    min-width: 200px;
    cursor: pointer;
    transition: background 0.2s;
}

.file-message:hover {
    background: rgba(0,0,0,0.25);
}

.file-icon {
    width: 40px;
    height: 40px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-icon svg {
    width: 22px;
    height: 22px;
    fill: white;
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 11px;
    color: var(--text-secondary);
}

/* 表情消息 */
.emoji-message {
    font-size: 32px;
    line-height: 1.2;
}

/* 输入区域 */
.chat-input-area {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px));
}

.input-toolbar {
    display: flex;
    gap: 4px;
    padding-bottom: 6px;
}

.tool-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.tool-btn:hover {
    background: rgba(255,255,255,0.08);
    color: var(--accent);
}

.tool-btn svg {
    width: 22px;
    height: 22px;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

#messageInput {
    flex: 1;
    background: var(--bg-input);
    border: none;
    border-radius: 20px;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 14px;
    resize: none;
    max-height: 120px;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
    transition: background 0.2s;
}

#messageInput::placeholder {
    color: var(--text-secondary);
}

#messageInput:focus {
    background: #2a3a4a;
}

.send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* 表情面板 */
.emoji-panel {
    position: absolute;
    bottom: 100px;
    left: 12px;
    right: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    max-height: 300px;
    overflow: hidden;
    z-index: 20;
    box-shadow: 0 -4px 20px var(--shadow);
    animation: slideUp 0.2s ease-out;
}

.emoji-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.emoji-tab {
    flex: 1;
    text-align: center;
    padding: 10px 0;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    user-select: none;
}

.emoji-tab.active {
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
    font-weight: 600;
}

.emoji-tab:hover {
    background: rgba(255,255,255,0.05);
}

.emoji-grid {
    display: none;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    padding: 12px;
    overflow-y: auto;
    max-height: 240px;
}

.emoji-grid.active {
    display: grid;
}

.sticker-grid {
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 12px;
    overflow-y: auto;
    max-height: 240px;
}

.sticker-grid.active {
    display: grid;
}

.sticker-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.sticker-item:hover {
    background: rgba(255,255,255,0.08);
    transform: scale(1.05);
}

.sticker-item:active {
    transform: scale(0.95);
}

.sticker-emoji {
    font-size: 36px;
    line-height: 1;
    animation: stickerBounce 2s ease-in-out infinite;
}

.sticker-item:nth-child(2n) .sticker-emoji { animation-delay: 0.3s; }
.sticker-item:nth-child(3n) .sticker-emoji { animation-delay: 0.6s; }
.sticker-item:nth-child(4n) .sticker-emoji { animation-delay: 0.9s; }

.sticker-label {
    font-size: 11px;
    color: var(--text-secondary);
}

@keyframes stickerBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    25% { transform: translateY(-4px) scale(1.1); }
    50% { transform: translateY(0) scale(1); }
    75% { transform: translateY(-2px) scale(1.05); }
}

/* 贴纸消息气泡 */
.sticker-bubble {
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
}

.sticker-message {
    font-size: 64px;
    line-height: 1;
    display: block;
    animation: stickerPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), stickerFloat 2.5s ease-in-out 0.4s infinite;
}

@keyframes stickerPop {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes stickerFloat {
    0%, 100% { transform: translateY(0) scale(1); }
    30% { transform: translateY(-6px) scale(1.08); }
    60% { transform: translateY(2px) scale(0.96); }
}

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

.emoji-grid::-webkit-scrollbar,
.sticker-grid::-webkit-scrollbar {
    width: 4px;
}

.emoji-grid::-webkit-scrollbar-thumb,
.sticker-grid::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}

.emoji-item {
    font-size: 24px;
    text-align: center;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: all 0.15s;
    user-select: none;
}

.emoji-item:hover {
    background: rgba(255,255,255,0.1);
    transform: scale(1.2);
}

/* 评价弹窗 */
.rating-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.rating-modal {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 28px;
    width: 90%;
    max-width: 360px;
    text-align: center;
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.rating-title {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.rating-stars {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
}

.rating-stars .star {
    font-size: 36px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.rating-stars .star:hover,
.rating-stars .star.active {
    color: #ffc107;
    transform: scale(1.15);
}

#ratingComment {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 14px;
    resize: none;
    outline: none;
    font-family: inherit;
    margin-bottom: 16px;
}

#ratingComment::placeholder {
    color: var(--text-secondary);
}

.rating-submit {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.rating-submit:hover {
    background: var(--accent-hover);
}

/* 邮箱提示弹窗 */
.email-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.email-modal {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 28px;
    width: 90%;
    max-width: 360px;
    text-align: center;
    animation: modalIn 0.3s ease-out;
}

.email-modal-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.email-modal-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.email-modal-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 20px;
}

.email-modal-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    font-family: inherit;
    margin-bottom: 16px;
    transition: border-color 0.2s;
}

.email-modal-input:focus {
    border-color: var(--accent);
}

.email-modal-input::placeholder {
    color: var(--text-secondary);
}

.email-modal-btns {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.email-modal-btn {
    width: 100%;
    padding: 11px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.email-modal-btn.primary {
    background: var(--accent);
    color: white;
}

.email-modal-btn.primary:hover {
    background: var(--accent-hover);
}

.email-modal-btn.skip {
    background: transparent;
    color: var(--text-secondary);
}

.email-modal-btn.skip:hover {
    background: var(--hover);
}

/* 图片预览 */
.image-preview-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    cursor: zoom-out;
}

.image-preview-overlay img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
    border-radius: 4px;
}

.image-preview-close {
    position: absolute;
    top: 16px;
    right: 20px;
    font-size: 32px;
    color: white;
    cursor: pointer;
    z-index: 201;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    transition: background 0.2s;
}

.image-preview-close:hover {
    background: rgba(255,255,255,0.2);
}

/* 响应式 */
@media (max-width: 600px) {
    #chat-app {
        max-width: 100%;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(7, 1fr);
    }
    
    .sticker-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .message-wrapper {
        max-width: 85%;
    }
}

/* 打字指示器 */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    align-self: flex-start;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}
