.collab-chat-panel {
  position: fixed;
  bottom: 80px;
  right: 24px;
  width: min(360px, calc(100vw - 32px));
  height: min(520px, calc(100dvh - 120px));
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.16);
  border: 1px solid var(--collab-border, #e2e8f0);
  z-index: var(--collab-z-chat, 999);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  // Hidden state — use visibility + opacity for a11y, not display:none
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.2s, visibility 0.2s, transform 0.2s;

  &--open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: all;
  }

  &__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--collab-border, #e2e8f0);
    flex-shrink: 0;
    background: var(--collab-surface, #f7fafc);
    border-radius: 16px 16px 0 0;
  }

  &__title {
    font-size: 14px;
    font-weight: 700;
    color: var(--collab-text-primary, #1a202c);
    display: flex;
    align-items: center;
    gap: 6px;
  }

  &__count {
    font-weight: 400;
    color: var(--collab-text-muted, #718096);
  }

  &__messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
  }

  &__empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--collab-text-muted, #718096);
    font-size: 13px;
    text-align: center;
    padding: 32px 16px;

    span {
      font-size: 32px;
    }

    p {
      margin: 0;
    }
  }

  &__input-area {
    flex-shrink: 0;
    padding: 12px;
    border-top: 1px solid var(--collab-border, #e2e8f0);
  }
}

.collab-chat-bubble {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 90%;

  // Other person's bubble — left-aligned (default)

  &--mine {
    flex-direction: row-reverse;
    align-self: flex-end;

    .collab-chat-bubble__body {
      align-items: flex-end;
    }

    .collab-chat-bubble__text {
      background: var(--collab-teal, #38b2ac);
      color: #fff;
      border-radius: 16px 16px 4px 16px;
    }
  }

  &__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    margin-bottom: 20px;
  }

  &__body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: flex-start;
    min-width: 0;
  }

  &__name {
    font-size: 11px;
    font-weight: 600;
    padding-left: 4px;
  }

  &__text {
    padding: 8px 12px;
    background: var(--collab-surface, #f7fafc);
    border: 1px solid var(--collab-border, #e2e8f0);
    border-radius: 16px 16px 16px 4px;
    font-size: 13px;
    color: var(--collab-text-primary, #1a202c);
    line-height: 1.4;
    word-break: break-word;
    white-space: pre-wrap;
  }

  &__time {
    font-size: 10px;
    color: var(--collab-text-muted, #718096);
    font-family: 'DM Mono', monospace;
    padding: 0 4px;
  }
}

.collab-chat-input-wrapper {
  border: 1px solid var(--collab-border, #e2e8f0);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.15s;

  &:focus-within {
    border-color: var(--collab-teal, #38b2ac);
    box-shadow: 0 0 0 3px rgba(56, 178, 172, 0.15);
  }

  &--over {
    border-color: var(--collab-red, #fc8181);

    &:focus-within {
      border-color: var(--collab-red, #fc8181);
      box-shadow: 0 0 0 3px rgba(252, 129, 129, 0.15);
    }
  }
}

.collab-chat-input {
  width: 100%;
  border: none;
  outline: none;
  padding: 10px 12px 6px;
  font-size: 13px;
  color: var(--collab-text-primary, #1a202c);
  resize: none;
  font-family: inherit;
  box-sizing: border-box;
  background: #fff;
}

.collab-chat-input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 6px;
  background: #fff;
}

.collab-chat-input-count {
  font-size: 11px;
  font-family: 'DM Mono', monospace;
  color: var(--collab-text-muted, #718096);

  &.over {
    color: var(--collab-red, #fc8181);
  }
}

.collab-chat-send-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--collab-teal, #38b2ac);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: background 0.15s, opacity 0.15s;

  &:hover:not(:disabled) {
    background: #319795;
  }

  &:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }
}

.collab-icon-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--collab-text-muted, #718096);
  transition: background 0.15s;

  &:hover {
    background: var(--collab-border, #e2e8f0);
  }
}

[dir='rtl'] {
  .collab-chat-panel {
    right: auto;
    left: 24px;
  }

  .collab-chat-bubble {
    &--mine {
      flex-direction: row;
      align-self: flex-start;
    }
  }
}
