﻿/* ตัวแปร CSS สำหรับสี */
:root {
    --chat-primary: #FFC107; /* ปรับให้เข้ากับสีหลักของเว็บไซต์ */
    --chat-primary-dark: #FFA000;
    --chat-light-bg: #f8f9fa;
    --chat-user-bg: #FFF8E1;
    --chat-user-text: #FF6F00;
    --chat-bot-bg: #ffffff;
    --chat-bot-text: #333333;
    --chat-border: #e0e0e0;
    --chat-shadow: rgba(255, 193, 7, 0.15);
    --chat-shadow-heavy: rgba(255, 193, 7, 0.25);
    /* เพิ่มตัวแปรเพื่อความหลากหลาย */
    --chat-border-radius: 16px;
    --chat-message-radius: 18px;
}

/* เอฟเฟกต์พิมพ์ดีด */
@keyframes blink {
    0%, 100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background-color: var(--chat-user-text);
    margin-left: 2px;
    vertical-align: middle;
    animation: blink 0.8s step-end infinite;
}

/* โครงสร้างหลัก */
.chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

/* ปุ่มเปิด/ปิด Chat */
.chat-widget-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-image: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--chat-shadow-heavy);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

    .chat-widget-button:hover {
        transform: scale(1.1) rotate(5deg);
    }

    .chat-widget-button i {
        font-size: 24px;
    }

/* กล่อง Chat */
.chat-widget {
    position: relative;
    width: 360px;
    height: 500px;
    background-color: var(--chat-bot-bg);
    border-radius: var(--chat-border-radius);
    box-shadow: 0 12px 28px var(--chat-shadow), 0 5px 10px var(--chat-shadow);
    margin-bottom: 15px;
    overflow: hidden;
    display: none;
    flex-direction: column;
    transition: all 0.3s ease;
    animation: slideUp 0.3s forwards;
    backdrop-filter: blur(10px);
}

/* ส่วนหัว */
.chat-header {
    background-image: linear-gradient(to right, var(--chat-primary), var(--chat-primary-dark));
    padding: 15px 20px;
    border-radius: var(--chat-border-radius) var(--chat-border-radius) 0 0;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
}

.chat-logo {
    width: 45px;
    height: 45px;
    margin-right: 10px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-logo-icon {
    font-size: 20px;
    margin-right: 10px;
}

.header-info {
    display: flex;
    flex-direction: column;
}

.logo h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.status-indicator {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #4CAF50;
    border-radius: 50%;
    margin-right: 5px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }

    70% {
        box-shadow: 0 0 0 6px rgba(76, 175, 80, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
    }
}

.pulse-animation {
    animation: pulse 2s infinite;
}

.header-actions {
    display: flex;
    align-items: center;
}

.minimize-btn, .close-btn, .fullscreen-btn, .reset-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    margin-left: 5px;
    background-color: rgba(255, 255, 255, 0.2);
    transition: background-color 0.2s;
}

    .minimize-btn:hover, .close-btn:hover, .fullscreen-btn:hover, .reset-btn:hover {
        background-color: rgba(255, 255, 255, 0.4);
    }

/* โหมดเต็มจอ */
.chat-widget.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 0;
    z-index: 10000;
}

    .chat-widget.fullscreen .chat-messages {
        height: calc(100% - 130px);
    }

/* พื้นที่แสดงข้อความ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background-color: var(--chat-light-bg);
    scroll-behavior: smooth;
}

.message {
    display: flex;
    margin-bottom: 12px;
    animation: message-appear 0.3s ease-out;
}

.user-message {
    justify-content: flex-end;
}

.bot-message {
    justify-content: flex-start;
}

.message-content {
    max-width: 80%;
    padding: 10px 12px;
    border-radius: var(--chat-message-radius);
    font-size: 14px;
    line-height: 1.4;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    transition: transform 0.2s ease;
}

    .message-content:hover {
        transform: translateY(-2px);
    }

.user-message .message-content {
    background-color: var(--chat-user-bg);
    color: var(--chat-user-text);
    border-top-right-radius: 4px;
}

.bot-message .message-content {
    background-color: var(--chat-bot-bg);
    color: var(--chat-bot-text);
    border-top-left-radius: 4px;
    box-shadow: 0 1px 2px var(--chat-shadow);
}

/* ข้อความที่จัดรูปแบบ */
.formatted-message {
    word-wrap: break-word;
}

    .formatted-message p {
        margin: 0 0 8px 0;
    }

        .formatted-message p:last-child {
            margin-bottom: 0;
        }

    .formatted-message strong,
    .formatted-message b {
        font-weight: 700;
        color: var(--chat-user-text);
    }

    .formatted-message em,
    .formatted-message i {
        font-style: italic;
    }

    .formatted-message ul,
    .formatted-message ol {
        margin: 8px 0;
        padding-left: 20px;
    }

    .formatted-message li {
        margin-bottom: 4px;
    }

    .formatted-message a {
        color: var(--chat-primary-dark);
        text-decoration: none;
        position: relative;
    }

        .formatted-message a:after {
            content: '';
            position: absolute;
            width: 100%;
            height: 1px;
            bottom: 0;
            left: 0;
            background-color: var(--chat-primary-dark);
            transform: scaleX(0);
            transition: transform 0.3s ease;
        }

        .formatted-message a:hover:after {
            transform: scaleX(1);
        }

    .formatted-message blockquote {
        border-left: 4px solid #bbdefb;
        margin: 8px 0;
        padding: 4px 12px;
        background-color: rgba(187, 222, 251, 0.2);
    }

/* รายการสินค้า */
.product-list-note {
    margin: 10px 0;
    padding: 8px;
    background-color: #fff8e1;
    border-left: 4px solid #ffca28;
    border-radius: 0 4px 4px 0;
    font-size: 12px;
    color: #795548;
}

/* ส่วนแสดงกำลังโหลด */
.loading-dots {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 20px;
}

.dot {
    width: 6px;
    height: 6px;
    margin: 0 3px;
    background-color: #999;
    border-radius: 50%;
    animation: dot-pulse 1.5s infinite ease-in-out;
}

    .dot:nth-child(2) {
        animation-delay: 0.2s;
    }

    .dot:nth-child(3) {
        animation-delay: 0.4s;
    }

@keyframes dot-pulse {
    0%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* ส่วนป้อนข้อความ */
.chat-input {
    padding: 15px;
    background-color: white;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 0 0 var(--chat-border-radius) var(--chat-border-radius);
}

#chat-form {
    display: flex;
    align-items: center;
}

.input-container {
    display: flex;
    align-items: center;
    background-color: #F5F5F5;
    border-radius: 24px;
    padding: 4px 12px;
    transition: box-shadow 0.3s ease;
    width: 100%;
}

    .input-container:focus-within {
        box-shadow: 0 0 0 2px var(--chat-primary);
        background-color: white;
    }

#user-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px;
    font-size: 14px;
    outline: none;
}

.input-actions {
    display: flex;
    align-items: center;
}

.action-btn {
    border: none;
    background: transparent;
    color: #9E9E9E;
    cursor: pointer;
    transition: transform 0.3s ease, color 0.3s ease;
    padding: 8px;
    border-radius: 50%;
}

    .action-btn:hover {
        color: var(--chat-primary);
        transform: scale(1.1);
    }

#send-btn {
    color: var(--chat-primary);
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    margin-top: 12px;
    gap: 8px;
}

.chip {
    padding: 8px 16px;
    background-color: #F5F5F5;
    border: 1px solid #EEEEEE;
    border-radius: 18px;
    font-size: 13px;
    color: #424242;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
}

    .chip:hover {
        background-color: var(--chat-user-bg);
        border-color: var(--chat-primary);
        color: var(--chat-primary-dark);
        transform: translateY(-2px);
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    }

/* CSS for emoji picker has been removed */

/* CSS for feedback buttons has been removed */

/* ปรับแต่ง scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 10px;
}

    .chat-messages::-webkit-scrollbar-thumb:hover {
        background: var(--chat-primary);
    }

/* ทูลทิป */
.header-actions > div {
    position: relative;
}

    .header-actions > div:hover::after {
        content: attr(title);
        position: absolute;
        top: -25px;
        left: 50%;
        transform: translateX(-50%);
        background-color: rgba(0, 0, 0, 0.7);
        color: white;
        padding: 3px 8px;
        border-radius: 4px;
        font-size: 12px;
        white-space: nowrap;
        z-index: 1;
    }

/* การปรับให้เข้ากับอุปกรณ์ต่างๆ */
@media (max-width: 768px) {
    .chat-widget {
        width: 90%;
        max-width: 360px;
        height: 450px;
    }

        .chat-widget.fullscreen {
            width: 100%;
            height: 100%;
            max-width: 100%;
        }

            .chat-widget.fullscreen .chat-messages {
                height: calc(100% - 110px);
            }

    body.chat-fullscreen-active {
        overflow: hidden;
    }

    /* แก้ไขปัญหา Chat Widget ทับกับ mobile-menu */
    .chat-widget-container {
        bottom: 75px; /* เพิ่มระยะห่างจากด้านล่าง ให้พ้น mobile-menu */
    }
}

@media (max-width: 480px) {
    .chat-widget-container {
        bottom: 75px; /* เพิ่มระยะห่างจากด้านล่าง ให้พ้น mobile-menu */
        right: 10px;
    }

    .chat-widget {
        width: calc(100vw - 20px);
        max-width: 400px;
        height: 420px; /* ลดความสูงลงเล็กน้อย */
    }

    .chat-widget-button {
        width: 50px;
        height: 50px;
    }

        .chat-widget-button i {
            font-size: 20px;
        }

    .message-content {
        max-width: 85%;
    }

    .suggestion-chips {
        overflow-x: auto;
        padding-bottom: 5px;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        scroll-snap-type: x mandatory;
    }

    .chip {
        flex-shrink: 0;
        scroll-snap-align: start;
    }
}

/* สำหรับโหมดแนวนอนบนมือถือ */
@media (max-height: 480px) and (orientation: landscape) {
    .chat-widget {
        height: 280px;
    }

        .chat-widget.fullscreen {
            height: 100%;
        }

            .chat-widget.fullscreen .chat-messages {
                height: calc(100% - 100px);
            }
}

/* Animations */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ตารางในข้อความ */
.formatted-message table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* ทำให้ตารางสามารถเลื่อนได้ในแนวนอน */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 10px 0;
    border-radius: 8px;
    background-color: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.formatted-message th {
    background-color: var(--chat-primary);
    color: white;
    padding: 8px 12px;
    text-align: left;
    white-space: nowrap;
}

.formatted-message td {
    padding: 8px 12px;
    border-bottom: 1px solid #EEEEEE;
    white-space: normal;
    word-break: break-word;
}

.formatted-message tr:last-child td {
    border-bottom: none;
}

.formatted-message tr:nth-child(even) {
    background-color: #FAFAFA;
}

/* แสดงตารางในรูปแบบการ์ดเมื่อไม่ใช่โหมด fullscreen */
.formatted-message .mobile-card-table {
    display: block;
    border: none;
    box-shadow: none;
    background: transparent;
}

    .formatted-message .mobile-card-table thead {
        display: none;
    }

    .formatted-message .mobile-card-table tbody {
        display: block;
    }

    .formatted-message .mobile-card-table tr {
        display: block;
        margin-bottom: 10px;
        border-radius: 8px;
        overflow: hidden;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        background-color: white;
    }

    .formatted-message .mobile-card-table td {
        display: flex;
        padding: 8px 10px;
        text-align: left;
        border-bottom: 1px solid #eee;
    }

        .formatted-message .mobile-card-table td:before {
            content: attr(data-label);
            width: 40%;
            font-weight: bold;
            margin-right: 10px;
        }

        .formatted-message .mobile-card-table td:last-child {
            border-bottom: none;
        }

/* เมื่ออยู่ในโหมด fullscreen ให้ตารางแสดงผลปกติ */
.chat-widget.fullscreen .mobile-card-table {
    display: table;
    width: 100%;
    border-collapse: collapse;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    background-color: white;
}

    .chat-widget.fullscreen .mobile-card-table thead {
        display: table-header-group;
    }

    .chat-widget.fullscreen .mobile-card-table tbody {
        display: table-row-group;
    }

    .chat-widget.fullscreen .mobile-card-table tr {
        display: table-row;
        margin-bottom: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-widget.fullscreen .mobile-card-table th,
    .chat-widget.fullscreen .mobile-card-table td {
        display: table-cell;
        padding: 8px 12px;
        text-align: left;
        border-bottom: 1px solid #EEEEEE;
    }

        .chat-widget.fullscreen .mobile-card-table td:before {
            content: none;
        }

/* สไตล์สำหรับปุ่มที่ถูกปิดการใช้งาน */
.action-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* สไตล์สำหรับข้อความแจ้งเตือนการจำกัดจำนวนข้อความ */
.chat-limit-notice {
    background-color: rgba(255, 193, 7, 0.2);
    color: #856404;
    padding: 10px 15px;
    margin: 10px 0;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}

/* สไตล์สำหรับข้อความแจ้งเตือนที่เน้นย้ำ */
.chat-limit-warning {
    background-color: rgba(220, 53, 69, 0.1);
    color: #721c24;
    border: 1px solid rgba(220, 53, 69, 0.2);
}

/* ปุ่ม Reset ที่มีเอฟเฟค pulse */
.pulse-btn-container {
    margin-top: 10px;
    text-align: center;
}

.pulse-reset-btn {
    background-color: #FFC107;
    color: #333;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-weight: bold;
    cursor: pointer;
    animation: pulse-animation 2s infinite;
}

    .pulse-reset-btn:hover {
        background-color: #FFA000;
        animation: none;
    }

/* เอฟเฟค animation สำหรับปุ่ม Reset ในแถบเครื่องมือ */
.attention-pulse {
    animation: pulse-animation 2s infinite;
}

@keyframes pulse-animation {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(255, 193, 7, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 193, 7, 0);
    }
}

/* ปรับสไตล์สำหรับ input เมื่อถูกปิดการใช้งาน */
#user-input:disabled {
    background-color: #f8f9fa;
    color: #6c757d;
    font-style: italic;
}

/* สไตล์สำหรับกล่องข้อความแจ้งเตือนขีดจำกัด */
.limit-reached-notice {
    width: 100%;
    margin: 15px 0;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}
