/* risk/chat.css — สไตล์แชทบอท ใช้ร่วมกันระหว่างกล่องแชทใน index.php และหน้าแชทเต็มจอ chat-page.php */

/* ---------- ปุ่มลอยและกล่องแชท (index.php) ---------- */
#chatFab {
  position: fixed; right: 22px; bottom: 22px; z-index: 900;
  display: flex; align-items: center; gap: 9px;
  background: linear-gradient(135deg, #9945ff, #6d3ad6);
  color: #fff; border: none; border-radius: 999px;
  padding: 13px 20px; font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; box-shadow: 0 10px 30px rgba(153,69,255,.4);
  transition: transform .18s, opacity .18s;
}
#chatFab:hover { transform: translateY(-2px); }
#chatFab.hidden { opacity: 0; pointer-events: none; transform: scale(.9); }
#chatPanel {
  position: fixed; right: 22px; bottom: 22px; z-index: 901;
  width: min(420px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 44px));
  background: var(--card); border: 1px solid var(--border); border-radius: 18px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
  opacity: 0; pointer-events: none; transform: translateY(14px) scale(.98);
  transition: opacity .2s, transform .2s;
}
#chatPanel.open { opacity: 1; pointer-events: auto; transform: none; }

/* ---------- ส่วนหัว ---------- */
.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 17px; border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(153,69,255,.16), transparent);
}
.chat-head b { font-size: 14.5px; display: block; }
.chat-head small { font-size: 11.5px; color: var(--muted); }
.chat-head-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.chat-head-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--muted);
  font-size: 16px; line-height: 1; cursor: pointer; padding: 5px 7px; border-radius: 8px;
  text-decoration: none;
}
.chat-head-btn:hover, .chat-head-btn:focus-visible { color: var(--text); background: rgba(255,255,255,.06); }
#chatKbCount, #chatClear { font-size: 12px; white-space: nowrap; }
#chatClear { font-family: inherit; }

/* ---------- ข้อความ ---------- */
.chat-body { flex: 1; overflow-y: auto; padding: 16px 17px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; flex-direction: column; max-width: 92%; }
.msg.user { align-self: flex-end; align-items: flex-end; max-width: 85%; }
.msg .bubble { padding: 11px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.75; word-break: break-word; }
.msg.user .bubble { background: linear-gradient(135deg, #9945ff, #6d3ad6); color: #fff; border-bottom-right-radius: 5px; }
.msg.bot .bubble { background: #111827; border: 1px solid var(--border); border-bottom-left-radius: 5px; color: #dbe3f0; }
.msg .meta { font-size: 10.5px; color: #5b6679; margin-top: 4px; padding: 0 4px; }
.msg .bubble p { margin: 0; }
.msg .bubble p + p { margin-top: 7px; }
.msg .bubble ul { margin: 6px 0 6px 4px; padding-left: 15px; }
.msg .bubble li { margin-bottom: 5px; }
.msg .bubble strong { color: #fff; font-weight: 600; }
.msg .bubble em { color: var(--muted); font-style: normal; font-size: 12.5px; }
.msg .bubble code { background: #0b1220; padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.msg .bubble hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.msg .bubble .gap { height: 7px; }
.typing { display: inline-flex; gap: 4px; padding: 3px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.3s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ---------- รูปในข้อความและรูปที่รอส่ง ---------- */
.msg-pics { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg.user .msg-pics { justify-content: flex-end; }
.msg-pics img {
  width: 132px; height: 92px; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--border); background: #0b1220;
}
.chat-attach { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 14px 0; }
.attach-item { position: relative; }
.attach-item img {
  width: 64px; height: 64px; object-fit: cover;
  border-radius: 9px; border: 1px solid var(--border); display: block;
}
.attach-remove {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #1f2937; border: 1px solid var(--border); color: var(--text);
  font-size: 11px; line-height: 1; cursor: pointer; padding: 0;
}
.attach-remove:hover { background: #ef4444; border-color: #ef4444; }
#chatAttachBtn {
  flex-shrink: 0; height: 40px; width: 40px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border); border-radius: 10px;
  color: var(--muted); cursor: pointer;
}
#chatAttachBtn:hover, #chatAttachBtn:focus-visible { color: var(--text); border-color: var(--muted); }
#chatPanel.drag-over, .chat-page.drag-over { outline: 2px dashed #9945ff; outline-offset: -6px; }

/* ---------- ฟอร์มใส่รหัสผ่าน ---------- */
.chat-lock { padding: 14px 17px; border-top: 1px solid var(--border); }
.chat-lock p { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.chat-lock form { display: flex; gap: 8px; }
.chat-lock input {
  flex: 1; height: 40px; padding: 0 12px; border-radius: 10px;
  background: #0b1220; border: 1px solid var(--border); color: var(--text);
  font-family: inherit; font-size: 14px;
}
.chat-lock input:focus { outline: none; border-color: #9945ff; }
.chat-lock button {
  flex-shrink: 0; height: 40px; padding: 0 16px; border: none; border-radius: 10px;
  background: #9945ff; color: #fff; font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.chat-lock .lock-note { color: #f87171; font-size: 12px; margin: 8px 0 0; min-height: 16px; }

/* ---------- คำถามแนะนำและช่องพิมพ์ ---------- */
.chat-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 11px 17px; border-top: 1px solid var(--border); }
.chip {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 5px 10px; font-size: 11.5px; font-family: inherit; cursor: pointer;
}
.chip:hover, .chip:focus-visible { color: var(--text); border-color: var(--muted); }
.chat-input { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); align-items: flex-end; }
.chat-input textarea {
  flex: 1; resize: none; min-height: 40px; max-height: 120px;
  padding: 10px 12px; border-radius: 11px; line-height: 1.5;
  background: #0b1220; border: 1px solid var(--border); color: var(--text); font-family: inherit; font-size: 14px;
}
.chat-input textarea:focus { outline: none; border-color: #9945ff; }
#chatSend {
  flex-shrink: 0; height: 40px; padding: 0 16px; border: none; border-radius: 10px;
  background: #9945ff; color: #fff; font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
#chatSend:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- หน้าแชทเต็มจอ (chat-page.php) ---------- */
.chat-page {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  width: min(900px, 100%);
  margin: 0 auto;
  background: var(--card);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.chat-page .chat-head { padding: 15px 18px; }
.chat-page .chat-head-btn { font-size: 13px; }
.chat-page .chat-head b { font-size: 16px; }
.chat-page .chat-body { padding: 20px 18px; }
.chat-page .msg { max-width: min(92%, 680px); }
.chat-page .msg.user { max-width: min(85%, 560px); }
.chat-page .msg .bubble { font-size: 14.5px; }
.chat-page .chat-input { padding: 12px 18px 16px; }

@media (max-width: 560px) {
  #chatPanel { right: 8px; left: 8px; bottom: 8px; width: auto; height: calc(100vh - 16px); }
  #chatFab { right: 14px; bottom: 14px; }
  .chat-page { border: none; }
  .chat-page .chat-chips { overflow-x: auto; flex-wrap: nowrap; }
  .chat-page .chip { white-space: nowrap; }
  .chat-page .chat-head-actions { flex-shrink: 1; flex-wrap: wrap; justify-content: flex-end; }
}

/* ---------------------------------------------------- แชท v3: สตรีม, ปุ่มใต้คำตอบ, กราฟ, การ์ดไม้เทรด */

.cursor {
  display: inline-block; width: 7px; height: 1em; margin-left: 2px; vertical-align: text-bottom;
  background: #a98bff; animation: chat-blink 1s steps(2) infinite;
}
@keyframes chat-blink { 50% { opacity: 0; } }

.tool-status {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px; font-size: 12.5px; color: var(--muted, #8b97ad);
}
.tool-status .spin {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(153,69,255,.35); border-top-color: #9945ff;
  animation: chat-spin .8s linear infinite;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }

.msg-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg-actions button {
  background: none; border: 1px solid var(--border, #232a36); color: var(--muted, #8b97ad);
  font: inherit; font-size: 12px; padding: 4px 9px; border-radius: 999px; cursor: pointer;
}
.msg-actions button:hover:not(:disabled) { color: var(--text, #e6e9ef); border-color: #9945ff; }
.msg-actions button:focus-visible { outline: 2px solid #9945ff; outline-offset: 1px; }
.msg-actions button:disabled { opacity: .7; cursor: default; }

.chip-fill { border-style: dashed; }

.chat-chart {
  margin: 8px 0 0; padding: 10px 10px 4px; width: 100%; max-width: 680px;
  background: rgba(255,255,255,.02); border: 1px solid var(--border, #232a36); border-radius: 12px;
}
.chat-chart figcaption {
  display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--muted, #8b97ad); margin-bottom: 4px;
}
.chat-chart figcaption b { color: var(--text, #e6e9ef); font-weight: 600; }
.chat-chart svg { display: block; width: 100%; height: auto; }
.chat-chart .cc-grid { stroke: rgba(139,151,173,.14); stroke-width: 1; }
.chat-chart .cc-axis { fill: #8b97ad; font-size: 11px; }
.chat-chart .cc-up { stroke: #22c55e; fill: #22c55e; }
.chat-chart .cc-down { stroke: #ef4444; fill: #ef4444; }
.chat-chart .cc-last { fill: #e6e9ef; }
.chat-chart .cc-lv { stroke-width: 1.3; stroke-dasharray: 5 4; }
.chat-chart .cc-support { stroke: #22c55e; }
.chat-chart .cc-resistance { stroke: #f87171; }
.chat-chart .cc-entry { stroke: #60a5fa; stroke-dasharray: none; }
.chat-chart .cc-sl { stroke: #ef4444; stroke-dasharray: 2 3; }
.chat-chart .cc-tp { stroke: #4ade80; stroke-dasharray: 2 3; }
.chat-chart .cc-other { stroke: #a78bfa; }
.chat-chart [class$="-t"] { font-size: 11px; font-weight: 600; }
.chat-chart .cc-support-t, .chat-chart .cc-tp-t { fill: #4ade80; }
.chat-chart .cc-resistance-t, .chat-chart .cc-sl-t { fill: #f87171; }
.chat-chart .cc-entry-t { fill: #60a5fa; }
.chat-chart .cc-other-t { fill: #a78bfa; }

.trade-card {
  display: block; margin-top: 8px; padding: 9px 12px; border-radius: 10px;
  background: rgba(20,241,149,.08); border: 1px solid rgba(20,241,149,.3);
  color: var(--text, #e6e9ef); text-decoration: none; font-size: 13px; line-height: 1.5;
}
.trade-card:hover, .trade-card:focus-visible { border-color: #14f195; outline: none; }
.trade-card .go { color: #a98bff; white-space: nowrap; }
.trade-card .up { color: #4ade80; }
.trade-card .down { color: #f87171; }
.chat-chart .cc-name { font-weight: 500; paint-order: stroke; stroke: #141922; stroke-width: 3px; }
