/* ==========================================================================
   CVwerk AI Support Assistant & Contact Widget
   ========================================================================== */

#cvwerk-support-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: #18181b;
    line-height: 1.5;
}

/* Floating Launcher Button */
.cvw-chat-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #0f7a5a 0%, #0d5f47 100%);
    color: #ffffff;
    border: none;
    border-radius: 9999px;
    padding: 12px 18px 12px 16px;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(15, 122, 90, 0.38), 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    outline: none;
    font-size: 14px;
    font-weight: 600;
}

.cvw-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 22px rgba(15, 122, 90, 0.48), 0 3px 8px rgba(0, 0, 0, 0.2);
    background: linear-gradient(135deg, #128c68 0%, #0f7a5a 100%);
}

.cvw-chat-btn:active {
    transform: translateY(0);
}

.cvw-chat-btn-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.cvw-chat-btn-icon svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.cvw-status-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    background-color: #22c55e;
    border: 2px solid #0f7a5a;
    border-radius: 50%;
}

/* Chat Dialog Window */
.cvw-chat-box {
    display: none;
    position: absolute;
    bottom: 66px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 100px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22), 0 3px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid #e4e4e7;
    overflow: hidden;
    flex-direction: column;
    animation: cvwSlideIn 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

.cvw-chat-box.open {
    display: flex;
}

@keyframes cvwSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.cvw-chat-header {
    background: linear-gradient(135deg, #0f7a5a 0%, #0d5f47 100%);
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

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

.cvw-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.cvw-header-title {
    font-size: 14px;
    font-weight: 700;
    margin: 0;
}

.cvw-header-sub {
    font-size: 11px;
    color: #d1fae5;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.cvw-header-sub::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #34d399;
}

.cvw-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.cvw-header-btn {
    background: transparent;
    border: none;
    color: #ffffff;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0.85;
    transition: opacity 0.15s, background-color 0.15s;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cvw-header-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

.cvw-lang-select {
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    max-width: 130px;
    text-overflow: ellipsis;
    transition: background 0.15s, border-color 0.15s;
    font-family: inherit;
}

.cvw-lang-select:hover {
    background: rgba(255, 255, 255, 0.26);
}

.cvw-lang-select:focus {
    border-color: #ffffff;
    background: rgba(255, 255, 255, 0.3);
}

.cvw-lang-select option {
    background: #ffffff;
    color: #18181b;
    font-weight: 500;
}

/* Tabs: Chat vs Email Form */
.cvw-chat-tabs {
    display: flex;
    background: #f4f4f5;
    border-bottom: 1px solid #e4e4e7;
    font-size: 12px;
}

.cvw-tab-btn {
    flex: 1;
    padding: 8px 10px;
    background: none;
    border: none;
    font-weight: 600;
    color: #71717a;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}

.cvw-tab-btn.active {
    background: #ffffff;
    color: #0f7a5a;
    border-bottom: 2px solid #0f7a5a;
}

/* Messages container */
.cvw-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fafafa;
    scroll-behavior: smooth;
}

.cvw-msg {
    display: flex;
    flex-direction: column;
    max-width: 86%;
    font-size: 13.5px;
    line-height: 1.45;
}

.cvw-msg.bot {
    align-self: flex-start;
}

.cvw-msg.user {
    align-self: flex-end;
}

.cvw-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    word-break: break-word;
}

.cvw-msg.bot .cvw-msg-bubble {
    background: #ffffff;
    color: #27272a;
    border: 1px solid #e4e4e7;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.cvw-msg.user .cvw-msg-bubble {
    background: #0f7a5a;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.cvw-msg-time {
    font-size: 10px;
    color: #a1a1aa;
    margin-top: 3px;
    padding: 0 4px;
}

.cvw-msg.user .cvw-msg-time {
    text-align: right;
}

/* Markdown formatting inside bubbles */
.cvw-msg-bubble p {
    margin: 0 0 8px 0;
}
.cvw-msg-bubble p:last-child {
    margin-bottom: 0;
}
.cvw-msg-bubble ul, .cvw-msg-bubble ol {
    margin: 4px 0 8px 18px;
    padding: 0;
}
.cvw-msg-bubble li {
    margin-bottom: 4px;
}
.cvw-msg-bubble a {
    color: #0f7a5a;
    font-weight: 600;
    text-decoration: underline;
}
.cvw-msg.user .cvw-msg-bubble a {
    color: #ffffff;
}

/* Quick question chips */
.cvw-quick-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.cvw-chip-btn {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    font-size: 11.5px;
    padding: 5px 9px;
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 500;
}

.cvw-chip-btn:hover {
    background: #dcfce7;
    border-color: #86efac;
    transform: translateY(-1px);
}

/* Escalation card */
.cvw-escalate-box {
    margin-top: 8px;
    padding: 10px 12px;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 8px;
    font-size: 12px;
    color: #92400e;
}

.cvw-escalate-btn {
    display: inline-block;
    margin-top: 6px;
    background: #0f7a5a;
    color: #ffffff !important;
    padding: 6px 12px;
    border-radius: 6px;
    text-decoration: none !important;
    font-weight: 600;
    font-size: 11.5px;
    cursor: pointer;
    border: none;
}

/* Typing Indicator */
.cvw-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid #e4e4e7;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.cvw-typing-dot {
    width: 6px;
    height: 6px;
    background-color: #9ca3af;
    border-radius: 50%;
    animation: cvwBounce 1.4s infinite ease-in-out both;
}

.cvw-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.cvw-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes cvwBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Input form area */
.cvw-chat-input-area {
    padding: 10px 12px;
    background: #ffffff;
    border-top: 1px solid #e4e4e7;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cvw-chat-input {
    flex: 1;
    border: 1px solid #d4d4d8;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13.5px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
}

.cvw-chat-input:focus {
    border-color: #0f7a5a;
    box-shadow: 0 0 0 2px rgba(15, 122, 90, 0.15);
}

.cvw-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #0f7a5a;
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s, transform 0.1s;
    flex-shrink: 0;
}

.cvw-send-btn:hover {
    background: #0d5f47;
}

.cvw-send-btn:disabled {
    background: #d4d4d8;
    cursor: not-allowed;
}

.cvw-send-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    margin-left: 1px;
}

/* Email Contact Form Container */
.cvw-email-panel {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #ffffff;
    flex-direction: column;
    gap: 12px;
}

.cvw-email-panel.active {
    display: flex;
}

.cvw-field-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cvw-field-group label {
    font-size: 12px;
    font-weight: 600;
    color: #3f3f46;
}

.cvw-form-input, .cvw-form-textarea {
    border: 1px solid #d4d4d8;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
}

.cvw-form-input:focus, .cvw-form-textarea:focus {
    border-color: #0f7a5a;
    box-shadow: 0 0 0 2px rgba(15, 122, 90, 0.15);
}

.cvw-form-textarea {
    min-height: 90px;
    resize: vertical;
}

.cvw-submit-mail-btn {
    background: #0f7a5a;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 4px;
}

.cvw-submit-mail-btn:hover {
    background: #0d5f47;
}

.cvw-submit-mail-btn:disabled {
    background: #a1a1aa;
    cursor: not-allowed;
}

.cvw-alert {
    padding: 10px;
    border-radius: 8px;
    font-size: 12.5px;
    display: none;
}

.cvw-alert.success {
    display: block;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.cvw-alert.error {
    display: block;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    /* Mobilde sadece yuvarlak chat simgesi görünsün (metin gizlenir) */
    .cvw-chat-btn {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        padding: 0;
        justify-content: center;
        box-shadow: 0 4px 18px rgba(15, 122, 90, 0.42), 0 2px 8px rgba(0, 0, 0, 0.2);
    }

    #cvw-btn-badge-text {
        display: none !important;
    }

    .cvw-chat-btn-icon {
        width: 24px;
        height: 24px;
    }

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

    .cvw-status-dot {
        top: -1px;
        right: -1px;
        width: 9px;
        height: 9px;
    }

    /* Normal sayfalarda alt köşe mesafesi */
    #cvwerk-support-widget {
        bottom: calc(16px + env(safe-area-inset-bottom));
        right: 16px;
    }

    /* Editor ve Anschreiben sayfalarında sabit alt barın (İndir / Düzenle butonlarının) ÜSTÜNE yerleştir */
    body.editor-body #cvwerk-support-widget,
    body.cvw-has-editor-bar #cvwerk-support-widget,
    #cvwerk-support-widget.cvw-on-editor {
        bottom: calc(84px + env(safe-area-inset-bottom)) !important;
        right: 16px !important;
    }

    .cvw-chat-box {
        bottom: 58px;
        right: 0;
        width: calc(100vw - 32px);
        height: 75vh;
        max-height: 520px;
    }

    body.editor-body .cvw-chat-box,
    body.cvw-has-editor-bar .cvw-chat-box,
    #cvwerk-support-widget.cvw-on-editor .cvw-chat-box {
        bottom: 58px;
        max-height: calc(100vh - 160px);
    }
}
