/* ===== WebyChat Widget Styles ===== */
:root {
    --webychat-primary: #6C5CE7;
    --webychat-primary-dark: #5a4bd6;
    --webychat-primary-light: #a29bfe;
    --webychat-radius: 16px;
    --webychat-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    --webychat-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ===== RESET for widget scope ===== */
#webychat-widget,
#webychat-widget *,
#webychat-widget *::before,
#webychat-widget *::after {
    box-sizing: border-box;
    line-height: normal;
}
#webychat-widget button { font-family: var(--webychat-font); }

/* Force all SVGs inside widget */
#webychat-widget svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

/* ===== Launcher Button ===== */
#webychat-launcher {
    position: fixed;
    bottom: 24px;
    z-index: 999998;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--webychat-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--webychat-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    padding: 0;
    margin: 0;
    outline: none;
}
#webychat-launcher:hover {
    transform: scale(1.08);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
}
#webychat-launcher svg {
    width: 28px;
    height: 28px;
    transition: transform 0.3s ease;
}
#webychat-launcher.open svg {
    transform: rotate(90deg);
}

.webychat-position-bottom-right #webychat-launcher { right: 24px; }
.webychat-position-bottom-left #webychat-launcher { left: 24px; }

/* ===== Chat Window ===== */
#webychat-window {
    position: fixed;
    bottom: 100px;
    z-index: 999999;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: var(--webychat-radius);
    box-shadow: var(--webychat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    font-family: var(--webychat-font);
}
#webychat-window.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.webychat-position-bottom-right #webychat-window { right: 24px; }
.webychat-position-bottom-left #webychat-window { left: 24px; }

/* ===== Header ===== */
.webychat-header {
    background: var(--webychat-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.webychat-header-avatar {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.webychat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.webychat-header-avatar svg {
    width: 20px;
    height: 20px;
    color: #fff;
}
.webychat-header-info {
    flex: 1;
    min-width: 0;
}
.webychat-header-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    margin: 0;
    padding: 0;
}
.webychat-header-subtitle {
    font-size: 12px;
    opacity: 0.8;
    margin-top: 2px;
}

/* Header Action Buttons */
.webychat-header-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.webychat-header-actions button {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 30px;
    height: 30px;
    min-width: 30px;
    min-height: 30px;
    max-width: 30px;
    max-height: 30px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
    margin: 0;
    outline: none;
}
.webychat-header-actions button:hover {
    background: rgba(255,255,255,0.25);
}
.webychat-header-actions button svg {
    width: 15px;
    height: 15px;
    color: #fff;
}

/* ===== Mode Toggle (Text / Voice) ===== */
.webychat-mode-toggle {
    display: flex;
    background: #f3f3f5;
    padding: 4px;
    flex-shrink: 0;
    gap: 4px;
}
.webychat-mode-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: transparent;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-family: var(--webychat-font);
    color: #888;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    line-height: 1;
    white-space: nowrap;
    margin: 0;
    outline: none;
}
.webychat-mode-btn:hover {
    color: #555;
    background: rgba(255,255,255,0.5);
}
.webychat-mode-btn.active {
    background: #fff;
    color: var(--webychat-primary);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    font-weight: 600;
}
.webychat-mode-btn svg {
    width: 16px;
    height: 16px;
    color: currentColor;
}

/* ===== Messages Area ===== */
.webychat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
.webychat-messages::-webkit-scrollbar { width: 4px; }
.webychat-messages::-webkit-scrollbar-track { background: transparent; }
.webychat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

/* ===== Message Bubbles ===== */
.webychat-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    animation: webychat-fadeIn 0.3s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
    position: relative;
}
.webychat-msg.user {
    background: var(--webychat-primary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.webychat-msg.assistant {
    background: #f0f1f3;
    color: #1a1a1a;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.webychat-msg .voice-badge {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 4px;
}
.webychat-msg code {
    background: rgba(0,0,0,0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
}

/* ===== TTS Button (inside messages) ===== */
.webychat-tts-btn {
    background: none !important;
    border: none !important;
    cursor: pointer;
    color: #bbb;
    padding: 2px !important;
    margin: 4px 0 0 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto !important;
    height: auto !important;
    min-width: auto !important;
    min-height: auto !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 4px !important;
}
.webychat-tts-btn:hover { color: var(--webychat-primary); }
.webychat-tts-btn.speaking { color: var(--webychat-primary); }
.webychat-tts-btn svg {
    width: 14px !important;
    height: 14px !important;
}

/* ===== Typing Indicator ===== */
.webychat-typing {
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    align-self: flex-start;
    background: #f0f1f3;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
.webychat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #bbb;
    display: block;
    animation: webychat-bounce 1.4s infinite;
}
.webychat-typing span:nth-child(2) { animation-delay: 0.2s; }
.webychat-typing span:nth-child(3) { animation-delay: 0.4s; }

/* ===== Input Area ===== */
.webychat-input-area {
    padding: 10px 14px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: #fff;
}
.webychat-input-area textarea {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 9px 14px;
    font-size: 14px;
    font-family: var(--webychat-font);
    resize: none;
    max-height: 80px;
    min-height: 38px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s;
    background: #fafafa;
    color: #333;
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}
.webychat-input-area textarea:focus {
    border-color: var(--webychat-primary);
    background: #fff;
}
.webychat-input-area textarea::placeholder { color: #aaa; }

/* ===== Send & Mic Buttons ===== */
.webychat-send-btn,
.webychat-mic-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    max-width: 38px;
    max-height: 38px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    padding: 0;
    margin: 0;
    outline: none;
}
.webychat-send-btn svg,
.webychat-mic-btn svg {
    width: 17px;
    height: 17px;
}
.webychat-send-btn {
    background: var(--webychat-primary);
    color: #fff;
}
.webychat-send-btn:hover { background: var(--webychat-primary-dark); }
.webychat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.webychat-send-btn:disabled:hover { background: var(--webychat-primary); }

.webychat-mic-btn {
    background: #f0f1f3;
    color: #666;
}
.webychat-mic-btn:hover { background: #e4e5e8; }
.webychat-mic-btn.recording {
    background: #ff4757;
    color: #fff;
    animation: webychat-pulse 1.5s infinite;
}

/* ===== Voice Mode Area ===== */
.webychat-voice-area {
    padding: 30px 20px;
    text-align: center;
    flex-shrink: 0;
    display: none;
}
.webychat-voice-area.active { display: block; }

.webychat-voice-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 3px solid var(--webychat-primary);
    background: #fff;
    color: var(--webychat-primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    margin: 0 auto 10px;
    padding: 0;
    outline: none;
}
.webychat-voice-btn:hover { background: #f5f3ff; }
.webychat-voice-btn.recording {
    background: #ff4757;
    border-color: #ff4757;
    color: #fff;
    animation: webychat-pulse 1.5s infinite;
}
.webychat-voice-btn svg {
    width: 28px;
    height: 28px;
}
.webychat-voice-status {
    font-size: 13px;
    color: #888;
    margin-top: 6px;
}

/* ===== Waveform Animation ===== */
.webychat-waveform {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 30px;
    margin: 8px auto;
}
.webychat-waveform span {
    width: 3px;
    background: var(--webychat-primary);
    border-radius: 2px;
    display: block;
    animation: webychat-wave 1s ease-in-out infinite;
}
.webychat-waveform span:nth-child(1) { height: 10px; animation-delay: 0s; }
.webychat-waveform span:nth-child(2) { height: 18px; animation-delay: 0.1s; }
.webychat-waveform span:nth-child(3) { height: 26px; animation-delay: 0.2s; }
.webychat-waveform span:nth-child(4) { height: 18px; animation-delay: 0.3s; }
.webychat-waveform span:nth-child(5) { height: 10px; animation-delay: 0.4s; }

/* ===== Lead Capture Form ===== */
.webychat-lead-form {
    padding: 24px 20px;
    text-align: center;
}
.webychat-lead-form h3 {
    margin: 0 0 6px;
    padding: 0;
    font-size: 18px;
    color: #333;
    font-weight: 700;
}
.webychat-lead-form p {
    margin: 0 0 18px;
    padding: 0;
    color: #888;
    font-size: 13px;
}
.webychat-lead-form input[type="text"],
.webychat-lead-form input[type="email"],
.webychat-lead-form input[type="tel"] {
    display: block;
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 10px;
    margin-bottom: 10px;
    font-size: 14px;
    font-family: var(--webychat-font);
    outline: none;
    box-sizing: border-box;
    background: #fafafa;
    color: #333;
    -webkit-appearance: none;
    appearance: none;
}
.webychat-lead-form input:focus {
    border-color: var(--webychat-primary);
    background: #fff;
}
.webychat-lead-form input::placeholder { color: #aaa; }

.webychat-lead-start-btn {
    width: 100%;
    padding: 12px;
    background: var(--webychat-primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--webychat-font);
    transition: background 0.2s;
    margin-top: 4px;
    outline: none;
}
.webychat-lead-start-btn:hover { background: var(--webychat-primary-dark); }
.webychat-lead-skip {
    margin-top: 12px;
    font-size: 13px;
    color: #999;
    cursor: pointer;
    display: inline-block;
}
.webychat-lead-skip:hover { color: #666; }

/* ===== Branding ===== */
.webychat-branding {
    text-align: center;
    padding: 7px;
    font-size: 11px;
    color: #bbb;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}
.webychat-branding a {
    color: #999;
    text-decoration: none;
    font-weight: 600;
}
.webychat-branding a:hover { color: var(--webychat-primary); }

/* ===== Animations ===== */
@keyframes webychat-fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes webychat-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}
@keyframes webychat-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.4); }
    50% { box-shadow: 0 0 0 12px rgba(255, 71, 87, 0); }
}
@keyframes webychat-wave {
    0%, 100% { transform: scaleY(0.5); }
    50% { transform: scaleY(1); }
}

/* ===== Mobile Responsive ===== */
@media (max-width: 480px) {
    #webychat-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        bottom: 8px;
        right: 8px !important;
        left: 8px !important;
        border-radius: 12px;
        max-height: none;
    }
    #webychat-launcher {
        bottom: 16px;
        width: 54px;
        height: 54px;
    }
    .webychat-position-bottom-right #webychat-launcher { right: 16px; }
    .webychat-position-bottom-left #webychat-launcher { left: 16px; }
}
