/**
 * 前端样式 - 悬浮通讯插件
 * Chrome 兼容性修复：明确写死所有默认值，确保与 Edge 一致
 */

/* 重置所有浏览器默认样式 */
.fc-floating-widget *,
.fc-floating-widget *::before,
.fc-floating-widget *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* 主容器 */
.fc-floating-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* 新消息提示冒泡 */
.fc-notification-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    background: #ff4444;
    color: #ffffff;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    padding: 0 6px;
    box-shadow: 0 2px 8px rgba(255, 68, 68, 0.5);
    z-index: 10000;
    line-height: 1;
    animation: badgeBlink 1.5s infinite;
    transition: animation 0.3s ease;
    border: 2px solid #ffffff;
    box-sizing: border-box;
    overflow: visible;
}

/* 闪烁动画 */
@keyframes badgeBlink {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
        box-shadow: 0 2px 8px rgba(255, 68, 68, 0.5);
    }
    50% {
        opacity: 0.7;
        transform: scale(0.98);
        box-shadow: 0 2px 12px rgba(255, 68, 68, 0.7);
    }
}

/* 悬停时停止闪烁，显示未读数量 */
.fc-main-button:hover .fc-notification-badge {
    animation: none;
    opacity: 1;
    transform: scale(1);
    min-width: auto;
    padding: 0 6px;
}

/* 未读数量提示工具提示 */
.fc-notification-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.9);
    color: #ffffff;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    display: block !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(5px);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s linear 0.3s;
    z-index: 10001;
    min-width: 150px;
    max-width: 280px;
    width: auto;
    text-align: left;
    line-height: 1.5;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    box-sizing: border-box;
    overflow: visible;
    margin: 0;
    border: none;
    /* 确保在Chrome中正确显示 */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform: translateZ(0);
    will-change: opacity, transform, visibility;
}

/* Chrome/Edge 专用修复 */
@supports (-webkit-appearance: none) {
    .fc-notification-tooltip {
        -webkit-backface-visibility: hidden;
        -webkit-transform: translateZ(0);
        will-change: opacity, transform, visibility;
    }
    
    .fc-main-button:hover .fc-notification-tooltip,
    .fc-notification-badge:hover .fc-notification-tooltip {
        -webkit-transform: translateY(0) translateZ(0);
    }
}

.fc-notification-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 12px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid rgba(0, 0, 0, 0.9);
}

/* 只有在有未读消息时才显示 tooltip */
.fc-main-button:hover .fc-notification-tooltip[data-has-unread="true"],
.fc-notification-badge:hover .fc-notification-tooltip[data-has-unread="true"],
.fc-main-button:hover ~ .fc-notification-tooltip[data-has-unread="true"] {
    opacity: 1 !important;
    transform: translateY(0) !important;
    visibility: visible !important;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s linear 0s !important;
    display: block !important;
}

/* 确保没有未读消息时，tooltip 完全隐藏 */
.fc-main-button:hover .fc-notification-tooltip:not([data-has-unread="true"]),
.fc-notification-badge:hover .fc-notification-tooltip:not([data-has-unread="true"]),
.fc-main-button:hover ~ .fc-notification-tooltip:not([data-has-unread="true"]) {
    opacity: 0 !important;
    visibility: hidden !important;
    display: none !important;
}

.fc-main-button {
    position: relative;
}

/* 主按钮 */
.fc-main-button {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    width: 60px;
    height: 60px;
    min-width: 60px;
    min-height: 60px;
    overflow: visible;
    box-sizing: border-box;
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    /* 退场动画（鼠标离开时）：完美倒放的悬停动画 */
    transition: min-width 0.35s cubic-bezier(0.4, 0, 0.2, 1) 0s,
                padding 0.35s cubic-bezier(0.4, 0, 0.2, 1) 0s,
                gap 0.35s cubic-bezier(0.4, 0, 0.2, 1) 0s,
                border-radius 0.35s cubic-bezier(0.4, 0, 0.2, 1) 0.15s,
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) 0s,
                box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1) 0s;
}

.fc-main-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    border-radius: 50px;
    padding: 0 16px;
    gap: 8px;
    min-width: 150px;
    width: auto;
    justify-content: center;
    /* 入场动画（鼠标悬停时）：先变圆角，然后展开宽度和间距 */
    transition: border-radius 0.35s cubic-bezier(0.4, 0, 0.2, 1) 0s,
                padding 0.35s cubic-bezier(0.4, 0, 0.2, 1) 0.05s,
                gap 0.35s cubic-bezier(0.4, 0, 0.2, 1) 0.05s,
                min-width 0.35s cubic-bezier(0.4, 0, 0.2, 1) 0.1s,
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) 0s,
                box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1) 0s;
}

.fc-main-button:active {
    transform: translateY(0);
}

/* 面板打开时隐藏主按钮 */
.fc-main-button.fc-button-hidden {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.8);
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 按钮图标 */
.fc-button-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    min-width: 28px;
    flex-shrink: 0;
    /* 图标保持稳定，不受父元素动画影响 */
    position: relative;
    z-index: 1;
}

.fc-button-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
    display: block;
}

/* 按钮文本 */
.fc-button-text {
    font-weight: 500;
    white-space: nowrap;
    color: #ffffff;
    opacity: 0;
    max-width: 0;
    overflow: hidden;
    display: inline-block;
    line-height: 1;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    /* 退场动画（鼠标离开时）：完美倒放的悬停动画 */
    /* 倒放顺序：先隐藏文本，然后收缩宽度和间距 */
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1) 0s,
                max-width 0.35s cubic-bezier(0.4, 0, 0.2, 1) 0.15s;
}

/* 悬停时显示文本 */
.fc-main-button:hover .fc-button-text {
    opacity: 1;
    max-width: 120px;
    /* 入场动画（鼠标悬停时）：先展开宽度，然后文本淡入 */
    transition: max-width 0.35s cubic-bezier(0.4, 0, 0.2, 1) 0.1s,
                opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1) 0.2s;
}


/* 渠道面板 */
.fc-channels-panel {
    position: absolute;
    bottom: 80px;
    left: 0;
    width: 280px;
    max-height: 400px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    pointer-events: none;
}

/* 当按钮隐藏时，调整面板位置使其更靠近底部 */
.fc-main-button.fc-button-hidden ~ .fc-channels-panel {
    bottom: 20px;
}

.fc-channels-panel.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* 渠道列表 */
.fc-channels-list {
    max-height: 400px;
    overflow-y: auto;
    padding: 8px;
}

.fc-channels-list::-webkit-scrollbar {
    width: 6px;
}

.fc-channels-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.fc-channels-list::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.fc-channels-list::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 渠道项 */
.fc-channel-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    text-decoration: none;
    color: #333333;
    transition: all 0.2s ease;
    margin-bottom: 4px;
    /* 隐藏悬停时显示的URL */
    pointer-events: auto;
}

/* 隐藏链接的URL提示 */
.fc-channel-item[href="javascript:void(0);"] {
    cursor: pointer;
}

.fc-channel-item:hover {
    background: #f5f5f5;
    transform: translateX(4px);
}

.fc-channel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
}

.fc-channel-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.fc-channel-desc {
    font-size: 14px;
    color: #666;
}

/* 渠道未读消息标记（图标上的红点） */
.fc-channel-icon {
    position: relative;
    flex-shrink: 0;
}

.fc-channel-unread-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ff4444 !important;
    color: #ffffff !important;
    border-radius: 10px;
    min-width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    padding: 0 5px;
    box-sizing: border-box;
    border: 2px solid #ffffff;
    z-index: 10;
    line-height: 1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* 渠道未读消息数量文本 */
.fc-channel-unread-count {
    font-size: 12px;
    font-weight: 500;
    color: #ff4444;
    margin-left: 4px;
    white-space: nowrap;
}

/* 有未读消息的渠道项高亮 */
.fc-channel-item.fc-channel-has-unread {
    background: rgba(255, 68, 68, 0.05) !important;
    border-left: 3px solid #ff4444 !important;
    padding-left: 9px !important; /* 调整padding以补偿border */
}

.fc-channel-item.fc-channel-has-unread:hover {
    background: rgba(255, 68, 68, 0.1) !important;
}

.fc-channel-item:last-child {
    margin-bottom: 0;
}

/* 渠道图标 */
.fc-channel-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f0f0f0;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.fc-channel-item:hover .fc-channel-icon {
    background: #e0e0e0;
    transform: scale(1.1);
}

.fc-channel-icon svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    color: #666666;
}

/* WhatsApp 图标特殊颜色 */
.fc-channel-item[data-channel-id="whatsapp"] .fc-channel-icon {
    background: #25D366;
}

.fc-channel-item[data-channel-id="whatsapp"] .fc-channel-icon svg {
    color: #ffffff;
}

/* 渠道内容 */
.fc-channel-content {
    flex: 1;
    min-width: 0;
}

.fc-channel-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
    color: #333333;
}

.fc-channel-desc {
    font-size: 13px;
    color: #666666;
    line-height: 1.4;
}

/* 位置：左侧 */
.fc-floating-widget[data-position="left"] {
    left: 30px;
    bottom: 30px;
}

.fc-floating-widget[data-position="left"] .fc-channels-panel {
    left: 0;
}

/* 位置：右侧 */
.fc-floating-widget[data-position="right"] {
    right: 30px;
    bottom: 30px;
    left: auto;
}

.fc-floating-widget[data-position="right"] .fc-channels-panel {
    right: 0;
    left: auto;
}

/* 隐藏状态 */
.fc-floating-widget.fc-hidden {
    transform: translateX(-70%);
    opacity: 0.7;
}

.fc-floating-widget[data-position="right"].fc-hidden {
    transform: translateX(70%);
}

/* 有未读时保持可见：避免移动端“半隐藏”把红点一起滑出屏幕 */
.fc-floating-widget.fc-has-unread,
.fc-floating-widget.fc-has-unread.fc-hidden,
.fc-floating-widget[data-position="right"].fc-has-unread.fc-hidden {
    transform: translateX(0) !important;
    opacity: 1 !important;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .fc-floating-widget {
        left: 20px !important;
        right: auto !important;
        bottom: 20px !important;
    }
    
    .fc-floating-widget[data-position="right"] {
        left: 20px !important;
        right: auto !important;
    }
    
    .fc-main-button {
        width: 56px;
        height: 56px;
        min-width: 56px;
        min-height: 56px;
        padding: 0;
    }
    
    .fc-main-button:hover {
        width: 56px;
        height: 56px;
        padding: 0;
        gap: 0;
        border-radius: 50%;
    }
    
    .fc-button-text {
        display: none !important;
    }
    
    .fc-channels-panel {
        width: calc(100vw - 40px);
        max-width: 320px;
        left: 0 !important;
        right: auto !important;
    }
    
    .fc-floating-widget.fc-hidden {
        transform: translateX(-70%);
    }
    
    /* 移动端禁用 hover 效果 */
    .fc-main-button:hover {
        transform: none;
    }
    
    .fc-channel-item:hover {
        transform: none;
    }
}

/* 设备显示控制 */
.fc-hide-mobile {
    display: none !important;
}

@media (min-width: 769px) {
    .fc-hide-mobile {
        display: flex !important;
    }
    
    .fc-hide-desktop {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .fc-hide-desktop {
        display: flex !important;
    }
}

/* 动画优化 */
.fc-floating-widget,
.fc-main-button,
.fc-channels-panel,
.fc-channel-item {
    will-change: transform, opacity;
}

/* 无障碍支持 */
.fc-main-button:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

.fc-channel-item:focus {
    outline: 2px solid rgba(0, 0, 0, 0.2);
    outline-offset: 2px;
}
