﻿/* Messages page (#/messages) — AGENT-B — ดีไซน์ตาม demo/messages-home.html */

/* ---- โครงหน้า: sidebar rail ซ้าย + เนื้อหาขวา ---- */
.msg-shell{flex:1;display:flex;align-items:stretch;min-height:0;
  /* ดัน rail ลงให้สุดขอบล่างของหน้า (ทะลุ padding เผื่อ bottom nav ของ #page-root) */
  margin-bottom:calc(-1 * (var(--nav-h) + 14px))}
.msg-main{flex:1;min-width:0;display:flex;flex-direction:column;
  padding-bottom:calc(var(--nav-h) + 22px)}

/* ---- sidebar rail (พื้นน้ำเงินเข้มโปร่งเล็กน้อยแบบเดโม่) ---- */
.msg-rail{width:64px;flex:none;display:flex;flex-direction:column;align-items:center;
  padding:calc(18px + env(safe-area-inset-top)) 0 calc(18px + env(safe-area-inset-bottom));
  background:linear-gradient(175deg,#1a0fbd 0%,#10069f 60%,#0a0468 100%);
  backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);
  border-right:1px solid rgba(255,255,255,.08)}
.rail-logo{width:40px;height:40px;border-radius:14px;flex:none;
  display:flex;align-items:center;justify-content:center;color:var(--accent);
  background:rgba(47,139,255,.2);box-shadow:0 8px 30px rgba(47,139,255,.35);
  margin-bottom:28px}
.rail-logo svg{width:24px;height:24px}
.rail-nav{display:flex;flex-direction:column;align-items:center;gap:22px}
.rail-btn{position:relative;width:40px;height:40px;border-radius:14px;
  display:flex;align-items:center;justify-content:center;color:#8fa9c9;
  transition:color .15s, background .15s, transform .12s}
.rail-btn:active{transform:scale(.9)}
.rail-btn:hover{color:#fff}
.rail-btn svg{width:20px;height:20px}
.rail-btn.active{color:#fff;background:rgba(255,255,255,.15);
  box-shadow:0 6px 20px rgba(80,140,220,.25)}
.rail-dot{position:absolute;right:3px;bottom:3px;width:9px;height:9px;border-radius:50%;
  background:var(--red);border:1.5px solid #0f2748}

/* ---- top bar: search pill + avatar ตัวเอง ---- */
.msg-top{display:flex;align-items:center;gap:10px;padding:16px 16px 8px;
  padding-top:calc(16px + env(safe-area-inset-top))}
.msg-search{flex:1;display:flex;align-items:center;gap:10px;min-width:0;
  padding:12px 16px;border-radius:26px;cursor:text;
  background:var(--card-glass);border:1px solid var(--card-brd);
  backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);
  box-shadow:0 6px 20px rgba(80,140,220,.15), inset 0 1px 0 rgba(255,255,255,.9);
  transition:border-color .15s, box-shadow .15s}
.msg-search:focus-within{border-color:var(--accent);
  box-shadow:0 4px 18px rgba(47,139,255,.22), inset 0 1px 0 rgba(255,255,255,.9)}
.msg-search svg{width:18px;height:18px;flex:none;color:var(--card-ink-dim)}
.msg-search input{flex:1;min-width:0;font-size:15px;color:var(--card-ink)}
.msg-search input::placeholder{color:var(--card-ink-dim)}
.msg-search input::-webkit-search-cancel-button{-webkit-appearance:none}
.msg-me{flex:none;border-radius:50%;transition:transform .12s}
.msg-me:active{transform:scale(.92)}

/* ---- การ์ดกระจกขาวแบบเดโม่ (override glass-card ของ base) ---- */
.theme-light .msg-contacts,
.theme-light .chat-card,
.theme-light .msg-ai-card{
  background:var(--card-glass);
  border:1px solid var(--card-brd);
  backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);
  box-shadow:0 6px 20px rgba(80,140,220,.15)}
.theme-light .msg-contacts,
.theme-light .msg-ai-card{border-radius:26px}
.theme-light .chat-card{border-radius:20px}

/* ---- แถวสถานะออนไลน์ (scroll แนวนอน) ---- */
.msg-contacts{display:flex;gap:14px;overflow-x:auto;overscroll-behavior-x:contain;
  margin:6px 14px 4px;padding:12px 14px 10px;scroll-snap-type:x proximity}
.msg-contact{display:flex;flex-direction:column;align-items:center;gap:6px;
  flex:none;min-width:56px;scroll-snap-align:start;transition:transform .12s}
.msg-contact:active{transform:scale(.93)}
.msg-contact .st{font-size:11px;line-height:1;display:inline-flex;align-items:center;gap:4px;
  color:var(--card-ink-dim);white-space:nowrap;font-weight:500}
.msg-contact .st::before{content:'';width:6px;height:6px;border-radius:50%;
  background:var(--ink-faint);flex:none}
.msg-contact .st-online{color:#1d9e63}
.msg-contact .st-online::before{background:#4ade80}
.msg-contact .st-away{color:#b28a12}
.msg-contact .st-away::before{background:var(--amber)}
.msg-contact .st-busy{color:#d64545}
.msg-contact .st-busy::before{background:var(--red)}

/* ---- รายการแชท ---- */
.msg-list{display:flex;flex-direction:column;gap:12px;padding:8px 14px 4px}
.chat-card{display:flex;align-items:center;gap:12px;width:100%;text-align:left;
  padding:13px 14px;
  animation:cardIn .4s cubic-bezier(.22,.9,.3,1) backwards;
  transition:transform .13s, box-shadow .13s}
.chat-card:active{transform:scale(.98)}
@keyframes cardIn{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:none}}
.chat-card .name-row{display:flex;align-items:center;gap:7px;min-width:0}
.chat-card .name{font-weight:700;font-size:15.5px;color:var(--card-ink)}
.chat-card .mem{flex:none;font-size:10.5px;line-height:1;color:var(--card-ink-dim);
  background:rgba(120,170,230,.18);border:1px solid rgba(120,170,230,.25);
  padding:3px 8px;border-radius:var(--r-pill)}
.chat-card .last{font-size:13px;color:var(--card-ink-dim);margin-top:3px}
.chat-card .meta{display:flex;flex-direction:column;align-items:flex-end;gap:7px;flex:none}
.chat-card .time{font-size:11.5px;color:var(--card-ink-dim);white-space:nowrap}
.chat-card .chev{display:flex;color:var(--card-ink-dim);opacity:.8}
.chat-card .chev svg{width:15px;height:15px}

/* แชท AI — ไอคอน + ขอบเรืองเขียวจาง */
.theme-light .chat-card.is-ai{border-color:rgba(87,230,168,.5);
  box-shadow:0 0 16px rgba(87,230,168,.25), 0 6px 20px rgba(80,140,220,.15)}
.chat-card .ai-ico{display:flex;flex:none;color:#17a86e;
  filter:drop-shadow(0 0 5px rgba(87,230,168,.65))}
.chat-card .ai-ico svg{width:16px;height:16px}

.msg-empty{padding:34px 0;text-align:center;font-size:14px}

/* ---- การ์ด AI ผู้ช่วย (ล่างสุด) ---- */
.msg-ai-card{margin:10px 14px 16px;padding:16px 16px 15px;
  animation:cardIn .4s cubic-bezier(.22,.9,.3,1) .12s backwards}
.msg-ai-card h3{font-size:15px;font-weight:700;color:var(--card-ink);margin-bottom:11px}
.msg-ai-row{display:flex;gap:9px}
.msg-ai-row input{flex:1;min-width:0;padding:11px 14px;font-size:14px;
  border-radius:var(--r-sm);color:var(--card-ink);
  background:rgba(190,215,240,.32);border:1px solid var(--lt-card-brd);
  transition:border-color .15s}
.msg-ai-row input:focus{border-color:var(--accent)}
.msg-ai-row input::placeholder{color:var(--card-ink-dim)}
.msg-ai-go{flex:none;width:48px;border-radius:var(--r-sm);display:flex;
  align-items:center;justify-content:center;color:#fff;
  background:linear-gradient(135deg,#4aa4ff,var(--accent));
  box-shadow:0 5px 14px rgba(47,139,255,.4);transition:transform .12s}
.msg-ai-go:active{transform:scale(.93)}
.msg-ai-go svg{width:19px;height:19px}

/* ---- จอแคบ: rail 64px + เนื้อหา ต้องไม่ล้นที่ 360px ---- */
@media (max-width:420px){
  .msg-top{padding:14px 12px 6px;padding-top:calc(14px + env(safe-area-inset-top))}
  .msg-contacts{margin:6px 10px 4px;padding:12px 12px 10px}
  .msg-list{padding:8px 10px 4px}
  .msg-ai-card{margin:8px 10px 14px}
}
@media (max-width:374px){
  .msg-top{padding:12px 8px 6px;padding-top:calc(12px + env(safe-area-inset-top))}
  .msg-contacts{margin:6px 6px 4px;padding:10px 10px 8px;gap:10px}
  .msg-list{padding:8px 6px 4px;gap:9px}
  .chat-card{padding:11px 12px;gap:10px}
  .msg-ai-card{margin:8px 6px 12px;padding:14px 12px 13px}
}

/* ---- ปักหมุด (favorites) ---- */
.rail-btn.on{color:#ffd66b;background:rgba(255,214,107,.16);
  box-shadow:0 6px 20px rgba(255,190,60,.28)}
.msg-group-h{padding:2px 6px 0;font-size:12px;font-weight:700;letter-spacing:.2px;
  color:var(--card-ink-dim);display:flex;align-items:center;gap:8px}
.msg-group-h::after{content:'';flex:1;height:1px;
  background:linear-gradient(90deg,rgba(120,170,230,.35),transparent)}
.msg-list .chat-card{cursor:pointer}
.chat-card .fav-star{flex:none;width:32px;height:32px;border-radius:50%;
  display:flex;align-items:center;justify-content:center;color:#a9bed6;
  transition:transform .15s ease, color .15s, background .15s}
.chat-card .fav-star svg{width:17px;height:17px}
.chat-card .fav-star:hover{background:rgba(255,214,107,.16);color:#e0a92b}
.chat-card .fav-star:active{transform:scale(.82)}
.chat-card .fav-star.on{color:#f0b429;filter:drop-shadow(0 0 5px rgba(240,180,41,.5))}
.theme-light .chat-card.is-fav{border-color:rgba(240,180,41,.5);
  box-shadow:0 0 14px rgba(240,180,41,.18), 0 6px 20px rgba(80,140,220,.15)}
.chat-card:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (max-width:374px){
  .chat-card .fav-star{width:28px;height:28px}
  .chat-card .fav-star svg{width:15px;height:15px}
}

/* ====== v3.1: ผูกการ์ด/ตัวหนังสือกับโทเคนธีม (ทุกธีมผ่าน data-wtheme บน <html>) ====== */
html[data-wtheme] .theme-light .msg-contacts,
html[data-wtheme] .theme-light .chat-card,
html[data-wtheme] .theme-light .msg-ai-card{background:var(--card-glass);
  border:1px solid var(--card-brd);box-shadow:var(--neon), inset 0 1px 0 rgba(255,255,255,.14)}
html[data-wtheme] .msg-search{background:var(--card-glass);border:1px solid var(--card-brd);
  box-shadow:var(--neon)}
html[data-wtheme] .msg-search input{color:var(--card-ink)}
html[data-wtheme] .msg-search input::placeholder{color:var(--card-ink-dim)}
html[data-wtheme] .msg-search svg{color:var(--card-ink-dim)}
html[data-wtheme] .chat-card .name{color:var(--card-ink)}
html[data-wtheme] .chat-card .last,
html[data-wtheme] .chat-card .time,
html[data-wtheme] .chat-card .chev{color:var(--card-ink-dim)}
html[data-wtheme] .chat-card .mem{color:var(--card-ink-dim);
  background:rgba(127,127,200,.16);border-color:var(--card-brd)}
html[data-wtheme] .msg-group-h{color:var(--card-ink-dim)}
html[data-wtheme] .msg-ai-card h3{color:var(--card-ink)}
html[data-wtheme] .msg-ai-row input{color:var(--card-ink);
  background:rgba(127,127,200,.15);border-color:var(--card-brd)}
html[data-wtheme] .msg-ai-row input::placeholder{color:var(--card-ink-dim)}
/* คงสีสถานะออนไลน์ (ความหมายเฉพาะ ไม่ตามธีม) */
html[data-wtheme] .msg-contact .st{color:var(--card-ink-dim)}
html[data-wtheme] .msg-contact .st-online{color:#2fe08d}
html[data-wtheme] .msg-contact .st-away{color:#f5c542}
html[data-wtheme] .msg-contact .st-busy{color:#ff6b74}
/* การ์ด AI = ขอบนีออนเรืองตามธีม (ตามภาพอ้างอิง) */
html[data-wtheme] .theme-light .chat-card.is-ai{border-color:var(--glass-brd-hi);
  box-shadow:var(--glow), var(--neon)}
html[data-wtheme] .chat-card .ai-ico{color:#b985ff;
  filter:drop-shadow(0 0 6px rgba(170,90,255,.6))}
/* ชิป AI Toolset บนการ์ด AI + แถวชิปกรอง + ปุ่มเริ่มแชทใหม่ */
.msg-ai-chips{display:flex;gap:6px;margin-top:7px;flex-wrap:wrap}
.msg-ai-chip{padding:4px 11px;border-radius:var(--r-pill);font-size:11px;font-weight:700;
  color:#fff;background:linear-gradient(160deg,#7a3cff,#4b18d8);
  box-shadow:0 2px 10px rgba(110,50,230,.4), inset 0 1px 0 rgba(255,255,255,.35);
  transition:transform .13s}
.msg-ai-chip:active{transform:scale(.93)}
.msg-ai-chip.alt{background:linear-gradient(160deg,#ff4552,#e60012)}
.msg-filter{display:flex;gap:7px;margin:8px 14px 0}
.msg-new-cta{margin:6px 14px 14px}
@media (max-width:420px){.msg-filter{margin:8px 10px 0}.msg-new-cta{margin:6px 10px 12px}}
.msg-ai-spark{flex:none;display:flex;align-items:center;color:#8b5cf6;
  filter:drop-shadow(0 0 5px rgba(150,90,255,.5));transition:transform .13s}
.msg-ai-spark:active{transform:scale(.85)}
.msg-ai-spark svg{width:18px;height:18px}
/* rail ซ้ายเปลี่ยนโทนตามธีม */
html[data-wtheme="night"] .msg-rail{background:linear-gradient(175deg,#0d1742,#03040f);
  border-right-color:rgba(0,190,255,.25)}
html[data-wtheme="power"] .msg-rail{background:linear-gradient(175deg,#4a0511,#120108);
  border-right-color:rgba(255,90,110,.3)}
html[data-wtheme="duo"] .msg-rail{background:linear-gradient(175deg,#1626d8,#5a1ed0 60%,#a4127a);
  border-right-color:rgba(200,150,255,.35)}
