/* ==========================================================================
   AI Chat Widget — Pongsak Clinic
   Supports both old .chatbot-* classes and new .chat-* classes
   ========================================================================== */

/* --- Widget Container --- */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Prompt', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* --- Toggle Button --- */
.chat-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #496275, #6a8fa7);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s, box-shadow 0.3s;
    position: relative;
}
.chat-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #D5CD94;
    color: #496275;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 8px;
}

/* --- Chat Window --- */
.chat-window {
    position: absolute;
    bottom: 75px;
    right: 0;
    width: 380px;
    height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.chat-window.active {
    display: flex;
}

/* --- Header --- */
.chat-header {
    background: linear-gradient(135deg, #496275, #6a8fa7);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
.chat-avatar {
    width: 38px;
    height: 38px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}
.chat-header-text h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}
.chat-header-text p {
    margin: 0;
    font-size: 11px;
    opacity: 0.85;
}
.chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}
.chat-close:hover { opacity: 1; }

/* --- Notice Bar --- */
.chat-notice {
    background: #fef9e7;
    border-bottom: 1px solid #f0e6c0;
    padding: 8px 14px;
    font-size: 11px;
    color: #7d6608;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* --- Messages Area --- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: #f7f8fa;
}

/* --- Message Bubble --- */
.chat-msg {
    margin-bottom: 12px;
    display: flex;
    animation: chatFadeIn 0.25s ease;
}
@keyframes chatFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-msg.bot { justify-content: flex-start; }
.chat-msg.user { justify-content: flex-end; }

.chat-msg-content {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.chat-msg.bot .chat-msg-content {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.chat-msg.user .chat-msg-content {
    background: #496275;
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* --- Streaming cursor --- */
.chat-msg.streaming .chat-msg-content::after {
    content: '';
    display: inline-block;
    width: 2px;
    height: 1em;
    background: #496275;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: chatBlink 0.7s step-end infinite;
}
@keyframes chatBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* --- Suggestions --- */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    margin-bottom: 8px;
}
.chat-suggestion {
    background: #fff;
    border: 1px solid #c9d4dc;
    color: #496275;
    padding: 5px 12px;
    border-radius: 14px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.chat-suggestion:hover {
    background: #496275;
    color: #fff;
    border-color: #496275;
}

/* --- Input Area --- */
.chat-input-area {
    padding: 12px 14px;
    background: #fff;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    align-items: center;
}
.chat-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}
.chat-input:focus {
    border-color: #496275;
}
.chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #496275;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}
.chat-send:hover { background: #5a7a8f; }
.chat-send:disabled {
    background: #bbb;
    cursor: not-allowed;
}

/* --- Mobile --- */
@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 30px);
        height: calc(100vh - 100px);
        bottom: 75px;
        right: -10px;
        border-radius: 12px;
    }
    .chat-msg-content { max-width: 85%; }
}


/* ==========================================================================
   Legacy .chatbot-* classes (kept for backward compatibility)
   ========================================================================== */
.chatbot-widget { position: fixed; bottom: 20px; right: 20px; z-index: 9999; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
.chatbot-button { width: 60px; height: 60px; border-radius: 50%; background: linear-gradient(135deg, #496275, #6a8fa7); border: none; cursor: pointer; box-shadow: 0 4px 15px rgba(0,0,0,0.2); display: flex; align-items: center; justify-content: center; transition: transform 0.3s, box-shadow 0.3s; position: relative; }
.chatbot-button:hover { transform: scale(1.05); box-shadow: 0 6px 20px rgba(0,0,0,0.25); }
.chatbot-button svg { width: 30px; height: 30px; fill: white; }
.chatbot-badge { position: absolute; top: -5px; right: -5px; background: #ff4757; color: white; font-size: 12px; font-weight: bold; padding: 2px 8px; border-radius: 10px; }
.chatbot-window { position: absolute; bottom: 75px; right: 0; width: 380px; height: 500px; background: white; border-radius: 16px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); display: none; flex-direction: column; overflow: hidden; }
.chatbot-window.active { display: flex; }
.chatbot-header { background: linear-gradient(135deg, #496275, #6a8fa7); color: white; padding: 15px 20px; display: flex; align-items: center; justify-content: space-between; }
.chatbot-header-info { display: flex; align-items: center; gap: 10px; }
.chatbot-avatar { width: 40px; height: 40px; background: rgba(255,255,255,0.2); border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.chatbot-avatar svg { width: 24px; height: 24px; fill: white; }
.chatbot-header-text h3 { margin: 0; font-size: 16px; font-weight: 600; }
.chatbot-header-text p { margin: 0; font-size: 12px; opacity: 0.9; }
.chatbot-close { background: none; border: none; color: white; font-size: 24px; cursor: pointer; padding: 5px; line-height: 1; }
.chatbot-notice { background: #fff3cd; border-left: 4px solid #ffc107; padding: 10px 15px; font-size: 12px; color: #856404; display: flex; align-items: flex-start; gap: 8px; }
.chatbot-notice svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; }
.chatbot-messages { flex: 1; overflow-y: auto; padding: 15px; background: #f8f9fa; }
.chatbot-message { margin-bottom: 15px; display: flex; align-items: flex-start; gap: 8px; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.chatbot-message.bot { flex-direction: row; }
.chatbot-message.user { flex-direction: row-reverse; }
.chatbot-message-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.chatbot-message.bot .chatbot-message-avatar { background: #496275; }
.chatbot-message.user .chatbot-message-avatar { background: #6c757d; }
.chatbot-message-avatar svg { width: 18px; height: 18px; fill: white; }
.chatbot-message-content { max-width: 75%; padding: 12px 16px; border-radius: 18px; font-size: 14px; line-height: 1.5; }
.chatbot-message.bot .chatbot-message-content { background: white; color: #333; border-bottom-left-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.chatbot-message.user .chatbot-message-content { background: #496275; color: white; border-bottom-right-radius: 4px; }
.chatbot-suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; padding-left: 40px; }
.chatbot-suggestion { background: white; border: 1px solid #496275; color: #496275; padding: 6px 12px; border-radius: 16px; font-size: 12px; cursor: pointer; transition: all 0.2s; }
.chatbot-suggestion:hover { background: #496275; color: white; }
.chatbot-fallback { background: #e3f2fd; border-radius: 12px; padding: 15px; margin-top: 10px; text-align: center; }
.chatbot-fallback p { margin: 0 0 10px 0; font-size: 13px; color: #1976d2; }
.chatbot-fallback-buttons { display: flex; gap: 10px; justify-content: center; }
.chatbot-fallback-btn { display: flex; align-items: center; gap: 5px; padding: 8px 12px; border-radius: 8px; font-size: 13px; text-decoration: none; color: white; transition: transform 0.2s; }
.chatbot-fallback-btn:hover { transform: scale(1.05); }
.chatbot-fallback-btn.line { background: #00b900; }
.chatbot-fallback-btn.messenger { background: #0084ff; }
.chatbot-fallback-btn svg { width: 18px; height: 18px; fill: white; }
.chatbot-input-area { padding: 15px; background: white; border-top: 1px solid #e9ecef; display: flex; gap: 10px; }
.chatbot-input { flex: 1; border: 1px solid #ddd; border-radius: 20px; padding: 10px 15px; font-size: 14px; outline: none; transition: border-color 0.2s; }
.chatbot-input:focus { border-color: #496275; }
.chatbot-send { width: 40px; height: 40px; border-radius: 50%; background: #496275; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.2s; }
.chatbot-send:hover { background: #5a7a8f; }
.chatbot-send svg { width: 20px; height: 20px; fill: white; }
.chatbot-send:disabled { background: #ccc; cursor: not-allowed; }
.chatbot-typing { display: none; align-items: center; gap: 4px; padding: 12px 16px; background: white; border-radius: 18px; border-bottom-left-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); width: fit-content; }
.chatbot-typing.active { display: flex; }
.chatbot-typing span { width: 8px; height: 8px; background: #496275; border-radius: 50%; animation: typing 1.4s infinite; }
.chatbot-typing span:nth-child(2) { animation-delay: 0.2s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-10px); } }
@media (max-width: 480px) { .chatbot-window { width: calc(100vw - 40px); height: calc(100vh - 100px); bottom: 80px; right: -10px; } }
