/* ============================================
   TONY Thailand — Navy / Cream / Gold / White
   Chat-only fullscreen (ล็อกหน้าจอ ไม่เลื่อน)
   ============================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --navy: #1e2749;
    --navy-deep: #161d38;
    --navy-soft: #2c3760;
    --gold: #c9a24e;
    --gold-light: #ddb96a;
    --gold-deep: #a8823a;
    --cream: #f6f1e7;
    --cream-soft: #fbf8f1;
    --paper: #ffffff;
    --ink: #20283f;
    --text-mute: #6b7280;
    --text-light: #4b5468;
    --line: #e4ddcd;
    --line-soft: #ece5d6;
    --line-gold: rgba(201,162,78,0.35);
}

html, body {
    height: 100%;
    overflow: hidden;               /* ล็อก ไม่ให้หน้าเลื่อน */
}
body {
    font-family: 'Noto Sans Thai', sans-serif;
    background: var(--navy);
    color: var(--ink);
    line-height: 1.75;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior: none;      /* กันเด้งบนมือถือ */
}

/* ===== แชตเต็มจอ ===== */
.chat-fullscreen {
    position: fixed;
    inset: 0;
    height: 100dvh;                 /* dynamic vh — หดตามแป้นพิมพ์มือถือ */
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    background: var(--paper);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* หัวแชต — บรรทัดเดียว เตี้ย ประหยัดพื้นที่ */
.chat-header {
    flex-shrink: 0;
    background: var(--navy);
    padding: 11px 20px;
    display: flex; align-items: center; justify-content: center;
}
.chat-brand {
    font-family: 'Cormorant Garamond', 'Noto Sans Thai', serif;
    color: var(--cream-soft);
    font-size: 19px; font-weight: 700;
    display: flex; align-items: baseline; gap: 8px;
    line-height: 1.2;
}
.chat-brand span {
    font-family: 'Noto Sans Thai', sans-serif;
    color: var(--gold-light);
    font-size: 13px; font-weight: 400;
}

/* พื้นที่ข้อความ — ส่วนเดียวที่เลื่อนได้ */
.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px;
    display: flex; flex-direction: column; gap: 14px;
    background: var(--cream-soft);
}

/* ปุ่มคำถามสำเร็จรูป */
.chat-quick {
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    padding: 10px 16px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--paper);
    scrollbar-width: none;
}
.chat-quick::-webkit-scrollbar { display: none; }
.quick-chip {
    flex-shrink: 0;
    background: var(--cream-soft);
    border: 1px solid var(--line);
    color: var(--ink);
    border-radius: 50px;
    padding: 7px 14px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.quick-chip:hover { border-color: var(--gold); color: var(--gold-deep); }

/* ===== แถบพรีวิวรูปที่แนบ (ก่อนส่ง) ===== */
.chat-attach-bar {
    flex-shrink: 0;
    display: none;                  /* widget.js เปลี่ยนเป็น flex เมื่อมีรูป */
    align-items: center;
    gap: 10px;
    padding: 10px 16px 0;
    background: var(--paper);
}
#chat-attach-thumb {
    width: 52px; height: 52px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--cream-soft);
}
.chat-attach-label {
    flex: 1;
    font-size: 13px;
    color: var(--text-mute);
    line-height: 1.4;
}
.chat-attach-remove {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid var(--line);
    color: var(--text-mute);
    border-radius: 50%;
    width: 30px; height: 30px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}
.chat-attach-remove:hover { border-color: #c0392b; color: #c0392b; }

/* แถบพิมพ์ */
.chat-input-area {
    flex-shrink: 0;
    display: flex; gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--line);
    background: var(--paper);
    padding-bottom: calc(14px + env(safe-area-inset-bottom)); /* กันชนขอบล่างมือถือ */
}
/* ปุ่มแนบรูป */
#chat-attach {
    flex-shrink: 0;
    width: 50px;
    background: var(--cream-soft);
    border: 1px solid var(--line);
    border-radius: 12px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}
#chat-attach:hover { border-color: var(--gold); background: var(--cream); }
#chat-input {
    flex: 1;
    min-width: 0;
    background: var(--cream-soft);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 16px;
    font-size: 16px;                /* 16px กัน iOS ซูมอัตโนมัติตอนโฟกัส */
    font-family: inherit;
    color: var(--ink);
    outline: none;
}
#chat-input::placeholder { color: var(--text-mute); }
#chat-input:focus { border-color: var(--gold); }
#chat-send {
    background: linear-gradient(135deg, var(--gold-light), var(--gold-deep));
    color: var(--navy-deep);
    border: none;
    padding: 0 26px;
    border-radius: 12px;
    font-weight: 600; font-size: 15px;
    font-family: inherit;
    cursor: pointer;
    transition: filter 0.2s;
    flex-shrink: 0;
}
#chat-send:hover { filter: brightness(1.07); }
#chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== บับเบิลข้อความ ===== */
.msg {
    flex-shrink: 0;                 /* กัน flex column บีบบับเบิลจนแบน */
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 15px;
    line-height: 1.7;
    white-space: pre-wrap;          /* ขึ้นบรรทัดใหม่ + เว้นวรรคได้ */
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.msg-bot {
    background: var(--paper);
    border: 1px solid var(--line);
    color: var(--ink);
    align-self: flex-start;
    border-bottom-left-radius: 5px;
    box-shadow: 0 2px 8px rgba(30,39,73,0.05);
}
.msg-user {
    background: linear-gradient(135deg, var(--navy-soft), var(--navy));
    color: var(--cream-soft);
    font-weight: 400;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}
.msg-typing { color: var(--text-mute); font-style: italic; background: transparent; border: none; box-shadow: none; }

/* รูปที่ลูกค้าส่งในบับเบิล */
.msg-img {
    display: block;
    max-width: 200px;
    max-height: 240px;
    border-radius: 10px;
    cursor: pointer;
    margin-bottom: 6px;
}
.msg-img:last-child { margin-bottom: 0; }

/* ===== ปุ่มเครื่องมือใต้ข้อความบอท (คัดลอก / ฟังเสียง) ===== */
.msg-tools {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--line-soft);
    white-space: normal;            /* ไม่เอา pre-wrap ของ .msg */
}
.msg-tool-btn {
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 4px 11px;
    font-size: 12px;
    color: var(--text-mute);
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1.5;
}
.msg-tool-btn:hover { border-color: var(--gold); color: var(--gold-deep); }
.msg-tool-ok { border-color: #2e8b57 !important; color: #2e8b57 !important; }
.msg-tool-active {
    border-color: var(--gold) !important;
    color: var(--navy) !important;
    background: var(--cream) !important;
}

/* ===== การ์ดสินค้าในแชต ===== */
.product-card-chat {
    flex-shrink: 0;                 /* กัน flex column บีบการ์ดจนหาย */
    align-self: flex-start;
    max-width: 85%;
    width: 280px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    margin-top: -4px;
    box-shadow: 0 2px 8px rgba(30,39,73,0.06);
}
/* การ์ดที่มีหลายรูป — กว้างขึ้นเพื่อเห็นรูปหลายใบ */
.product-card-chat.pcc-multi {
    width: 420px;
}
/* แถบรูป: เรียงจากขวาไล่ไปซ้าย เลื่อนดูได้ */
.pcc-images {
    display: flex;
    flex-direction: row-reverse;    /* รูปแรกอยู่ขวาสุด ไล่ไปซ้าย */
    overflow-x: auto;
    gap: 4px;
    background: var(--cream-soft);
    -webkit-overflow-scrolling: touch;
}
.pcc-images .pcc-image {
    flex-shrink: 0;
}
/* รูปเดียว = เต็มความกว้างการ์ด, หลายรูป = ใบละ 200px */
.pcc-images .pcc-image:only-child { width: 100%; }
.pcc-multi .pcc-images .pcc-image { width: 200px; }
.pcc-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
    cursor: pointer;
    transition: opacity 0.2s;
    background: var(--cream-soft);
}
.pcc-image:hover { opacity: 0.92; }
.pcc-body { padding: 11px 14px; }
.pcc-name { font-size: 14px; font-weight: 600; color: var(--navy); }
.pcc-name-en {
    font-weight: 400; color: var(--text-mute); font-size: 12px;
    letter-spacing: 0.5px;
}
.pcc-video-btn {
    margin-top: 8px;
    width: 100%;
    background: transparent;
    color: var(--gold-deep);
    border: 1px solid var(--gold);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}
.pcc-video-btn:hover { background: var(--gold); color: var(--paper); }

/* ===== overlay รูป/วิดีโอ ===== */
.media-overlay {
    position: fixed; inset: 0;
    background: rgba(22,29,56,0.94);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 9999; padding: 20px;
}
.media-overlay-img {
    max-width: 95%; max-height: 90%;
    border-radius: 10px; object-fit: contain;
}
.media-overlay-video {
    width: 100%; max-width: 800px;
    aspect-ratio: 16 / 9;
    background: #000; border-radius: 10px; overflow: hidden;
}
.media-overlay-video iframe,
.media-overlay-video video { width: 100%; height: 100%; border: none; }
.media-overlay-close {
    margin-top: 16px;
    background: var(--gold);
    color: var(--navy-deep);
    border: none;
    padding: 10px 26px;
    border-radius: 50px;
    font-size: 14px; font-weight: 600;
    font-family: inherit; cursor: pointer;
}

/* ===== มือถือ ===== */
@media (max-width: 560px) {
    .chat-brand { font-size: 16px; }
    .chat-brand span { font-size: 11px; }
    .chat-messages { padding: 16px 14px; }
    .msg { max-width: 88%; font-size: 15px; }
    .chat-input-area { padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
    #chat-attach { width: 46px; font-size: 18px; }
    #chat-send { padding: 0 18px; }
}
