/* Builds on theme.css + home.css */

.topbar .actions { margin-left: auto; }
.header-avatar { overflow: hidden; background-size: cover; background-position: center; }

.chat-layout {
  max-width: 1280px; margin: 0 auto;
  height: calc(100vh - 79px);
  display: grid; grid-template-columns: 360px minmax(0, 1fr);
  border-left: 1px solid var(--line); border-right: 1px solid var(--line);
}

/* List */
.chat-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chat-list-head { padding: 20px 20px 12px; }
.chat-list-head h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.2px; }
.convos { list-style: none; margin: 0; padding: 0 8px 16px; overflow-y: auto; flex: 1; }
.convo {
  display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; gap: 12px; align-items: center;
  padding: 12px; border-radius: 8px; text-decoration: none; color: var(--ink);
}
.convo:hover { background: var(--soft); }
.convo[aria-current="true"] { background: var(--soft); }
.convo-main { min-width: 0; }
.convo-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.convo-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-time { font-size: 12px; color: var(--muted); flex: none; }
.convo-item { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.convo-last { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.convo.unread .convo-last { color: var(--ink); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green-dark); flex: none; }
.convo-thumb { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; background: var(--soft); }

.avatar-sm {
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  background: var(--green-tint); color: var(--green-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px;
}

/* Thread */
.thread { position: relative; min-height: 0; display: flex; flex-direction: column; }
.thread-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  color: var(--muted);
}
.thread-empty[hidden] { display: none; }
.thread-empty svg { width: 40px; height: 40px; }
.thread-empty p { margin: 0; font-size: 15px; }
.thread-inner { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.thread-inner[hidden] { display: none; }

.thread-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.thread-head .avatar-sm { width: 42px; height: 42px; font-size: 16px; }
.thread-back {
  display: none;
  width: 40px; height: 40px; border-radius: 50%; margin-left: -8px;
  align-items: center; justify-content: center; color: var(--ink);
}
.thread-back svg { width: 22px; height: 22px; }
.thread-who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.thread-who strong { font-size: 16px; }
.verified { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--green-dark); font-weight: 600; }
.verified svg { width: 13px; height: 13px; }

.item-bar {
  display: flex; align-items: center; gap: 12px;
  margin: 12px 20px 0; padding: 10px 14px 10px 10px;
  border-radius: 8px; background: var(--soft); text-decoration: none; color: var(--ink);
}
.item-bar img { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; }
.item-bar > div { flex: 1; min-width: 0; }
.item-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-price { font-size: 15px; font-weight: 700; }
.item-view { font-size: 14px; font-weight: 600; color: var(--green-dark); }

.messages {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 20px; display: flex; flex-direction: column; gap: 6px;
}
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0; }
.msg {
  max-width: min(72%, 520px); padding: 10px 14px; border-radius: 10px;
  font-size: 15px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.them { align-self: flex-start; background: var(--soft); border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 6px; }
.msg-time { font-size: 11px; color: var(--muted); margin: 0 4px 6px; }
.msg-time.me { align-self: flex-end; }

.quick { display: flex; gap: 8px; padding: 0 20px 10px; overflow-x: auto; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.quick[hidden] { display: none; }
.quick button {
  flex: none; height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1.5px solid var(--border-soft); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; cursor: pointer;
}
.quick button:hover { background: var(--soft); }

.composer {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 20px 16px; border-top: 1px solid var(--line);
}
.composer input {
  flex: 1; min-width: 0; height: 48px; padding: 0 18px; border-radius: 8px;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 16px;
}
.composer input::placeholder { color: var(--placeholder); }
.composer input:focus { outline: none; border-color: var(--green-dark); box-shadow: 0 0 0 3px rgba(20, 163, 94, .18); }
.send {
  width: 48px; height: 48px; border-radius: 8px; border: 0; flex: none;
  background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.send:disabled { opacity: .4; cursor: default; }
.send svg { width: 20px; height: 20px; stroke-width: 2.4; }

/* Phone */
@media (max-width: 760px) {
  .chat-layout {
    grid-template-columns: minmax(0, 1fr);
    height: auto; border: 0;
  }
  .chat-list { border-right: 0; padding-bottom: 90px; }
  .chat-list-head { padding: 8px 16px 8px; }
  .convos { padding: 0 4px; overflow: visible; }
  .thread { display: none; }

  /* Thread open: full screen */
  .chats-page.in-thread .topbar,
  .chats-page.in-thread .bottom-nav,
  .chats-page.in-thread .chat-list { display: none; }
  .chats-page.in-thread .thread { display: flex; height: 100vh; height: 100dvh; }
  .thread-back { display: inline-flex; }
  .thread-head { padding: 10px 16px; }
  .item-bar { margin: 10px 16px 0; }
  .messages { padding: 16px; }
  .msg { max-width: 82%; }
  .quick { padding: 0 16px 8px; }
  .composer { padding: 10px 16px 14px; }
}

.thread-person { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; color: inherit; text-decoration: none; }
.thread-person:hover strong { text-decoration: underline; }

/* Back: in the empty space to the left of the chat box (laptop and up); beside the title on smaller screens */
.chat-list-head { display: flex; align-items: center; gap: 12px; }
.chat-list-head .back-link { margin: 0; }
@media (min-width: 761px) {
  .chat-layout { position: relative; max-width: none; margin: 0 21px 0 calc(21px + 108px); }
  .chat-list-head .back-link { position: absolute; top: 16px; right: calc(100% + 24px); }
}
