.chat-widget {
    position: fixed;
    right: 30px;
    bottom: 30px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.chat-trigger {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    box-shadow: 0 4px 15px rgba(79, 172, 254, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.chat-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(79, 172, 254, 0.5);
}

.chat-trigger img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.chat-status-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #fff;
}

.chat-status-dot.online {
    background: #52c41a;
}

.chat-status-dot.offline {
    background: #d9d9d9;
}

.chat-window {
    width: 360px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    position: absolute;
    right: 0;
    bottom: 70px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.chat-window.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.chat-header {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #fff;
}

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

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.7);
}

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

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

.chat-header-title {
    font-weight: 600;
    font-size: 16px;
}

.chat-header-status {
    font-size: 12px;
    opacity: 0.9;
}

.chat-close-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chat-close-btn:hover svg {
    fill: #ff4757;
}

.chat-close-btn svg {
    width: 16px;
    height: 16px;
}

.chat-avatar-selector {
    padding: 10px 16px;
    background: #fff;
    border-bottom: 1px solid #e8e8e8;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-avatar-label {
    font-size: 12px;
    color: #666;
}

.chat-avatar-option {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.chat-avatar-option:hover {
    transform: scale(1.1);
}

.chat-avatar-option.selected {
    border-color: #4facfe;
}

.chat-nickname-label {
    font-size: 12px;
    color: #666;
    margin-left: 10px;
}

.chat-nickname-input {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid #e8e8e8;
    border-radius: 4px;
    font-size: 12px;
    outline: none;
    margin-left: 5px;
}

.chat-nickname-input:focus {
    border-color: #4facfe;
}

.chat-body {
    height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: #f5f7fa;
}

.chat-body::-webkit-scrollbar {
    width: 4px;
}

.chat-body::-webkit-scrollbar-track {
    background: #e8e8e8;
    border-radius: 2px;
}

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

.chat-message {
    display: flex;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
    gap: 8px;
    width: 100%;
}

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

.chat-message.visitor {
    justify-content: flex-start;
    flex-direction: row-reverse;
}

.chat-message.admin {
    justify-content: flex-start;
}

.chat-message.system {
    justify-content: center;
    gap: 0;
}

.chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

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

.chat-message-content {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.chat-message-bubble {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    word-break: break-all;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    max-width: 260px;
}

.chat-message.visitor .chat-message-bubble {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: #fff;
    border-bottom-right-radius: 3px;
}

.chat-message.admin .chat-message-bubble {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 3px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.chat-message.system .chat-message-bubble {
    background: #e8f4fd;
    color: #666;
    font-size: 12px;
    padding: 6px 12px;
}

.chat-message-time {
    font-size: 10px;
    color: #999;
    margin-top: 4px;
}

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

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

.chat-footer {
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid #eee;
    position: relative;
}

.chat-emoji-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #666;
    border-radius: 50%;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-emoji-btn:hover {
    background: #f0f0f0;
    color: #4facfe;
}

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

.chat-emoji-panel {
    position: absolute;
    bottom: 56px;
    left: 16px;
    right: 16px;
    max-height: 180px;
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 8px;
    background: #fff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 10;
}

.chat-emoji-panel::-webkit-scrollbar {
    width: 4px;
}

.chat-emoji-panel::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

.chat-emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
    gap: 4px;
}

.chat-emoji-item {
    width: 32px;
    height: 32px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s;
}

.chat-emoji-item:hover {
    transform: scale(1.2);
    background: #e8f4fd;
}

.chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-input {
    flex: 1;
    min-height: 36px;
    max-height: 100px;
    padding: 8px 12px 8px 8px;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    font-size: 14px;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    overflow-y: auto;
    overflow-x: hidden;
    word-break: break-all;
    box-sizing: border-box;
}

.chat-input::-webkit-scrollbar {
    width: 4px;
}

.chat-input::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 2px;
}

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

.chat-input::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.chat-input:focus {
    border-color: #4facfe;
}

.chat-input::placeholder {
    color: #bbb;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    transform: scale(1.05);
}

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

.chat-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

.chat-send-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-offline-tip {
    padding: 10px 16px;
    background: #fff3e0;
    border-top: 1px solid #ffe0b2;
    font-size: 12px;
    color: #e65100;
    display: flex;
    align-items: center;
    gap: 6px;
}

@media (max-width: 480px) {
    .chat-widget {
        right: 15px;
        bottom: 15px;
    }

    .chat-window {
        width: calc(100vw - 60px);
        max-width: 340px;
    }
}