/* ============================================
   CHECK ENGINE HELP — LiveChat-style Widget v2
   Contrast fixes + upload + rating support
   ============================================ */

/* ── Launcher button ── */
.ceh-chat-launcher {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

.ceh-chat-launcher-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #c76b2a 0%, #a0541e 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(199, 107, 42, 0.4), 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.ceh-chat-launcher-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(199, 107, 42, 0.5), 0 2px 8px rgba(0,0,0,0.15);
}

.ceh-chat-launcher-btn:active {
    transform: scale(0.96);
}

.ceh-chat-launcher-btn svg {
    width: 28px;
    height: 28px;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ceh-chat-launcher-btn .icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}

.ceh-chat-launcher.is-open .ceh-chat-launcher-btn .icon-chat {
    opacity: 0;
    transform: rotate(90deg);
}

.ceh-chat-launcher.is-open .ceh-chat-launcher-btn .icon-close {
    opacity: 1;
    transform: rotate(0deg);
}

/* Unread badge */
.ceh-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #d32f2f;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid #fff;
    animation: cehBadgePulse 2s ease-in-out infinite;
    line-height: 1;
}

.ceh-chat-badge[hidden] { display: none; }

@keyframes cehBadgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* Greeting bubble */
.ceh-chat-greeting {
    background: #fff;
    border-radius: 12px 12px 4px 12px;
    padding: 0.75rem 1rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    max-width: 260px;
    font-size: 0.88rem;
    line-height: 1.5;
    color: #38291d;
    cursor: pointer;
    transition: opacity 0.3s ease, transform 0.3s ease;
    animation: cehGreetSlide 0.4s ease;
}

.ceh-chat-greeting:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,0.14);
}

.ceh-chat-greeting[hidden] { display: none; }

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

.ceh-chat-greeting-close {
    float: right;
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    margin: -4px -4px 0 8px;
}

/* ── Chat window ── */
.ceh-chat-window {
    position: fixed;
    bottom: 5.5rem;
    right: 1.25rem;
    width: 380px;
    max-height: calc(100vh - 7rem);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 8px 40px rgba(0,0,0,0.16), 0 2px 8px rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
    transition: opacity 0.25s ease, transform 0.25s ease;
    transform-origin: bottom right;
}

.ceh-chat-window[hidden] {
    display: none;
}

.ceh-chat-window.ceh-animating-in {
    animation: cehWindowIn 0.3s ease forwards;
}

.ceh-chat-window.ceh-animating-out {
    animation: cehWindowOut 0.2s ease forwards;
}

@keyframes cehWindowIn {
    from { opacity: 0; transform: scale(0.85) translateY(16px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes cehWindowOut {
    from { opacity: 1; transform: scale(1) translateY(0); }
    to { opacity: 0; transform: scale(0.85) translateY(16px); }
}

/* ── Header ── */
.ceh-chat-header {
    background: linear-gradient(135deg, #c76b2a 0%, #a85a22 60%, #915020 100%);
    color: #fff;
    padding: 1rem 1.1rem 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.ceh-chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}

.ceh-chat-avatar svg {
    width: 22px;
    height: 22px;
    color: #fff;
}

.ceh-chat-avatar-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #c76b2a;
    background: #4caf50;
}

.ceh-chat-avatar-status.offline {
    background: #999;
}

.ceh-chat-header-info {
    flex: 1;
    min-width: 0;
}

.ceh-chat-header-title {
    font-weight: 700;
    font-size: 0.95rem;
    margin: 0;
}

.ceh-chat-header-subtitle {
    font-size: 0.78rem;
    opacity: 0.85;
    margin: 0.1rem 0 0;
}

/* ── Header action buttons — HIGH CONTRAST FIX ── */
.ceh-chat-header-actions {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
}

.ceh-chat-header-actions button {
    background: rgba(255,255,255,0.92);
    border: none;
    color: #7a4a1f;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.ceh-chat-header-actions button:hover {
    background: #fff;
    color: #c76b2a;
    transform: scale(1.08);
}

.ceh-chat-header-actions button:active {
    transform: scale(0.95);
}

/* ── Pre-chat form ── */
.ceh-chat-prechat {
    padding: 1.25rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: #faf8f5;
}

.ceh-chat-prechat h3 {
    margin: 0 0 0.25rem;
    font-size: 1.05rem;
    color: #38291d;
}

.ceh-chat-prechat p {
    margin: 0 0 1rem;
    font-size: 0.88rem;
    color: #6b5f54;
}

.ceh-chat-prechat-field {
    margin-bottom: 0.75rem;
}

.ceh-chat-prechat-field label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #5c6773;
    margin-bottom: 0.25rem;
}

.ceh-chat-prechat-field input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.9rem;
    background: #fff;
    transition: border-color 0.15s ease;
    box-sizing: border-box;
}

.ceh-chat-prechat-field input:focus {
    outline: none;
    border-color: #c76b2a;
    box-shadow: 0 0 0 3px rgba(199, 107, 42, 0.12);
}

.ceh-chat-prechat-btn {
    width: 100%;
    padding: 0.7rem;
    background: linear-gradient(135deg, #c76b2a 0%, #a0541e 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease;
    margin-top: 0.25rem;
}

.ceh-chat-prechat-btn:hover {
    opacity: 0.92;
}

/* ── Messages area ── */
.ceh-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #faf8f5;
    min-height: 260px;
    max-height: 360px;
    scroll-behavior: smooth;
}

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

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

.ceh-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.12);
    border-radius: 4px;
}

/* Welcome message */
.ceh-chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1rem 0.5rem;
}

.ceh-chat-welcome-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #c76b2a, #a0541e);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.ceh-chat-welcome-avatar svg {
    width: 28px;
    height: 28px;
    color: #fff;
}

.ceh-chat-welcome h4 {
    margin: 0 0 0.25rem;
    font-size: 0.95rem;
    color: #38291d;
}

.ceh-chat-welcome p {
    margin: 0;
    font-size: 0.85rem;
    color: #6b5f54;
    line-height: 1.5;
}

/* Message bubbles */
.ceh-msg {
    display: flex;
    margin-bottom: 0.65rem;
    align-items: flex-end;
    gap: 0.4rem;
    animation: cehMsgIn 0.25s ease;
}

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

.ceh-msg.is-visitor {
    flex-direction: row-reverse;
}

.ceh-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
}

.ceh-msg-avatar.bot {
    background: linear-gradient(135deg, #c76b2a, #a0541e);
}

.ceh-msg-avatar.agent {
    background: linear-gradient(135deg, #2e7d4f, #1b5e37);
}

.ceh-msg-avatar.visitor {
    background: linear-gradient(135deg, #5c6773, #3e4750);
}

.ceh-msg-content {
    max-width: 80%;
    min-width: 0;
}

.ceh-msg-bubble {
    padding: 0.6rem 0.85rem;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.ceh-msg-bubble p {
    margin: 0;
}

.ceh-msg-bubble a {
    color: #c76b2a;
    text-decoration: underline;
    word-break: break-all;
}

.ceh-msg-bubble a:hover {
    color: #a0541e;
}

/* Bubble colors */
.ceh-msg:not(.is-visitor) .ceh-msg-bubble {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 14px 14px 14px 4px;
    color: #333;
}

.ceh-msg.is-visitor .ceh-msg-bubble {
    background: linear-gradient(135deg, #c76b2a, #b0602a);
    color: #fff;
    border-radius: 14px 14px 4px 14px;
}

.ceh-msg.is-visitor .ceh-msg-bubble a {
    color: #ffe0c4;
}

.ceh-msg.is-admin .ceh-msg-bubble {
    background: #e8f5e9;
    border: 1px solid #c8e6c9;
    border-radius: 14px 14px 14px 4px;
    color: #2d5a3e;
}

/* Attachment inside messages */
.ceh-msg-attachment {
    margin-top: 6px;
}

.ceh-msg-attachment img {
    max-width: 220px;
    max-height: 160px;
    border-radius: 8px;
    cursor: pointer;
    display: block;
}

.ceh-msg-attachment a {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: #c76b2a;
    text-decoration: none;
}

.ceh-msg-attachment a:hover { text-decoration: underline; }

.ceh-msg.is-visitor .ceh-msg-attachment a {
    color: #ffe0c4;
}

.ceh-msg-meta {
    display: flex;
    gap: 0.5rem;
    align-items: baseline;
    margin-bottom: 0.15rem;
    padding: 0 0.15rem;
}

.ceh-msg.is-visitor .ceh-msg-meta {
    flex-direction: row-reverse;
}

.ceh-msg-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: #5c6773;
}

.ceh-msg-time {
    font-size: 0.7rem;
    color: #999;
}

/* Typing indicator */
.ceh-typing {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0;
}

.ceh-typing-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #c76b2a, #a0541e);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ceh-typing-avatar svg {
    width: 14px;
    height: 14px;
    color: #fff;
}

.ceh-typing-dots {
    display: flex;
    gap: 3px;
    padding: 0.6rem 0.85rem;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 14px 14px 14px 4px;
}

.ceh-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #bbb;
    animation: cehTypingBounce 1.4s ease-in-out infinite;
}

.ceh-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ceh-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* ── Input area ── */
.ceh-chat-input {
    border-top: 1px solid #eee;
    padding: 0.65rem 0.75rem;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: #fff;
    flex-shrink: 0;
}

/* Upload button */
.ceh-chat-upload-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid #e0e0e0;
    background: #faf8f5;
    color: #888;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.ceh-chat-upload-btn:hover {
    background: #c76b2a;
    color: #fff;
    border-color: #c76b2a;
}

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

.ceh-chat-upload-btn input[type="file"] {
    display: none;
}

.ceh-chat-input textarea {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 0.55rem 0.85rem;
    font-size: 0.88rem;
    resize: none;
    max-height: 100px;
    min-height: 38px;
    line-height: 1.4;
    background: #faf8f5;
    transition: border-color 0.15s ease;
    font-family: inherit;
    box-sizing: border-box;
    color: #333;
}

.ceh-chat-input textarea:focus {
    outline: none;
    border-color: #c76b2a;
}

.ceh-chat-input textarea::placeholder {
    color: #aaa;
}

.ceh-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #c76b2a, #a0541e);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 2px 6px rgba(199, 107, 42, 0.3);
}

.ceh-chat-send:hover {
    opacity: 0.9;
    box-shadow: 0 3px 10px rgba(199, 107, 42, 0.45);
}

.ceh-chat-send:active {
    transform: scale(0.92);
}

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

.ceh-chat-send svg {
    width: 18px;
    height: 18px;
}

/* ── Upload preview ── */
.ceh-chat-upload-preview {
    border-top: 1px solid #eee;
    padding: 8px 12px;
    background: #faf8f5;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: #555;
}

.ceh-chat-upload-preview .upload-thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
}

.ceh-chat-upload-preview .upload-file-icon {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: #e8e4e0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #888;
}

.ceh-chat-upload-preview .upload-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ceh-chat-upload-preview .upload-remove {
    background: none;
    border: none;
    color: #d32f2f;
    cursor: pointer;
    font-size: 18px;
    padding: 0 4px;
}

/* ── Rating overlay ── */
.ceh-chat-rating {
    padding: 1.5rem 1.25rem;
    background: #faf8f5;
    text-align: center;
    animation: cehMsgIn 0.3s ease;
}

.ceh-chat-rating h4 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    color: #38291d;
}

.ceh-chat-rating p {
    margin: 0 0 1rem;
    font-size: 0.85rem;
    color: #6b5f54;
}

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

.ceh-chat-rating-stars button {
    background: none;
    border: none;
    font-size: 32px;
    cursor: pointer;
    color: #ddd;
    transition: color 0.15s ease, transform 0.15s ease;
    padding: 0;
    line-height: 1;
}

.ceh-chat-rating-stars button:hover,
.ceh-chat-rating-stars button.active {
    color: #f1a42b;
    transform: scale(1.15);
}

.ceh-chat-rating textarea {
    width: 100%;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.85rem;
    resize: none;
    height: 60px;
    background: #fff;
    box-sizing: border-box;
    margin-bottom: 10px;
    font-family: inherit;
    color: #333;
}

.ceh-chat-rating textarea:focus {
    outline: none;
    border-color: #c76b2a;
}

.ceh-chat-rating-submit {
    padding: 8px 24px;
    background: linear-gradient(135deg, #c76b2a, #a0541e);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
}

.ceh-chat-rating-submit:hover { opacity: 0.9; }

.ceh-chat-rating-skip {
    display: block;
    margin: 8px auto 0;
    background: none;
    border: none;
    color: #999;
    font-size: 0.8rem;
    cursor: pointer;
}

.ceh-chat-rating-skip:hover { color: #666; }

.ceh-chat-rating-thanks {
    padding: 2rem 1.25rem;
    text-align: center;
    background: #faf8f5;
}

.ceh-chat-rating-thanks h4 {
    color: #38291d;
    margin: 0 0 0.5rem;
}

.ceh-chat-rating-thanks p {
    color: #6b5f54;
    font-size: 0.85rem;
    margin: 0;
}

/* ── Footer / powered by ── */
.ceh-chat-footer {
    text-align: center;
    padding: 0.4rem;
    font-size: 0.7rem;
    color: #bbb;
    background: #fff;
    border-top: 1px solid #f0f0f0;
}

.ceh-chat-footer a {
    color: #999;
    text-decoration: none;
}

.ceh-chat-footer a:hover {
    color: #c76b2a;
}

/* ── Status bar ── */
.ceh-chat-status {
    text-align: center;
    padding: 0.35rem;
    font-size: 0.78rem;
    color: #d32f2f;
    background: #fff3f3;
    border-top: 1px solid #fdd;
}

.ceh-chat-status:empty,
.ceh-chat-status[hidden] {
    display: none;
}

/* ── Sound toggle ── */
.ceh-chat-sound-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    transition: opacity 0.15s;
    padding: 2px;
}

.ceh-chat-sound-toggle:hover { opacity: 1; }
.ceh-chat-sound-toggle.muted { opacity: 0.4; }

/* ── Drag drop overlay ── */
.ceh-chat-dropzone {
    position: absolute;
    inset: 0;
    background: rgba(199, 107, 42, 0.12);
    border: 3px dashed #c76b2a;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
}

.ceh-chat-dropzone p {
    font-size: 0.95rem;
    font-weight: 600;
    color: #c76b2a;
}

/* ── Responsive ── */
@media (max-width: 480px) {
    .ceh-chat-launcher {
        bottom: 0.75rem;
        right: 0.75rem;
    }

    .ceh-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 100vh;
        border-radius: 16px 16px 0 0;
    }

    .ceh-chat-messages {
        max-height: calc(100vh - 14rem);
    }

    .ceh-chat-greeting { display: none !important; }
}

/* ── Hide old widget ── */
.support-chat { display: none !important; }
