/* ===================================================================
 * /css/chat.css — 108air AI Chat Widget styles
 * =================================================================== */

/* ===================================================================
 * Site Floating Dock — แถวเดียวที่รวม AI + Cart + Contact
 * โครงสร้างเดียวกับ 108auto.com
 * =================================================================== */
.site-floating-dock {
    position: fixed;
    right: 12px;
    bottom: 0;
    z-index: 9998;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    box-sizing: border-box;
    pointer-events: none;
    --dock-sz: 50px;
    overflow: visible;
}
.site-floating-dock > * { pointer-events: auto; }

.site-floating-dock__cell--sq {
    flex: 0 0 var(--dock-sz, 50px);
    width:  var(--dock-sz, 50px);
    min-width:  var(--dock-sz, 50px);
    max-width:  var(--dock-sz, 50px);
    min-height: var(--dock-sz, 50px);
    max-height: var(--dock-sz, 50px);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    overflow: visible;
}
.site-floating-dock__cell--grow {
    flex: 0 0 auto;
    min-width: 0;
    min-height: var(--dock-sz, 50px);
    max-height: var(--dock-sz, 50px);
    display: flex;
    align-items: stretch;
    justify-content: center;
    position: relative;
    z-index: 1;
    overflow: visible;
}
body:has(.site-floating-dock) {
    padding-bottom: calc(24px + var(--dock-sz, 50px) + env(safe-area-inset-bottom, 0px));
}

/* === AI Chat button (วงกลม 50x50 ใน dock cell) === */
.site-floating-dock .ai-chat-float-btn.ai-chat-float-standalone {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width:  var(--dock-sz, 50px);
    height: var(--dock-sz, 50px);
    min-width:  var(--dock-sz, 50px);
    min-height: var(--dock-sz, 50px);
    max-width:  var(--dock-sz, 50px);
    max-height: var(--dock-sz, 50px);
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    background: linear-gradient(135deg, #0984e3, #00b894);
    color: #fff;
    box-shadow: 0 3px 14px rgba(9, 132, 227, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: visible;
    box-sizing: border-box;
}
.site-floating-dock .ai-chat-float-btn.ai-chat-float-standalone:hover {
    transform: scale(1.04);
    box-shadow: 0 5px 20px rgba(9, 132, 227, 0.6);
}
.site-floating-dock .ai-chat-float-btn.ai-chat-float-standalone:active {
    transform: scale(0.97);
}
.site-floating-dock .ai-chat-float-btn i,
.site-floating-dock .ai-chat-float-btn img {
    position: relative;
    z-index: 1;
    line-height: 1;
    pointer-events: none;
}
.site-floating-dock .ai-chat-float-btn i {
    font-size: 1.45rem;
    animation: aiSpin 6s linear infinite;
}
.site-floating-dock .ai-chat-float-btn img {
    width: 50px;
    height: 50px;
    object-fit: contain;
    border-radius: 50%;
    display: block;
}

@keyframes aiSpin {
    from { transform: rotate(0); }
    to   { transform: rotate(360deg); }
}

/* === Pulse rings (2 ห่วง เหลื่อมเวลา) === */
.ai-chat-float-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid #00b894;
    animation: aiPulse 2s ease-out infinite;
    pointer-events: none;
    z-index: 0;
}
.ai-chat-float-pulse--delay {
    animation-delay: 1s;
    border-color: #4dd2c0;
}

@keyframes aiPulse {
    0%   { transform: scale(1);    opacity: 0.85; }
    80%  { transform: scale(1.55); opacity: 0;    }
    100% { transform: scale(1.55); opacity: 0;    }
}

/* === Chat popup overlay === */
.ai-chat-popup {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.ai-chat-popup.active {
    display: flex;
    opacity: 1;
}

.ai-chat-container {
    width: 100%;
    max-width: 480px;
    height: 80vh;
    max-height: 720px;
    background: linear-gradient(160deg, #1a2332 0%, #2c3e50 100%);
    border-radius: 16px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #f0f4f8;
    animation: aiSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes aiSlideUp {
    from { transform: translateY(30px) scale(0.97); opacity: 0; }
    to   { transform: translateY(0) scale(1);      opacity: 1; }
}

@media (max-width: 700px) {
    .ai-chat-popup { padding: 0; }
    .ai-chat-container {
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
}

/* === Header === */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: linear-gradient(135deg, #0984e3, #00b894);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.ai-chat-header-left { display: flex; align-items: center; gap: 12px; }

.ai-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: #fff;
}

.ai-avatar i { animation: aiSpin 8s linear infinite; }

.ai-chat-titles { display: flex; flex-direction: column; }

.ai-chat-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
}

.ai-status {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    gap: 5px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ecc71;
    box-shadow: 0 0 6px #2ecc71;
    animation: aiBlink 2s ease-in-out infinite;
}

@keyframes aiBlink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.5; }
}

.ai-chat-header-right { display: flex; align-items: center; gap: 6px; }

.ai-chat-contact-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #fff;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background 0.2s;
}

.ai-chat-contact-btn:hover { background: rgba(255, 255, 255, 0.28); }

@media (max-width: 480px) {
    .hide-sm { display: none; }
    .ai-chat-contact-btn { padding: 8px 10px; }
}

.ai-chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
    transition: transform 0.2s;
}

.ai-chat-close:hover { transform: scale(1.2); color: #ff7675; }

/* === Messages area === */
.ai-chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background: rgba(0, 0, 0, 0.15);
}

.ai-chat-messages::-webkit-scrollbar { width: 6px; }
.ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.ai-message-container {
    display: flex;
    max-width: 100%;
}

.ai-message-container.user { justify-content: flex-end; }
.ai-message-container.ai   { justify-content: flex-start; }
.ai-message-container.admin { justify-content: flex-start; }
.ai-message-container.system { justify-content: center; }

.ai-message-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.93rem;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.ai-message-bubble.user {
    background: linear-gradient(135deg, #0984e3, #0d6efd);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ai-message-bubble.ai {
    background: rgba(255, 255, 255, 0.08);
    color: #f0f4f8;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom-left-radius: 4px;
}

.ai-message-bubble.admin {
    background: linear-gradient(135deg, #ff9800, #e65100);
    color: #fff;
    border-bottom-left-radius: 4px;
}

.ai-message-bubble.system {
    background: rgba(255, 193, 7, 0.15);
    color: #ffd54f;
    font-size: 0.82rem;
    font-style: italic;
    text-align: center;
    border-radius: 12px;
}

.ai-message-bubble a { color: #4ecdc4; text-decoration: none; }
.ai-message-bubble a:hover { text-decoration: underline; }

/* === Typing indicator === */
.ai-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px 16px;
    align-self: flex-start;
}

.ai-typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ecdc4;
    animation: aiTyping 1.2s ease-in-out infinite;
}

.ai-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiTyping {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.5; }
    30%           { transform: translateY(-6px); opacity: 1;   }
}

/* === Form (input bar) === */
.ai-chat-form {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.ai-chat-attach-btn,
.ai-chat-send-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.ai-chat-attach-btn:hover { background: rgba(255, 255, 255, 0.18); }

.ai-chat-attach-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ai-chat-send-btn {
    background: linear-gradient(135deg, #0984e3, #00b894);
}

.ai-chat-send-btn:hover { box-shadow: 0 4px 14px rgba(9, 132, 227, 0.5); }
.ai-chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.ai-chat-form textarea {
    flex: 1;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.05);
    color: #f0f4f8;
    border-radius: 18px;
    padding: 9px 14px;
    font-family: inherit;
    font-size: 0.92rem;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
}

.ai-chat-form textarea:focus {
    outline: none;
    border-color: #4ecdc4;
    background: rgba(255, 255, 255, 0.08);
}

.ai-chat-form textarea::placeholder { color: rgba(255, 255, 255, 0.5); }

/* === Form container (จาก server: ai-form-container) === */
.ai-form-container {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 14px;
    color: #f0f4f8;
    font-size: 0.92rem;
    line-height: 1.55;
}

.ai-form-container label {
    display: block;
    font-size: 0.85em;
    color: #ccc;
    margin: 4px 0 4px;
}

.ai-form-container input,
.ai-form-container select,
.ai-form-container textarea {
    width: 100%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    padding: 8px 10px;
    color: #f0f4f8;
    font-size: 0.92em;
    font-family: inherit;
    box-sizing: border-box;
    margin-bottom: 6px;
}

.ai-form-container input:focus,
.ai-form-container select:focus,
.ai-form-container textarea:focus {
    outline: none;
    border-color: #4ecdc4;
    background: rgba(255, 255, 255, 0.12);
}

.ai-form-container button[type="submit"]:not(.ai-form-menu-btn) {
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    cursor: pointer;
    font-weight: 600;
    transition: filter 0.2s;
}

.ai-form-container button[type="submit"]:hover { filter: brightness(1.1); }

/* === Menu buttons grid === */
.ai-form-menu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 6px;
    margin: 6px 0;
}

.ai-form-menu-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: #f0f4f8;
    padding: 8px 10px;
    font-size: 0.88em;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.ai-form-menu-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    transform: translateY(-1px);
}

.ai-menu-section { margin: 8px 0; }

.ai-menu-title {
    font-size: 0.92em;
    font-weight: 600;
    color: #4ecdc4;
    margin-bottom: 4px;
    padding-bottom: 4px;
    border-bottom: 1px dashed rgba(78, 205, 196, 0.3);
}

/* === Product cards === */
.ai-product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    margin: 8px 0;
}

.ai-product-card {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 8px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-size: 0.82em;
}

.ai-product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(9, 132, 227, 0.3);
    border-color: #4ecdc4;
}

.ai-product-brand {
    font-size: 0.78em;
    color: #4ecdc4;
    font-weight: 600;
    margin-bottom: 4px;
}

.ai-product-img {
    width: 100%;
    height: 90px;
    object-fit: contain;
    margin: 4px 0;
    border-radius: 4px;
    background: #fff;
}

.ai-product-model {
    font-size: 0.82em;
    color: #ddd;
    margin: 4px 0 2px;
    word-break: break-all;
}

.ai-product-price {
    font-size: 0.85em;
    color: #ffeaa7;
    font-weight: 600;
}

/* ===================================================================
 * Override: Cart pill ภายใน .site-floating-dock (grow cell)
 * - ลบ position: fixed เดิมของ .floating-cart-btn
 * - ทำเป็น pill 50px สูงเท่า dock
 * =================================================================== */
.site-floating-dock .floating-cart-btn {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    z-index: auto;
    height: var(--dock-sz, 50px);
    min-height: var(--dock-sz, 50px);
    padding: 0 16px;
    margin: 0;
    border-radius: 25px;
    background-color: #28a745;
    color: #fff;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: 'Kanit', 'Sarabun', sans-serif;
    font-weight: 600;
    border: 2px solid #fff;
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.35);
    transition: transform .2s, box-shadow .2s;
    box-sizing: border-box;
    white-space: nowrap;
}
.site-floating-dock .floating-cart-btn:hover {
    transform: translateY(-1px);
    background-color: #218838;
    color: #fff;
    box-shadow: 0 6px 18px rgba(40, 167, 69, 0.45);
}
.site-floating-dock .floating-cart-btn .cart-icon-box {
    position: relative;
    font-size: 1.3rem;
}
.site-floating-dock .floating-cart-btn .cart-text {
    font-size: 0.95rem;
    font-weight: 600;
}

/* ===================================================================
 * Override: Contact FAB ภายใน .site-floating-dock (sq cell)
 * - ลบ position: fixed; bottom; right; ของ .floating-chat-widget
 * - ลด #fab-toggle จาก 60x60 → 50x50 ให้เท่ากับปุ่มอื่น
 * =================================================================== */
.site-floating-dock .floating-chat-widget {
    position: relative;
    bottom: auto;
    right: auto;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    width: var(--dock-sz, 50px);
    height: var(--dock-sz, 50px);
    pointer-events: none;
}
.site-floating-dock .floating-chat-widget .fab-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin: 0 0 12px 0;
    list-style: none;
    padding: 0;
}
/* fab-menu ตอน "ปิด" ห้ามรับ click — เพราะ layout box ของมันใหญ่ (~250x225)
   จะไปครอบเมนู/ปุ่ม อื่นในหน้า ทำให้กดไม่โดน */
.site-floating-dock .floating-chat-widget:not(.active) .fab-menu {
    pointer-events: none;
}
.site-floating-dock .floating-chat-widget.active .fab-menu {
    pointer-events: auto;
}
.site-floating-dock #fab-toggle {
    width:  var(--dock-sz, 50px);
    height: var(--dock-sz, 50px);
    min-width:  var(--dock-sz, 50px);
    min-height: var(--dock-sz, 50px);
    max-width:  var(--dock-sz, 50px);
    max-height: var(--dock-sz, 50px);
    box-shadow: 0 3px 14px rgba(20, 163, 32, 0.45);
    pointer-events: auto;
}
.site-floating-dock #fab-toggle .fab-icon {
    font-size: 22px;
}

/* ===================================================================
 * Mobile: ย่อ cart text + ลด gap ของ dock
 * =================================================================== */
@media (max-width: 768px) {
    .site-floating-dock {
        right: 8px;
        gap: 8px;
        --dock-sz: 50px;
    }
    .site-floating-dock .floating-cart-btn {
        padding: 0 12px;
    }
    .site-floating-dock .floating-cart-btn .cart-text {
        display: none;
    }
    .site-floating-dock .floating-cart-btn .cart-icon-box {
        font-size: 1.1rem;
    }
}
