/* 在线客服样式 - 支持 iOS 和 Android */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary-color: #07c160;
    --primary-dark: #06ad56;
    --bg-color: #f5f5f5;
    --white: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-light: #999999;
    --border-color: #e5e5e5;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --safe-bottom: env(safe-area-inset-bottom, 0);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    color: var(--text-primary);
    background: var(--bg-color);
    -webkit-font-smoothing: antialiased;
}

/* 容器 */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 500px;
    margin: 0 auto;
    background: var(--white);
    position: relative;
    overflow: hidden;
}

@media (min-width: 768px) {
    .chat-container {
        height: 100vh;
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        margin-top: 20px;
        margin-bottom: 20px;
    }
}

/* 头部 */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--white);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    padding-top: calc(12px + env(safe-area-inset-top, 0));
}

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

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-color);
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.info .name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
}

.info .status {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-light);
    margin-top: 2px;
}

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

.status-dot.online {
    background: var(--primary-color);
}

.btn-icon {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background 0.2s;
}

.btn-icon:active {
    background: var(--bg-color);
}

/* 消息列表 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: var(--bg-color);
    -webkit-overflow-scrolling: touch;
}

.welcome-message {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}

.message-item {
    display: flex;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
}

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

.message-item.visitor {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--white);
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    max-width: 70%;
    margin: 0 10px;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
}

.message-item.agent .message-bubble {
    background: var(--white);
    color: var(--text-primary);
    border-top-left-radius: 4px;
}

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

.message-bubble img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    display: block;
}

.message-time {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 4px;
    text-align: right;
}

.message-item.agent .message-time {
    text-align: left;
}

.message-item.system {
    justify-content: center;
}

.message-item.system .message-bubble {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-light);
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 12px;
    max-width: 80%;
    text-align: center;
}

/* 撤回消息 */
.message-bubble.revoked {
    background: transparent !important;
    color: var(--text-light) !important;
    font-style: italic;
    font-size: 13px;
}

/* 消息操作 */
.message-actions {
    position: absolute;
    top: -30px;
    right: 0;
    background: var(--white);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 4px 8px;
    display: none;
}

.message-item.visitor:hover .message-actions {
    display: flex;
}

.action-btn {
    background: none;
    border: none;
    padding: 4px 8px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
}

.action-btn:active {
    color: var(--primary-color);
}

/* 输入状态 */
.typing-indicator {
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-light);
    background: var(--bg-color);
}

/* 输入区域 */
.chat-input {
    background: var(--white);
    border-top: 1px solid var(--border-color);
    padding-bottom: var(--safe-bottom);
    flex-shrink: 0;
}

.input-tools {
    display: flex;
    padding: 8px 12px;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
}

.tool-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.tool-btn:active {
    background: var(--bg-color);
    color: var(--primary-color);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    padding: 12px;
    gap: 8px;
}

.input-wrapper textarea {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 15px;
    resize: none;
    outline: none;
    max-height: 100px;
    line-height: 1.4;
    font-family: inherit;
    transition: border-color 0.2s;
}

.input-wrapper textarea:focus {
    border-color: var(--primary-color);
}

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

.send-btn:active {
    background: var(--primary-dark);
    transform: scale(0.95);
}

.send-btn:disabled {
    background: var(--border-color);
    cursor: not-allowed;
}

/* 表情面板 */
.emoji-panel {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--white);
    border-top: 1px solid var(--border-color);
    padding: 12px;
    max-height: 200px;
    overflow-y: auto;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
}

.emoji-item {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}

.emoji-item:active {
    background: var(--bg-color);
}

/* 更多菜单 */
.more-menu {
    position: absolute;
    top: 60px;
    right: 16px;
    background: var(--white);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    z-index: 100;
}

.menu-item {
    padding: 12px 20px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s;
}

.menu-item:active {
    background: var(--bg-color);
}

/* 弹窗 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--white);
    border-radius: var(--radius);
    width: 100%;
    max-width: 320px;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 500;
}

.modal-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    font-size: 24px;
    color: var(--text-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.modal-close:active {
    background: var(--bg-color);
}

.modal-body {
    padding: 20px;
}

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

.star {
    font-size: 32px;
    color: var(--border-color);
    cursor: pointer;
    transition: color 0.2s;
}

.star.active,
.star:hover,
.star:hover ~ .star {
    color: #ffc107;
}

.modal-body textarea {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    resize: none;
    outline: none;
    font-family: inherit;
}

.modal-body textarea:focus {
    border-color: var(--primary-color);
}

.modal-footer {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-default {
    background: var(--bg-color);
    color: var(--text-primary);
}

.btn-default:active {
    background: var(--border-color);
}

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

.btn-primary:active {
    background: var(--primary-dark);
}

/* 图片预览 */
.image-preview {
    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: 2000;
    padding: 20px;
}

.image-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* 加载状态 */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* 隐藏文件输入 */
#imageInput {
    display: none;
}

/* 已读/未读状态 */
.read-status {
    font-size: 11px;
    color: #999;
    margin-left: 4px;
}

.read-status.unread {
    color: #ff4d4f;
}
