/* ================================== */
/* CSS สำหรับ Gemini Chat (สมบูรณ์) */
/* ================================== */

/* --- 1. ตัวแปรหลักและ Font --- */
:root {
    --ai-chat-primary: #0d6efd;
    --ai-chat-secondary: #6c757d;
    --ai-chat-bg: #f8f9fa;
    --ai-chat-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}


/* ใช้กับกล่องแชทและลูกหลานทั้งหมด */
#aiChatPopup, #aiChatPopup * {
  font-family: "Kanit", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", "Helvetica Neue", Arial, sans-serif;
}


/* --- 2. ปุ่มลอย (Floating Button) --- */
.ai-chat-float-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--ai-chat-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 9998;
    transition: transform 0.2s ease;
}

.ai-chat-float-btn:hover {
    transform: scale(1.1);
}

/* --- 3. หน้าต่าง Popup หลัก --- */
.ai-chat-popup {
    position: fixed;
    bottom: 0px;
    width: 100%;
    max-width: 500px;
    height: 90vh !important; 
    max-height: 100%;
    background: #fff;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    right: 20px;
    left: auto;
    top: auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Animation */
    transform: scale(0.5) translateY(50px);
    opacity: 0;
    pointer-events: none;
    transform-origin: bottom right;
    transition: all 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.ai-chat-popup.show {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* --- 4. ส่วนประกอบภายใน Popup --- */

/* โค้ดส่วนนี้ของคุณถูกต้องแล้ว: สำหรับจัดวาง "AI Assistant" และ "กลุ่มปุ่ม" */
.ai-chat-header {
    flex-shrink: 0;
    padding: 10px 15px;
    background: var(--ai-chat-primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
}

/* === เพิ่มโค้ดส่วนนี้ เพื่อแก้ปัญหาปุ่มไม่ตรงกัน === */
/* เลือกกล่อง div ที่เป็นลูกของ .ai-chat-header โดยตรง เพื่อจัดเรียงปุ่มข้างใน */
.ai-chat-header > div {
    display: flex;
    align-items: center; /* จัดให้ปุ่มอยู่กลางแนวตั้งตรงกัน */
    gap: 30px;            /* เพิ่มระยะห่างระหว่างปุ่ม */
}

.ai-chat-body {
    flex-grow: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-color: #c2eff3;
}

.ai-chat-form {
    flex-shrink: 0;
    display: flex;
    padding: 10px;
    border-top: 1px solid #dee2e6;
    gap: 10px;
    align-items: flex-end;
    background: #fff;
}
/* --- 5. การแสดงข้อความ (ปรับปรุงให้อ่านง่ายขึ้น) --- */
.ai-message-container {
    display: flex;
    flex-direction: column;
    max-width: 90%;
    gap: 6px;
    margin-bottom: 12px;
}
.ai-message-container.user {
    align-self: flex-end;
    align-items: flex-end;
}
.ai-message-container.ai,
.ai-message-container.admin {
    align-self: flex-start;
    align-items: flex-start;
}

.ai-message-timestamp {
    font-size: 12px;
    color: var(--ai-chat-text-secondary, #888);
    padding: 0 10px;
}

.ai-message {
    padding: 12px 5px;
    border-radius: 18px;
    line-height: 1.6;
    word-wrap: break-word;
    font-size: 16px;
}
.ai-message.user {
    background: var(--ai-chat-primary);
    color: white;
    border-bottom-right-radius: 5px;
}
.ai-message.ai,
.ai-message.admin {
    background: #fff;
    color: #212529;
    border-bottom-left-radius: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.07);
}

.ai-message img,
.ai-message video {
    max-width: 100%;
    border-radius: 10px;
    margin-top: 5px;
    display: block;
}

/* --- 6. ส่วนประกอบอื่นๆ --- */
#aiUserInput {
    flex-grow: 1;
    border: 1px solid #ccc;
    border-radius: 20px;
    padding: 10px 15px;
    resize: none;
    font-family: inherit;
    font-size: 16px;
    max-height: 80px;
    line-height: 1.4;
}

.ai-chat-form button {
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: var(--ai-chat-primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-contact-btn {
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 4px 10px;
    font-size: 13px;
    cursor: pointer;
    margin-right: 10px;
    transition: background-color 0.2s;
}
.ai-chat-contact-btn:hover { background-color: #218838; }

.ai-chat-close-btn {
    background: none; border: none; color: white;
    font-size: 20px; line-height: 1; cursor: pointer;
    padding: 0 5px; opacity: 0.8;
}

.ai-typing-indicator {
    padding: 10px 20px;
}
.ai-typing-indicator span {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background-color: #ccc;
    margin: 0 2px;
    animation: typing-bounce 1.2s infinite ease-in-out;
}


/* ================================== */
/* 7. CSS สำหรับมือถือ (Media Query) */
/* ================================== */
@media (max-width: 768px) {
    /* --- ✅ [แก้ไขทั้งหมด] --- */
    .ai-chat-popup {
        width: 100%;
        height: 100%; /* ให้สูงเต็มจอ */
        max-width: none;
        max-height: none;
        top: 0;      /* ชิดขอบบน */
        left: 0;
        right: 0;
        bottom: 0;   /* ชิดขอบล่าง */
        border-radius: 0;
        /* ไม่ต้องกำหนด height หรือ bottom ที่นี่อีกต่อไป */
    }
    
    .ai-chat-header {
        border-radius: 0;
    }
}

/* ... โค้ดส่วนที่เหลือทั้งหมดของคุณ ... */
@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    } 40% {
        transform: scale(1.0);
    }
}
/* ================================================= */
/* การ์ดสินค้าแต่ละใบ (ดีไซน์ใหม่) */
/* ================================================= */

.ai-chat-body .ai-product-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 15px;
}

.ai-chat-body .ai-product-card {
    background: var(--ai-chat-surface);
    border: 1px solid #cccccc !important;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    text-align: center;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    padding: 0;
    height: auto;
}

.ai-product-brand {
    background-color: #2A6F7A;
    color: #ffffff;
    font-size: 14px;
    font-weight: 300;
    padding: 2px;
    text-transform: uppercase;
}

.ai-product-image-wrapper {
    padding: 2px;
    background-color: #ffffff;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ai-product-image-wrapper img {
    width: 100%;
    height: 100px;
    object-fit: contain;
}

.ai-product-model {
    padding: 1px;
    font-size: 14px;
    font-weight: 500;
    color: var(--ai-chat-text-primary);
}

.ai-product-price {
    padding: 1px;
    font-size: 14px;
    color: #28a745;
    border-top: 1px solid var(--ai-chat-border);
}

/* ================================================= */
/* CSS สำหรับ "กำลังพิมพ์" แบบใหม่ */
/* ================================================= */
.typing-dots {
    display: flex;
    align-items: center;
}
.typing-dots span {
    width: 8px;
    height: 8px;
    margin: 0 3px;
    background-color: #9db2c2;
    border-radius: 50%;
    display: inline-block;
    animation: bounce 1.4s infinite ease-in-out both;
}
html.dark-mode .typing-dots span {
    background-color: #7a7a7a;
}
.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}
.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

/* ================================================= */
/* CSS สำหรับฟอร์มคำนวณราคา (ดีไซน์ใหม่) */
/* ================================================= */

.ai-size-wrapper {
    background-color: var(--ai-chat-surface);
    border: 1px solid var(--ai-chat-border);
    border-radius: 12px;
    padding: 16px;
    margin-top: 10px;
}

.ai-size-wrapper h4 {
    margin: 0 0 16px 0;
    padding-bottom: 10px;
    font-size: 1em;
    font-weight: 600;
    color: var(--ai-chat-primary);
    border-bottom: 2px solid var(--ai-chat-primary);
    text-align: left;
}

.ai-size-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.ai-size-grid label {
    display: block;
    font-size: 0.85em;
    font-weight: 500;
    color: var(--ai-chat-text-secondary);
    margin-bottom: 4px;
    text-align: left;
}

.ai-size-wrapper input[type="number"] {
    width: 100%;
    padding: 10px;
    border: 1px solid #28a745;
    border-radius: 8px;
    background-color: var(--ai-chat-bg);
    color: var(--ai-chat-text-primary);
    font-size: 1em;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-size-wrapper input[type="number"]:focus {
    outline: none;
    border-color: var(--ai-chat-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ai-chat-primary) 20%, transparent);
}

.ai-size-result {
    margin-top: 16px;
    padding: 1px;
    background-color: white;
    border-radius: 12px;
    font-size: 1em;
    color: var(--ai-chat-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.ai-size-result .ai-calc-result-inner {
    text-align: left;
    width: 100%;
    line-height: 1.7;
    font-size: 13px;
    color: var(--ai-chat-text-primary);
}

.ai-calc-result-inner p, 
.ai-calc-result-inner div {
    margin-bottom: 8px;
}
.ai-calc-result-inner p:last-child,
.ai-calc-result-inner div:last-child {
    margin-bottom: 0;
}
.ai-calc-result-inner strong {
    color: var(--ai-chat-primary);
}

.ai-hr {
    border: none;
    height: 1px;
    background-color: var(--ai-chat-border);
    margin: 16px 0;
}

.ai-follow-up p {
    font-size: 14px;
    color: var(--ai-chat-text-secondary);
    margin-top: 16px;
    margin-bottom: 0;
    text-align: center;
}
@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    } 40% {
        transform: scale(1.0);
    }
}
/* ============================================= */
/* Gemini Chat - Mobile Fullscreen Lock          */
/* ============================================= */

/* ใช้ Media Query เพื่อให้สไตล์นี้ทำงานเฉพาะบนจอมือถือ (ความกว้างไม่เกิน 768px) */
@media (max-width: 768px) {

  /* เลือก Popup (#aiChatPopup) เฉพาะตอนที่มีคลาส .is-mobile-fullscreen */
  #aiChatPopup.is-mobile-fullscreen {
    position: fixed; /* 1. ตรึง popup ไว้กับหน้าจอ ไม่ให้เลื่อนตามเว็บ */
    top: var(--header-height, 60px); /* 2. กำหนดขอบบนให้อยู่ใต้ header พอดี (ใช้ค่าที่ JS ส่งมา) */
    bottom: 0; /* 3. ยืด popup ไปจนสุดขอบล่างของหน้าจอ */
    left: 0; /* 4. ยืด popup ไปจนสุดขอบซ้าย */
    width: 100%; /* ทำให้เต็มความกว้าง */
    height: auto; /* ความสูงจะถูกกำหนดโดย top และ bottom */
    
    border-radius: 0; /* ลบขอบโค้งในโหมดเต็มจอ */
    box-shadow: none; /* ลบเงาในโหมดเต็มจอ */
    max-height: none; /* ไม่จำกัดความสูงสูงสุด */
  }

  /* * เพิ่มส่วนนี้เพื่อให้แถบข้อความอยู่ล่างสุดเสมอ และส่วนแชทสกอลล์ได้พอดี
   */
  #aiChatPopup.is-mobile-fullscreen .ai-chat-container {
    height: 100%; /* ทำให้ container สูงเต็มพื้นที่ของ popup */
    display: flex; /* ใช้ Flexbox จัดการ layout */
    flex-direction: column; /* เรียงจากบนลงล่าง (header, body, footer) */
  }

  #aiChatPopup.is-mobile-fullscreen #aiChatBody {
    flex: 1; /* ทำให้ส่วนแสดงข้อความ (body) ยืดขนาดจนเต็มพื้นที่ที่เหลือ */
    min-height: 0; /*จำเป็นสำหรับ Flexbox เพื่อให้ overflow ทำงานถูกต้อง*/
  }
}
/* ============================================= */
/* Gemini Chat - Customer Info Form Styles       */
/* ============================================= */

.ai-form-container {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 16px;
    margin-top: 8px;
}

.ai-form-container h5 {
    margin-top: 0;
    margin-bottom: 8px;
    font-size: 16px;
    color: #333;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 8px;
}

.ai-form-container p {
    font-size: 14px;
    color: #6c757d;
    margin-top: 0;
    margin-bottom: 16px;
}

.ai-form-container form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-form-container label {
    font-size: 14px;
    font-weight: bold;
    color: #495057;
    margin-bottom: -8px; /* Move label closer to input */
}

.ai-form-container input[type="text"],
.ai-form-container input[type="tel"],
.ai-form-container textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 15px;
    box-sizing: border-box; /* Important for 100% width */
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.ai-form-container input:focus,
.ai-form-container textarea:focus {
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}


.ai-form-container button[type="submit"] {
    background-color: #007bff;
    color: white;
    padding: 12px 15px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-top: 8px;
}

.ai-form-container button[type="submit"]:hover {
    background-color: #0056b3;
}