/* My Support — Embeddable Chat Widget CSS */
/* Customize via CSS variables on :root or the widget container */

.my-support-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.my-support-widget {
    --ms-primary: #2563eb;
    --ms-primary-hover: #1d4ed8;
    --ms-bg: #ffffff;
    --ms-bg-secondary: #f8fafc;
    --ms-text: #1e293b;
    --ms-text-light: #64748b;
    --ms-user-bubble: #2563eb;
    --ms-user-text: #ffffff;
    --ms-ai-bubble: #f1f5f9;
    --ms-ai-text: #1e293b;
    --ms-border: #e2e8f0;
    --ms-shadow: 0 4px 24px rgba(0,0,0,0.12);
    --ms-radius: 16px;
    --ms-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: var(--ms-font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--ms-text);
}

/* ── Chat Bubble Button ─────────────────────────────── */

.ms-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--ms-primary);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: var(--ms-shadow);
    transition: transform 0.2s, background 0.2s;
    position: relative;
    margin-left: auto;
}

.ms-toggle:hover {
    background: var(--ms-primary-hover);
    transform: scale(1.05);
}

.ms-toggle svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

.ms-toggle .ms-close-icon {
    display: none;
}

.ms-toggle.ms-open .ms-chat-icon {
    display: none;
}

.ms-toggle.ms-open .ms-close-icon {
    display: block;
}

/* ── Chat Panel ─────────────────────────────────────── */

.ms-panel {
    display: none;
    flex-direction: column;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--ms-bg);
    border-radius: var(--ms-radius);
    box-shadow: var(--ms-shadow);
    overflow: hidden;
    margin-bottom: 12px;
    position: absolute;
    bottom: 72px;
    right: 0;
}

.ms-panel.ms-open {
    display: flex;
}

/* ── Header ─────────────────────────────────────────── */

.ms-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--ms-primary);
    color: white;
    flex-shrink: 0;
}

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

.ms-header-info {
    flex: 1;
}

.ms-header-name {
    font-weight: 600;
    font-size: 15px;
}

.ms-header-status {
    font-size: 12px;
    opacity: 0.85;
}

.ms-header-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    opacity: 0.7;
    padding: 4px;
}

.ms-header-close:hover {
    opacity: 1;
}

/* ── Messages ───────────────────────────────────────── */

.ms-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--ms-bg-secondary);
}

.ms-message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: ms-fade-in 0.2s ease;
}

@keyframes ms-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.ms-message.ms-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ms-message-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.ms-user .ms-message-bubble {
    background: var(--ms-user-bubble);
    color: var(--ms-user-text);
    border-bottom-right-radius: 4px;
}

.ms-ai .ms-message-bubble {
    background: var(--ms-ai-bubble);
    color: var(--ms-ai-text);
    border-bottom-left-radius: 4px;
}

.ms-message-time {
    font-size: 11px;
    color: var(--ms-text-light);
    margin-top: 4px;
    text-align: right;
}

/* ── Typing Indicator ───────────────────────────────── */

.ms-typing {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--ms-ai-bubble);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    max-width: 60px;
}

.ms-typing.ms-visible {
    display: flex;
}

.ms-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ms-text-light);
    animation: ms-bounce 1.4s infinite;
}

.ms-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ms-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes ms-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* ── Input Area ─────────────────────────────────────── */

.ms-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--ms-border);
    background: var(--ms-bg);
    flex-shrink: 0;
}

.ms-input {
    flex: 1;
    border: 1px solid var(--ms-border);
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: var(--ms-font);
    outline: none;
    resize: none;
    max-height: 80px;
    line-height: 1.4;
}

.ms-input:focus {
    border-color: var(--ms-primary);
}

.ms-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--ms-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.ms-send-btn:hover {
    background: var(--ms-primary-hover);
}

.ms-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ms-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ── Error Banner ───────────────────────────────────── */

.ms-error {
    display: none;
    padding: 8px 16px;
    background: #fef2f2;
    color: #dc2626;
    font-size: 12px;
    text-align: center;
    border-bottom: 1px solid #fecaca;
}

.ms-error.ms-visible {
    display: block;
}

/* ── Mobile Responsive ──────────────────────────────── */

@media (max-width: 480px) {
    .my-support-widget {
        bottom: 0;
        right: 0;
        left: 0;
    }

    .ms-panel {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        margin-bottom: 0;
        bottom: 0;
        position: fixed;
        top: 0;
        left: 0;
    }

    .ms-toggle {
        position: fixed;
        bottom: 16px;
        right: 16px;
    }
}