:root {
    /* สีหลักสำหรับธีมความมืด */
    --bg-dark: #0b0f19;
    --box-bg: rgba(22, 28, 45, 0.7);
    --border-glass: rgba(255, 255, 255, 0.08);
    --text-primary: #f0f2f5;
    --text-secondary: #94a3b8;
    
    /* ตัวผู้ใช้ฝั่งขวา */
    --user-bg: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    
    /* บอทฝั่งซ้าย (กระจกสีเทาใส) */
    --bot-bg: rgba(30, 41, 59, 0.8);
    
    /* ซอร์ส/แหล่งที่มา (สีส้ม/ทองให้สะดุดตาเบาๆ) */
    --source-bg: rgba(245, 158, 11, 0.15);
    --source-text: #fcd34d;
    --source-border: rgba(245, 158, 11, 0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', 'Noto Sans Thai', sans-serif;
    background-color: var(--bg-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    color: var(--text-primary);
    overflow: hidden;
    position: relative;
}

/* เอฟเฟกต์แสงไฟเบลอๆ พื้นหลังให้อารมณ์ล้ำยุค */
.app-background {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.glow-orb {
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.15;
    animation: drift 15s infinite alternate ease-in-out;
}

.orb-1 {
    top: -100px; left: -100px;
    background: #7c3aed;
}

.orb-2 {
    bottom: -200px; right: -100px;
    background: #0ea5e9;
    animation-delay: -5s;
}

@keyframes drift {
    100% { transform: translate(50px, 50px) scale(1.1); }
}

/* ------------------------------------- */

.chat-container {
    width: 100%;
    max-width: 900px;
    height: 94vh;
    display: flex;
    flex-direction: column;
    z-index: 10;
    background: var(--box-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

/* ส่วนหัว */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 25px;
    border-bottom: 1px solid var(--border-glass);
    background: rgba(15, 23, 42, 0.6);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 26px;
    background: var(--user-bg);
    width: 45px;
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.4);
}

.logo-info h1 {
    font-size: 1.1rem;
    font-weight: 600;
}

.badge {
    font-size: 0.65rem;
    background: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 4px;
    color: #38bdf8;
    vertical-align: middle;
    margin-left: 4px;
}

.logo-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 3px;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 10px #10b981;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.2); }
    100% { opacity: 1; transform: scale(1); }
}

/* ส่วนแชทหน้าจอ */
.chat-box {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

/* ซ่อน Scrollbar นอกใน Chrome */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* กล่องข้อความ */
.message {
    display: flex;
    gap: 15px;
    max-width: 85%;
    animation: fadeUp 0.4s ease-out forwards;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.avatar {
    width: 38px;
    height: 38px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    flex-shrink: 0;
    font-size: 18px;
    border: 1px solid var(--border-glass);
}

.user { align-self: flex-end; flex-direction: row-reverse; }
.user .avatar { background: var(--user-bg); color: #fff; font-weight: 600; font-size: 14px; border: none;}
.bot .avatar { background: var(--bot-bg); }

.msg-bubble {
    padding: 16px 20px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.6;
    word-wrap: break-word;
}

.bot .msg-bubble {
    background: var(--bot-bg);
    border: 1px solid rgba(255,255,255,0.05);
    border-top-left-radius: 4px;
    color: #e2e8f0;
}

.user .msg-bubble {
    background: var(--user-bg);
    border-top-right-radius: 4px;
    color: #fff;
    box-shadow: 0 4px 15px rgba(79, 70, 229, 0.3);
}

/* การตกแต่งตัวอักษรของบอท */
.msg-bubble p { margin-bottom: 12px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { color: #fff; }
.msg-bubble ul { margin-left: 20px; margin-bottom: 15px; }
.msg-bubble li { margin-bottom: 8px; }

/* จุดพิมพ์ Loading ... */
.typing-dots {
    display: flex;
    gap: 5px;
    padding: 10px 5px;
}
.dot {
    width: 6px;
    height: 6px;
    background: #cbd5e1;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4;}
    40% { transform: scale(1); opacity: 1; }
}

/* โซนแหล่งอ้างอิง Sources */
.sources-area {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px dashed rgba(255,255,255,0.1);
}
.sources-title {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.source-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
    background: var(--source-bg);
    color: var(--source-text);
    border: 1px solid var(--source-border);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    display: inline-block;
    cursor: default;
    transition: all 0.2s;
}
.pill:hover { background: rgba(245, 158, 11, 0.3); transform: translateY(-2px); }

/* จุดพิมพ์แชท */
.chat-input-area {
    padding: 20px 25px;
    background: rgba(15, 23, 42, 0.8);
    border-top: 1px solid var(--border-glass);
}
.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
#user-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255,255,255,0.15);
    padding: 18px 65px 18px 25px;
    border-radius: 30px;
    color: #fff;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s;
    font-family: 'Inter', 'Noto Sans Thai', sans-serif;
}
#user-input:focus {
    border-color: #6366f1;
    background: rgba(0,0,0,0.6);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}
#send-btn {
    position: absolute;
    right: 8px;
    background: var(--user-bg);
    color: #fff;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
#send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(124, 58, 237, 0.5);
}
#send-btn:active { transform: scale(0.95); }
#send-btn:disabled {
    background: #334155; color: #64748b; cursor: not-allowed; transform: none; box-shadow: none;
}
.footer-note {text-align: center; color: #64748b; font-size: 0.7rem; margin-top: 10px;}
