/* ── Chat Page ── */
.chat-page { width: 100%; }
.chat-hero {
  background: linear-gradient(135deg, #a855f7 0%, #e84393 50%, #f5a623 100%);
  padding: 2rem 0;
  text-align: center;
}
.chat-hero-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--white);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.2);
}
.chat-hero-sub {
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ── Chat Container ── */
.chat-container {
  border: 2px solid var(--black);
  box-shadow: 6px 6px 0 var(--black);
  background: var(--white);
  border-radius: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.chat-messages {
  min-height: 300px; max-height: 65vh; overflow-y: auto;
  background: var(--cream); padding: 0; flex: 1;
}
.chat-loading {
  text-align: center;
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  color: #999;
  padding: 2rem 1rem;
}

/* ── Messages ── */
.chat-msg {
  display: flex;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  transition: background 0.1s;
}
.chat-msg:hover { background: rgba(168,85,247,0.03); }
.chat-msg.own { background: rgba(168,85,247,0.04); }
.chat-msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Space Mono', monospace; font-size: 0.7rem;
  font-weight: 700; color: var(--white); overflow: hidden;
}
.chat-msg-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.chat-msg-content { flex: 1; min-width: 0; overflow: hidden; }
.chat-msg-header { display: flex; align-items: baseline; gap: 0.4rem; flex-wrap: wrap; }
.chat-msg-username {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem; font-weight: 700; color: var(--black);
}
.chat-msg-time { font-family: 'Space Mono', monospace; font-size: 0.55rem; color: #999; }
.chat-msg-body {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.85rem; line-height: 1.5; word-break: break-word;
  overflow-wrap: anywhere;
}
.chat-msg-deleted { opacity: 0.4; font-style: italic; }

/* ── Message Menu ── */
.chat-msg-menu { position: relative; opacity: 0; transition: opacity 0.1s; }
.chat-msg:hover .chat-msg-menu { opacity: 1; }
.chat-msg-menu-btn {
  width: 20px; height: 20px; background: transparent; border: none;
  color: #ccc; cursor: pointer; font-size: 0.8rem; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.chat-msg-menu-btn:hover { color: var(--black); }
.chat-msg-menu-dropdown {
  position: absolute; right: 0; top: 100%; min-width: 100px;
  background: var(--white); border: 2px solid var(--black);
  box-shadow: 3px 3px 0 var(--black); display: none; z-index: 20;
}
.chat-msg-menu.open .chat-msg-menu-dropdown { display: block; }
.chat-msg-menu-dropdown button {
  display: block; width: 100%; text-align: left;
  padding: 0.4rem 0.6rem; font-family: 'Space Mono', monospace;
  font-size: 0.6rem; background: none; border: none; cursor: pointer;
}
.chat-msg-menu-dropdown button:hover { background: rgba(168,85,247,0.08); }

/* ── Item Pills ── */
.chat-item-pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.15rem 0.6rem; border: 2px solid var(--purple);
  border-radius: 999px; background: rgba(168,85,247,0.06);
  text-decoration: none; font-family: 'Space Mono', monospace;
  font-size: 0.6rem; font-weight: 700; color: var(--purple);
  vertical-align: middle; max-width: 280px;
  overflow: hidden; white-space: nowrap; transition: all 0.12s;
}
.chat-item-pill:hover {
  background: rgba(168,85,247,0.14);
  box-shadow: 2px 2px 0 var(--black);
  transform: translateY(-1px);
}
.chat-pill-title { overflow: hidden; text-overflow: ellipsis; }
.chat-pill-price { color: #16a34a; flex-shrink: 0; }

/* ── Input Area ── */
.chat-input-wrap {
  border-top: 2px solid var(--black); background: var(--white);
  padding: 0.75rem 1rem; flex-shrink: 0;
}
.chat-input-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.chat-input-container { flex: 1; position: relative; min-width: 0; }
.chat-textarea {
  width: 100%; border: 2px solid #ddd; padding: 0.6rem 0.75rem;
  font-family: 'Space Grotesk', sans-serif; font-size: 16px;
  resize: none; background: var(--cream); transition: border-color 0.15s;
  min-height: 42px; max-height: 120px; outline: none; box-sizing: border-box;
}
.chat-textarea:focus { border-color: var(--purple); }
.chat-send-btn {
  background: var(--black); color: white; border: 2px solid var(--black);
  padding: 0.6rem 1.2rem; font-family: 'Space Mono', monospace;
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  cursor: pointer; letter-spacing: 0.05em; transition: all 0.12s; flex-shrink: 0;
}
.chat-send-btn:hover { background: var(--purple); border-color: var(--purple); }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-input-hint {
  font-family: 'Space Mono', monospace; font-size: 0.55rem;
  color: #aaa; margin-top: 0.3rem;
}

/* ── Login Gate ── */
.chat-login-gate {
  padding: 2rem; text-align: center;
  border-top: 2px solid var(--black); background: rgba(168,85,247,0.04);
}
.chat-login-gate p {
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem; font-weight: 700; margin-bottom: 1rem;
}
.chat-login-btn {
  display: inline-block;
  background: linear-gradient(135deg, #a855f7, #e84393);
  color: white; border: 2px solid var(--black);
  padding: 0.6rem 1.2rem; font-family: 'Space Mono', monospace;
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  text-decoration: none; letter-spacing: 0.05em;
  cursor: pointer; transition: all 0.12s;
}

/* ── Mention Autocomplete ── */
.chat-mention-dropdown {
  position: absolute; bottom: 100%; left: 0; right: 0;
  max-height: 200px; overflow-y: auto; background: var(--white);
  border: 2px solid var(--black); box-shadow: 4px -4px 0 var(--black);
  display: none; z-index: 50;
}
.chat-mention-dropdown.visible { display: block; }
.chat-mention-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.75rem; cursor: pointer;
  font-family: 'Space Mono', monospace; font-size: 0.7rem; font-weight: 700;
}
.chat-mention-item:hover,
.chat-mention-item.active { background: rgba(168,85,247,0.08); }
.chat-mention-avatar {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.55rem; font-weight: 700; color: var(--white); overflow: hidden;
  font-family: 'Space Mono', monospace;
}
img.chat-mention-avatar { object-fit: cover; }

/* ── New Messages Indicator ── */
.chat-new-indicator {
  position: sticky; bottom: 0; text-align: center;
  background: linear-gradient(135deg, #a855f7, #e84393);
  color: white; padding: 0.4rem;
  font-family: 'Space Mono', monospace; font-size: 0.65rem;
  font-weight: 700; cursor: pointer; letter-spacing: 0.05em;
  text-transform: uppercase; display: none;
}
.chat-new-indicator.visible { display: block; }

/* ── Scrollbar ── */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: #bbb; }

/* ── Message Highlight (notification deep-link) ── */
.chat-msg-highlight {
  animation: chatHighlight 3s ease-out;
}
@keyframes chatHighlight {
  0% { background: rgba(168,85,247,0.25); }
  70% { background: rgba(168,85,247,0.1); }
  100% { background: transparent; }
}

/* ── Reply/Thread Styles ── */
.chat-msg[data-depth="1"] { margin-left: 1.5rem; border-left: 2px solid #e5e5e5; padding-left: 0.75rem; }
.chat-msg[data-depth="2"] { margin-left: 1.5rem; border-left: 2px solid rgba(168,85,247,0.2); padding-left: 0.75rem; }
.chat-msg[data-depth="3"] { margin-left: 1.5rem; border-left: 2px solid rgba(232,67,147,0.2); padding-left: 0.75rem; }

.chat-msg-actions {
  display: flex; align-items: center; gap: 0.75rem; margin-top: 0.25rem;
}

.chat-reply-btn {
  background: none; border: none; cursor: pointer;
  font-family: 'Space Mono', monospace; font-size: 0.6rem; font-weight: 700;
  color: #999; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 0; transition: color 0.12s;
}
.chat-reply-btn:hover { color: var(--purple); }

.chat-thread-btn {
  background: none; border: none; cursor: pointer;
  font-family: 'Space Mono', monospace; font-size: 0.6rem; font-weight: 700;
  color: var(--purple); padding: 0; transition: opacity 0.12s;
}
.chat-thread-btn:hover { opacity: 0.7; }

.chat-thread {
  border-left: 2px solid rgba(168,85,247,0.15);
  margin-left: 1rem;
  background: rgba(168,85,247,0.02);
}
.chat-thread .chat-msg { border-bottom-color: rgba(0,0,0,0.04); }

.chat-thread-loading, .chat-thread-empty {
  padding: 0.6rem 1rem;
  font-family: 'Space Mono', monospace; font-size: 0.65rem;
  color: #999; font-style: italic;
}

/* Reply form */
.chat-reply-form {
  padding: 0.5rem 1rem 0.5rem 2.5rem;
  background: rgba(168,85,247,0.03);
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.chat-reply-form-inner {
  display: flex; gap: 0.4rem; align-items: flex-end;
}
.chat-reply-textarea {
  flex: 1; border: 2px solid #ddd; padding: 0.4rem 0.6rem;
  font-family: 'Space Grotesk', sans-serif; font-size: 16px;
  resize: none; background: var(--white); outline: none;
  min-height: 34px; max-height: 80px; box-sizing: border-box;
}
.chat-reply-textarea:focus { border-color: var(--purple); }
.chat-reply-send {
  background: var(--purple); color: white; border: 2px solid var(--purple);
  padding: 0.4rem 0.8rem; font-family: 'Space Mono', monospace;
  font-size: 0.6rem; font-weight: 700; text-transform: uppercase;
  cursor: pointer; flex-shrink: 0; transition: opacity 0.12s;
}
.chat-reply-send:hover { opacity: 0.85; }
.chat-reply-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Responsive: Tablet ── */
@media (max-width: 768px) {
  .chat-messages { max-height: 55vh; }
  .chat-hero { padding: 1.5rem 0; }
  .chat-hero-title { font-size: 1.4rem; }
}

/* ── Responsive: Mobile — full-screen chat experience ── */
@media (max-width: 600px) {
  /* Hide hero and footer, make chat fill the screen */
  .chat-page .chat-hero { display: none; }
  .chat-page ~ .footer-brutal { display: none; }

  .chat-page { display: flex; flex-direction: column; }

  .chat-page > .max-w-\[900px\] {
    flex: 1; display: flex; flex-direction: column;
    max-width: 100%; padding: 0 !important; margin: 0;
  }

  .chat-container {
    flex: 1; display: flex; flex-direction: column;
    border: none; box-shadow: none; border-radius: 0;
    min-height: calc(100dvh - 52px); /* subtract nav height */
  }

  .chat-messages {
    flex: 1; max-height: none; min-height: 0;
    -webkit-overflow-scrolling: touch;
  }

  .chat-input-wrap {
    position: sticky; bottom: 0; z-index: 10;
    padding: 0.5rem 0.75rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
    border-top: 2px solid var(--black);
    background: var(--white);
  }

  .chat-input-hint { display: none; }

  .chat-send-btn {
    padding: 0.55rem 0.75rem; font-size: 0.65rem;
    min-height: 42px;
  }

  .chat-msg { padding: 0.5rem 0.75rem; gap: 0.5rem; }
  .chat-msg-avatar { width: 28px; height: 28px; font-size: 0.6rem; }
  .chat-msg-body { font-size: 0.85rem; }
  .chat-item-pill { max-width: 220px; font-size: 0.55rem; }

  .chat-mention-dropdown { max-height: 160px; }
  .chat-mention-item { padding: 0.6rem 0.75rem; }

  .chat-msg[data-depth="1"],
  .chat-msg[data-depth="2"],
  .chat-msg[data-depth="3"] { margin-left: 0.75rem; }
  .chat-thread { margin-left: 0.5rem; }
  .chat-reply-form { padding-left: 1.25rem; }
}
