/* =========================================================
   SaigonScience Messenger 98 — khung chat, tin nhắn, thẻ
   ========================================================= */

.chat {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
}

/* ---------- Header ---------- */
.chat__head {
  display: flex; align-items: center; gap: 10px;
  min-height: 56px;
  padding: 6px 6px 6px 8px;
  box-shadow: var(--thin-sunken);
  margin-bottom: 4px;
}
.chat__back { display: none; min-height: 32px; padding: 2px 10px; font-size: 16px; }
.chat__av { position: relative; width: 40px; height: 40px; flex: none; }
.chat__av .pixel { width: 40px; height: 40px; }
.chat__av .dot { position: absolute; right: -2px; bottom: -2px; }
.chat__who { min-width: 0; flex: 1; }
.chat__name {
  display: flex; align-items: center; gap: 8px;
  margin: 0; font-size: 16px; line-height: 1.25;
}
.chat__name span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat__sub {
  margin: 1px 0 0; font-size: 12.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat__actions { display: flex; gap: 4px; flex: none; }
.chat__actions .btn { min-height: 30px; padding: 2px 10px; }

/* ---------- Log (giấy kẻ ô — sổ tay thí nghiệm) ---------- */
.chat__log {
  flex: 1; min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background-color: #fffef9;
  background-image:
    linear-gradient(rgba(0, 0, 128, .075) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 128, .075) 1px, transparent 1px);
  background-size: 18px 18px;
  background-attachment: local;
}
.log__inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 14px 16px 18px;
  display: flex; flex-direction: column; gap: 3px;
}

.divider {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 0 10px;
  font: 18px/1 var(--font-pixel); color: #6b6b8a;
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px dashed #b8b8cc; }

.sys {
  align-self: center;
  margin: 8px 0;
  padding: 2px 10px;
  font-size: 12.5px; color: var(--muted); font-style: italic;
  text-align: center;
}
.sys--buzz {
  font: 30px/1 var(--font-pixel); font-style: normal;
  color: #e0302a; letter-spacing: 1px;
}

/* ---------- Messages ---------- */
.msg {
  display: flex; align-items: flex-end; gap: 8px;
  animation: msg-in .22s steps(3) both;
}
.msg + .msg { margin-top: 1px; }
.msg.is-first { margin-top: 10px; }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } }

.msg__av { width: 32px; height: 32px; flex: none; visibility: hidden; }
.msg__av .pixel { width: 32px; height: 32px; }
.msg.is-last .msg__av { visibility: visible; }
.msg__col { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: min(600px, 82%); }
.msg__who {
  margin: 0 0 2px 6px;
  font-size: 12px; font-weight: 700; color: var(--accent, var(--navy));
}

.msg--me { justify-content: flex-end; }
.msg--me .msg__col { align-items: flex-end; }

.bubble {
  max-width: 100%;
  border-style: solid;
  border-width: 5px 6px 6px 5px;
  border-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' shape-rendering='crispEdges'%3E%3Cpath fill='%2300002a' fill-opacity='.22' d='M5 2h6v1h2v2h1v6h-1v2h-2v1H5v-1H3v-2H2V5h1V3h2z'/%3E%3Cpath d='M3 0h6v1h2v2h1v6h-1v2H9v1H3v-1H1V9H0V3h1V1h2z'/%3E%3Cpath fill='%23fff' d='M3 1h6v1h1v1h1v6h-1v1H9v1H3v-1H2V9H1V3h1V2h1z'/%3E%3C/svg%3E") 5 6 6 5 fill;
  padding: 3px 8px 2px 9px;
  font-size: 14.5px; line-height: 1.55;
  overflow-wrap: anywhere;
}
.msg--me .bubble {
  color: #fff;
  border-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' shape-rendering='crispEdges'%3E%3Cpath fill='%2300002a' fill-opacity='.22' d='M5 2h6v1h2v2h1v6h-1v2h-2v1H5v-1H3v-2H2V5h1V3h2z'/%3E%3Cpath d='M3 0h6v1h2v2h1v6h-1v2H9v1H3v-1H1V9H0V3h1V1h2z'/%3E%3Cpath fill='%23000080' d='M3 1h6v1h1v1h1v6h-1v1H9v1H3v-1H2V9H1V3h1V2h1z'/%3E%3C/svg%3E") 5 6 6 5 fill;
}
.bubble p { margin: 0; }
.bubble p + p { margin-top: 6px; }
.bubble a { color: var(--navy); font-weight: 600; }
.msg--me .bubble a { color: #fff; }
.bubble code {
  font: 500 13px var(--font-mono);
  background: #eef0ff; padding: 0 4px;
}
.bubble strong { font-weight: 700; }
.bubble--emoji {
  border: 0; border-image: none; padding: 0 2px;
  font-size: 44px; line-height: 1.1;
}
.bubble--quote {
  padding: 10px 14px 8px 12px;
  font: 30px/1.05 var(--font-pixel); color: var(--navy);
}
.bubble--quote small { display: block; margin-top: 6px; font: italic 13px var(--font-ui); color: var(--muted); }

/* mini window embedded in chat */
.card {
  width: 440px;
  max-width: 100%;
  margin: 2px 0;
  animation: msg-in .22s steps(3) both;
}
.card .title-bar { min-height: 22px; padding: 1px 3px 1px 5px; }
.card .title-bar__text { font-size: 18px; }
.card .tb-btn { width: 16px; height: 14px; }
.card .tb-btn .ico-close { transform: scale(.8); }
.card__body { padding: 8px; }
.card__body--white { background: #fff; box-shadow: var(--sunken); margin: 4px 2px 2px; padding: 10px 12px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.stat { padding: 8px 10px 6px; background: #fff; box-shadow: var(--sunken); }
.stat__v { font: 40px/1 var(--font-pixel); color: var(--navy); }
.stat__k { font-size: 12.5px; line-height: 1.35; color: #333; }

/* list */
.ilist { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ilist li { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 8px; }
.ilist__ico { font-size: 20px; line-height: 1.3; text-align: center; }
.ilist b { display: block; font-size: 14px; }
.ilist span { display: block; font-size: 13px; line-height: 1.45; color: #333; }

/* timeline */
.tline { list-style: none; margin: 0; padding: 0 0 0 4px; display: grid; gap: 8px; }
.tline li { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; align-items: baseline; }
.tline__y { font: 24px/1 var(--font-pixel); color: var(--navy); }
.tline li span:last-child { font-size: 13.5px; line-height: 1.45; }

/* chart */
.bars { display: grid; gap: 8px; }
.bars__row { display: grid; grid-template-columns: 56px minmax(0, 1fr) 44px; gap: 8px; align-items: center; }
.bars__label { font: 20px/1 var(--font-pixel); }
.bars__track { height: 18px; padding: 2px; background: #fff; box-shadow: var(--sunken); }
.bars__fill {
  height: 100%; width: 0;
  background: repeating-linear-gradient(90deg, var(--navy) 0 8px, transparent 8px 10px);
  transition: width .9s steps(12);
}
.bars__val { font: 20px/1 var(--font-pixel); text-align: right; }
.card__note { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

/* code (Notepad) */
.notepad__menu { display: flex; gap: 12px; padding: 2px 6px; font-size: 12px; }
.notepad pre {
  margin: 0 2px 2px;
  padding: 10px 12px;
  background: #fff; box-shadow: var(--sunken);
  font: 12.5px/1.6 var(--font-mono);
  overflow-x: auto;
  white-space: pre;
}
.notepad .c { color: #6a737d; }
.notepad .k { color: #000080; font-weight: 500; }
.notepad .s { color: #a31515; }

/* file */
.file {
  display: flex; align-items: center; gap: 10px;
  width: 380px; max-width: 100%;
  padding: 8px 10px;
  background: #fff; box-shadow: var(--raised);
  animation: msg-in .22s steps(3) both;
}
.file .pixel { width: 32px; height: 32px; }
.file__meta { flex: 1; min-width: 0; }
.file__name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file__size { font-size: 12px; color: var(--muted); }

/* actions */
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 2px; animation: msg-in .22s steps(3) both; }
.actions .btn { min-height: 32px; }

/* handoff contact card */
.handoff {
  display: flex; align-items: center; gap: 10px;
  width: 380px; max-width: 100%;
  padding: 8px 10px;
  background: var(--face); box-shadow: var(--window-edge);
  animation: msg-in .22s steps(3) both;
}
.handoff .pixel { width: 40px; height: 40px; }
.handoff__meta { flex: 1; min-width: 0; }
.handoff__name { display: flex; gap: 6px; align-items: center; font-weight: 700; font-size: 14px; }
.handoff__why { font-size: 12.5px; color: #333; }

/* ---------- Typing ---------- */
.typing {
  height: 20px;
  padding: 0 12px;
  font-size: 12.5px; font-style: italic; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.typing__dots { display: inline-flex; gap: 3px; }
.typing__dots i {
  width: 5px; height: 5px; background: var(--navy);
  animation: blink 1s steps(1) infinite;
}
.typing__dots i:nth-child(2) { animation-delay: .2s; }
.typing__dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: .15; } }

/* ---------- Suggestions ---------- */
.suggest {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 2px 2px 8px;
  min-height: 40px;
  align-content: flex-start;
}
.chip { min-height: 32px; padding: 4px 12px; font-size: 13px; font-weight: 500; }
.chip:active { padding: 5px 11px 3px 13px; }
.chip--ghost { background: transparent; box-shadow: none; text-decoration: underline; color: var(--navy); }
.chip--ghost:active { box-shadow: none; }
.chip--next { font-weight: 700; }

/* ---------- Composer ---------- */
.composer { position: relative; display: flex; align-items: stretch; gap: 6px; }
.composer__tools { display: flex; gap: 4px; }
.btn--tool { min-height: 36px; padding: 2px 10px; font-size: 13px; }
.btn--tool[data-action="buzz"] { color: #c01818; font-weight: 700; }
.composer__row { flex: 1; display: flex; gap: 6px; min-width: 0; }
.composer__field { flex: 1; display: flex; align-items: center; padding: 2px 8px; min-width: 0; }
.composer__field input { height: 30px; }
.composer__send { min-height: 36px; padding: 2px 16px; }

.emoji-pop {
  position: absolute; bottom: calc(100% + 6px); left: 60px; z-index: 30;
  display: grid; grid-template-columns: repeat(6, 36px); gap: 2px;
}
.emoji-pop[hidden] { display: none; }
.emoji-pop button {
  width: 36px; height: 36px; border: 0; background: transparent;
  font-size: 20px; line-height: 1;
}
.emoji-pop button:hover, .emoji-pop button:focus-visible { background: var(--navy); outline: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .log__inner { padding: 12px 12px 16px; }
}

@media (max-width: 760px) {
  .chat__back { display: inline-flex; }
  .chat__head { min-height: 52px; gap: 8px; padding: 4px; }
  .chat__actions .btn span { display: none; }
  .log__inner { padding: 10px 8px 14px; }
  .msg__col { max-width: 86%; }
  .msg__av, .msg__av .pixel { width: 28px; height: 28px; }
  .bubble { font-size: 15px; }
  .suggest {
    flex-wrap: nowrap; overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 6px;
    -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent);
            mask-image: linear-gradient(90deg, #000 88%, transparent);
  }
  .suggest::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  .btn--tool[data-action="buzz"] { padding: 2px 8px; }
  .composer__send { padding: 2px 12px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat__v { font-size: 34px; }
  .emoji-pop { left: 0; }
}

@media (max-width: 380px) {
  .btn--tool[data-action="buzz"] { font-size: 0; }
  .btn--tool[data-action="buzz"]::before { content: "📳"; font-size: 16px; }
}

/* ---------- bổ sung ---------- */
.no-anim, .no-anim .card, .no-anim .file,
.no-anim .actions, .no-anim .handoff { animation: none !important; }
.msg__who { display: none; }
.msg.is-first .msg__who { display: block; }
.typing .pixel { width: 18px; height: 18px; }
.typing:empty { visibility: hidden; }
.chat__name { font-weight: 700; }
