/* Chatbot กยศ.มรย. — หน้าแชท (โทนสีจากโลโก้: น้ำเงินกรมท่า กยศ. · ชมพู YRU · มิ้นต์ · แดง) */
:root {
  --brand: #1f1c7a;                                   /* เปลี่ยนได้รายบอทในแดชบอร์ด */
  --pink: #ec4c8c;
  --red: #ed1c24;
  --mint: #8fd3cc;
  --brand-2: color-mix(in srgb, var(--brand) 22%, var(--pink));
  --grad: linear-gradient(135deg, var(--brand) 0%, color-mix(in srgb, var(--brand) 55%, var(--pink)) 55%, var(--brand-2) 100%);
  --accent: var(--pink);
  --teal: #0f8f86;
  --bg: #f5f4fb;
  --panel: #ffffff;
  --panel-2: #f7f8fe;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e6e8f5;
  --bot-bubble: #ffffff;
  --user-text: #ffffff;
  --error: #be123c;
  --error-bg: #fff1f3;
  --shadow-sm: 0 1px 2px rgba(30, 27, 75, .06), 0 2px 8px rgba(30, 27, 75, .05);
  --shadow: 0 20px 60px -20px rgba(49, 46, 129, .28), 0 4px 16px rgba(49, 46, 129, .08);
  --radius: 20px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0d1f;
    --panel: #111530;
    --panel-2: #161b3b;
    --text: #e6e9ff;
    --muted: #9aa3c7;
    --line: #232a52;
    --bot-bubble: #181e42;
    --error-bg: #2d1020;
    --error: #fda4af;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 20px 60px -20px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex; justify-content: center; align-items: stretch;
  padding: 24px 16px;
  position: relative; overflow: hidden;
}
/* วงแสงตกแต่งพื้นหลัง */
body::before, body::after {
  content: ''; position: fixed; z-index: -1; border-radius: 50%; filter: blur(70px); opacity: .55; pointer-events: none;
}
body::before { width: 520px; height: 520px; left: -140px; top: -160px; background: color-mix(in srgb, var(--brand) 45%, transparent); }
body::after { width: 480px; height: 480px; right: -160px; bottom: -180px; background: color-mix(in srgb, var(--pink) 35%, transparent); }
.app::before { /* วงแหวนมิ้นต์แบบโลโก้ */
  content: ''; position: fixed; z-index: -1; width: 760px; height: 760px; right: -300px; top: -300px; border-radius: 50%; pointer-events: none;
  background: repeating-radial-gradient(circle, transparent 0 18px, color-mix(in srgb, var(--mint) 45%, transparent) 18px 21px);
  opacity: .32; mask: radial-gradient(circle, transparent 38%, #000 40%, #000 62%, transparent 64%);
}
body.embed { padding: 0; background: var(--panel); }
body.embed::before, body.embed::after { display: none; }

.app {
  width: 100%; max-width: 860px; height: calc(100dvh - 48px);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(12px);
  border-radius: 28px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--brand) 12%, var(--line));
}
.embed .app { height: 100dvh; max-width: none; border-radius: 0; border: 0; box-shadow: none; }

/* ---------- Header ---------- */
.chat-header {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; color: #fff; background: var(--grad);
}
.chat-header::after { /* เส้นทองด้านล่าง */
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: linear-gradient(90deg, var(--red), var(--pink), var(--mint));
}
.bot-id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.bot-title { min-width: 0; }
.chat-header h1 { font-size: 1.1rem; margin: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: .01em; }
.status { margin: 2px 0 0; font-size: .8rem; opacity: .92; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 0 rgba(74, 222, 128, .6); animation: pulse 2s infinite; }

.header-actions { display: flex; gap: 8px; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, .16); color: #fff;
  border: 1px solid rgba(255, 255, 255, .3);
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  font: inherit; font-size: .85rem; font-weight: 500;
  transition: background .15s, transform .12s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .28); transform: translateY(-1px); }

.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%; overflow: hidden;
  display: grid; place-items: center; font-size: .7rem; font-weight: 700;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bot-avatar { background: #fff; box-shadow: 0 0 0 2px color-mix(in srgb, var(--mint) 70%, transparent), var(--shadow-sm); }
.bot-avatar.ring { width: 46px; height: 46px; box-shadow: 0 0 0 3px rgba(255, 255, 255, .55); }
.staff-avatar { background: linear-gradient(135deg, #5eead4, var(--teal)); color: #fff; box-shadow: var(--shadow-sm); }

.staff-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 20px; font-size: .9rem; font-weight: 500;
  background: linear-gradient(90deg, color-mix(in srgb, var(--mint) 30%, var(--panel)), color-mix(in srgb, var(--pink) 12%, var(--panel)));
  border-bottom: 1px solid var(--line);
}
.staff-banner button {
  font: inherit; font-size: .82rem; cursor: pointer; white-space: nowrap;
  border: 1px solid color-mix(in srgb, var(--brand) 35%, var(--line)); background: var(--panel); color: var(--text);
  padding: 6px 14px; border-radius: 999px;
}

/* ---------- Messages ---------- */
.messages { flex: 1; overflow-y: auto; padding: 22px 20px 10px; scroll-behavior: smooth; }
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.welcome { text-align: center; padding: 26px 4px 12px; animation: fadeUp .45s ease; }
.hero-logo {
  display: block; width: 132px; height: 132px; margin: 0 auto 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--mint) 35%, transparent), 0 18px 40px -16px color-mix(in srgb, var(--brand) 55%, transparent);
  animation: float 4s ease-in-out infinite;
}
.welcome-title { font-size: 1.35rem; margin: 0 0 6px; font-weight: 700; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.welcome-text { font-size: 1.1rem; line-height: 1.75; margin: 0 0 6px; font-weight: 500; }
.hint { color: var(--muted); font-size: .86rem; margin: 0 0 16px; }

.chips { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; text-align: left; max-width: 640px; margin: 0 auto; }
.chip {
  --c: var(--brand);
  font: inherit; font-size: .92rem; color: var(--text); cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 16px;
  background: color-mix(in srgb, var(--c) 7%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--c) 22%, var(--line));
  transition: transform .14s, box-shadow .14s, background .14s;
}
.chip:hover { transform: translateY(-2px); box-shadow: 0 8px 20px -10px color-mix(in srgb, var(--c) 70%, transparent); background: color-mix(in srgb, var(--c) 13%, var(--panel)); }
.chip-ic { flex: none; width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-size: 1.05rem; background: color-mix(in srgb, var(--c) 16%, var(--panel)); }
.chip.c0 { --c: #1f1c7a; } .chip.c1 { --c: #db2777; } .chip.c2 { --c: #0f8f86; }
.chip.c3 { --c: #dc2626; } .chip.c4 { --c: #7c3aed; } .chip.c5 { --c: #0284c7; }
@media (prefers-color-scheme: dark) { .chip.c0 { --c: #818cf8; } }

.msg { display: flex; gap: 10px; margin: 0 0 16px; align-items: flex-end; animation: fadeUp .25s ease; }
.msg.user { justify-content: flex-end; }
.bubble-wrap { max-width: min(78%, 640px); display: flex; flex-direction: column; }
.msg.user .bubble-wrap { align-items: flex-end; }

.bubble { padding: 12px 16px; border-radius: var(--radius); line-height: 1.7; font-size: .97rem; overflow-wrap: anywhere; }
.msg.bot .bubble { background: var(--bot-bubble); border: 1px solid var(--line); border-bottom-left-radius: 6px; box-shadow: var(--shadow-sm); }
.msg.user .bubble { background: var(--grad); color: var(--user-text); border-bottom-right-radius: 6px; white-space: pre-wrap; box-shadow: 0 6px 16px -8px color-mix(in srgb, var(--brand) 70%, transparent); }
.msg.staff .bubble { background: color-mix(in srgb, var(--teal) 9%, var(--bot-bubble)); border-color: color-mix(in srgb, var(--teal) 40%, var(--line)); }
.msg.system .bubble { background: color-mix(in srgb, var(--mint) 22%, var(--bot-bubble)); border-color: color-mix(in srgb, var(--mint) 60%, var(--line)); font-size: .93rem; }
.msg.error .bubble { background: var(--error-bg); color: var(--error); border-color: color-mix(in srgb, var(--error) 30%, transparent); }

.tag {
  align-self: flex-start; font-size: .72rem; font-weight: 600; margin: 0 0 5px 2px;
  padding: 2px 10px; border-radius: 999px;
  color: #0f5f59; background: color-mix(in srgb, var(--mint) 40%, var(--panel));
}
.msg.staff .tag { color: #fff; background: var(--teal); }

.bubble p { margin: 0 0 .6em; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: .3em 0 .6em; padding-left: 1.3em; }
.bubble li::marker { color: var(--brand); }
.bubble strong { color: color-mix(in srgb, var(--brand) 70%, var(--text)); }
.msg.user .bubble strong { color: inherit; }
.bubble code { background: color-mix(in srgb, var(--brand) 10%, transparent); padding: 1px 6px; border-radius: 6px; font-size: .88em; }
.bubble pre { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 12px; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }
.bubble a { color: var(--brand); font-weight: 500; }
@media (prefers-color-scheme: dark) { .bubble a, .bubble strong, .bubble li::marker { color: #a5b4fc; } .tag { color: #c9f1ec; } }
.bubble table { border-collapse: collapse; margin: .4em 0; font-size: .9em; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 5px 9px; }
.bubble th { background: color-mix(in srgb, var(--brand) 8%, transparent); }

.meta { font-size: .72rem; color: var(--muted); margin-top: 5px; display: flex; gap: 12px; align-items: center; padding: 0 4px; flex-wrap: wrap; }
.copy-btn { font: inherit; font-size: .74rem; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0; }
.copy-btn:hover { color: var(--brand); text-decoration: underline; }

.typing { display: inline-flex; gap: 5px; padding: 15px 18px; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--pink); animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }

/* ---------- Dock: ปุ่มลัด + กล่องพิมพ์ ---------- */
.dock { position: relative; padding: 6px 16px 12px; border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.quick-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 2px 4px; font-size: .78rem; color: var(--muted); font-weight: 500; }
.quick { display: flex; flex-wrap: wrap; gap: 7px; padding: 2px 2px 8px; max-height: 40px; overflow: hidden; }
.quick.open { max-height: min(36vh, 260px); overflow-y: auto; }
.quick-more { flex: none; border: 0; background: none; color: var(--brand); font: inherit; font-size: .78rem; font-weight: 600; cursor: pointer; padding: 2px 4px; }
@media (prefers-color-scheme: dark) { .quick-more { color: #a5b4fc; } }
.chip.mini { flex: none; max-width: 100%; padding: 6px 11px; border-radius: 999px; font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; gap: 4px; display: inline-block; }

.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 8px 8px 8px 18px; border-radius: 24px;
  background: var(--panel-2); border: 1.5px solid var(--line);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 16%, transparent); background: var(--panel); }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 1rem; line-height: 1.5; padding: 8px 0; max-height: 160px;
}
.composer textarea::placeholder { color: var(--muted); }
.send-btn {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--grad); color: #fff; display: grid; place-items: center;
  box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--brand) 80%, transparent);
  transition: transform .12s, opacity .15s;
}
.send-btn:hover:not(:disabled) { transform: scale(1.07) rotate(-8deg); }
.send-btn:disabled { opacity: .45; cursor: not-allowed; }
.scroll-btn {
  position: absolute; right: 22px; top: -54px; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel); color: var(--brand); cursor: pointer;
  display: grid; place-items: center; box-shadow: var(--shadow-sm); animation: fadeUp .2s ease;
}
.disclaimer { text-align: center; font-size: .72rem; color: var(--muted); margin: 8px 0 0; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, .6); } 70% { box-shadow: 0 0 0 7px rgba(74, 222, 128, 0); } 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

@media (max-width: 600px) {
  body { padding: 0; }
  .app { height: 100dvh; border-radius: 0; border: 0; }
  .chat-header { padding: 12px 14px; }
  .icon-btn { padding: 8px 10px; }
  .icon-btn span { display: none; }
  .bubble-wrap { max-width: 85%; }
  .msg .avatar { width: 30px; height: 30px; font-size: .6rem; }
  .chips { grid-template-columns: 1fr; gap: 8px; }
  .chip { padding: 10px 12px; }
  .chip-ic { width: 30px; height: 30px; }
  .hero-logo { width: 96px; height: 96px; }
  .welcome { padding-top: 12px; }
  .welcome-text { font-size: 1rem; }
  .messages { padding: 16px 12px 8px; }
  .dock { padding: 6px 10px calc(10px + env(safe-area-inset-bottom)); }
}

/* ---------- ช่องทางติดต่อ / ไม่พบคำตอบ ---------- */
.follow { margin-top: 22px; }
.follow .hint { margin-bottom: 10px; }
.channels { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.noanswer .channels { justify-content: flex-start; }
.ch {
  font: inherit; font-size: .84rem; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 4px; padding: 7px 13px; border-radius: 999px;
  color: var(--text); background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  transition: transform .12s, border-color .12s;
}
.ch:hover { transform: translateY(-1px); border-color: var(--brand); }
.ch-website { border-color: color-mix(in srgb, #1f1c7a 30%, var(--line)); }
.ch-facebook { border-color: color-mix(in srgb, #1877f2 40%, var(--line)); }
.ch-tiktok { border-color: color-mix(in srgb, #ec4c8c 40%, var(--line)); }
.ch-line { border-color: color-mix(in srgb, #06c755 45%, var(--line)); }
.ch-staff { background: var(--grad); color: #fff; border-color: transparent; }
.noanswer { margin-top: 8px; padding: 10px 12px; border-radius: 14px; background: color-mix(in srgb, var(--mint) 16%, var(--panel)); border: 1px dashed color-mix(in srgb, var(--mint) 70%, var(--line)); }
.noanswer p { margin: 0 0 8px; font-size: .84rem; color: var(--muted); }

/* ---------- ฟอร์มข้อมูลติดต่อ ---------- */
.app { position: relative; }
.sheet-backdrop { position: absolute; inset: 0; z-index: 20; background: rgba(15, 12, 50, .45); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 16px; animation: fadeUp .2s ease; }
.sheet { width: 100%; max-width: 480px; max-height: 100%; overflow-y: auto; background: var(--panel); border-radius: 22px; padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--line); position: relative; }
.sheet::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; border-radius: 22px 22px 0 0; background: linear-gradient(90deg, var(--red), var(--pink), var(--mint)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet h2 { margin: 0; font-size: 1.12rem; }
.sheet-close { border: 0; background: var(--panel-2); color: var(--muted); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: .9rem; }
.sheet-sub { color: var(--muted); font-size: .88rem; margin: 4px 0 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.sheet label { display: flex; flex-direction: column; gap: 5px; font-size: .86rem; font-weight: 500; }
.sheet input:not([type=checkbox]) { font: inherit; font-size: 1rem; color: var(--text); background: var(--panel-2); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%; }
.sheet input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 15%, transparent); }
.sheet .consent { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; font-size: .8rem; line-height: 1.55; color: var(--muted);
  background: color-mix(in srgb, var(--mint) 14%, var(--panel)); border: 1px solid color-mix(in srgb, var(--mint) 50%, var(--line)); border-radius: 12px; padding: 10px 12px; margin: 4px 0 12px; }
.sheet .consent input { margin-top: 3px; width: 18px; height: 18px; flex: none; accent-color: var(--brand); }
.sheet .consent strong { color: var(--text); }
.sheet-error { color: var(--error); background: var(--error-bg); border-radius: 10px; padding: 8px 12px; font-size: .86rem; margin: 0 0 10px; }
.sheet-submit { width: 100%; border: 0; border-radius: 14px; padding: 13px; font: inherit; font-weight: 600; font-size: 1rem; color: #fff; background: var(--grad); cursor: pointer;
  box-shadow: 0 10px 20px -10px color-mix(in srgb, var(--brand) 80%, transparent); }
.sheet-submit:disabled { opacity: .6; }
.sheet-skip { width: 100%; margin-top: 8px; border: 0; background: none; color: var(--muted); font: inherit; font-size: .82rem; text-decoration: underline; cursor: pointer; padding: 6px; }
@media (max-width: 600px) { .field-row { grid-template-columns: 1fr; } .sheet-backdrop { align-items: flex-end; padding: 0; } .sheet { border-radius: 22px 22px 0 0; } }

/* ---------- อินโฟกราฟิกในคำตอบ ---------- */
.media-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 8px; max-width: 520px; }
.media-grid.one { grid-template-columns: minmax(0, 1fr); max-width: 360px; }
.media-card { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-sm); }
.media-thumb { display: block; width: 100%; padding: 0; border: 0; background: #fff; cursor: zoom-in; }
.media-thumb img { display: block; width: 100%; height: auto; max-height: 460px; object-fit: contain; }
.media-card figcaption { font-size: .78rem; color: var(--muted); padding: 7px 10px; border-top: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(8, 6, 30, .92); display: flex; flex-direction: column; animation: fadeUp .18s ease; }
.lb-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; color: #fff; }
.lb-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-btn { font: inherit; font-size: .86rem; color: #fff; text-decoration: none; background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .25); border-radius: 999px; padding: 7px 14px; cursor: pointer; }
.lb-body { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 8px 12px 20px; }
.lb-body img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; background: #fff; }
@media (max-width: 600px) { .lb-body { align-items: flex-start; } .lb-body img { max-height: none; } }
