/* ============================================================
   Tuzhi 客服系统 - 完整样式
   包含：浮动按钮、弹窗表单、对话页面、通知横幅、评价等
   ============================================================ */

/* ========== 1. 浮动按钮 ========== */
.kefu-trigger {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background: #1976d2;
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(25, 118, 210, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 99999;
    transition: transform 0.3s, box-shadow 0.3s;
    border: none;
    user-select: none;
}
.kefu-trigger:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 28px rgba(25, 118, 210, 0.5);
}
.kefu-trigger:active {
    transform: scale(0.95);
}
.kefu-trigger svg {
    width: 32px;
    height: 32px;
    fill: #fff;
}
/* 按钮上的小提示点（可选的未读消息标记） */
.kefu-trigger .badge-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: #ef5350;
    border-radius: 50%;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* ========== 2. 弹窗面板（未登录表单） ========== */
.kefu-panel {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 400px;
    max-width: calc(100vw - 40px);
    max-height: 80vh;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 99998;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: kefuSlideUp 0.3s ease;
}
.kefu-panel.active {
    display: flex;
}
@keyframes kefuSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
.kefu-panel .kefu-header {
    background: #1976d2;
    color: #fff;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    flex-shrink: 0;
}
.kefu-panel .kefu-header .close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    opacity: 0.8;
    padding: 0 4px;
    line-height: 1;
}
.kefu-panel .kefu-header .close-btn:hover {
    opacity: 1;
}
.kefu-panel .kefu-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.kefu-panel .form-group {
    margin-bottom: 16px;
}
.kefu-panel .form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
    font-size: 14px;
    color: #333;
}
.kefu-panel .form-group input,
.kefu-panel .form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}
.kefu-panel .form-group input:focus,
.kefu-panel .form-group textarea:focus {
    border-color: #1976d2;
    outline: none;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
}
.kefu-panel .form-group textarea {
    min-height: 80px;
    resize: vertical;
}
.kefu-panel .file-upload-wrapper {
    position: relative;
}
.kefu-panel .file-upload-wrapper input[type="file"] {
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}
.kefu-panel .file-upload-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: 2px dashed #ccc;
    border-radius: 8px;
    background: #f9fafb;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    font-size: 13px;
    color: #555;
}
.kefu-panel .file-upload-btn:hover {
    border-color: #1976d2;
    background: #f0f7ff;
}
.kefu-panel .file-upload-btn.has-file {
    border-color: #2e7d32;
    background: #e8f5e9;
    color: #2e7d32;
}
.kefu-panel .file-name {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
    word-break: break-all;
}
.kefu-panel .btn-submit {
    width: 100%;
    padding: 12px;
    background: #1976d2;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.kefu-panel .btn-submit:hover {
    background: #1565c0;
}
.kefu-panel .btn-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.kefu-panel .form-msg {
    text-align: center;
    margin-top: 12px;
    font-size: 14px;
    padding: 8px;
    border-radius: 8px;
}
.kefu-panel .form-msg.success {
    color: #2e7d32;
    background: #e8f5e9;
}
.kefu-panel .form-msg.error {
    color: #c62828;
    background: #fce4ec;
}

/* ========== 3. 对话页面通用样式（供 chat.php 复用，也可内联） ========== */
.kefu-chat-container {
    max-width: 700px;
    margin: 0 auto;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}
.kefu-chat-header {
    background: #1976d2;
    color: #fff;
    padding: 16px 20px;
}
.kefu-chat-header h2 {
    margin: 0;
    font-size: 18px;
}
.kefu-chat-header .sub {
    font-size: 13px;
    opacity: 0.8;
    margin-top: 4px;
}
.kefu-chat-body {
    padding: 20px;
    max-height: 500px;
    overflow-y: auto;
}
.kefu-msg {
    display: flex;
    margin-bottom: 16px;
    animation: kefuFadeIn 0.3s ease;
}
@keyframes kefuFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.kefu-msg-user {
    justify-content: flex-end;
}
.kefu-msg-admin {
    justify-content: flex-start;
}
.kefu-msg .bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.6;
    position: relative;
}
.kefu-msg-user .bubble {
    background: #1976d2;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.kefu-msg-admin .bubble {
    background: #f1f3f5;
    color: #1e293b;
    border-bottom-left-radius: 4px;
}
.kefu-msg .time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    display: block;
}
.kefu-msg-user .time {
    text-align: right;
    color: rgba(255, 255, 255, 0.7);
}
.kefu-msg .attachment-link {
    color: inherit;
    text-decoration: underline;
}
.kefu-msg-user .attachment-link {
    color: #fff;
}
.kefu-msg-new {
    animation: kefuHighlight 1s ease;
}
@keyframes kefuHighlight {
    0% {
        background: rgba(25, 118, 210, 0.2);
    }
    100% {
        background: transparent;
    }
}

/* 状态标签 */
.kefu-status-badge {
    padding: 2px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    display: inline-block;
    margin-top: 4px;
}
.kefu-status-pending {
    background: #fff3e0;
    color: #e65100;
}
.kefu-status-replied {
    background: #e3f2fd;
    color: #0d47a1;
}
.kefu-status-closed {
    background: #e8f5e9;
    color: #2e7d32;
}

/* 回复表单 */
.kefu-reply-form {
    padding: 16px 20px;
    border-top: 1px solid #eee;
}
.kefu-reply-form textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    min-height: 80px;
    resize: vertical;
    box-sizing: border-box;
    font-family: inherit;
}
.kefu-reply-form textarea:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}
.kefu-reply-form button {
    padding: 10px 24px;
    background: #1976d2;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    margin-top: 8px;
    transition: background 0.2s;
}
.kefu-reply-form button:hover {
    background: #1565c0;
}
.kefu-reply-form button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.kefu-reply-form .tip {
    font-size: 12px;
    color: #999;
    margin-left: 12px;
}

/* 新消息横幅 */
.kefu-new-banner {
    background: #e3f2fd;
    color: #0d47a1;
    padding: 10px 16px;
    text-align: center;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 1px solid #bbdefb;
    display: none;
}
.kefu-new-banner:hover {
    background: #bbdefb;
}
.kefu-new-banner .badge {
    background: #ef5350;
    color: #fff;
    border-radius: 50%;
    padding: 0 8px;
    font-size: 12px;
    margin-left: 6px;
}

/* 评价区域 */
.kefu-rating-section {
    padding: 16px 20px;
    border-top: 1px solid #eee;
    text-align: center;
    display: none;
}
.kefu-rating-section .stars {
    font-size: 30px;
    cursor: pointer;
    user-select: none;
}
.kefu-rating-section .stars span {
    transition: 0.2s;
}
.kefu-rating-section .stars span:hover {
    transform: scale(1.2);
}
.kefu-rating-section .stars .active {
    color: #ffc107;
}
.kefu-rating-section .stars .inactive {
    color: #ddd;
}
.kefu-rating-section textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    min-height: 60px;
    resize: vertical;
    box-sizing: border-box;
    margin-top: 8px;
    font-family: inherit;
}
.kefu-rating-section button {
    padding: 8px 24px;
    background: #4caf50;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    margin-top: 8px;
    transition: background 0.2s;
}
.kefu-rating-section button:hover {
    background: #388e3c;
}
.kefu-rating-done {
    color: #2e7d32;
    font-size: 14px;
}

/* 消息结果提示 */
.kefu-msg-result {
    padding: 8px 16px;
    border-radius: 8px;
    margin-top: 8px;
    display: none;
}
.kefu-msg-result.success {
    background: #e8f5e9;
    color: #2e7d32;
    display: block;
}
.kefu-msg-result.error {
    background: #fce4ec;
    color: #c62828;
    display: block;
}

/* 底部 */
.kefu-footer {
    text-align: center;
    padding: 12px;
    font-size: 13px;
    color: #999;
    border-top: 1px solid #eee;
}
.kefu-footer a {
    color: #1976d2;
    text-decoration: none;
}

/* ========== 4. 移动端适配 ========== */
@media (max-width: 480px) {
    .kefu-panel {
        bottom: 80px;
        right: 10px;
        left: 10px;
        width: auto;
        max-height: 80vh;
    }
    .kefu-trigger {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
    }
    .kefu-trigger svg {
        width: 28px;
        height: 28px;
    }
    .kefu-chat-container {
        margin: 0 10px;
        border-radius: 12px;
    }
    .kefu-chat-body {
        padding: 12px;
        max-height: 400px;
    }
    .kefu-msg .bubble {
        max-width: 85%;
        font-size: 13px;
        padding: 8px 12px;
    }
    .kefu-reply-form {
        padding: 12px 16px;
    }
    .kefu-reply-form textarea {
        min-height: 60px;
        font-size: 13px;
    }
    .kefu-panel .kefu-body {
        padding: 16px;
    }
}

/* ========== 5. 工具类 ========== */
.kefu-hidden {
    display: none !important;
}
.kefu-text-center {
    text-align: center;
}
.kefu-text-muted {
    color: #999;
}
.kefu-mt-8 {
    margin-top: 8px;
}
.kefu-mb-8 {
    margin-bottom: 8px;
}

/* ===== 对话窗特有样式 ===== */
.kefu-chat-panel {
    height: 550px;
    max-height: 80vh;
}
.kefu-chat-panel .kefu-chat-header {
    background: #1976d2;
    color: #fff;
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.kefu-chat-panel .kefu-chat-header .kefu-status-badge {
    font-size: 11px;
    background: rgba(255,255,255,0.2);
    color: #fff;
    border-radius: 12px;
    padding: 2px 10px;
    margin-left: 8px;
}
.kefu-chat-panel .kefu-new-banner {
    background: #e3f2fd;
    color: #0d47a1;
    padding: 8px 16px;
    text-align: center;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 1px solid #bbdefb;
    display: none;
}
.kefu-chat-panel .kefu-new-banner:hover {
    background: #bbdefb;
}
.kefu-chat-panel .kefu-new-banner .badge {
    background: #ef5350;
    color: #fff;
    border-radius: 50%;
    padding: 0 8px;
    font-size: 12px;
    margin-left: 6px;
}
.kefu-chat-panel #kefuChatBody {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
    background: #f8faff;
}
.kefu-chat-panel #kefuReplyArea {
    padding: 12px 20px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
}
.kefu-chat-panel #kefuReplyArea textarea {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    resize: none;
    height: 44px;
    box-sizing: border-box;
    font-family: inherit;
}
.kefu-chat-panel #kefuReplyArea textarea:focus {
    border-color: #1976d2;
    outline: none;
    box-shadow: 0 0 0 3px rgba(25,118,210,0.1);
}
.kefu-chat-panel #kefuReplyArea button {
    padding: 0 18px;
    background: #1976d2;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}
.kefu-chat-panel #kefuReplyArea button:hover {
    background: #1565c0;
}
.kefu-chat-panel #kefuReplyArea button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.kefu-chat-panel .kefu-msg {
    display: flex;
    margin-bottom: 12px;
}
.kefu-chat-panel .kefu-msg-user {
    justify-content: flex-end;
}
.kefu-chat-panel .kefu-msg-admin {
    justify-content: flex-start;
}
.kefu-chat-panel .kefu-msg .bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 12px;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.5;
}
.kefu-chat-panel .kefu-msg-user .bubble {
    background: #1976d2;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.kefu-chat-panel .kefu-msg-admin .bubble {
    background: #f1f3f5;
    color: #1e293b;
    border-bottom-left-radius: 4px;
}
.kefu-chat-panel .kefu-msg .time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    display: block;
}
.kefu-chat-panel .kefu-msg-user .time {
    text-align: right;
    color: rgba(255,255,255,0.7);
}
.kefu-chat-panel .kefu-msg .attachment-link {
    text-decoration: underline;
}
.kefu-chat-panel .kefu-msg-user .attachment-link {
    color: #fff;
}
.kefu-chat-panel #kefuRatingArea {
    padding: 12px 20px;
    border-top: 1px solid #eee;
    text-align: center;
    display: none;
}
.kefu-chat-panel #kefuRatingArea .kefu-stars {
    font-size: 28px;
    cursor: pointer;
    user-select: none;
}
.kefu-chat-panel #kefuRatingArea .kefu-stars span {
    transition: 0.2s;
}
.kefu-chat-panel #kefuRatingArea .kefu-stars span:hover {
    transform: scale(1.2);
}
.kefu-chat-panel #kefuRatingArea textarea {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    min-height: 40px;
    resize: vertical;
    margin-top: 6px;
    box-sizing: border-box;
    font-family: inherit;
}
.kefu-chat-panel #kefuRatingArea button {
    padding: 6px 20px;
    background: #4caf50;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    margin-top: 6px;
}
.kefu-chat-panel #kefuRatingArea button:hover {
    background: #388e3c;
}
.kefu-chat-panel #kefuRatingArea #kefuRatingMsg {
    margin-top: 6px;
    font-size: 13px;
}

/* 移动端适配对话窗 */
@media (max-width: 480px) {
    .kefu-chat-panel {
        bottom: 80px;
        right: 10px;
        left: 10px;
        width: auto;
        height: 80vh;
    }
}