.market-chat-fab,
.market-chat-panel,
.market-chat-panel * {
  box-sizing: border-box;
}

.market-chat-fab {
  position: fixed;
  right: max(28px, env(safe-area-inset-right, 0px));
  bottom: max(28px, env(safe-area-inset-bottom, 0px));
  z-index: 90;
  display: grid;
  place-items: center;
  width: 58px;
  min-width: 58px;
  height: 58px;
  min-height: 58px;
  padding: 0;
  border-radius: 50%;
  max-width: calc(100vw - 24px);
  line-height: 1;
  white-space: nowrap;
}

.market-chat-panel {
  position: fixed;
  right: max(28px, env(safe-area-inset-right, 0px));
  bottom: calc(100px + env(safe-area-inset-bottom, 0px));
}

.market-chat-fab svg {
  width: 24px;
  height: 24px;
}

.market-chat-panel {
  z-index: 91;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(420px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  height: min(560px, calc(100dvh - 112px));
  max-height: calc(100dvh - 112px);
  overflow: hidden;
  contain: layout paint;
}

.market-chat-panel[hidden] {
  display: none;
}

@media (min-width: 721px) {
  .marketplace-page[data-market-page="home"] .market-chat-fab,
  .market-chat-fab {
    right: max(28px, env(safe-area-inset-right, 0px));
    bottom: max(28px, env(safe-area-inset-bottom, 0px));
  }
}

.market-chat-head {
  min-width: 0;
}

.market-chat-head > div,
.market-chat-head strong,
.market-chat-head span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.market-chat-messages {
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  background: linear-gradient(180deg, #fffaf3 0%, #f8f5ef 100%);
}

.market-chat-bubble,
.market-chat-empty {
  max-width: min(86%, 320px);
  padding: 10px 13px;
  border-radius: 18px;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.48;
  word-break: break-word;
  white-space: pre-wrap;
}

.market-chat-bubble.is-user {
  justify-self: end;
  border-bottom-right-radius: 7px;
  color: #fffaf3;
  background: linear-gradient(135deg, #171416 0%, #3d3336 100%);
  box-shadow: 0 14px 28px rgba(23, 20, 22, .18);
}

.market-chat-bubble.is-system,
.market-chat-empty {
  justify-self: start;
  border: 1px solid rgba(199, 161, 149, .26);
  border-bottom-left-radius: 7px;
  color: #2f292b;
  background: #ffffff;
  box-shadow: 0 12px 26px rgba(23, 20, 22, .08);
}

.market-chat-empty {
  color: #7a6c70;
  background: #fffaf3;
}

.market-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.market-chat-form input {
  min-width: 0;
  width: 100%;
}

.market-chat-form button {
  width: 46px;
  min-width: 46px;
  height: 46px;
  flex: 0 0 46px;
}

@media (max-width: 720px) {
  .market-chat-fab {
    right: max(14px, env(safe-area-inset-right, 0px));
    bottom: calc(86px + env(safe-area-inset-bottom, 0px));
    width: 54px;
    min-width: 54px;
    height: 54px;
    min-height: 54px;
  }

  .market-chat-panel {
    left: 12px;
    right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    width: auto;
    height: min(520px, calc(100dvh - 128px));
    max-height: calc(100dvh - 128px);
    border-radius: 22px;
  }
}

@media (max-width: 420px) {
  .market-chat-panel {
    left: 8px;
    right: 8px;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: calc(100vw - 16px);
  }

  .market-chat-bubble,
  .market-chat-empty {
    max-width: 92%;
  }
}
