/* ============================================
   MIDNIGHT LABS — Chat Messages & Input
   ============================================ */

/* === Messages container === */
#msgs {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--bd) transparent;
  position: relative;
}
#msgs::-webkit-scrollbar { width: 4px; }
#msgs::-webkit-scrollbar-thumb { background: var(--bd); border-radius: 2px; }

.scroll-btn {
  position: absolute;
  bottom: 16px; right: 16px;
  background: var(--rs);
  border: 1px solid var(--bd);
  border-radius: 50%;
  width: 34px; height: 34px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .12s, opacity .18s;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  z-index: 10;
}
.scroll-btn.show { display: flex; animation: fadeUp .18s ease both; }
.scroll-btn:hover { background: var(--hv); }
.scroll-btn svg { width: 14px; height: 14px; color: var(--t2); }

/* === Empty state === */
#empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px 120px;
  background-image: radial-gradient(circle, var(--bs) 1px, transparent 1px);
  background-size: 30px 30px;
}
.empty-h {
  font-size: 26px;
  font-weight: 700;
  color: var(--tx);
  letter-spacing: -0.025em;
  text-align: center;
  margin-bottom: 10px;
  animation: fadeUp .36s ease both .06s;
}
.empty-s {
  font-size: 14.5px;
  color: var(--t3);
  text-align: center;
  margin-bottom: 40px;
  animation: fadeUp .36s ease both .14s;
  max-width: 440px;
  line-height: 1.6;
}
.pg {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
  max-width: 560px;
  width: 100%;
  animation: fadeUp .36s ease both .22s;
}
.pg-c {
  background: var(--sf);
  border: 1px solid var(--bs);
  border-radius: var(--r);
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  transition: background .13s, border-color .13s;
  position: relative;
  overflow: hidden;
}
.pg-c::before {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--ag) 0%, transparent 60%);
  opacity: 0;
  transition: opacity .18s;
}
.pg-c:hover { background: var(--rs); border-color: var(--bd); }
.pg-c:hover::before { opacity: 1; }
.pg-ct { font-size: 13px; font-weight: 700; color: var(--tx); margin-bottom: 3px; position: relative; z-index: 1; }
.pg-cd { font-size: 12px; color: var(--t3); line-height: 1.45; position: relative; z-index: 1; }

/* === User messages === */
.mw { animation: fadeUp .18s ease both; }
.mw[data-i] { animation: none; }
.mu { display: flex; justify-content: flex-end; padding: 18px 28px 0; }
.mu-b {
  max-width: 72%;
  background: var(--sf);
  border: 1px solid var(--bd);
  border-radius: 14px 14px 4px 14px;
  padding: 11px 16px;
  font-size: 14.5px;
  color: var(--tx);
  line-height: 1.72;
  word-break: break-word;
}
.mu-b p { margin-bottom: 10px; }
.mu-b p:last-child { margin-bottom: 0; }
.mu-b code {
  font-family: var(--mono);
  background: var(--rs);
  border: 1px solid var(--bs);
  padding: 2px 6px;
  border-radius: var(--rxs);
  font-size: 12px;
  color: #a8d8b9;
}
.mu-b pre {
  background: var(--rs);
  border: 1px solid var(--bs);
  border-radius: var(--rsm);
  padding: 12px 14px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
}
.mu-b pre code { background: transparent; border: none; padding: 0; font-size: 12px; }

/* === AI messages === */
.mai { padding: 22px 28px 0; }
.mai-hd { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.mai-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ac) 0%, #6e42ca 100%);
  flex-shrink: 0;
}
.mai-nm { font-size: 12.5px; font-weight: 700; color: var(--tx); letter-spacing: .02em; }
.mai-tm { font-size: 11px; color: var(--t4); }
.mai-bd {
  font-size: 15px;
  color: var(--tx);
  line-height: 1.82;
  padding-left: 26px;
}
.mai-bd p { margin-bottom: 14px; }
.mai-bd p:last-child { margin-bottom: 0; }
.mai-bd ul, .mai-bd ol { padding-left: 22px; margin-bottom: 14px; }
.mai-bd li { margin-bottom: 5px; }
.mai-bd h1, .mai-bd h2, .mai-bd h3 { font-weight: 700; color: var(--tx); margin: 22px 0 9px; letter-spacing: -0.015em; }
.mai-bd h1 { font-size: 19px; }
.mai-bd h2 { font-size: 17px; }
.mai-bd h3 { font-size: 15px; color: var(--t2); }
.mai-bd strong { font-weight: 700; color: var(--tx); }
.mai-bd em { font-style: italic; color: var(--t2); }
.mai-bd a { color: var(--ac); text-decoration: none; }
.mai-bd a:hover { text-decoration: underline; }
.mai-bd hr { border: none; border-top: 1px solid var(--bs); margin: 20px 0; }
.mai-bd blockquote { border-left: 2px solid var(--bd); padding-left: 14px; margin: 14px 0; color: var(--t2); }
.mai-bd table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 13.5px; }
.mai-bd th, .mai-bd td { border: 1px solid var(--bd); padding: 9px 12px; text-align: left; }
.mai-bd th { background: var(--rs); font-weight: 700; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--t2); }
.mai-bd td { color: var(--t2); }
.mai-bd code {
  font-family: var(--mono);
  background: var(--rs);
  border: 1px solid var(--bs);
  padding: 2px 6px;
  border-radius: var(--rxs);
  font-size: 12.5px;
  color: #a8d8b9;
}

/* Code blocks */
.cb { margin: 16px 0; border: 1px solid var(--bd); border-radius: var(--r); overflow: hidden; background: #0f0f0f; }
.cb-hd { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--rs); border-bottom: 1px solid var(--bs); }
.cb-hl { display: flex; align-items: center; gap: 10px; }
.cb-lang { font-size: 10.5px; font-weight: 700; color: var(--t3); text-transform: uppercase; letter-spacing: .12em; font-family: var(--mono); }
.cb-lns { font-size: 10.5px; color: var(--t4); font-family: var(--mono); }
.cb-acts { display: flex; align-items: center; gap: 2px; }
.cb-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: none;
  color: var(--t3);
  font-family: var(--f);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--rxs);
  transition: background .1s, color .1s;
  white-space: nowrap;
}
.cb-btn:hover { background: var(--hv); color: var(--t2); }
.cb-btn.ok { color: var(--gn); }
.cb-btn svg { width: 12px; height: 12px; }
.mai-bd .cb pre { padding: 16px; overflow-x: auto; margin: 0; border: none; background: transparent; }
.mai-bd .cb pre code { background: transparent; border: none; padding: 0; font-size: 13px; line-height: 1.7; font-family: var(--mono); color: inherit; }
.mai-bd .cb pre code.hljs { background: transparent; }

/* Auto-diff suggestion */
.autodiff-bar { display: flex; align-items: center; gap: 10px; padding: 9px 14px; margin: 8px 0; background: var(--ag); border: 1px solid rgba(91,127,255,.2); border-radius: var(--rsm); }
.autodiff-bar span { font-size: 12.5px; color: var(--t2); flex: 1; }
.autodiff-run { background: var(--ac); border: none; border-radius: var(--rxs); color: #fff; font-family: var(--f); font-size: 12px; font-weight: 700; padding: 5px 12px; cursor: pointer; transition: background .12s; }
.autodiff-run:hover { background: #4a6ef0; }

/* Think accordion */
.tb-w { margin: 14px 0; border: 1px solid var(--bs); border-radius: var(--rsm); overflow: hidden; background: var(--sf); }
.tb-w summary {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  cursor: pointer;
  user-select: none;
  font-size: 11px;
  font-weight: 700;
  color: var(--t4);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: var(--rs);
  list-style: none;
  transition: color .12s, background .12s;
}
.tb-w summary:hover { color: var(--t3); background: var(--hv); }
.tb-w summary svg { width: 11px; height: 11px; }
.tb-bd { padding: 12px 14px; font-size: 13.5px; color: var(--t3); font-style: italic; border-top: 1px solid var(--bs); line-height: 1.65; }

/* Message action buttons */
.mai-ac { display: flex; align-items: center; gap: 2px; padding: 8px 0 4px 26px; opacity: 0; transition: opacity .14s; }
.mw:hover .mai-ac { opacity: 1; }
.mai-abt {
  background: transparent;
  border: none;
  color: var(--t4);
  cursor: pointer;
  padding: 5px 8px;
  border-radius: var(--rxs);
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--f);
  font-size: 12px;
  transition: background .1s, color .1s;
}
.mai-abt:hover { background: var(--hv); color: var(--t2); }
.mai-abt svg { width: 12px; height: 12px; }

/* Typing indicator */
.typ-r { display: flex; align-items: center; gap: 10px; padding: 20px 28px; opacity: 0; transition: opacity .18s; }
.typ-r.on { opacity: 1; }
.typ-b { width: 18px; height: 18px; border-radius: 50%; background: linear-gradient(135deg, var(--ac), #6e42ca); flex-shrink: 0; display: flex; align-items: center; justify-content: center; gap: 2.5px; }
.td { width: 3.5px; height: 3.5px; border-radius: 50%; background: #fff; animation: blink 1.3s ease-in-out infinite; }
.td:nth-child(2) { animation-delay: .22s; }
.td:nth-child(3) { animation-delay: .44s; }

/* File upload indicator */
.up-ind { display: none; align-items: center; gap: 8px; padding: 8px 14px; background: var(--rs); border-radius: var(--rsm); margin-bottom: 8px; border: 1px solid var(--bs); animation: fadeUp .16s ease both; }
.up-ind.show { display: flex; }
.up-nm { font-size: 12.5px; color: var(--t2); font-family: var(--mono); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up-sz { font-size: 11.5px; color: var(--t4); font-family: var(--mono); flex-shrink: 0; }
.up-rm { background: transparent; border: none; color: var(--t3); cursor: pointer; padding: 2px; border-radius: var(--rxs); display: flex; transition: color .1s; }
.up-rm:hover { color: var(--rd); }
.up-rm svg { width: 13px; height: 13px; }

/* Context bar */
#ctx-bar { flex-shrink: 0; padding: 10px 28px 0; }
.ctx-r { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--t4); margin-bottom: 5px; font-family: var(--mono); }
.ctx-tr { height: 1px; background: var(--rs); border-radius: 1px; overflow: hidden; }
.ctx-f { height: 100%; width: 0; background: linear-gradient(90deg, var(--ac), #6e42ca); transition: width .4s; }

/* Input area */
#input-wrap { flex-shrink: 0; padding: 10px 28px 22px; animation: fadeUp .38s ease both .08s; }
.drop-z { border-radius: var(--r); transition: background .14s; }
.drop-z.drag { background: var(--ag); outline: 2px dashed rgba(91,127,255,.3); outline-offset: -2px; }
.input-box { background: var(--sf); border: 1px solid var(--bd); border-radius: var(--r); overflow: hidden; transition: border-color .18s, box-shadow .18s; }
.input-box:focus-within { border-color: rgba(91,127,255,.3); box-shadow: 0 0 0 3px rgba(91,127,255,.06); }
.input-top { padding: 12px 14px 0; }
#ci {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--tx);
  font-family: var(--f);
  font-size: 14.5px;
  font-weight: 400;
  line-height: 1.65;
  resize: none;
  min-height: 24px;
  max-height: 200px;
  overflow-y: auto;
  caret-color: var(--ac);
  scrollbar-width: thin;
  display: block;
  padding-bottom: 12px;
}
#ci::placeholder { color: var(--t4); }
.input-ft { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 10px; border-top: 1px solid var(--bs); }
.input-tl { display: flex; align-items: center; gap: 2px; }
.it { background: transparent; border: none; color: var(--t3); cursor: pointer; padding: 6px 8px; border-radius: var(--rsm); display: flex; align-items: center; gap: 5px; font-family: var(--f); font-size: 12px; font-weight: 500; transition: background .1s, color .1s; }
.it:hover { background: var(--hv); color: var(--t2); }
.it svg { width: 13px; height: 13px; }
.input-r { display: flex; align-items: center; gap: 8px; }
.cc { font-size: 11px; color: var(--t4); font-family: var(--mono); }
.cc.yw { color: var(--yw); }
.cc.rd { color: var(--rd); }
.send-b { background: var(--ac); border: none; border-radius: var(--rsm); color: #fff; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: background .12s; flex-shrink: 0; padding: 0; }
.send-b:hover { background: #4a6ef0; }
.send-b:disabled { background: var(--bd); cursor: default; opacity: .45; }
.send-b svg { width: 14px; height: 14px; }

/* Mobile */
@media (max-width: 768px) {
  .mu { padding: 14px 16px 0; }
  .mai { padding: 16px 16px 0; }
  .mai-bd { padding-left: 0; }
  .mai-ac { padding-left: 0; }
}
