.chat-dock {
  position: fixed;
  left: 18px;
  bottom: 72px;
  z-index: 19;
  width: min(440px, calc(100vw - 36px));
  opacity: 1;
  transform: translateY(0) scale(1);
  transform-origin: bottom left;
}

.chat-dock.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.98);
}

.chat-dock.market-chat {
  left: 194px;
  top: 14px;
  bottom: 14px;
  width: min(620px, calc(100vw - 222px));
  transform-origin: top left;
}

.chat-dock.market-chat .chat-card {
  height: 100%;
  min-height: 0;
}

.chat-card {
  display: flex;
  flex-direction: column;
  height: min(680px, calc(100vh - 104px));
  min-height: 460px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 28px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.chat-head {
  display: flex;
  justify-content: flex-end;
  padding: 10px 10px 0;
  border-bottom: 1px solid var(--line);
}

.chat-status-label,
.chat-toolbar-label,
.chat-field-label {
  color: var(--soft);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.chat-state,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.ghost-btn {
  justify-content: center;
  width: 32px;
  padding: 0;
}

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

.chat-feed-shell {
  flex: 1;
  min-height: 0;
  padding: 0 18px 14px;
}

.chat-feed {
  display: grid;
  align-content: start;
  gap: 13px;
  height: 100%;
  min-height: 280px;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(1, 5, 10, 0.28);
}

.chat-message {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: end;
}

.chat-message.own {
  grid-template-columns: minmax(0, 1fr) auto;
}

.chat-message.system {
  grid-template-columns: minmax(0, 1fr);
}

.chat-avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--accent);
  font-weight: 900;
}

.chat-message.own .chat-avatar {
  order: 2;
}

.chat-bubble {
  justify-self: start;
  max-width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 18px 18px 18px 8px;
  background: rgba(255, 255, 255, 0.06);
}

.chat-message.own .chat-bubble {
  order: 1;
  justify-self: end;
  border-radius: 18px 18px 8px 18px;
  background: rgba(181, 255, 61, 0.1);
}

.chat-message.system .chat-bubble {
  justify-self: stretch;
  border-color: rgba(75, 164, 255, 0.24);
  border-radius: 14px;
  background: rgba(75, 164, 255, 0.1);
}

.chat-message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 5px;
}

.chat-author {
  color: var(--text);
  font-size: 12px;
}

.chat-meta {
  color: var(--soft);
  font-size: 10px;
  font-weight: 800;
}

.chat-text {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

.chat-empty {
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
}

.chat-form {
  display: grid;
  gap: 12px;
  padding: 0 18px 18px;
}

.chat-field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.chat-compose input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.chat-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.chat-compose input {
  min-height: 48px;
  padding: 0 15px;
  border-radius: 16px;
}

.chat-form button[type="submit"] {
  min-width: 92px;
  min-height: 48px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #07100b;
  font-weight: 900;
}

@media (prefers-color-scheme: light) {
  .chat-card {
    background: #ffffff;
    box-shadow: 0 22px 54px rgba(39, 73, 92, 0.14);
  }

  .chat-feed {
    background: #f6fafc;
  }

  .chat-bubble,
  .chat-compose input,
  .ghost-btn {
    background: #ffffff;
    color: #111c27;
  }

  .chat-message.own .chat-bubble {
    background: #eff9e6;
  }
}

@media (max-width: 640px) {
  .chat-dock {
    left: 10px;
    right: 10px;
    bottom: 70px;
    width: auto;
  }

  .chat-dock.market-chat {
    left: 10px;
    top: 84px;
    right: 10px;
    bottom: 10px;
    width: auto;
  }

  .chat-card {
    height: calc(100vh - 92px);
  }

  .chat-head,
  .chat-toolbar {
    flex-direction: column;
  }

  .chat-head-actions,
  .chat-toolbar-caption {
    width: 100%;
    justify-items: start;
    text-align: left;
  }
}
